Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Incorrect `collection_path` is generated for uncountable shallow resources #241

Merged
merged 1 commit into from

2 participants

Dimitrij Denissenko Joel Moss
Dimitrij Denissenko

The title says it all, nothing to add :)

Dimitrij Denissenko
dim commented

Any news? This is really quite an annoying bug, even if not many other people seem to be affected by it.

Joel Moss joelmoss merged commit aa52a0a into from
Joel Moss

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 44 additions and 4 deletions.
  1. +4 −4 lib/inherited_resources/url_helpers.rb
  2. +40 −0 test/url_helpers_test.rb
8 lib/inherited_resources/url_helpers.rb
View
@@ -47,7 +47,8 @@ def create_resources_url_helpers!
resource_segments, resource_ivars = [], []
resource_config = self.resources_configuration[:self]
- singleton = self.resources_configuration[:self][:singleton]
+ singleton = resource_config[:singleton]
+ uncountable = !singleton && resource_config[:route_collection_name] == resource_config[:route_instance_name]
polymorphic = self.parents_symbols.include?(:polymorphic)
# Add route_prefix if any.
@@ -123,9 +124,8 @@ def create_resources_url_helpers!
end
# If route is uncountable then add "_index" suffix to collection index route name
- #
- if !singleton && resource_config[:route_collection_name] == resource_config[:route_instance_name]
- collection_segments << :index
+ if uncountable
+ collection_segments << :"#{collection_segments.pop}_index"
end
generate_url_and_path_helpers nil, :collection, collection_segments, collection_ivars
40 test/url_helpers_test.rb
View
@@ -62,6 +62,13 @@ class SheepController < InheritedResources::Base
belongs_to :news, :table, :polymorphic => true
end
+class Fish
+ extend ActiveModel::Naming
+end
+class FishController < InheritedResources::Base
+ belongs_to :bed, :shallow => true
+end
+
class Desk
extend ActiveModel::Naming
end
@@ -505,6 +512,39 @@ def test_url_helpers_on_polymorphic_belongs_to_using_uncountable
controller.send("parent_url", :arg)
end
+ def test_url_helpers_on_shallow_belongs_to_using_uncountable
+ fish = Fish.new
+ bed = Bed.new
+
+ new_fish = Fish.new
+ new_fish.stubs(:persisted?).returns(false)
+ Sheep.stubs(:new).returns(new_fish)
+
+ controller = FishController.new
+ controller.instance_variable_set('@bed', bed)
+ controller.instance_variable_set('@fish', fish)
+
+ [:url, :path].each do |path_or_url|
+ controller.expects("bed_fish_index_#{path_or_url}").with(bed, {}).once
+ controller.send("collection_#{path_or_url}")
+
+ controller.expects("fish_#{path_or_url}").with(fish, {}).once
+ controller.send("resource_#{path_or_url}")
+
+ controller.expects("new_bed_fish_#{path_or_url}").with(bed, {}).once
+ controller.send("new_resource_#{path_or_url}")
+
+ controller.expects("edit_fish_#{path_or_url}").with(fish, {}).once
+ controller.send("edit_resource_#{path_or_url}")
+
+ controller.expects("bed_#{path_or_url}").with(bed, {}).once
+ controller.send("parent_#{path_or_url}")
+
+ controller.expects("edit_bed_#{path_or_url}").with(bed, {}).once
+ controller.send("edit_parent_#{path_or_url}")
+ end
+ end
+
def test_url_helpers_on_namespaced_polymorphic_belongs_to
house = House.new
desk = Desk.new
Something went wrong with that request. Please try again.