josevalim-inherited_resources 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +13 -37
- data/README +10 -6
- data/lib/inherited_resources/base_helpers.rb +1 -1
- data/lib/inherited_resources/class_methods.rb +14 -4
- data/lib/inherited_resources/url_helpers.rb +7 -9
- data/test/class_methods_test.rb +7 -7
- data/test/url_helpers_test.rb +7 -6
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,45 +1,30 @@
|
|
1
|
-
# Version 0.5.
|
1
|
+
# Version 0.5.2
|
2
2
|
|
3
|
+
* Decoupled routes name from :instance_name and :collection_name. This way we
|
4
|
+
have more flexibility. Use route_instance_name and route_collection_name to
|
5
|
+
to change routes.
|
6
|
+
* Avoid calling human_name on nil when a resource class is not defined.
|
3
7
|
* Only call I18n if it's defined.
|
4
8
|
|
5
|
-
# Version 0.4.6
|
9
|
+
# Version 0.4.6-0
|
6
10
|
|
7
|
-
* Dealing with namespaced controllers out of the box
|
11
|
+
* Dealing with namespaced controllers out of the box.
|
8
12
|
* Added support to namespaced routes through :route_prefix.
|
9
|
-
|
10
|
-
# Version 0.4.5
|
11
|
-
|
12
13
|
* Added fix when resource_url is not defined.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
* Added better handling for namespaced controllers;
|
17
|
-
* Added flash messages scoped by namespaced controllers;
|
14
|
+
* Added better handling for namespaced controllers.
|
15
|
+
* Added flash messages scoped by namespaced controllers.
|
18
16
|
* Deprecated {{resource}} in I18n, use {{resource_name}} instead.
|
19
|
-
|
20
|
-
# Version 0.4.3
|
21
|
-
|
22
17
|
* rspec bug fix is not automatically required anymore. User has to do it
|
23
18
|
explicitly.
|
24
|
-
|
25
|
-
# Version 0.4.2
|
26
|
-
|
27
19
|
* Added a file which fix a rspec bug when render is called inside a method
|
28
20
|
which receives a block.
|
29
|
-
|
30
|
-
# Version 0.4.1
|
31
|
-
|
32
21
|
* parent? does not take begin_of_association_chain into account anymore
|
33
22
|
* Added options to url helpers.
|
34
|
-
|
35
|
-
# Version 0.4
|
36
|
-
|
37
23
|
* Added :optional to belongs_to associations. It allows you to deal with
|
38
24
|
categories/1/products/2 and /products/2 with just one controller.
|
39
|
-
|
40
25
|
* Cleaned up tests.
|
41
26
|
|
42
|
-
# Version 0.3
|
27
|
+
# Version 0.3.0
|
43
28
|
|
44
29
|
* Minor bump after three bug fixes.
|
45
30
|
* Bug fix when showing warning of constant redefinition.
|
@@ -48,24 +33,15 @@
|
|
48
33
|
raise "NoMethodError _url", not it will call root_url.
|
49
34
|
* More comments on UrlHelpers.
|
50
35
|
|
51
|
-
# Version 0.2.1
|
36
|
+
# Version 0.2.1-0
|
52
37
|
|
53
38
|
* Bug fix when ApplicationController is already loaded when we load respond_to.
|
54
|
-
|
55
|
-
# Version 0.2.0
|
56
|
-
|
57
39
|
* Added support success/failure blocks.
|
58
40
|
* Eager loading of files to work properly in multithreaded environments.
|
59
41
|
|
60
|
-
# Version 0.1.2
|
42
|
+
# Version 0.1.2-0
|
61
43
|
|
62
44
|
* Added more helper_methods.
|
63
|
-
|
64
|
-
# Version 0.1.1
|
65
|
-
|
66
45
|
* Added Rails 2.3.0 and changed tests to work with ActionController::TestCase.
|
67
|
-
|
68
|
-
# Version 0.1.0
|
69
|
-
|
70
|
-
* Initial release. Support to I18n, singleton controllers, polymorphic
|
46
|
+
* First release. Support to I18n, singleton controllers, polymorphic
|
71
47
|
controllers, belongs_to, nested_belongs_to and url helpers.
|
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Inherited Resources
|
2
2
|
License: MIT
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.2
|
4
4
|
|
5
5
|
You can also read this README in pretty html at the GitHub project Wiki page:
|
6
6
|
|
@@ -103,14 +103,18 @@ Overwriting defaults
|
|
103
103
|
Now that you learned the default behavior and basic configuration, let's see
|
104
104
|
how to extend it.
|
105
105
|
|
106
|
-
|
107
|
-
User
|
108
|
-
just doing:
|
106
|
+
Some people usually have an AccountsController to deal with all account
|
107
|
+
management while the resource is an User. So you can overwrite the resource class,
|
108
|
+
collection name and instance name just doing:
|
109
109
|
|
110
|
-
class
|
111
|
-
defaults :resource_class => User, :collection_name
|
110
|
+
class AccountsController < InheritedResources::Base
|
111
|
+
defaults :resource_class => User, :collection_name, 'users', :instance_name => 'user'
|
112
112
|
end
|
113
113
|
|
114
|
+
In the case above, in your views you will have @users and @user variables, but
|
115
|
+
the routes used will still be accounts_url and account_url. If you plan also to
|
116
|
+
change the routes, you can use :route_collection_name and :route_instance_name.
|
117
|
+
|
114
118
|
Namespaced controllers work out of the box, but if you need to specify a
|
115
119
|
different route prefix, you can do the following:
|
116
120
|
|
@@ -189,7 +189,7 @@ module InheritedResources #:nodoc:
|
|
189
189
|
|
190
190
|
options = {
|
191
191
|
:default => default_message || '',
|
192
|
-
:resource_name => resource_class.human_name,
|
192
|
+
:resource_name => resource_class ? resource_class.human_name : 'Resource',
|
193
193
|
}.merge(interpolation_options)
|
194
194
|
|
195
195
|
defaults = []
|
@@ -231,12 +231,18 @@ module InheritedResources #:nodoc:
|
|
231
231
|
# When you inherit from InheritedResources::Base, we make some assumptions on
|
232
232
|
# what is your resource_class, instance_name and collection_name.
|
233
233
|
#
|
234
|
-
# You can change those values by calling the class method defaults
|
234
|
+
# You can change those values by calling the class method <tt>defaults</tt>.
|
235
|
+
# This is useful, for example, in an accounts controller, where the object
|
236
|
+
# is an User but controller and routes are accounts.
|
235
237
|
#
|
236
|
-
# class
|
237
|
-
# defaults :resource_class => User, :instance_name => 'user',
|
238
|
+
# class AccountController < InheritedResources::Base
|
239
|
+
# defaults :resource_class => User, :instance_name => 'user',
|
240
|
+
# :collection_name => 'users', :singleton => true
|
238
241
|
# end
|
239
242
|
#
|
243
|
+
# If you want to change your urls, you can use :route_instance_name and
|
244
|
+
# :route_collection_name helpers.
|
245
|
+
#
|
240
246
|
# You can also provide :class_name, which is the same as :resource_class
|
241
247
|
# but accepts string (this is given for ActiveRecord compatibility).
|
242
248
|
#
|
@@ -245,7 +251,8 @@ module InheritedResources #:nodoc:
|
|
245
251
|
|
246
252
|
options.symbolize_keys!
|
247
253
|
options.assert_valid_keys(:resource_class, :collection_name, :instance_name,
|
248
|
-
:class_name, :route_prefix, :
|
254
|
+
:class_name, :route_prefix, :route_collection_name,
|
255
|
+
:route_instance_name, :singleton)
|
249
256
|
|
250
257
|
# Checks for special argument :resource_class and :class_name and sets it right away.
|
251
258
|
self.resource_class = options.delete(:resource_class) if options[:resource_class]
|
@@ -391,6 +398,9 @@ module InheritedResources #:nodoc:
|
|
391
398
|
config[:collection_name] = base.controller_name.to_sym
|
392
399
|
config[:instance_name] = base.controller_name.singularize.to_sym
|
393
400
|
|
401
|
+
config[:route_collection_name] = config[:collection_name]
|
402
|
+
config[:route_instance_name] = config[:instance_name]
|
403
|
+
|
394
404
|
# Deal with namespaced controllers
|
395
405
|
namespaces = base.controller_path.split('/')[0..-2]
|
396
406
|
config[:route_prefix] = namespaces.join('_') unless namespaces.empty?
|
@@ -77,7 +77,7 @@ module InheritedResources #:nodoc:
|
|
77
77
|
# This is where you are going to be redirected after destroying the manager.
|
78
78
|
#
|
79
79
|
unless base.singleton
|
80
|
-
resource_segments << resource_config[:
|
80
|
+
resource_segments << resource_config[:route_collection_name]
|
81
81
|
generate_url_and_path_helpers(base, nil, :collection, resource_segments, resource_ivars, polymorphic)
|
82
82
|
resource_segments.pop
|
83
83
|
else
|
@@ -85,7 +85,7 @@ module InheritedResources #:nodoc:
|
|
85
85
|
end
|
86
86
|
|
87
87
|
# Prepare and add new_resource_url
|
88
|
-
resource_segments << resource_config[:
|
88
|
+
resource_segments << resource_config[:route_instance_name]
|
89
89
|
generate_url_and_path_helpers(base, :new, :resource, resource_segments, resource_ivars, polymorphic)
|
90
90
|
|
91
91
|
# We don't add the resource_ivar to edit and show url if singleton.
|
@@ -95,7 +95,7 @@ module InheritedResources #:nodoc:
|
|
95
95
|
#
|
96
96
|
# Instead of:
|
97
97
|
#
|
98
|
-
#
|
98
|
+
# edit_project_manager_url(@project, @manager)
|
99
99
|
#
|
100
100
|
resource_ivars << resource_config[:instance_name] unless base.singleton
|
101
101
|
|
@@ -134,18 +134,16 @@ module InheritedResources #:nodoc:
|
|
134
134
|
# polymorphic_url(@company)
|
135
135
|
# polymorphic_url(@project)
|
136
136
|
#
|
137
|
-
# Obviously, this won't work properly. So in such
|
138
|
-
#
|
137
|
+
# Obviously, this won't work properly. So in such polymorphic with
|
138
|
+
# singletons cases we have to do this:
|
139
139
|
#
|
140
140
|
# polymorphic_url(@company, 'manager')
|
141
141
|
# polymorphic_url(@project, 'manager')
|
142
142
|
#
|
143
143
|
# This is exactly what we are doing here.
|
144
144
|
#
|
145
|
-
# The other case to
|
146
|
-
# polymorphic urls.
|
147
|
-
#
|
148
|
-
# In such cases, we usually would not send anything:
|
145
|
+
# The other case to handle is collection and new helpers with
|
146
|
+
# polymorphic urls. In such cases, we usually would not send anything:
|
149
147
|
#
|
150
148
|
# project_tasks_url(@project)
|
151
149
|
# new_project_task_url(@project)
|
data/test/class_methods_test.rb
CHANGED
@@ -100,49 +100,49 @@ class BelongsToClassMethodTest < TEST_CLASS
|
|
100
100
|
@controller.response = @response = ActionController::TestResponse.new
|
101
101
|
end
|
102
102
|
|
103
|
-
def
|
103
|
+
def test_expose_the_resquested_school_with_chosen_instance_variable_on_index
|
104
104
|
GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
|
105
105
|
Professor.stubs(:find).returns([mock_professor])
|
106
106
|
get :index, :school_title => 'nice'
|
107
107
|
assert_equal mock_school, assigns(:great_school)
|
108
108
|
end
|
109
109
|
|
110
|
-
def
|
110
|
+
def test_expose_the_resquested_school_with_chosen_instance_variable_on_show
|
111
111
|
GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
|
112
112
|
Professor.stubs(:find).returns(mock_professor)
|
113
113
|
get :show, :school_title => 'nice'
|
114
114
|
assert_equal mock_school, assigns(:great_school)
|
115
115
|
end
|
116
116
|
|
117
|
-
def
|
117
|
+
def test_expose_the_resquested_school_with_chosen_instance_variable_on_new
|
118
118
|
GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
|
119
119
|
Professor.stubs(:build).returns(mock_professor)
|
120
120
|
get :new, :school_title => 'nice'
|
121
121
|
assert_equal mock_school, assigns(:great_school)
|
122
122
|
end
|
123
123
|
|
124
|
-
def
|
124
|
+
def test_expose_the_resquested_school_with_chosen_instance_variable_on_edit
|
125
125
|
GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
|
126
126
|
Professor.stubs(:find).returns(mock_professor)
|
127
127
|
get :edit, :school_title => 'nice'
|
128
128
|
assert_equal mock_school, assigns(:great_school)
|
129
129
|
end
|
130
130
|
|
131
|
-
def
|
131
|
+
def test_expose_the_resquested_school_with_chosen_instance_variable_on_create
|
132
132
|
GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
|
133
133
|
Professor.stubs(:build).returns(mock_professor(:save => true))
|
134
134
|
post :create, :school_title => 'nice'
|
135
135
|
assert_equal mock_school, assigns(:great_school)
|
136
136
|
end
|
137
137
|
|
138
|
-
def
|
138
|
+
def test_expose_the_resquested_school_with_chosen_instance_variable_on_update
|
139
139
|
GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
|
140
140
|
Professor.stubs(:find).returns(mock_professor(:update_attributes => true))
|
141
141
|
put :update, :school_title => 'nice'
|
142
142
|
assert_equal mock_school, assigns(:great_school)
|
143
143
|
end
|
144
144
|
|
145
|
-
def
|
145
|
+
def test_expose_the_resquested_school_with_chosen_instance_variable_on_destroy
|
146
146
|
GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
|
147
147
|
Professor.stubs(:find).returns(mock_professor(:destroy => true))
|
148
148
|
delete :destroy, :school_title => 'nice'
|
data/test/url_helpers_test.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class Universe; end
|
4
4
|
class UniversesController < InheritedResources::Base
|
5
|
-
defaults :singleton => true
|
5
|
+
defaults :singleton => true, :route_instance_name => 'universum'
|
6
6
|
end
|
7
7
|
|
8
8
|
class House; end
|
@@ -12,6 +12,7 @@ end
|
|
12
12
|
class Backpack; end
|
13
13
|
module Admin; end
|
14
14
|
class Admin::BackpacksController < InheritedResources::Base
|
15
|
+
defaults :route_collection_name => 'tour_backpacks'
|
15
16
|
end
|
16
17
|
|
17
18
|
class Table; end
|
@@ -94,7 +95,7 @@ class UrlHelpersTest < ActiveSupport::TestCase
|
|
94
95
|
assert_equal 'admin', controller.class.resources_configuration[:self][:route_prefix]
|
95
96
|
|
96
97
|
[:url, :path].each do |path_or_url|
|
97
|
-
controller.expects("
|
98
|
+
controller.expects("admin_tour_backpacks_#{path_or_url}").with({}).once
|
98
99
|
controller.send("collection_#{path_or_url}")
|
99
100
|
|
100
101
|
controller.expects("admin_backpack_#{path_or_url}").with(:backpack, {}).once
|
@@ -127,18 +128,18 @@ class UrlHelpersTest < ActiveSupport::TestCase
|
|
127
128
|
controller.expects("root_#{path_or_url}").with({}).once
|
128
129
|
controller.send("collection_#{path_or_url}")
|
129
130
|
|
130
|
-
controller.expects("
|
131
|
+
controller.expects("universum_#{path_or_url}").with({}).once
|
131
132
|
controller.send("resource_#{path_or_url}")
|
132
133
|
|
133
|
-
controller.expects("
|
134
|
+
controller.expects("new_universum_#{path_or_url}").with({}).once
|
134
135
|
controller.send("new_resource_#{path_or_url}")
|
135
136
|
|
136
|
-
controller.expects("
|
137
|
+
controller.expects("edit_universum_#{path_or_url}").with({}).once
|
137
138
|
controller.send("edit_resource_#{path_or_url}")
|
138
139
|
|
139
140
|
# With options
|
140
141
|
# Also tests that argument sent are not used
|
141
|
-
controller.expects("
|
142
|
+
controller.expects("universum_#{path_or_url}").with(:page => 1).once
|
142
143
|
controller.send("resource_#{path_or_url}", :arg, :page => 1)
|
143
144
|
end
|
144
145
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: josevalim-inherited_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jos\xC3\xA9 Valim"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|