inherited_resources 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -1
- data/Gemfile +1 -2
- data/Gemfile.lock +37 -72
- data/MIT-LICENSE +1 -1
- data/README.md +11 -3
- data/inherited_resources.gemspec +2 -0
- data/lib/generators/rails/templates/controller.rb +9 -0
- data/lib/inherited_resources/class_methods.rb +6 -5
- data/lib/inherited_resources/polymorphic_helpers.rb +19 -7
- data/lib/inherited_resources/version.rb +1 -1
- data/test/aliases_test.rb +0 -7
- data/test/base_test.rb +1 -15
- data/test/class_methods_test.rb +30 -0
- data/test/test_helper.rb +4 -3
- metadata +44 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 121b6dce978ba43045adaee54c37906c299ced3a
|
4
|
+
data.tar.gz: 1b1549e0cc0feae4551f0455434c2df483c11598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 747c499e0d0f62c0a42ac5915782159678471318a232ce00251315edddd86f900edbb0aeef47c93ad8883983df2fafc426680a1b1812fa87bc4d987a385ade7a
|
7
|
+
data.tar.gz: b687a4fd01330c6246fc57748c8d522e46e2e892a185d8aac18b9c6c148432864a49947f6587724a0f7191739e52764abe95487cffb07a382252a19fb7ee57c0
|
data/CHANGELOG
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
# 1.5.
|
1
|
+
# Version 1.5.1
|
2
|
+
|
3
|
+
* Lock the Rails version until only 4.2.
|
4
|
+
* Fix parent class lookup.
|
5
|
+
* Fix resource_class default value definition.
|
6
|
+
|
7
|
+
# Version 1.5.0
|
2
8
|
|
3
9
|
* Supports nested modules (namespaced models and controllers).
|
4
10
|
* Supports Rails 4 Strong Parameters notation.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,106 +1,71 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
inherited_resources (1.5.
|
4
|
+
inherited_resources (1.5.1)
|
5
|
+
actionpack (>= 3.2, < 4.2)
|
5
6
|
has_scope (~> 0.6.0.rc)
|
7
|
+
railties (>= 3.2, < 4.2)
|
6
8
|
responders (~> 1.0)
|
7
9
|
|
8
10
|
GEM
|
9
11
|
remote: https://rubygems.org/
|
10
12
|
specs:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
actionpack (4.0.0)
|
15
|
-
activesupport (= 4.0.0)
|
16
|
-
builder (~> 3.1.0)
|
17
|
-
erubis (~> 2.7.0)
|
13
|
+
actionpack (4.1.5)
|
14
|
+
actionview (= 4.1.5)
|
15
|
+
activesupport (= 4.1.5)
|
18
16
|
rack (~> 1.5.2)
|
19
17
|
rack-test (~> 0.6.2)
|
20
|
-
|
21
|
-
activesupport (= 4.
|
22
|
-
builder (~> 3.1
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
minitest (~> 4.2)
|
32
|
-
multi_json (~> 1.3)
|
18
|
+
actionview (4.1.5)
|
19
|
+
activesupport (= 4.1.5)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubis (~> 2.7.0)
|
22
|
+
activemodel (4.1.5)
|
23
|
+
activesupport (= 4.1.5)
|
24
|
+
builder (~> 3.1)
|
25
|
+
activesupport (4.1.5)
|
26
|
+
i18n (~> 0.6, >= 0.6.9)
|
27
|
+
json (~> 1.7, >= 1.7.7)
|
28
|
+
minitest (~> 5.1)
|
33
29
|
thread_safe (~> 0.1)
|
34
|
-
tzinfo (~>
|
35
|
-
|
36
|
-
arel (4.0.0)
|
37
|
-
atomic (1.1.10)
|
38
|
-
builder (3.1.4)
|
30
|
+
tzinfo (~> 1.1)
|
31
|
+
builder (3.2.2)
|
39
32
|
erubis (2.7.0)
|
40
33
|
has_scope (0.6.0.rc)
|
41
34
|
actionpack (>= 3.2, < 5)
|
42
35
|
activesupport (>= 3.2, < 5)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
minitest (4.7.5)
|
51
|
-
mocha (0.14.0)
|
36
|
+
i18n (0.6.11)
|
37
|
+
json (1.8.1)
|
38
|
+
metaclass (0.0.4)
|
39
|
+
minitest (5.4.1)
|
40
|
+
minitest-rg (5.1.0)
|
41
|
+
minitest (~> 5.0)
|
42
|
+
mocha (1.1.0)
|
52
43
|
metaclass (~> 0.0.1)
|
53
|
-
multi_json (1.7.7)
|
54
|
-
polyglot (0.3.3)
|
55
44
|
rack (1.5.2)
|
56
45
|
rack-test (0.6.2)
|
57
46
|
rack (>= 1.0)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
activerecord (= 4.0.0)
|
62
|
-
activesupport (= 4.0.0)
|
63
|
-
bundler (>= 1.3.0, < 2.0)
|
64
|
-
railties (= 4.0.0)
|
65
|
-
sprockets-rails (~> 2.0.0)
|
66
|
-
railties (4.0.0)
|
67
|
-
actionpack (= 4.0.0)
|
68
|
-
activesupport (= 4.0.0)
|
47
|
+
railties (4.1.5)
|
48
|
+
actionpack (= 4.1.5)
|
49
|
+
activesupport (= 4.1.5)
|
69
50
|
rake (>= 0.8.7)
|
70
51
|
thor (>= 0.18.1, < 2.0)
|
71
|
-
rake (10.
|
72
|
-
responders (1.1.
|
73
|
-
railties (>= 3.2, <
|
74
|
-
sprockets (2.10.0)
|
75
|
-
hike (~> 1.2)
|
76
|
-
multi_json (~> 1.0)
|
77
|
-
rack (~> 1.0)
|
78
|
-
tilt (~> 1.1, != 1.3.0)
|
79
|
-
sprockets-rails (2.0.0)
|
80
|
-
actionpack (>= 3.0)
|
81
|
-
activesupport (>= 3.0)
|
82
|
-
sprockets (~> 2.8)
|
52
|
+
rake (10.3.2)
|
53
|
+
responders (1.1.1)
|
54
|
+
railties (>= 3.2, < 4.2)
|
83
55
|
strong_parameters (0.1.4)
|
84
56
|
actionpack (>= 3.2.0)
|
85
57
|
activemodel (>= 3.2.0)
|
86
58
|
railties (>= 3.2.0)
|
87
|
-
thor (0.
|
88
|
-
thread_safe (0.
|
89
|
-
|
90
|
-
|
91
|
-
treetop (1.4.14)
|
92
|
-
polyglot
|
93
|
-
polyglot (>= 0.3.1)
|
94
|
-
turn (0.9.6)
|
95
|
-
ansi
|
96
|
-
tzinfo (0.3.37)
|
59
|
+
thor (0.19.1)
|
60
|
+
thread_safe (0.3.4)
|
61
|
+
tzinfo (1.2.2)
|
62
|
+
thread_safe (~> 0.1)
|
97
63
|
|
98
64
|
PLATFORMS
|
99
65
|
ruby
|
100
66
|
|
101
67
|
DEPENDENCIES
|
102
68
|
inherited_resources!
|
69
|
+
minitest-rg
|
103
70
|
mocha
|
104
|
-
rails (>= 3.2, < 5)
|
105
71
|
strong_parameters
|
106
|
-
turn
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## Deprecation notice
|
2
|
+
|
3
|
+
Since Rails 3 came out, I have no longer used Inherited Resources and it is no
|
4
|
+
longer actively maintained. I have found that the responders abstraction
|
5
|
+
offers the perfect balance between hiding and showing too much logic in controllers.
|
6
|
+
That said, I suggest developers to make use of Rails' `respond_with` feature
|
7
|
+
alongside the [responders gem](https://github.com/plataformatec/responders) as a
|
8
|
+
replacement to Inherited Resources.
|
9
|
+
|
1
10
|
## Inherited Resources
|
2
11
|
|
3
12
|
Inherited Resources speeds up development by making your controllers inherit
|
@@ -208,7 +217,7 @@ projects collection:
|
|
208
217
|
class ProjectsController < InheritedResources::Base
|
209
218
|
protected
|
210
219
|
def collection
|
211
|
-
|
220
|
+
get_collection_ivar || set_collection_ivar(end_of_association_chain.paginate(:page => params[:page]))
|
212
221
|
end
|
213
222
|
end
|
214
223
|
```
|
@@ -726,5 +735,4 @@ If you discover any bugs, please describe it in the issues tracker, including Ra
|
|
726
735
|
|
727
736
|
Questions are better handled on StackOverflow.
|
728
737
|
|
729
|
-
Copyright (c) 2009-2012 José Valim
|
730
|
-
See the attached MIT License.
|
738
|
+
MIT License. Copyright (c) 2009-2012 José Valim.
|
data/inherited_resources.gemspec
CHANGED
@@ -19,5 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_dependency("responders", "~> 1.0")
|
22
|
+
s.add_dependency("actionpack", ">= 3.2", "< 4.2")
|
23
|
+
s.add_dependency("railties", ">= 3.2", "< 4.2")
|
22
24
|
s.add_dependency("has_scope", "~> 0.6.0.rc")
|
23
25
|
end
|
@@ -2,4 +2,13 @@ class <%= controller_class_name %>Controller < InheritedResources::Base
|
|
2
2
|
<% if options[:singleton] -%>
|
3
3
|
defaults :singleton => true
|
4
4
|
<% end -%>
|
5
|
+
<% if Rails::VERSION::MAJOR >= 4 || defined?(ActiveModel::ForbiddenAttributesProtection) -%>
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def <%= singular_name %>_params
|
10
|
+
params.require(:<%= singular_name %>).permit(<%= attributes_names.map{ |a_name| ":#{a_name}" }.join(", ") %>)
|
11
|
+
end
|
12
|
+
<% end -%>
|
5
13
|
end
|
14
|
+
|
@@ -182,8 +182,9 @@ module InheritedResources
|
|
182
182
|
|
183
183
|
klass = model_name
|
184
184
|
while namespace != ''
|
185
|
-
|
186
|
-
if
|
185
|
+
new_klass = "#{namespace}::#{model_name}"
|
186
|
+
if new_klass.safe_constantize
|
187
|
+
klass = new_klass
|
187
188
|
break
|
188
189
|
else
|
189
190
|
namespace = namespace.deconstantize
|
@@ -312,7 +313,7 @@ module InheritedResources
|
|
312
313
|
def initialize_resources_class_accessors! #:nodoc:
|
313
314
|
# First priority is the namespaced model, e.g. User::Group
|
314
315
|
self.resource_class ||= begin
|
315
|
-
namespaced_class = self.name.sub(/Controller
|
316
|
+
namespaced_class = self.name.sub(/Controller$/, '').singularize
|
316
317
|
namespaced_class.constantize
|
317
318
|
rescue NameError
|
318
319
|
nil
|
@@ -320,7 +321,7 @@ module InheritedResources
|
|
320
321
|
|
321
322
|
# Second priority is the top namespace model, e.g. EngineName::Article for EngineName::Admin::ArticlesController
|
322
323
|
self.resource_class ||= begin
|
323
|
-
namespaced_classes = self.name.sub(/Controller
|
324
|
+
namespaced_classes = self.name.sub(/Controller$/, '').split('::')
|
324
325
|
namespaced_class = [namespaced_classes.first, namespaced_classes.last].join('::').singularize
|
325
326
|
namespaced_class.constantize
|
326
327
|
rescue NameError
|
@@ -329,7 +330,7 @@ module InheritedResources
|
|
329
330
|
|
330
331
|
# Third priority the camelcased c, i.e. UserGroup
|
331
332
|
self.resource_class ||= begin
|
332
|
-
camelcased_class = self.name.sub(/Controller
|
333
|
+
camelcased_class = self.name.sub(/Controller$/, '').gsub('::', '').singularize
|
333
334
|
camelcased_class.constantize
|
334
335
|
rescue NameError
|
335
336
|
nil
|
@@ -15,9 +15,15 @@ module InheritedResources
|
|
15
15
|
#
|
16
16
|
# Your routes should be something like:
|
17
17
|
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
18
|
+
# resources :files do
|
19
|
+
# resources :comments #=> /files/13/comments
|
20
|
+
# end
|
21
|
+
# resources :tasks do
|
22
|
+
# resources :comments #=> /tasks/17/comments
|
23
|
+
# end
|
24
|
+
# resources :messages do
|
25
|
+
# resources :comments #=> /messages/11/comments
|
26
|
+
# end
|
21
27
|
#
|
22
28
|
# When using polymorphic associations, you get some free helpers:
|
23
29
|
#
|
@@ -74,10 +80,16 @@ module InheritedResources
|
|
74
80
|
#
|
75
81
|
# Finally your routes should be something like:
|
76
82
|
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
83
|
+
# resources :projects do
|
84
|
+
# resources :files do
|
85
|
+
# resources :comments #=> /projects/1/files/13/comments
|
86
|
+
# end
|
87
|
+
# resources :tasks do
|
88
|
+
# resources :comments #=> /projects/1/tasks/17/comments
|
89
|
+
# end
|
90
|
+
# resources :messages do
|
91
|
+
# resources :comments #=> /projects/1/messages/11/comments
|
92
|
+
# end
|
81
93
|
# end
|
82
94
|
#
|
83
95
|
# The helpers work in the same way as above.
|
data/test/aliases_test.rb
CHANGED
@@ -129,13 +129,6 @@ class AliasesTest < ActionController::TestCase
|
|
129
129
|
mock_student = mock_student(:save => true, :to_xml => "XML")
|
130
130
|
Student.stubs(:new).returns(mock_student)
|
131
131
|
|
132
|
-
# Bug in mocha does not accept strings on respond_to
|
133
|
-
mock_student.singleton_class.class_eval do
|
134
|
-
def respond_to?(method, *)
|
135
|
-
method == "to_xml" || super
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
132
|
post :create
|
140
133
|
assert_equal "http://test.host/", @response.location
|
141
134
|
end
|
data/test/base_test.rb
CHANGED
@@ -105,13 +105,6 @@ class ShowActionBaseTest < ActionController::TestCase
|
|
105
105
|
User.expects(:find).with('42').returns(mock_user)
|
106
106
|
mock_user.expects(:to_xml).returns("Generated XML")
|
107
107
|
|
108
|
-
# Bug in mocha does not accept strings on respond_to
|
109
|
-
mock_user.singleton_class.class_eval do
|
110
|
-
def respond_to?(method, *)
|
111
|
-
method == "to_xml" || super
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
108
|
get :show, :id => '42'
|
116
109
|
assert_response :success
|
117
110
|
assert_equal 'Generated XML', @response.body
|
@@ -139,13 +132,6 @@ class NewActionBaseTest < ActionController::TestCase
|
|
139
132
|
User.expects(:new).returns(mock_user)
|
140
133
|
mock_user.expects(:to_xml).returns("Generated XML")
|
141
134
|
|
142
|
-
# Bug in mocha does not accept strings on respond_to
|
143
|
-
mock_user.singleton_class.class_eval do
|
144
|
-
def respond_to?(method, *)
|
145
|
-
method == "to_xml" || super
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
135
|
get :new
|
150
136
|
assert_response :success
|
151
137
|
assert_equal 'Generated XML', @response.body
|
@@ -198,7 +184,7 @@ class CreateActionBaseTest < ActionController::TestCase
|
|
198
184
|
def test_redirect_to_the_created_user
|
199
185
|
User.stubs(:new).returns(mock_user(:save => true))
|
200
186
|
@controller.expects(:resource_url).returns('http://test.host/')
|
201
|
-
post :create
|
187
|
+
post :create, format: :html
|
202
188
|
assert_redirected_to 'http://test.host/'
|
203
189
|
end
|
204
190
|
|
data/test/class_methods_test.rb
CHANGED
@@ -23,6 +23,22 @@ class DeansController < InheritedResources::Base
|
|
23
23
|
belongs_to :school
|
24
24
|
end
|
25
25
|
|
26
|
+
module Controller
|
27
|
+
class User; end
|
28
|
+
|
29
|
+
class UsersController < InheritedResources::Base; end
|
30
|
+
|
31
|
+
module Admin
|
32
|
+
class UsersController < InheritedResources::Base; end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class ControllerGroup; end
|
37
|
+
|
38
|
+
module Controller
|
39
|
+
class GroupsController < InheritedResources::Base; end
|
40
|
+
end
|
41
|
+
|
26
42
|
module Library
|
27
43
|
class Category
|
28
44
|
end
|
@@ -148,8 +164,22 @@ class BelongsToErrorsTest < ActiveSupport::TestCase
|
|
148
164
|
assert_equal Library::Category, Library::SubcategoriesController.resources_configuration[:category][:parent_class]
|
149
165
|
end
|
150
166
|
|
167
|
+
def test_belongs_to_for_namespaced_controller_and_non_namespaced_model_sets_parent_class_properly
|
168
|
+
Library::SubcategoriesController.send(:belongs_to, :book)
|
169
|
+
assert_equal Book, Library::SubcategoriesController.resources_configuration[:book][:parent_class]
|
170
|
+
end
|
171
|
+
|
151
172
|
def test_belongs_to_without_namespace_sets_parent_class_properly
|
152
173
|
FoldersController.send(:belongs_to, :book)
|
153
174
|
assert_equal Book, FoldersController.resources_configuration[:book][:parent_class]
|
154
175
|
end
|
155
176
|
end
|
177
|
+
|
178
|
+
class SpecialCasesClassMethodTest < ActionController::TestCase
|
179
|
+
|
180
|
+
def test_resource_class_to_corresponding_model_class
|
181
|
+
assert_equal Controller::User, Controller::UsersController.send(:resource_class)
|
182
|
+
assert_equal Controller::User, Controller::Admin::UsersController.send(:resource_class)
|
183
|
+
assert_equal ControllerGroup, Controller::GroupsController.send(:resource_class)
|
184
|
+
end
|
185
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -3,9 +3,10 @@ require 'bundler'
|
|
3
3
|
|
4
4
|
Bundler.setup
|
5
5
|
|
6
|
-
require '
|
7
|
-
require 'mocha/
|
8
|
-
|
6
|
+
require 'minitest'
|
7
|
+
require 'mocha/mini_test'
|
8
|
+
require 'minitest/rg'
|
9
|
+
require 'minitest/autorun'
|
9
10
|
|
10
11
|
ENV["RAILS_ENV"] = "test"
|
11
12
|
RAILS_ROOT = "anywhere"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inherited_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: responders
|
@@ -25,6 +25,46 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: actionpack
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.2'
|
35
|
+
- - "<"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '4.2'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '3.2'
|
45
|
+
- - "<"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.2'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: railties
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- - "<"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '4.2'
|
58
|
+
type: :runtime
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3.2'
|
65
|
+
- - "<"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '4.2'
|
28
68
|
- !ruby/object:Gem::Dependency
|
29
69
|
name: has_scope
|
30
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
230
|
version: '0'
|
191
231
|
requirements: []
|
192
232
|
rubyforge_project: inherited_resources
|
193
|
-
rubygems_version: 2.
|
233
|
+
rubygems_version: 2.4.2
|
194
234
|
signing_key:
|
195
235
|
specification_version: 4
|
196
236
|
summary: Inherited Resources speeds up development by making your controllers inherit
|
@@ -295,3 +335,4 @@ test_files:
|
|
295
335
|
- test/views/users/update.js.erb
|
296
336
|
- test/views/venue/show.html.erb
|
297
337
|
- test/views/widgets/new.html.erb
|
338
|
+
has_rdoc:
|