Permalink
Browse files

Handle the case where there is no external persistent identifier for …

…a model versioned by data generations.
  • Loading branch information...
1 parent d801e68 commit 693e4ea4e14ef29eb7e4a71f5b4b0871c8cd8268 @crowbot crowbot committed Apr 24, 2012
Showing with 25 additions and 9 deletions.
  1. +5 −1 lib/fixmytransport/data_generations.rb
  2. +20 −8 spec/models/route_spec.rb
@@ -174,7 +174,11 @@ def get_identity_hash
end
def identity_hash
- make_id_hash(self.class.data_generation_options_hash[:identity_fields])
+ if !self.class.data_generation_options_hash[:identity_fields]
+ return {}
+ else
+ make_id_hash(self.class.data_generation_options_hash[:identity_fields])
+ end
end
def temporary_identity_hash
@@ -27,8 +27,20 @@
:region_id => 1,
:status => 'ACT'
}
+ @default_attrs = { :name => 'A test route',
+ :status => 'ACT',
+ :number => 'ZZ9',
+ :transport_mode_id => 1 }
+ @model_type = Route
+ @expected_identity_hash = {}
+ @expected_temporary_identity_hash = { :id => nil }
end
+ it_should_behave_like "a model that exists in data generations"
+
+ it_should_behave_like "a model that exists in data generations and has slugs"
+
+
it "should create a new instance given valid attributes" do
route = Route.new(@valid_attributes)
route.valid?.should be_true
@@ -107,8 +119,8 @@
fixtures default_fixtures
- describe 'when looking for bus routes' do
-
+ describe 'when looking for bus routes' do
+
before do
@route = Route.new(:number => '807',
:transport_mode => transport_modes(:bus))
@@ -118,26 +130,26 @@
:to_stop => @new_stop,
:from_terminus => true)
end
-
+
it 'should include routes with the same number and one stop in common with the new route, with the same operator in the same admin area' do
@route.route_source_admin_areas.build({:operator_code => 'BUS',
:source_admin_area => admin_areas(:london)})
Route.find_existing_routes(@route).should include(routes(:number_807_bus))
end
-
+
it 'should include routes with the same number and one stop in common with the new route, with the same route operator' do
@route.route_operators.build({:operator => operators(:a_bus_company)})
Route.find_existing_routes(@route).should include(routes(:number_807_bus))
end
-
- it "should include routes with the same number and one stop in common with the new route, with one of the new route's operators" do
+
+ it "should include routes with the same number and one stop in common with the new route, with one of the new route's operators" do
@route.route_operators.build({:operator => operators(:a_bus_company)})
@route.route_operators.build({:operator => operators(:another_bus_company)})
Route.find_existing_routes(@route).should include(routes(:number_807_bus))
end
-
+
it 'should include routes with the same number, one stop area in common with the new route and the same operator code with no admin area' do
route_source_admin_area = routes(:number_807_bus).route_source_admin_areas.first
route_source_admin_area.source_admin_area_id = nil
@@ -176,7 +188,7 @@
end
end
-
+
describe 'when finding existing train routes' do
fixtures default_fixtures

0 comments on commit 693e4ea

Please sign in to comment.