2019-04-28 21:10:54 +03:00
|
|
|
require "rails_helper"
|
2015-04-20 18:55:06 +03:00
|
|
|
|
|
|
|
RSpec.describe CallForParticipation, type: :model do
|
2019-04-28 11:50:53 +03:00
|
|
|
let(:conference) { create :conference }
|
|
|
|
subject(:cfp) { build :call_for_participation, conference_id: conference.id }
|
2015-05-23 18:21:16 +03:00
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "belongs to a conference" do
|
2015-04-20 18:55:06 +03:00
|
|
|
conference = create :conference
|
|
|
|
cfp = create(:call_for_participation, conference_id: conference.id)
|
|
|
|
expect(CallForParticipation.find(cfp.id).conference).to eq conference
|
|
|
|
end
|
2015-05-23 18:21:16 +03:00
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "#open?" do
|
|
|
|
it "returns true when the CFP has an opens_at date in the past" do
|
2015-05-23 18:21:16 +03:00
|
|
|
cfp.opens_at = 10.minutes.ago
|
|
|
|
|
|
|
|
expect(cfp.open?).to be true
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "returns false when the CFP has no opens_at date" do
|
2015-05-23 18:21:16 +03:00
|
|
|
cfp.opens_at = nil
|
|
|
|
|
|
|
|
expect(cfp.open?).to be false
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "returns false when the CFP has an opens_at date in the future" do
|
2015-05-23 18:21:16 +03:00
|
|
|
cfp.opens_at = 10.minutes.from_now
|
|
|
|
|
|
|
|
expect(cfp.open?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "#closed?" do
|
|
|
|
it "returns true when the CFP has a closes_at date in the past" do
|
2015-05-23 18:21:16 +03:00
|
|
|
cfp.closes_at = 10.minutes.ago
|
|
|
|
|
|
|
|
expect(cfp.closed?).to be true
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "returns false when the CFP has no closes_at date" do
|
2015-05-23 18:21:16 +03:00
|
|
|
cfp.closes_at = nil
|
|
|
|
|
|
|
|
expect(cfp.closed?).to be false
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "returns false when the CFP has a closes_at date in the future" do
|
2015-05-23 18:21:16 +03:00
|
|
|
cfp.closes_at = 10.minutes.from_now
|
|
|
|
|
|
|
|
expect(cfp.closed?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "#in_progress?" do
|
|
|
|
it "returns true when the CFP has been opened and has not been closed" do
|
2015-05-23 18:21:16 +03:00
|
|
|
expect(cfp).to receive(:open?) { true }
|
|
|
|
expect(cfp).to receive(:closed?) { false }
|
|
|
|
|
|
|
|
expect(cfp.in_progress?).to be true
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "returns false when the CFP has not been opened" do
|
2015-05-23 18:21:16 +03:00
|
|
|
expect(cfp).to receive(:open?) { false }
|
|
|
|
|
|
|
|
expect(cfp.in_progress?).to be false
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "returns false when the CFP has been closed" do
|
2015-05-23 18:21:16 +03:00
|
|
|
expect(cfp).to receive(:open?) { true }
|
|
|
|
expect(cfp).to receive(:closed?) { true }
|
|
|
|
|
|
|
|
expect(cfp.in_progress?).to be false
|
|
|
|
end
|
|
|
|
end
|
2015-05-23 18:42:00 +03:00
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "#open!" do
|
|
|
|
it "changes the status of the CFP to open" do
|
2015-05-23 18:42:00 +03:00
|
|
|
expect { cfp.open! }.to change { cfp.open? }.from(false).to(true)
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "does not change the open time of the CFP when it has already been set" do
|
2015-05-23 18:42:00 +03:00
|
|
|
cfp.opens_at = 10.minutes.ago
|
|
|
|
expect { cfp.open! }.to_not change { cfp.opens_at }
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "unsets the close time of the CFP" do
|
2015-05-23 18:42:00 +03:00
|
|
|
cfp.closes_at = 10.minutes.ago
|
|
|
|
expect { cfp.open! }.to change { cfp.closes_at }.to(nil)
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "saves the record" do
|
2015-05-23 18:42:00 +03:00
|
|
|
expect { cfp.open! }.to change { cfp.persisted? }.from(false).to(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
describe "#close!" do
|
|
|
|
it "changes the status of the CFP to closed" do
|
2015-05-23 18:42:00 +03:00
|
|
|
expect { cfp.close! }.to change { cfp.closed? }.from(false).to(true)
|
|
|
|
end
|
|
|
|
|
2019-04-28 21:10:54 +03:00
|
|
|
it "saves the record" do
|
2015-05-23 18:42:00 +03:00
|
|
|
expect { cfp.close! }.to change { cfp.persisted? }.from(false).to(true)
|
|
|
|
end
|
|
|
|
end
|
2015-04-20 18:55:06 +03:00
|
|
|
end
|