josevalim-inherited_resources 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/README +1 -1
- data/VERSION +1 -1
- data/lib/inherited_resources/url_helpers.rb +14 -5
- data/test/url_helpers_test.rb +6 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Version 0.8
|
2
2
|
|
3
|
+
* Fixed a small bug on optional belongs to with namespaced controllers.
|
4
|
+
* Allow a parameter to be given to collection_url in polymorphic cases to replace
|
5
|
+
the parent.
|
3
6
|
* Allow InheritedResources to be called without inheritance.
|
4
7
|
* Ensure that controllers that inherit from a controller with InheritedResources
|
5
8
|
works properly.
|
data/README
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.5
|
@@ -43,9 +43,12 @@ module InheritedResources
|
|
43
43
|
resource_segments, resource_ivars = [], []
|
44
44
|
resource_config = self.resources_configuration[:self]
|
45
45
|
|
46
|
+
singleton = self.resources_configuration[:self][:singleton]
|
47
|
+
polymorphic = self.parents_symbols.include?(:polymorphic)
|
48
|
+
|
46
49
|
# Add route_prefix if any.
|
47
50
|
unless resource_config[:route_prefix].blank?
|
48
|
-
if
|
51
|
+
if polymorphic
|
49
52
|
resource_ivars << resource_config[:route_prefix].to_s.inspect
|
50
53
|
else
|
51
54
|
resource_segments << resource_config[:route_prefix]
|
@@ -66,9 +69,6 @@ module InheritedResources
|
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
69
|
-
singleton = self.resources_configuration[:self][:singleton]
|
70
|
-
polymorphic = self.parents_symbols.include?(:polymorphic)
|
71
|
-
|
72
72
|
collection_ivars = resource_ivars.dup
|
73
73
|
collection_segments = resource_segments.dup
|
74
74
|
|
@@ -108,7 +108,7 @@ module InheritedResources
|
|
108
108
|
new_ivars = resource_ivars
|
109
109
|
end
|
110
110
|
elsif polymorphic
|
111
|
-
collection_ivars << 'resource_class.new'
|
111
|
+
collection_ivars << '(@_resource_class_new ||= resource_class.new)'
|
112
112
|
end
|
113
113
|
|
114
114
|
generate_url_and_path_helpers nil, :collection, collection_segments, collection_ivars
|
@@ -130,6 +130,15 @@ module InheritedResources
|
|
130
130
|
ivars.push "(given_args.first || #{ivars.pop})"
|
131
131
|
end
|
132
132
|
|
133
|
+
# In collection in polymorphic cases, allow an argument to be given as a
|
134
|
+
# replacemente for the parent.
|
135
|
+
#
|
136
|
+
if name == :collection && polymorphic
|
137
|
+
index = ivars.index(:parent)
|
138
|
+
ivars.insert index, "(given_args.first || parent)"
|
139
|
+
ivars.delete(:parent)
|
140
|
+
end
|
141
|
+
|
133
142
|
# When polymorphic is true, the segments must be replace by :polymorphic
|
134
143
|
# and ivars should be gathered into an array, which is compacted when
|
135
144
|
# optional.
|
data/test/url_helpers_test.rb
CHANGED
@@ -302,6 +302,9 @@ class UrlHelpersTest < ActiveSupport::TestCase
|
|
302
302
|
controller.send("resource_url", :page => 1)
|
303
303
|
|
304
304
|
# With args
|
305
|
+
controller.expects("polymorphic_url").with([:arg, new_bed], {}).once
|
306
|
+
controller.send("collection_url", :arg)
|
307
|
+
|
305
308
|
controller.expects("polymorphic_url").with([house, :arg], {}).once
|
306
309
|
controller.send("resource_url", :arg)
|
307
310
|
|
@@ -341,6 +344,9 @@ class UrlHelpersTest < ActiveSupport::TestCase
|
|
341
344
|
controller.send("resource_url", :page => 1)
|
342
345
|
|
343
346
|
# With args
|
347
|
+
controller.expects("polymorphic_url").with(['admin', :arg, new_desk], {}).once
|
348
|
+
controller.send("collection_url", :arg)
|
349
|
+
|
344
350
|
controller.expects("polymorphic_url").with(['admin', house, :arg], {}).once
|
345
351
|
controller.send("resource_url", :arg)
|
346
352
|
|