adds published to polls

This commit is contained in:
Juanjo Bazán
2017-01-02 18:23:24 +01:00
parent fe1c12c661
commit 1aa845a9c6
5 changed files with 19 additions and 1 deletions

View File

@@ -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) }

View File

@@ -0,0 +1,5 @@
class AddPublishedToPolls < ActiveRecord::Migration
def change
add_column :polls, :published, :boolean, default: false
end
end

View File

@@ -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|

View File

@@ -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

View File

@@ -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)