aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/calendar_spec.rb
diff options
context:
space:
mode:
authorRobert2017-06-28 15:35:40 +0200
committerRobert2017-06-28 15:35:40 +0200
commitfa5bf7d280662be42531c4f1ea2f458e9981f8fa (patch)
tree527177518790ff6295c0a2cd5a5c48ce80edfbf2 /spec/models/calendar_spec.rb
parentead1b30f0c38c247e6d80a32a894bfd9af4c2566 (diff)
downloadchouette-core-fa5bf7d280662be42531c4f1ea2f458e9981f8fa.tar.bz2
Small refact and simplification of calendar model spex
Diffstat (limited to 'spec/models/calendar_spec.rb')
-rw-r--r--spec/models/calendar_spec.rb111
1 files changed, 2 insertions, 109 deletions
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 5d4ae1ed9..cf7e4aa27 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -21,87 +21,14 @@ RSpec.describe Calendar, :type => :model do
describe 'validations' do
it 'validates that dates and date_ranges do not overlap' do
- calendar = build(:calendar, dates: [Date.today], date_ranges: [Date.today..Date.tomorrow])
- expect {
- calendar.save!
- }.to raise_error(ActiveRecord::RecordInvalid)
+ expect(build(:calendar, dates: [Date.today], date_ranges: [Date.today..Date.tomorrow])).to_not be_valid
end
it 'validates that there are no duplicates in dates' do
- calendar = build(:calendar, dates: [Date.yesterday, Date.yesterday], date_ranges: [Date.today..Date.tomorrow])
- expect {
- calendar.save!
- }.to raise_error(ActiveRecord::RecordInvalid)
+ expect(build(:calendar, dates: [Date.yesterday, Date.yesterday], date_ranges: [Date.today..Date.tomorrow])).to_not be_valid
end
end
- describe 'Period' do
-
- subject { period }
-
- def period(attributes = {})
- @__period__ ||= {}
- @__period__.fetch(attributes){
- @__period__[attributes] = Calendar::Period.new(attributes)
- }
- end
-
- it 'should support mark_for_destruction (required by cocoon)' do
- period.mark_for_destruction
- expect(period).to be_marked_for_destruction
- end
-
- it 'should support _destroy attribute (required by coocon)' do
- period._destroy = true
- expect(period).to be_marked_for_destruction
- end
-
- it 'should support new_record? (required by cocoon)' do
- expect(Calendar::Period.new).to be_new_record
- expect(period(id: 42)).not_to be_new_record
- end
-
- it 'should cast begin as date attribute' do
- expect(period(begin: '2016-11-22').begin).to eq(Date.new(2016,11,22))
- end
-
- it 'should cast end as date attribute' do
- expect(period(end: '2016-11-22').end).to eq(Date.new(2016,11,22))
- end
-
- it { is_expected.to validate_presence_of(:begin) }
- it { is_expected.to validate_presence_of(:end) }
-
- it 'should validate that end is greather than or equlals to begin' do
- expect(period(begin: '2016-11-21', end: '2016-11-22')).to be_valid
- expect(period(begin: '2016-11-21', end: '2016-11-21')).to_not be_valid
- expect(period(begin: '2016-11-22', end: '2016-11-21')).to_not be_valid
- end
-
- describe 'intersect?' do
- it 'should detect date in common with other date_ranges' do
- november = period(begin: '2016-11-01', end: '2016-11-30')
- mid_november_mid_december = period(begin: '2016-11-15', end: '2016-12-15')
- expect(november.intersect?(mid_november_mid_december)).to be(true)
- end
-
- it 'should not intersect when no date is in common' do
- november = period(begin: '2016-11-01', end: '2016-11-30')
- december = period(begin: '2016-12-01', end: '2016-12-31')
-
- expect(november.intersect?(december)).to be(false)
-
- january = period(begin: '2017-01-01', end: '2017-01-31')
- expect(november.intersect?(december, january)).to be(false)
- end
-
- it 'should not intersect itself' do
- period = period(id: 42, begin: '2016-11-01', end: '2016-11-30')
- expect(period.intersect?(period)).to be(false)
- end
-
- end
- end
describe 'before_validation' do
let(:calendar) { create(:calendar, date_ranges: []) }
@@ -115,38 +42,4 @@ RSpec.describe Calendar, :type => :model do
end
end
- describe 'DateValue' do
- subject { date_value }
-
- def date_value(attributes = {})
- @__date_values__ ||= Hash.new
- @__date_values__.fetch(attributes) do
- @__date_values__[attributes] = Calendar::DateValue.new(attributes)
- end
- end
-
- it 'should support mark_for_destruction (required by cocoon)' do
- date_value.mark_for_destruction
- expect(date_value).to be_marked_for_destruction
- end
-
- it 'should support _destroy attribute (required by coocon)' do
- date_value._destroy = true
- expect(date_value).to be_marked_for_destruction
- end
-
- it 'should support new_record? (required by cocoon)' do
- expect(Calendar::DateValue.new).to be_new_record
- expect(date_value(id: 42)).not_to be_new_record
- end
-
- it 'should cast value as date attribute' do
- expect(date_value(value: '2017-01-03').value).to eq(Date.new(2017,01,03))
- end
-
- it 'validates presence' do
- is_expected.to validate_presence_of(:value)
- end
- end
end
-