From 0c6e7e75808844d32748c445f07b663ed67245cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 11 Jul 2018 15:46:10 +0200 Subject: [PATCH] Adds Sluggable concern to Poll model --- app/models/poll.rb | 5 +++++ spec/features/admin/poll/polls_spec.rb | 1 + 2 files changed, 6 insertions(+) diff --git a/app/models/poll.rb b/app/models/poll.rb index 4aca4ee25..7e9cef89a 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -5,6 +5,7 @@ class Poll < ApplicationRecord acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases include Notifiable + include Sluggable translates :name, touch: true translates :summary, touch: true @@ -129,6 +130,10 @@ class Poll < ApplicationRecord end end + def generate_slug? + slug.nil? + end + def only_one_active return unless starts_at.present? return unless ends_at.present? diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index a6c24446e..893b0ab2e 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -75,6 +75,7 @@ feature "Admin polls" do expect(page).to have_content "Upcoming poll" expect(page).to have_content I18n.l(start_date.to_date) expect(page).to have_content I18n.l(end_date.to_date) + expect(Poll.last.slug).to eq "#{Poll.last.name.to_s.parameterize}" end scenario "Edit" do