Poll::Question model spec refactor to improve DRYness
On branch aperez-validate-poll-question-is-selected
Changes to be committed:
modified: spec/models/poll/question_spec.rb
This commit is contained in:
@@ -1,25 +1,24 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Poll::Question, type: :model do
|
RSpec.describe Poll::Question, type: :model do
|
||||||
|
let(:poll_question) { build(:poll_question) }
|
||||||
|
|
||||||
describe "#valid_answers" do
|
describe "#valid_answers" do
|
||||||
it "gets a comma-separated string, but returns an array" do
|
it "gets a comma-separated string, but returns an array" do
|
||||||
q = create(:poll_question, valid_answers: "Yes, No")
|
poll_question.valid_answers = "Yes, No"
|
||||||
expect(q.valid_answers).to eq(["Yes", "No"])
|
expect(poll_question.valid_answers).to eq(["Yes", "No"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#poll_question_id" do
|
describe "#poll_question_id" do
|
||||||
it "should be invalid if a poll is not selected" do
|
it "should be invalid if a poll is not selected" do
|
||||||
q = create(:poll_question)
|
poll_question.poll_id = nil
|
||||||
q.poll_id = nil
|
expect(poll_question).to_not be_valid
|
||||||
expect(q).to_not be_valid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be valid if a poll is selected" do
|
it "should be valid if a poll is selected" do
|
||||||
q = create(:poll_question)
|
poll_question.poll_id = 1
|
||||||
q.poll_id = 1
|
expect(poll_question).to be_valid
|
||||||
expect(q).to be_valid
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -27,13 +26,12 @@ RSpec.describe Poll::Question, type: :model do
|
|||||||
it "copies the attributes from the proposal" do
|
it "copies the attributes from the proposal" do
|
||||||
create_list(:geozone, 3)
|
create_list(:geozone, 3)
|
||||||
p = create(:proposal)
|
p = create(:proposal)
|
||||||
q = create(:poll_question)
|
poll_question.copy_attributes_from_proposal(p)
|
||||||
q.copy_attributes_from_proposal(p)
|
expect(poll_question.valid_answers).to eq(['Yes', 'No'])
|
||||||
expect(q.valid_answers).to eq(['Yes', 'No'])
|
expect(poll_question.author).to eq(p.author)
|
||||||
expect(q.author).to eq(p.author)
|
expect(poll_question.author_visible_name).to eq(p.author.name)
|
||||||
expect(q.author_visible_name).to eq(p.author.name)
|
expect(poll_question.proposal_id).to eq(p.id)
|
||||||
expect(q.proposal_id).to eq(p.id)
|
expect(poll_question.title).to eq(p.title)
|
||||||
expect(q.title).to eq(p.title)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user