diff options
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 19 | ||||
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 53 |
3 files changed, 41 insertions, 33 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 85c09a3fda..589df218a8 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1442,7 +1442,7 @@ module ActionDispatch name = case @scope[:scope_level] when :nested - [member_name, prefix] + [name_prefix, prefix] when :collection [prefix, name_prefix, collection_name] when :new diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index bdd4606720..1a96587836 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -187,7 +187,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end resources :posts, :only => [:index, :show] do - resources :comments, :except => :destroy + namespace :admin do + root :to => "index#index" + end + resources :comments, :except => :destroy do + get "views" => "comments#views", :as => :views + end end resource :past, :only => :destroy @@ -2308,6 +2313,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_nested_route_in_nested_resource + get "/posts/1/comments/2/views" + assert_equal "comments#views", @response.body + assert_equal "/posts/1/comments/2/views", post_comment_views_path(:post_id => '1', :comment_id => '2') + end + + def test_root_in_deeply_nested_scope + get "/posts/1/admin" + assert_equal "admin/index#index", @response.body + assert_equal "/posts/1/admin", post_admin_root_path(:post_id => '1') + end + private def with_test_routes yield diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 4459b711e6..feca1e0035 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -590,8 +590,8 @@ class Fixtures fixtures.size end - def delete_existing_fixtures - @connection.delete "DELETE FROM #{@connection.quote_table_name(table_name)}", 'Fixture Delete' + def delete_existing_fixtures(table = table_name) + @connection.delete "DELETE FROM #{@connection.quote_table_name(table)}", 'Fixture Delete' end def insert_fixtures @@ -602,12 +602,7 @@ class Fixtures fixtures.delete('DEFAULTS') # track any join tables we need to insert later - habtm_fixtures = Hash.new do |h, path| - h[path] = HabtmFixtures.new( - @connection, - path, - Fixtures.find_table_name(path), nil) - end + habtm_fixtures = Hash.new { |h,k| h[k] = [] } rows = fixtures.map do |label, fixture| row = fixture.to_hash @@ -655,14 +650,11 @@ class Fixtures when :has_and_belongs_to_many if (targets = row.delete(association.name.to_s)) targets = targets.is_a?(Array) ? targets : targets.split(/\s*,\s*/) - join_fixtures = habtm_fixtures[association.options[:join_table]] - - targets.each do |target| - join_fixtures["#{label}_#{target}"] = Fixture.new( - { association.foreign_key => row[primary_key_name], - association.association_foreign_key => Fixtures.identify(target) }, - nil) - end + table_name = association.options[:join_table] + habtm_fixtures[table_name].concat targets.map { |target| + { association.foreign_key => row[primary_key_name], + association.association_foreign_key => Fixtures.identify(target) } + } end end end @@ -675,18 +667,19 @@ class Fixtures @connection.insert_fixture(row, table_name) end + habtm_fixtures.keys.each do |table| + delete_existing_fixtures(table) + end + # insert any HABTM join tables we discovered - habtm_fixtures.values.each do |fixture| - fixture.delete_existing_fixtures - fixture.insert_fixtures + habtm_fixtures.each do |table, fixtures| + fixtures.each do |row| + @connection.insert_fixture(row, table) + end end end private - class HabtmFixtures < ::Fixtures #:nodoc: - def read_fixture_files; end - end - def primary_key_name @primary_key_name ||= model_class && model_class.primary_key end @@ -789,7 +782,7 @@ class Fixture #:nodoc: class FormatError < FixtureError #:nodoc: end - attr_reader :model_class + attr_reader :model_class, :fixture def initialize(fixture, model_class) @fixture = fixture @@ -797,24 +790,22 @@ class Fixture #:nodoc: end def class_name - @model_class.name if @model_class + model_class.name if model_class end def each - @fixture.each { |item| yield item } + fixture.each { |item| yield item } end def [](key) - @fixture[key] + fixture[key] end - def to_hash - @fixture - end + alias :to_hash :fixture def find if model_class - model_class.find(self[model_class.primary_key]) + model_class.find(fixture[model_class.primary_key]) else raise FixtureClassNotFound, "No class attached to find." end |