diff options
| author | Zakaria BOUZIANE | 2015-03-09 14:40:32 +0100 |
|---|---|---|
| committer | Zakaria BOUZIANE | 2015-03-09 14:40:32 +0100 |
| commit | 05fb2b7aa8ca7d490a8960a096de7d934fffe133 (patch) | |
| tree | 9b6666380cdbd2eff1f79c79d97fbd302a768006 /spec | |
| parent | 0d5adf2fad5c0ddd8efc1eca9dc6d8e9c48b049d (diff) | |
| parent | a5f66f953120c08951b6338ad0f743c2d0eec86e (diff) | |
| download | chouette-core-05fb2b7aa8ca7d490a8960a096de7d934fffe133.tar.bz2 | |
Solving merge V2_5 pbs
Diffstat (limited to 'spec')
20 files changed, 221 insertions, 30 deletions
diff --git a/spec/controllers/rule_parameter_sets_controller_spec.rb b/spec/controllers/rule_parameter_sets_controller_spec.rb index 8615183c1..b2cdd0849 100644 --- a/spec/controllers/rule_parameter_sets_controller_spec.rb +++ b/spec/controllers/rule_parameter_sets_controller_spec.rb @@ -4,31 +4,33 @@ describe RuleParameterSetsController, :type => :controller do login_user let(:mode){"air"} - shared_examples_for "referential dependant" do - it "assigns referential as @referential" do - expect(assigns[:referential]).to eq(referential) + shared_examples_for "organisation dependant" do + it "assigns rule_parameter_set.organisation as current organisation" do + expect(assigns[:organisation]).to eq(organisation) end end describe "GET /index" do before(:each) do - get :index, - :referential_id => referential.id + get :index + end + it "should assign rule_parameter_sets to organisation rule_parameter_sets" do + assigns[:rule_parameter_sets].size.should == organisation.rule_parameter_sets.size + assigns[:rule_parameter_sets].each do |rps| + rps.organisation_id.should == organisation.id + end end - it_behaves_like "referential dependant" end describe "GET /new" do before(:each) do - get :new, - :referential_id => referential.id + get :new end - it_behaves_like "referential dependant" + it_behaves_like "organisation dependant" it "should assign rule_parameter_set with default params" do RuleParameterSet.default_params.each do |k,v| expect(assigns[:rule_parameter_set].send( k )).to eq(v) end - expect(assigns[:rule_parameter_set].referential_id).to eq(referential.id) end end end diff --git a/spec/factories.rb b/spec/factories.rb index 645807b28..64beb806a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -70,6 +70,6 @@ FactoryGirl.define do referential { Referential.find_by_slug("first") } end - factory :time_table_combination + factory :time_table_combination end diff --git a/spec/features/vehicle_journey_imports_spec.rb b/spec/features/vehicle_journey_imports_spec.rb index 9ba38398c..f18d9baf0 100644 --- a/spec/features/vehicle_journey_imports_spec.rb +++ b/spec/features/vehicle_journey_imports_spec.rb @@ -30,10 +30,10 @@ describe "VehicleJourneyImports", :type => :feature do row2 << cell end csv << row2 - elsif counter < 7 + elsif counter < 8 csv << row else - csv << ( row[0] = route.stop_points[counter - 7].id; row) + csv << ( row[0] = route.stop_points[counter - 8].id; row) end counter += 1 end diff --git a/spec/fixtures/vehicle_journey_imports_valid.csv b/spec/fixtures/vehicle_journey_imports_valid.csv index 3126ffe2b..85a505ab6 100644 --- a/spec/fixtures/vehicle_journey_imports_valid.csv +++ b/spec/fixtures/vehicle_journey_imports_valid.csv @@ -4,6 +4,7 @@ ;PMR (O(ui)|N(on)|vide si inconnu);Oui;;; ;TAD (O(ui)|N(on)|vide si inconnu);Oui;;; ;calendriers;;;; +;notes de bas de page;;;; id arrêt;nom arrêt;;;; 1;Arrêt 1;9:00:00;;11:10:00;12:10:00 2;Arrêt 2;9:05:00;10:05:00;11:15:00;12:15:00 diff --git a/spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv b/spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv index 7aa59009e..beec85c4c 100644 --- a/spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv +++ b/spec/fixtures/vehicle_journey_imports_with_vj_invalid.csv @@ -4,6 +4,7 @@ ;PMR (O(ui)|N(on)|vide si inconnu);Oui;; ;TAD (O(ui)|N(on)|vide si inconnu);Oui;; ;calendriers;;; +;notes de bas de page;;; id arrêt;nom arrêt;;; 1;Arrêt 1;9:00:00;10:05:00;11:10:00 2;Arrêt 2;11:05:00;;11:15:00 diff --git a/spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv b/spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv index df6b1acff..c1bb85881 100644 --- a/spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv +++ b/spec/fixtures/vehicle_journey_imports_with_vjas_bad_order.csv @@ -4,6 +4,7 @@ ;PMR (O(ui)|N(on)|vide si inconnu);Oui;; ;TAD (O(ui)|N(on)|vide si inconnu);Oui;; ;calendriers;;; +;notes de bas de page;;; id arrêt;nom arrêt;;; 1;Arrêt 1;9:05:00;10:05:00;11:10:00 2;Arrêt 2;11:05:00;;11:15:00 diff --git a/spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv b/spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv index bcb07a177..95799e9d9 100644 --- a/spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv +++ b/spec/fixtures/vehicle_journey_imports_with_vjas_invalid.csv @@ -4,6 +4,7 @@ ;PMR (O(ui)|N(on)|vide si inconnu);Oui;; ;TAD (O(ui)|N(on)|vide si inconnu);Oui;; ;calendriers;;;; +;notes de bas de page;;;; id arrêt;nom arrêt;;; 1;Arrêt 1;invalid time;10:05:00;11:10:00 2;Arrêt 2;9:05:00;;11:15:00 diff --git a/spec/models/line_spec.rb b/spec/models/line_spec.rb new file mode 100644 index 000000000..191101109 --- /dev/null +++ b/spec/models/line_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe "sdflkjskdjf" do + + subject { Factory(:line) } + + def set_large_object_id( line) + line.update_attributes :objectid => "AA:Line:123456789012345" + end + + describe "validation objectid unique constraint" do + let(:referential){subject.referential} + let(:objectid_a){ "A:Line:1234" } + let(:objectid_b){ "B:Line:1234" } + let!(:second_line){ Factory( :line, :objectid => objectid_a, :registration_number => "123456") } + context "when referential works with HUB" do + before( :each) do + referential.update_attributes :data_format => "hub" + subject.update_attributes :objectid => objectid_a + end + it "should have objectid with a third part shorter than 14 char" do + subject.update_attributes :objectid => objectid_b + subject.should_not be_valid + end + end + context "when referential doesn't works with HUB" do + before( :each) do + referential.update_attributes :data_format => "hub" + end + #it "should have objectid with a third part shorter than 14 char" do + # subject.update_attributes :objectid => objectid_b, :registration_number => '324' + # subject.should be_valid + #end + end + end + describe "validation objectid size" do + let(:referential){subject.referential} + context "when referential works with HUB" do + before( :each) do + referential.update_attributes :data_format => "hub" + end + it "should have objectid with a third part shorter than 14 char" do + set_large_object_id( subject) + subject.should_not be_valid + end + end + context "when referential doesn't works with HUB" do + before( :each) do + referential.update_attributes :data_format => "hub" + end + #it "should have objectid with a third part shorter than 14 char" do + # set_large_object_id( subject) + # subject.should be_valid + #end + end + end +end + diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb new file mode 100644 index 000000000..ffac3374b --- /dev/null +++ b/spec/models/organisation_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Organisation do + + it { should validate_presence_of(:name) } + it { should validate_uniqueness_of(:name) } + + it "create a rule_parameter_set" do + organisation = Factory.create(:organisation) + organisation.rule_parameter_sets.size.should == 1 + end +end diff --git a/spec/models/stop_area_copy_spec.rb b/spec/models/stop_area_copy_spec.rb index ad5bc41d8..ca532dcf7 100644 --- a/spec/models/stop_area_copy_spec.rb +++ b/spec/models/stop_area_copy_spec.rb @@ -8,18 +8,21 @@ describe StopAreaCopy, :type => :model do describe ".save" do it "should create a child for source" do - source = Chouette::StopArea.new( :area_type => "CommercialStopPoint", :name => "test1" ) + source = Factory(:stop_area, :area_type => "CommercialStopPoint", :name => "test1", + :registration_number => "123456", :city_name => "dummy", :zip_code => "12345") source.save subject.source_id = source.id subject.hierarchy = "child" subject.area_type = "Quay" subject.save + source.reload expect(source.children.length).to eq(1) expect(source.children[0].name).to eq("test1") end it "should create a parent for source" do - source = Chouette::StopArea.new( :area_type => "CommercialStopPoint", :name => "test2" ) + source = Factory(:stop_area, :area_type => "CommercialStopPoint", :name => "test2", + :registration_number => "123456", :city_name => "dummy", :zip_code => "12345") source.save subject.source_id = source.id subject.hierarchy = "parent" @@ -29,7 +32,7 @@ describe StopAreaCopy, :type => :model do expect(source.parent).not_to be_nil expect(source.parent.name).to eq('test2') end - + end end diff --git a/spec/models/vehicle_journey_export_spec.rb b/spec/models/vehicle_journey_export_spec.rb index 49c3d2fc6..6252a73f9 100644 --- a/spec/models/vehicle_journey_export_spec.rb +++ b/spec/models/vehicle_journey_export_spec.rb @@ -3,8 +3,9 @@ require 'spec_helper' describe VehicleJourneyExport, :type => :model do - let!(:route) { create(:route) } - let!(:other_route) { create(:route) } + let!(:line) { create(:line) } + let!(:route) { create(:route, :line => line) } + let!(:other_route) { create(:route, :line => line) } let!(:journey_pattern) { create(:journey_pattern, :route => route) } let!(:other_journey_pattern) { create(:journey_pattern_even, :route => route) } diff --git a/spec/models/vehicle_journey_import_spec.rb b/spec/models/vehicle_journey_import_spec.rb index 9d9a8e15e..c4d452f84 100644 --- a/spec/models/vehicle_journey_import_spec.rb +++ b/spec/models/vehicle_journey_import_spec.rb @@ -17,10 +17,10 @@ describe VehicleJourneyImport, :type => :model do row2 << cell end csv << row2 - elsif counter < 7 + elsif counter < 8 csv << row else - csv << ( row[0] = route.stop_points[counter - 7].id; row) + csv << ( row[0] = route.stop_points[counter - 8].id; row) end counter += 1 end diff --git a/spec/routing/companies_spec.rb b/spec/routing/companies_spec.rb new file mode 100644 index 000000000..25f86325b --- /dev/null +++ b/spec/routing/companies_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe CompaniesController do + describe "routing" do + it "not recognize #routes" do + get( "/referentials/1/companies/2/routes").should_not route_to( + :controller => "companies", :action => "routes", + :referential_id => "1", :id => "2" + ) + end + it "not recognize #lines" do + get( "/referentials/1/companies/2/lines").should_not route_to( + :controller => "companies", :action => "lines", + :referential_id => "1", :id => "2" + ) + end + it "recognize and generate #show" do + get( "/referentials/1/companies/2").should route_to( + :controller => "companies", :action => "show", + :referential_id => "1", :id => "2" + ) + end + end +end + diff --git a/spec/routing/group_of_lines_spec.rb b/spec/routing/group_of_lines_spec.rb new file mode 100644 index 000000000..ee5596cf7 --- /dev/null +++ b/spec/routing/group_of_lines_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe GroupOfLinesController do + describe "routing" do + it "not recognize #routes" do + get( "/referentials/1/group_of_lines/2/routes").should_not route_to( + :controller => "group_of_lines", :action => "routes", + :referential_id => "1", :id => "2" + ) + end + it "not recognize #lines" do + get( "/referentials/1/group_of_lines/2/lines").should_not route_to( + :controller => "group_of_lines", :action => "lines", + :referential_id => "1", :id => "2" + ) + end + it "recognize and generate #show" do + get( "/referentials/1/group_of_lines/2").should route_to( + :controller => "group_of_lines", :action => "show", + :referential_id => "1", :id => "2" + ) + end + end +end + diff --git a/spec/routing/networks_spec.rb b/spec/routing/networks_spec.rb new file mode 100644 index 000000000..c0544980d --- /dev/null +++ b/spec/routing/networks_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe NetworksController do + describe "routing" do + it "not recognize #routes" do + get( "/referentials/1/networks/2/routes").should_not route_to( + :controller => "networks", :action => "routes", + :referential_id => "1", :id => "2" + ) + end + it "not recognize #lines" do + get( "/referentials/1/networks/2/lines").should_not route_to( + :controller => "networks", :action => "lines", + :referential_id => "1", :id => "2" + ) + end + it "recognize and generate #show" do + get( "/referentials/1/networks/2").should route_to( + :controller => "networks", :action => "show", + :referential_id => "1", :id => "2" + ) + end + end +end + diff --git a/spec/routing/time_tables_spec.rb b/spec/routing/time_tables_spec.rb new file mode 100644 index 000000000..45e426f4c --- /dev/null +++ b/spec/routing/time_tables_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe TimeTablesController do + describe "routing" do + it "not recognize #routes" do + get( "/referentials/1/time_tables/2/routes").should_not route_to( + :controller => "time_tables", :action => "routes", + :referential_id => "1", :id => "2" + ) + end + it "not recognize #lines" do + get( "/referentials/1/time_tables/2/lines").should_not route_to( + :controller => "time_tables", :action => "lines", + :referential_id => "1", :id => "2" + ) + end + it "not recognize #time_table_periods" do + get( "/referentials/1/time_tables/2/time_table_periods").should_not route_to( + "time_table_periods#index", + :referential_id => "1", :time_table_id => "2" + ) + end + it "recognize and generate #show" do + get( "/referentials/1/time_tables/2").should route_to( + :controller => "time_tables", :action => "show", + :referential_id => "1", :id => "2" + ) + end + end +end + diff --git a/spec/support/referential.rb b/spec/support/referential.rb index b2a8cf279..d77a05f41 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -12,12 +12,18 @@ module ReferentialHelper end module ClassMethods - + def assign_referential before(:each) do assign :referential, referential end end + def assign_organisation + before(:each) do + assign :organisation, referential.organisation + end + end + end diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index 090624fbf..1984a0d25 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -5,7 +5,6 @@ describe "/routes/show", :type => :view do assign_referential let!(:line) { assign :line, create(:line) } let!(:route) { assign :route, create(:route, :line => line) } - let!(:stop_points) { assign :stop_points, Array.new(2) { create(:stop_point) }.paginate } let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } it "should render h2 with the route name" do diff --git a/spec/views/rule_parameter_sets/index.html.erb_spec.rb b/spec/views/rule_parameter_sets/index.html.erb_spec.rb index a2ed45665..9e00c3332 100644 --- a/spec/views/rule_parameter_sets/index.html.erb_spec.rb +++ b/spec/views/rule_parameter_sets/index.html.erb_spec.rb @@ -1,21 +1,21 @@ require 'spec_helper' -describe "/rule_parameter_sets/index", :type => :view do +describe "/organisations/show" do - assign_referential - let!(:rule_parameter_sets) { assign :rule_parameter_sets, [ create(:rule_parameter_set), - create(:rule_parameter_set)] } + assign_organisation + + let!(:rule_parameter_sets) { assign :rule_parameter_sets, [ Factory(:rule_parameter_set, :organisation => organisation), it "should render a show link for each rule_parameter_set" do render rule_parameter_sets.each do |rule_parameter_set| - expect(rendered).to have_selector(".rule_parameter_set a[href='#{view.referential_rule_parameter_set_path(referential, rule_parameter_set)}']", :text => rule_parameter_set.name) + rendered.should have_selector(".rule_parameter_sets a[href='#{view.organisation_rule_parameter_set_path( rule_parameter_set)}']", :text => rule_parameter_set.name) end end it "should render a link to create a new rule_parameter_set" do render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_rule_parameter_set_path(referential)}']") + view.content_for(:sidebar).should have_selector(".actions a[href='#{new_organisation_rule_parameter_set_path}']") end end diff --git a/spec/views/rule_parameter_sets/new.html.erb_spec.rb b/spec/views/rule_parameter_sets/new.html.erb_spec.rb index eed25b8f6..a0188686a 100644 --- a/spec/views/rule_parameter_sets/new.html.erb_spec.rb +++ b/spec/views/rule_parameter_sets/new.html.erb_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe "/rule_parameter_sets/new", :type => :view do - assign_referential - let!(:rule_parameter_set) { assign :rule_parameter_set, build( :rule_parameter_set, :referential => referential) } + assign_organisation + let!(:rule_parameter_set) { assign :rule_parameter_set, build( :rule_parameter_set, :organisation => organisation) } describe "form" do |
