diff --git a/app/models/poll.rb b/app/models/poll.rb index 47a955681..79726715e 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -13,6 +13,7 @@ class Poll < ActiveRecord::Base scope :current, -> { where('starts_at <= ? and ? <= ends_at', Time.current, Time.current) } scope :incoming, -> { where('? < starts_at', Time.current) } scope :expired, -> { where('ends_at < ?', Time.current) } + scope :published, -> { where('published = ?', true) } scope :sort_for_list, -> { order(:starts_at) } diff --git a/db/migrate/20170102170125_add_published_to_polls.rb b/db/migrate/20170102170125_add_published_to_polls.rb new file mode 100644 index 000000000..51da03f34 --- /dev/null +++ b/db/migrate/20170102170125_add_published_to_polls.rb @@ -0,0 +1,5 @@ +class AddPublishedToPolls < ActiveRecord::Migration + def change + add_column :polls, :published, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 2333356e8..af72fea7e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170102114446) do +ActiveRecord::Schema.define(version: 20170102170125) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -360,6 +360,7 @@ ActiveRecord::Schema.define(version: 20170102114446) do t.string "name" t.datetime "starts_at" t.datetime "ends_at" + t.boolean "published", default: false end create_table "proposal_notifications", force: :cascade do |t| diff --git a/spec/factories.rb b/spec/factories.rb index a9e000e19..d8b587015 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -282,6 +282,10 @@ FactoryGirl.define do starts_at { 1.month.ago } ends_at { 15.days.ago } end + + trait :published do + published true + end end factory :poll_question, class: 'Poll::Question' do diff --git a/spec/models/poll/poll_spec.rb b/spec/models/poll/poll_spec.rb index 1ce3f95e0..e410c31ce 100644 --- a/spec/models/poll/poll_spec.rb +++ b/spec/models/poll/poll_spec.rb @@ -55,6 +55,13 @@ describe :poll do end end + describe "#published?" do + it "returns true only when published is true" do + expect(create(:poll)).to_not be_published + expect(create(:poll, :published)).to be_published + end + end + describe "#document_has_voted?" do it "returns true if Poll::Voter with document exists" do booth_assignment = create(:poll_booth_assignment, poll: poll)