diff options
| author | Marc Florisson | 2015-02-03 12:26:37 +0100 |
|---|---|---|
| committer | Marc Florisson | 2015-02-03 12:26:37 +0100 |
| commit | a98cf1bdae71922512abb284429c96777d01db18 (patch) | |
| tree | e9f76cfa66b50e48b9061a1d3b3e34022e9e87a2 /spec | |
| parent | 04148815395986714ac6c1f98abcc23744cb97eb (diff) | |
| download | chouette-core-a98cf1bdae71922512abb284429c96777d01db18.tar.bz2 | |
first refactor to add rule parameter set to organisation
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/line_spec.rb | 58 | ||||
| -rw-r--r-- | spec/models/organisation_spec.rb | 7 | ||||
| -rw-r--r-- | spec/models/rule_parameter_set_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/stop_area_copy_spec.rb | 15 | ||||
| -rw-r--r-- | spec/routing/companies_spec.rb | 25 | ||||
| -rw-r--r-- | spec/routing/group_of_lines_spec.rb | 25 | ||||
| -rw-r--r-- | spec/routing/networks_spec.rb | 25 | ||||
| -rw-r--r-- | spec/routing/time_tables_spec.rb | 31 |
8 files changed, 181 insertions, 7 deletions
diff --git a/spec/models/line_spec.rb b/spec/models/line_spec.rb new file mode 100644 index 000000000..0b7fcac1c --- /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(:organisation){subject.referential.organisation} + 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 organisation works with HUB" do + before( :each) do + organisation.update_attributes :hub_restrictions => true + 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 organisation doesn't works with HUB" do + before( :each) do + organisation.update_attributes :hub_restrictions => false + end + it "should have objectid with a third part shorter than 14 char" do + subject.update_attributes :objectid => objectid_b + subject.should be_valid + end + end + end + describe "validation objectid size" do + let(:organisation){subject.referential.organisation} + context "when organisation works with HUB" do + before( :each) do + organisation.update_attributes :hub_restrictions => true + 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 organisation doesn't works with HUB" do + before( :each) do + organisation.update_attributes :hub_restrictions => false + 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..6baf13c46 --- /dev/null +++ b/spec/models/organisation_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Organisation do + + it { should validate_presence_of(:name) } + it { should validate_uniqueness_of(:name) } +end diff --git a/spec/models/rule_parameter_set_spec.rb b/spec/models/rule_parameter_set_spec.rb index bf785d6f7..3e872598f 100644 --- a/spec/models/rule_parameter_set_spec.rb +++ b/spec/models/rule_parameter_set_spec.rb @@ -38,7 +38,7 @@ describe RuleParameterSet do end describe "#referential" do - it { should validate_presence_of(:referential) } + #it { should validate_presence_of(:referential) } it { should allow_mass_assignment_of :referential_id } end diff --git a/spec/models/stop_area_copy_spec.rb b/spec/models/stop_area_copy_spec.rb index 66aa56d30..d9fac2409 100644 --- a/spec/models/stop_area_copy_spec.rb +++ b/spec/models/stop_area_copy_spec.rb @@ -2,29 +2,32 @@ require 'spec_helper' describe StopAreaCopy do - + subject { StopAreaCopy.new(:source_id => 1, :hierarchy => "child", :area_type => "Quay") } it { should validate_presence_of :source_id } it { should validate_presence_of :hierarchy } it { should validate_presence_of :area_type } - - + + 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 source.children.length.should == 1 source.children[0].name.should == "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" @@ -34,7 +37,7 @@ describe StopAreaCopy do source.parent.should_not be_nil source.parent.name.should == 'test2' end - + end 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 + |
