Sha256: b4807953c77620791c3d0e03e0483afab245998d0d447ccd3819e8bd06dff78e
Contents?: true
Size: 1.81 KB
Versions: 2
Compression:
Stored size: 1.81 KB
Contents
require_relative '../../../spec_helper' require_relative '../factories/position' require_relative '../factories/time_slot' require_relative '../factories/user' describe TimeSlot do it 'create time_slot' do expect do FactoryGirl.create(:time_slot) end.to change(TimeSlot, :count).by(1) end context 'Validation with scope and association' do it 'is not valid if exists time slot which have position with same person' do time_slot1 = FactoryGirl.create(:time_slot, starts_at: '2012-10-11'.to_date, ends_at: '2012-10-13'.to_date) time_slot2 = FactoryGirl.create(:time_slot, starts_at: '2012-10-15'.to_date, ends_at: '2012-10-16'.to_date) user = FactoryGirl.create(:user) user_2 = FactoryGirl.create(:user) position1 = FactoryGirl.create(:position, time_slot: time_slot1, user: user) position2 = FactoryGirl.create(:position, time_slot: time_slot2, user: user) position3 = FactoryGirl.create(:position, time_slot: time_slot2, user: user_2) time_slot2.reload time_slot2.starts_at = '2012-10-12'.to_date expect(time_slot2).not_to be_valid expect(time_slot2.errors[:base]).not_to be_empty end it 'is valid if exists time slot which have position with same person' do time_slot1 = FactoryGirl.create(:time_slot, starts_at: '2012-10-11'.to_date, ends_at: '2012-10-13'.to_date) time_slot2 = FactoryGirl.create(:time_slot, starts_at: '2012-10-14'.to_date, ends_at: '2012-10-16'.to_date) user = FactoryGirl.create(:user) position1 = FactoryGirl.create(:position, time_slot: time_slot1, user: user) position2 = FactoryGirl.build(:position, time_slot: time_slot2, user: user) time_slot2.starts_at = '2012-10-15'.to_date expect(time_slot2).to be_valid expect(time_slot2.errors[:base]).to be_empty end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
validates_overlap-0.8.0 | spec/dummy/spec/models/time_slot_spec.rb |
validates_overlap-0.7.0 | spec/dummy/spec/models/time_slot_spec.rb |