diff options
| author | Michel Etienne | 2014-07-11 11:34:23 +0200 |
|---|---|---|
| committer | Michel Etienne | 2014-07-11 11:34:23 +0200 |
| commit | 1d4ebedf4cfe07689530f9f0e443a020cc008fd4 (patch) | |
| tree | b5614ecdf47c97c2f84a8a489a5bb4f48df47c34 | |
| parent | e8a31cd30f9b35ef9d33ba114304b537ab7a638e (diff) | |
| download | chouette-core-1d4ebedf4cfe07689530f9f0e443a020cc008fd4.tar.bz2 | |
add union, intersection and disjunction operation on time tables specs, Mantis 26838
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | app/models/time_table_combination.rb | 1 | ||||
| -rw-r--r-- | app/views/time_tables/_combine.html.erb | 2 | ||||
| -rw-r--r-- | spec/factories.rb | 6 | ||||
| -rw-r--r-- | spec/models/time_table_combination_spec.rb | 90 |
5 files changed, 93 insertions, 8 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index cb5c574b8..544adef22 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/afimb/ninoxe.git - revision: c70e52ef6cd42b6f38f0ea8e26963972bf67fa45 + revision: cbb81eb9682d24b54c0971b4050b116d5a5275f4 branch: sismo specs: ninoxe (1.1.0) diff --git a/app/models/time_table_combination.rb b/app/models/time_table_combination.rb index a446b47df..d42a0aa49 100644 --- a/app/models/time_table_combination.rb +++ b/app/models/time_table_combination.rb @@ -25,7 +25,6 @@ class TimeTableCombination def combine source = Chouette::TimeTable.find( source_id) combined = Chouette::TimeTable.find( combined_id) - puts operation if operation == "union" source.merge! combined elsif operation == "intersection" diff --git a/app/views/time_tables/_combine.html.erb b/app/views/time_tables/_combine.html.erb index 900a8a4e8..0e40ec88e 100644 --- a/app/views/time_tables/_combine.html.erb +++ b/app/views/time_tables/_combine.html.erb @@ -22,6 +22,6 @@ hintText: '<%= t('search_hint') %>', noResultsText: '<%= t('no_result_text') %>', searchingText: '<%= t('searching_term') %>' - }); + }); }); </script> 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 + |
