Merge branch 'master' into user-recomendations

This commit is contained in:
BertoCQ
2017-09-19 18:56:12 +02:00
committed by GitHub
46 changed files with 221 additions and 223 deletions

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Geozone, type: :model do
describe Geozone do
let(:geozone) { build(:geozone) }
it "should be valid" do
@@ -13,6 +13,8 @@ RSpec.describe Geozone, type: :model do
end
describe "#safe_to_destroy?" do
let(:geozone) { create(:geozone) }
it "is true when not linked to other models" do
expect(geozone.safe_to_destroy?).to be_truthy
end

View File

@@ -25,20 +25,20 @@ describe :booth do
end
describe "#available" do
it "returns booths associated to current or incoming polls" do
booth_for_current_poll = create(:poll_booth)
booth_for_incoming_poll = create(:poll_booth)
booth_for_expired_poll = create(:poll_booth)
current_poll = create(:poll, :current)
incoming_poll = create(:poll, :incoming)
expired_poll = create(:poll, :expired)
create(:poll_booth_assignment, poll: current_poll, booth: booth_for_current_poll)
create(:poll_booth_assignment, poll: incoming_poll, booth: booth_for_incoming_poll)
create(:poll_booth_assignment, poll: expired_poll, booth: booth_for_expired_poll)
expect(Poll::Booth.available).to include(booth_for_current_poll)
expect(Poll::Booth.available).to include(booth_for_incoming_poll)
expect(Poll::Booth.available).to_not include(booth_for_expired_poll)

View File

@@ -1,11 +1,24 @@
require 'rails_helper'
RSpec.describe Poll::Question, type: :model do
let(:poll_question) { build(:poll_question) }
describe "#valid_answers" do
it "gets a comma-separated string, but returns an array" do
q = create(:poll_question, valid_answers: "Yes, No")
expect(q.valid_answers).to eq(["Yes", "No"])
poll_question.valid_answers = "Yes, No"
expect(poll_question.valid_answers).to eq(["Yes", "No"])
end
end
describe "#poll_question_id" do
it "should be invalid if a poll is not selected" do
poll_question.poll_id = nil
expect(poll_question).to_not be_valid
end
it "should be valid if a poll is selected" do
poll_question.poll_id = 1
expect(poll_question).to be_valid
end
end
@@ -13,13 +26,12 @@ RSpec.describe Poll::Question, type: :model do
it "copies the attributes from the proposal" do
create_list(:geozone, 3)
p = create(:proposal)
q = create(:poll_question)
q.copy_attributes_from_proposal(p)
expect(q.valid_answers).to eq(['Yes', 'No'])
expect(q.author).to eq(p.author)
expect(q.author_visible_name).to eq(p.author.name)
expect(q.proposal_id).to eq(p.id)
expect(q.title).to eq(p.title)
poll_question.copy_attributes_from_proposal(p)
expect(poll_question.valid_answers).to eq(['Yes', 'No'])
expect(poll_question.author).to eq(p.author)
expect(poll_question.author_visible_name).to eq(p.author.name)
expect(poll_question.proposal_id).to eq(p.id)
expect(poll_question.title).to eq(p.title)
end
end

View File

@@ -43,7 +43,7 @@ describe :shift do
officer_assignments = Poll::OfficerAssignment.all
expect(officer_assignments.count).to eq(2)
oa1 = officer_assignments.first
oa2 = officer_assignments.second
@@ -59,10 +59,10 @@ describe :shift do
end
describe "#persist_data" do
let(:user) { create(:user, username: "Ana", email: "ana@example.com") }
let(:officer) { create(:poll_officer, user: user) }
let(:shift) { create(:poll_shift, officer: officer) }
let(:user) { create(:user, username: "Ana", email: "ana@example.com") }
let(:officer) { create(:poll_officer, user: user) }
let(:shift) { create(:poll_shift, officer: officer) }
it "should maintain officer data after destroying associated user" do
shift.officer.user.destroy
@@ -79,5 +79,5 @@ describe :shift do
end
end
end

View File

@@ -71,5 +71,4 @@ describe Topic do
end
end