diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories.rb | 6 | ||||
| -rw-r--r-- | spec/models/time_table_combination_spec.rb | 90 |
2 files changed, 91 insertions, 5 deletions
diff --git a/spec/factories.rb b/spec/factories.rb index 205f020bb..2599645d3 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -70,10 +70,6 @@ FactoryGirl.define do f.referential { Referential.find_by_slug("first") } end - factory :file_validation_log_message do |f| - f.association :file_validation - f.sequence(:key) { "key_#{n}" } - end - + factory :time_table_combination end diff --git a/spec/models/time_table_combination_spec.rb b/spec/models/time_table_combination_spec.rb new file mode 100644 index 000000000..842c6f211 --- /dev/null +++ b/spec/models/time_table_combination_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper' + +describe TimeTableCombination do + let!(:source){ Factory(:time_table)} + let!(:combined){Factory(:time_table)} + subject {Factory.build(:time_table_combination)} + + it { should validate_presence_of :source_id } + it { should validate_presence_of :combined_id } + it { should validate_presence_of :operation } + + it { should ensure_inclusion_of(:operation).in_array(TimeTableCombination.operations) } + + + describe "#combine" do + context "when operation is union" do + before(:each) do + source.periods.clear + source.dates.clear + source.int_day_types = 508 + source.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,31)) + source.save + combined.periods.clear + combined.dates.clear + combined.int_day_types = 508 + combined.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,15), :period_end => Date.new(2014,9,15)) + combined.save + subject.operation = 'union' + subject.source_id = source.id + subject.combined_id = combined.id + subject.combine + source.reload + end + it "should add combined to source" do + source.periods.size.should == 1 + source.periods[0].period_start.should == Date.new(2014,8,1) + source.periods[0].period_end.should == Date.new(2014,9,15) + end + end + context "when operation is intersect" do + before(:each) do + source.periods.clear + source.dates.clear + source.int_day_types = 508 + source.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,31)) + source.save + combined.periods.clear + combined.dates.clear + combined.int_day_types = 508 + combined.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,15), :period_end => Date.new(2014,9,15)) + combined.save + subject.operation = 'intersection' + subject.source_id = source.id + subject.combined_id = combined.id + subject.combine + source.reload + end + it "should intersect combined to source" do + source.periods.size.should == 1 + source.periods[0].period_start.should == Date.new(2014,8,15) + source.periods[0].period_end.should == Date.new(2014,8,31) + end + end + context "when operation is disjoin" do + before(:each) do + source.periods.clear + source.dates.clear + source.int_day_types = 508 + source.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,1), :period_end => Date.new(2014,8,31)) + source.save + combined.periods.clear + combined.dates.clear + combined.int_day_types = 508 + combined.periods << Chouette::TimeTablePeriod.new(:period_start => Date.new(2014,8,15), :period_end => Date.new(2014,9,15)) + combined.save + subject.operation = 'disjunction' + subject.source_id = source.id + subject.combined_id = combined.id + subject.combine + source.reload + end + it "should disjoin combined to source" do + source.periods.size.should == 1 + source.periods[0].period_start.should == Date.new(2014,8,1) + source.periods[0].period_end.should == Date.new(2014,8,14) + end + end + end +end + |
