aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-07-06 17:38:16 +0200
committercedricnjanga2017-07-06 17:38:16 +0200
commitbf63449de6ac9624352af4c0319758da3c8d827e (patch)
treefe9a2b1ecffe5b25591f280885454447c4e84098
parentbb6f9da17477dfd05313fc6b071a6ac101af5077 (diff)
downloadchouette-core-bf63449de6ac9624352af4c0319758da3c8d827e.tar.bz2
Fix test according changes in model : boundaries are exclusive for between clean up
-rw-r--r--app/models/clean_up.rb5
-rw-r--r--spec/models/clean_up_spec.rb28
2 files changed, 16 insertions, 17 deletions
diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb
index 08e84faa0..a51a98260 100644
--- a/app/models/clean_up.rb
+++ b/app/models/clean_up.rb
@@ -83,13 +83,14 @@ class CleanUp < ActiveRecord::Base
day if day.public_send(operator, self.begin_date)
end
else
- days_in_cleanup_periode = ((self.begin_date + 1.day)...self.end_date)
+ days_in_cleanup_periode = (self.begin_date..self.end_date)
to_exclude_days = days_in_period & days_in_cleanup_periode
end
to_exclude_days.to_a.compact.each do |day|
# we ensure day is not already an exclude date
- if !day_out.include?(day)
+ # and that day is not equal to the boundariy date of the clean up
+ if !day_out.include?(day) && day != self.begin_date && day != self.end_date
self.add_exclude_date(period.time_table, day)
end
end
diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb
index ac0e30ec1..e03921582 100644
--- a/spec/models/clean_up_spec.rb
+++ b/spec/models/clean_up_spec.rb
@@ -53,23 +53,21 @@ RSpec.describe CleanUp, :type => :model do
let(:cleaner) { create(:clean_up, date_type: :between, begin_date: period.period_start + 3.day, end_date: period.period_end) }
it 'should add exclude date into period for overlapping period' do
- expected_day_out = ((cleaner.begin_date + 1.day)...cleaner.end_date).count
+
+ expected_day_out = (cleaner.begin_date..cleaner.end_date).count
expect { cleaner.exclude_dates_in_overlapping_period(period) }.to change {
time_table.dates.where(in_out: false).count
- }.by(expected_day_out)
- end
-
- # it 'should not add exclude date if no overlapping found' do
- # cleaner.begin_date = period.period_end + 1.day
- # cleaner.end_date = cleaner.begin_date + 1.day
- #
- # p (period.period_start..period.period_end)
- # p (cleaner.begin_date..cleaner.end_date)
- #
- # expect { cleaner.exclude_dates_in_overlapping_period(period) }.to_not change {
- # time_table.dates.where(in_out: false).count
- # }
- # end
+ }.by(expected_day_out - 2)
+ end
+
+ it 'should not add exclude date if no overlapping found' do
+ cleaner.begin_date = period.period_end + 1.day
+ cleaner.end_date = cleaner.begin_date + 1.day
+
+ expect { cleaner.exclude_dates_in_overlapping_period(period) }.to_not change {
+ time_table.dates.where(in_out: false).count
+ }
+ end
end
context '#overlapping_periods' do