From 84bafa8107d0190f20f1895725a3ac05d3da06e4 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 21 Nov 2016 11:19:03 +0100 Subject: [PATCH] adds specs for poll state --- app/models/poll/partial_result.rb | 3 +-- spec/models/poll/partial_result_spec.rb | 2 +- spec/models/poll/poll_spec.rb | 35 +++++++++++++++++++++---- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index 202f147bd..84f79a1fc 100644 --- a/app/models/poll/partial_result.rb +++ b/app/models/poll/partial_result.rb @@ -14,5 +14,4 @@ class Poll::PartialResult < ActiveRecord::Base scope :by_author, -> (author_id) { where(author_id: author_id) } scope :by_question, -> (question_id) { where(question_id: question_id) } - -end +end \ No newline at end of file diff --git a/spec/models/poll/partial_result_spec.rb b/spec/models/poll/partial_result_spec.rb index ef47ecd8c..0b3fea411 100644 --- a/spec/models/poll/partial_result_spec.rb +++ b/spec/models/poll/partial_result_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe Poll::PartialResult, type: :model do +describe Poll::PartialResult do describe "validations" do it "validates that the answers are included in the Enquiry's list" do diff --git a/spec/models/poll/poll_spec.rb b/spec/models/poll/poll_spec.rb index 7442cdc5a..0bb4f3136 100644 --- a/spec/models/poll/poll_spec.rb +++ b/spec/models/poll/poll_spec.rb @@ -4,13 +4,38 @@ describe :poll do let(:poll) { build(:poll) } - it "should be valid" do - expect(poll).to be_valid + describe "validations" do + it "should be valid" do + expect(poll).to be_valid + end + + it "should not be valid without a name" do + poll.name = nil + expect(poll).to_not be_valid + end end - it "should not be valid without a name" do - poll.name = nil - expect(poll).to_not be_valid + describe "#opened?" do + it "returns true only when it isn't too early or too late" do + expect(create(:poll, :incoming)).to_not be_current + expect(create(:poll, :expired)).to_not be_current + expect(create(:poll)).to be_current + end end + describe "#incoming?" do + it "returns true only when it is too early" do + expect(create(:poll, :incoming)).to be_incoming + expect(create(:poll, :expired)).to_not be_incoming + expect(create(:poll)).to_not be_incoming + end + end + + describe "#expired?" do + it "returns true only when it is too late" do + expect(create(:poll, :incoming)).to_not be_expired + expect(create(:poll, :expired)).to be_expired + expect(create(:poll)).to_not be_expired + end + end end \ No newline at end of file