inherited_resources 1.2.1 → 1.2.2
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.
- data/CHANGELOG +5 -0
- data/README.rdoc +7 -7
- data/lib/inherited_resources/actions.rb +1 -1
- data/lib/inherited_resources/base_helpers.rb +10 -2
- data/lib/inherited_resources/version.rb +1 -1
- data/test/base_test.rb +12 -0
- data/test/class_methods_test.rb +9 -9
- data/test/nested_model_with_shallow_test.rb +14 -0
- metadata +6 -6
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -15,11 +15,9 @@ http://akitaonrails.com/2009/09/01/screencast-real-thin-restful-controllers-with
|
|
15
15
|
|
16
16
|
=== Rails 3
|
17
17
|
|
18
|
-
|
18
|
+
You can let bundler install Inherited Resources by adding this line to your application's Gemfile:
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
gem 'inherited_resources', '~> 1.2.1'
|
20
|
+
gem 'inherited_resources'
|
23
21
|
|
24
22
|
And then execute:
|
25
23
|
|
@@ -27,13 +25,13 @@ And then execute:
|
|
27
25
|
|
28
26
|
Or install it yourself as:
|
29
27
|
|
30
|
-
gem install inherited_resources
|
28
|
+
gem install inherited_resources
|
31
29
|
|
32
30
|
=== Rails 2.3.x
|
33
31
|
|
34
32
|
If you want to use the Rails 2.3.x version, you should install:
|
35
33
|
|
36
|
-
|
34
|
+
gem install inherited_resources --version=1.0.6
|
37
35
|
|
38
36
|
Or checkout from the v1.0 branch:
|
39
37
|
|
@@ -71,6 +69,8 @@ that through the following configuration value:
|
|
71
69
|
|
72
70
|
InheritedResources.flash_keys = [ :success, :failure ]
|
73
71
|
|
72
|
+
Notice the CollectionResponder won't work with InheritedResources, as InheritedResources hardcodes the redirect path based on the current scope (like belongs to, polymorphic associations, etc).
|
73
|
+
|
74
74
|
== Basic Usage
|
75
75
|
|
76
76
|
To use Inherited Resources you just have to inherit (duh) it:
|
@@ -294,7 +294,7 @@ in destroy action calculate in following order collection_url, parent_url, root_
|
|
294
294
|
Example:
|
295
295
|
|
296
296
|
class ButtonsConntroller < InheritedResources::Base
|
297
|
-
|
297
|
+
belongs_to :window
|
298
298
|
actions :all, :except => [:show, :index]
|
299
299
|
end
|
300
300
|
|
@@ -20,7 +20,10 @@ module InheritedResources
|
|
20
20
|
# end
|
21
21
|
#
|
22
22
|
def collection
|
23
|
-
get_collection_ivar ||
|
23
|
+
get_collection_ivar || begin
|
24
|
+
c = end_of_association_chain
|
25
|
+
set_collection_ivar(c.respond_to?(:scoped) ? c.scoped : c.all)
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
29
|
# This is how the resource is loaded.
|
@@ -46,7 +49,7 @@ module InheritedResources
|
|
46
49
|
# instance variable.
|
47
50
|
#
|
48
51
|
def build_resource
|
49
|
-
get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build,
|
52
|
+
get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, resource_params))
|
50
53
|
end
|
51
54
|
|
52
55
|
# Responsible for saving the resource on :create method. Overwriting this
|
@@ -294,6 +297,11 @@ module InheritedResources
|
|
294
297
|
end
|
295
298
|
url ||= root_url rescue nil
|
296
299
|
end
|
300
|
+
|
301
|
+
# extract attributes from params
|
302
|
+
def resource_params
|
303
|
+
params[resource_request_name] || params[resource_instance_name] || {}
|
304
|
+
end
|
297
305
|
end
|
298
306
|
end
|
299
307
|
|
data/test/base_test.rb
CHANGED
@@ -35,6 +35,12 @@ module UserTestHelper
|
|
35
35
|
user = mock(expectations.except(:errors))
|
36
36
|
user.stubs(:class).returns(User)
|
37
37
|
user.stubs(:errors).returns(expectations.fetch(:errors, {}))
|
38
|
+
user.singleton_class.class_eval do
|
39
|
+
def method_missing(symbol, *arguments, &block)
|
40
|
+
raise NoMethodError.new('this is expected by Array#flatten') if symbol == :to_ary
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
38
44
|
user
|
39
45
|
end
|
40
46
|
end
|
@@ -70,6 +76,12 @@ class IndexActionBaseTest < ActionController::TestCase
|
|
70
76
|
assert_response :success
|
71
77
|
assert_equal 'Generated XML', @response.body
|
72
78
|
end
|
79
|
+
|
80
|
+
def test_scoped_is_called_only_when_available
|
81
|
+
User.stubs(:all).returns([mock_user])
|
82
|
+
get :index
|
83
|
+
assert_equal Array, assigns(:users).class
|
84
|
+
end
|
73
85
|
end
|
74
86
|
|
75
87
|
class ShowActionBaseTest < ActionController::TestCase
|
data/test/class_methods_test.rb
CHANGED
@@ -64,23 +64,23 @@ class DefaultsClassMethodTest < ActiveSupport::TestCase
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_defaults_are_set
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
assert_equal Folder, FoldersController.send(:resource_class)
|
68
|
+
assert_equal :folder, FoldersController.send(:resources_configuration)[:self][:instance_name]
|
69
|
+
assert_equal :folders, FoldersController.send(:resources_configuration)[:self][:collection_name]
|
70
70
|
end
|
71
71
|
|
72
72
|
def test_defaults_can_be_overwriten
|
73
73
|
BooksController.send(:defaults, :resource_class => String, :instance_name => 'string', :collection_name => 'strings')
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
assert_equal String, BooksController.send(:resource_class)
|
76
|
+
assert_equal :string, BooksController.send(:resources_configuration)[:self][:instance_name]
|
77
|
+
assert_equal :strings, BooksController.send(:resources_configuration)[:self][:collection_name]
|
78
78
|
|
79
79
|
BooksController.send(:defaults, :class_name => 'Fixnum', :instance_name => :fixnum, :collection_name => :fixnums)
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
assert_equal Fixnum, BooksController.send(:resource_class)
|
82
|
+
assert_equal :fixnum, BooksController.send(:resources_configuration)[:self][:instance_name]
|
83
|
+
assert_equal :fixnums, BooksController.send(:resources_configuration)[:self][:collection_name]
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_defaults_raises_invalid_key
|
@@ -57,6 +57,20 @@ class NestedModelWithShallowTest < ActionController::TestCase
|
|
57
57
|
assert_equal mock_group, assigns(:group)
|
58
58
|
end
|
59
59
|
|
60
|
+
def test_expose_a_newly_create_group_with_speciality
|
61
|
+
Speciality.expects(:find).with('37').twice.returns(mock_speciality)
|
62
|
+
Plan::Group.expects(:build).with({'these' => :params}).returns(mock_group(:save => true))
|
63
|
+
post :create, :speciality_id => '37', :group => {:these => :params}
|
64
|
+
assert_equal mock_group, assigns(:group)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_expose_a_update_group_with_speciality
|
68
|
+
should_find_parents
|
69
|
+
mock_group.expects(:update_attributes).with('these' => :params).returns(true)
|
70
|
+
post :update, :id => 'forty_two', :group => {:these => :params}
|
71
|
+
assert_equal mock_group, assigns(:group)
|
72
|
+
end
|
73
|
+
|
60
74
|
protected
|
61
75
|
def should_find_parents
|
62
76
|
Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inherited_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 2
|
10
|
+
version: 1.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Jos\xC3\xA9 Valim"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-17 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
requirements: []
|
201
201
|
|
202
202
|
rubyforge_project: inherited_resources
|
203
|
-
rubygems_version: 1.3
|
203
|
+
rubygems_version: 1.5.3
|
204
204
|
signing_key:
|
205
205
|
specification_version: 3
|
206
206
|
summary: Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important.
|