inherited_resources 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +86 -0
- data/README.rdoc +91 -37
- data/Rakefile +0 -22
- data/inherited_resources.gemspec +24 -0
- data/lib/inherited_resources.rb +7 -2
- data/lib/inherited_resources/actions.rb +4 -4
- data/lib/inherited_resources/base.rb +11 -10
- data/lib/inherited_resources/base_helpers.rb +32 -3
- data/lib/inherited_resources/class_methods.rb +102 -10
- data/lib/inherited_resources/shallow_helpers.rb +87 -0
- data/lib/inherited_resources/url_helpers.rb +48 -2
- data/lib/inherited_resources/version.rb +1 -1
- data/test/aliases_test.rb +1 -1
- data/test/association_chain_test.rb +1 -1
- data/test/base_test.rb +16 -8
- data/test/belongs_to_test.rb +44 -2
- data/test/belongs_to_with_shallow_test.rb +93 -0
- data/test/class_methods_test.rb +6 -4
- data/test/customized_base_test.rb +1 -1
- data/test/customized_belongs_to_test.rb +2 -2
- data/test/customized_redirect_to_test.rb +32 -0
- data/test/defaults_test.rb +117 -11
- data/test/locales/en.yml +17 -0
- data/test/nested_belongs_to_test.rb +1 -1
- data/test/nested_belongs_to_with_shallow_test.rb +123 -0
- data/test/nested_model_with_shallow_test.rb +133 -0
- data/test/optional_belongs_to_test.rb +4 -4
- data/test/polymorphic_test.rb +5 -5
- data/test/redirect_to_test.rb +1 -1
- data/test/singleton_test.rb +5 -2
- data/test/test_helper.rb +8 -24
- data/test/url_helpers_test.rb +243 -2
- data/test/views/cars/edit.html.erb +1 -0
- data/test/views/cars/index.html.erb +1 -0
- data/test/views/cars/new.html.erb +1 -0
- data/test/views/cars/show.html.erb +1 -0
- data/test/views/cities/edit.html.erb +1 -0
- data/test/views/cities/index.html.erb +1 -0
- data/test/views/cities/new.html.erb +1 -0
- data/test/views/cities/show.html.erb +1 -0
- data/test/views/comments/edit.html.erb +1 -0
- data/test/views/comments/index.html.erb +1 -0
- data/test/views/comments/new.html.erb +1 -0
- data/test/views/comments/show.html.erb +1 -0
- data/test/views/educations/new.html.erb +0 -0
- data/test/views/employees/edit.html.erb +1 -0
- data/test/views/employees/index.html.erb +1 -0
- data/test/views/employees/new.html.erb +1 -0
- data/test/views/employees/show.html.erb +1 -0
- data/test/views/groups/edit.html.erb +0 -0
- data/test/views/managers/edit.html.erb +1 -0
- data/test/views/managers/new.html.erb +1 -0
- data/test/views/managers/show.html.erb +1 -0
- data/test/views/painters/edit.html.erb +1 -0
- data/test/views/painters/index.html.erb +1 -0
- data/test/views/painters/new.html.erb +1 -0
- data/test/views/painters/show.html.erb +1 -0
- data/test/views/pets/edit.html.erb +1 -0
- data/test/views/pets/index.html.erb +1 -0
- data/test/views/pets/new.html.erb +1 -0
- data/test/views/pets/show.html.erb +1 -0
- data/test/views/plates/edit.html.erb +1 -0
- data/test/views/plates/index.html.erb +1 -0
- data/test/views/plates/new.html.erb +1 -0
- data/test/views/plates/show.html.erb +1 -0
- data/test/views/products/edit.html.erb +1 -0
- data/test/views/products/index.html.erb +1 -0
- data/test/views/products/new.html.erb +1 -0
- data/test/views/products/show.html.erb +1 -0
- data/test/views/professors/edit.html.erb +1 -0
- data/test/views/professors/index.html.erb +1 -0
- data/test/views/professors/new.html.erb +1 -0
- data/test/views/professors/show.html.erb +1 -0
- data/test/views/projects/index.html.erb +1 -0
- data/test/views/projects/index.json.erb +1 -0
- data/test/views/projects/respond_to_skip_default_template.html.erb +1 -0
- data/test/views/projects/respond_with_resource.html.erb +1 -0
- data/test/views/students/edit.html.erb +1 -0
- data/test/views/students/new.html.erb +1 -0
- data/test/views/tags/edit.html.erb +1 -0
- data/test/views/tags/index.html.erb +1 -0
- data/test/views/tags/new.html.erb +1 -0
- data/test/views/tags/show.html.erb +1 -0
- data/test/views/trees/edit.html.erb +1 -0
- data/test/views/trees/index.html.erb +1 -0
- data/test/views/trees/new.html.erb +1 -0
- data/test/views/trees/show.html.erb +1 -0
- data/test/views/university/professors/edit.html.erb +1 -0
- data/test/views/university/professors/index.html.erb +1 -0
- data/test/views/university/professors/new.html.erb +1 -0
- data/test/views/university/professors/show.html.erb +1 -0
- data/test/views/users/create.js.erb +1 -0
- data/test/views/users/destroy.js.erb +1 -0
- data/test/views/users/edit.html.erb +1 -0
- data/test/views/users/index.html.erb +1 -0
- data/test/views/users/new.html.erb +1 -0
- data/test/views/users/show.html.erb +1 -0
- data/test/views/users/update.js.erb +1 -0
- metadata +180 -9
data/test/base_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
class User
|
4
4
|
extend ActiveModel::Naming
|
@@ -29,12 +29,12 @@ module UserTestHelper
|
|
29
29
|
end
|
30
30
|
|
31
31
|
protected
|
32
|
-
|
32
|
+
|
33
33
|
def mock_user(expectations={})
|
34
34
|
@mock_user ||= begin
|
35
35
|
user = mock(expectations.except(:errors))
|
36
36
|
user.stubs(:class).returns(User)
|
37
|
-
user.stubs(:errors).returns(expectations.fetch(:errors, {}))
|
37
|
+
user.stubs(:errors).returns(expectations.fetch(:errors, {}))
|
38
38
|
user
|
39
39
|
end
|
40
40
|
end
|
@@ -44,19 +44,19 @@ class IndexActionBaseTest < ActionController::TestCase
|
|
44
44
|
include UserTestHelper
|
45
45
|
|
46
46
|
def test_expose_all_users_as_instance_variable
|
47
|
-
User.expects(:
|
47
|
+
User.expects(:all).returns([mock_user])
|
48
48
|
get :index
|
49
49
|
assert_equal [mock_user], assigns(:users)
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_apply_scopes_if_method_is_available
|
53
|
-
User.expects(:
|
53
|
+
User.expects(:all).returns([mock_user])
|
54
54
|
get :index
|
55
55
|
assert @controller.scopes_applied
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_controller_should_render_index
|
59
|
-
User.stubs(:
|
59
|
+
User.stubs(:all).returns([mock_user])
|
60
60
|
get :index
|
61
61
|
assert_response :success
|
62
62
|
assert_equal 'Index HTML', @response.body.strip
|
@@ -64,7 +64,7 @@ class IndexActionBaseTest < ActionController::TestCase
|
|
64
64
|
|
65
65
|
def test_render_all_users_as_xml_when_mime_type_is_xml
|
66
66
|
@request.accept = 'application/xml'
|
67
|
-
User.expects(:
|
67
|
+
User.expects(:all).returns(mock_user)
|
68
68
|
mock_user.expects(:to_xml).returns('Generated XML')
|
69
69
|
get :index
|
70
70
|
assert_response :success
|
@@ -201,6 +201,14 @@ class UpdateActionBaseTest < ActionController::TestCase
|
|
201
201
|
assert_redirected_to 'http://test.host/'
|
202
202
|
end
|
203
203
|
|
204
|
+
def test_redirect_to_the_users_list_if_show_undefined
|
205
|
+
@controller.class.send(:actions, :all, :except => :show)
|
206
|
+
User.stubs(:find).returns(mock_user(:update_attributes => true))
|
207
|
+
@controller.expects(:collection_url).returns('http://test.host/')
|
208
|
+
put :update
|
209
|
+
assert_redirected_to 'http://test.host/'
|
210
|
+
end
|
211
|
+
|
204
212
|
def test_show_flash_message_when_success
|
205
213
|
User.stubs(:find).returns(mock_user(:update_attributes => true))
|
206
214
|
put :update
|
@@ -229,7 +237,7 @@ end
|
|
229
237
|
|
230
238
|
class DestroyActionBaseTest < ActionController::TestCase
|
231
239
|
include UserTestHelper
|
232
|
-
|
240
|
+
|
233
241
|
def test_the_requested_user_is_destroyed
|
234
242
|
User.expects(:find).with('42').returns(mock_user)
|
235
243
|
mock_user.expects(:destroy).returns(true)
|
data/test/belongs_to_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
class Post
|
4
4
|
extend ActiveModel::Naming
|
@@ -24,7 +24,7 @@ class BelongsToTest < ActionController::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_expose_all_comments_as_instance_variable_on_index
|
27
|
-
Comment.expects(:
|
27
|
+
Comment.expects(:all).returns([mock_comment])
|
28
28
|
get :index, :post_id => '37'
|
29
29
|
assert_equal mock_post, assigns(:post)
|
30
30
|
assert_equal [mock_comment], assigns(:comments)
|
@@ -51,6 +51,14 @@ class BelongsToTest < ActionController::TestCase
|
|
51
51
|
assert_equal mock_comment, assigns(:comment)
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_redirect_to_the_post_on_update_if_show_and_index_undefined
|
55
|
+
@controller.class.send(:actions, :all, :except => [:show, :index])
|
56
|
+
@controller.expects(:parent_url).returns('http://test.host/')
|
57
|
+
Comment.expects(:build).with({'these' => 'params'}).returns(mock_comment(:save => true))
|
58
|
+
post :create, :post_id => '37', :comment => {:these => 'params'}
|
59
|
+
assert_redirected_to 'http://test.host/'
|
60
|
+
end
|
61
|
+
|
54
62
|
def test_expose_a_newly_create_comment_on_create
|
55
63
|
Comment.expects(:build).with({'these' => 'params'}).returns(mock_comment(:save => true))
|
56
64
|
post :create, :post_id => '37', :comment => {:these => 'params'}
|
@@ -58,6 +66,14 @@ class BelongsToTest < ActionController::TestCase
|
|
58
66
|
assert_equal mock_comment, assigns(:comment)
|
59
67
|
end
|
60
68
|
|
69
|
+
def test_redirect_to_the_post_on_update_if_show_and_index_undefined
|
70
|
+
@controller.class.send(:actions, :all, :except => [:show, :index])
|
71
|
+
Comment.stubs(:find).returns(mock_comment(:update_attributes => true))
|
72
|
+
@controller.expects(:parent_url).returns('http://test.host/')
|
73
|
+
put :update, :id => '42', :post_id => '37', :comment => {:these => 'params'}
|
74
|
+
assert_redirected_to 'http://test.host/'
|
75
|
+
end
|
76
|
+
|
61
77
|
def test_update_the_requested_object_on_update
|
62
78
|
Comment.expects(:find).with('42').returns(mock_comment)
|
63
79
|
mock_comment.expects(:update_attributes).with({'these' => 'params'}).returns(true)
|
@@ -66,6 +82,15 @@ class BelongsToTest < ActionController::TestCase
|
|
66
82
|
assert_equal mock_comment, assigns(:comment)
|
67
83
|
end
|
68
84
|
|
85
|
+
def test_redirect_to_the_post_on_destroy_if_show_and_index_undefined
|
86
|
+
@controller.class.send(:actions, :all, :except => [:show, :index])
|
87
|
+
Comment.expects(:find).with('42').returns(mock_comment)
|
88
|
+
mock_comment.expects(:destroy)
|
89
|
+
@controller.expects(:parent_url).returns('http://test.host/')
|
90
|
+
delete :destroy, :id => '42', :post_id => '37'
|
91
|
+
assert_redirected_to 'http://test.host/'
|
92
|
+
end
|
93
|
+
|
69
94
|
def test_the_requested_comment_is_destroyed_on_destroy
|
70
95
|
Comment.expects(:find).with('42').returns(mock_comment)
|
71
96
|
mock_comment.expects(:destroy)
|
@@ -74,6 +99,23 @@ class BelongsToTest < ActionController::TestCase
|
|
74
99
|
assert_equal mock_comment, assigns(:comment)
|
75
100
|
end
|
76
101
|
|
102
|
+
def helper_methods
|
103
|
+
@controller.class._helpers.instance_methods.map {|m| m.to_s }
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_helpers
|
107
|
+
mock_post.stubs(:class).returns(Post)
|
108
|
+
|
109
|
+
Comment.expects(:all).returns([mock_comment])
|
110
|
+
get :index, :post_id => '37'
|
111
|
+
|
112
|
+
assert helper_methods.include?('parent?')
|
113
|
+
assert @controller.send(:parent?)
|
114
|
+
assert_equal mock_post, assigns(:post)
|
115
|
+
assert helper_methods.include?('parent')
|
116
|
+
assert_equal mock_post, @controller.send(:parent)
|
117
|
+
end
|
118
|
+
|
77
119
|
protected
|
78
120
|
|
79
121
|
def mock_post(stubs={})
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class Post
|
4
|
+
extend ActiveModel::Naming
|
5
|
+
end
|
6
|
+
|
7
|
+
class Tag
|
8
|
+
extend ActiveModel::Naming
|
9
|
+
end
|
10
|
+
|
11
|
+
class TagsController < InheritedResources::Base
|
12
|
+
belongs_to :post, :shallow => true, :finder => :find_by_slug
|
13
|
+
end
|
14
|
+
|
15
|
+
class BelongsToWithShallowTest < ActionController::TestCase
|
16
|
+
tests TagsController
|
17
|
+
|
18
|
+
def setup
|
19
|
+
Post.expects(:find_by_slug).with('thirty_seven').returns(mock_post)
|
20
|
+
mock_post.expects(:tags).returns(Tag)
|
21
|
+
|
22
|
+
@controller.stubs(:resource_url).returns('/')
|
23
|
+
@controller.stubs(:collection_url).returns('/')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_expose_all_tags_as_instance_variable_on_index
|
27
|
+
Tag.expects(:all).returns([mock_tag])
|
28
|
+
get :index, :post_id => 'thirty_seven'
|
29
|
+
assert_equal mock_post, assigns(:post)
|
30
|
+
assert_equal [mock_tag], assigns(:tags)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_expose_a_new_tag_on_new
|
34
|
+
Tag.expects(:build).returns(mock_tag)
|
35
|
+
get :new, :post_id => 'thirty_seven'
|
36
|
+
assert_equal mock_post, assigns(:post)
|
37
|
+
assert_equal mock_tag, assigns(:tag)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_expose_a_newly_create_tag_on_create
|
41
|
+
Tag.expects(:build).with({'these' => 'params'}).returns(mock_tag(:save => true))
|
42
|
+
post :create, :post_id => 'thirty_seven', :tag => {:these => 'params'}
|
43
|
+
assert_equal mock_post, assigns(:post)
|
44
|
+
assert_equal mock_tag, assigns(:tag)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_expose_the_requested_tag_on_show
|
48
|
+
should_find_parents
|
49
|
+
get :show, :id => '42'
|
50
|
+
assert_equal mock_post, assigns(:post)
|
51
|
+
assert_equal mock_tag, assigns(:tag)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_expose_the_requested_tag_on_edit
|
55
|
+
should_find_parents
|
56
|
+
get :edit, :id => '42'
|
57
|
+
assert_equal mock_post, assigns(:post)
|
58
|
+
assert_equal mock_tag, assigns(:tag)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_update_the_requested_object_on_update
|
62
|
+
should_find_parents
|
63
|
+
mock_tag.expects(:update_attributes).with({'these' => 'params'}).returns(true)
|
64
|
+
put :update, :id => '42', :tag => {:these => 'params'}
|
65
|
+
assert_equal mock_post, assigns(:post)
|
66
|
+
assert_equal mock_tag, assigns(:tag)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_the_requested_tag_is_destroyed_on_destroy
|
70
|
+
should_find_parents
|
71
|
+
mock_tag.expects(:destroy)
|
72
|
+
delete :destroy, :id => '42', :post_id => '37'
|
73
|
+
assert_equal mock_post, assigns(:post)
|
74
|
+
assert_equal mock_tag, assigns(:tag)
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
def should_find_parents
|
79
|
+
mock_tag.expects(:post).returns(mock_post)
|
80
|
+
mock_post.expects(:to_param).returns('thirty_seven')
|
81
|
+
Tag.expects(:find).with('42').twice.returns(mock_tag)
|
82
|
+
end
|
83
|
+
|
84
|
+
def mock_post(stubs={})
|
85
|
+
@mock_post ||= mock(stubs)
|
86
|
+
end
|
87
|
+
|
88
|
+
def mock_tag(stubs={})
|
89
|
+
@mock_tag ||= mock(stubs)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
data/test/class_methods_test.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
class Book; end
|
4
4
|
class Folder; end
|
5
5
|
|
6
6
|
class BooksController < InheritedResources::Base
|
7
|
+
custom_actions :collection => :search, :resource => [:delete]
|
7
8
|
actions :index, :show
|
8
9
|
end
|
9
10
|
|
@@ -33,9 +34,9 @@ class ActionsClassMethodTest < ActionController::TestCase
|
|
33
34
|
|
34
35
|
def test_actions_are_undefined
|
35
36
|
action_methods = BooksController.send(:action_methods).map(&:to_sym)
|
36
|
-
assert_equal
|
37
|
+
assert_equal 4, action_methods.size
|
37
38
|
|
38
|
-
[:index, :show].each do |action|
|
39
|
+
[:index, :show, :delete, :search].each do |action|
|
39
40
|
assert action_methods.include?(action)
|
40
41
|
end
|
41
42
|
|
@@ -54,6 +55,7 @@ class ActionsClassMethodTest < ActionController::TestCase
|
|
54
55
|
assert action_methods.include? action
|
55
56
|
end
|
56
57
|
end
|
58
|
+
|
57
59
|
end
|
58
60
|
|
59
61
|
class DefaultsClassMethodTest < ActiveSupport::TestCase
|
@@ -129,4 +131,4 @@ class BelongsToErrorsTest < ActiveSupport::TestCase
|
|
129
131
|
ensure
|
130
132
|
DeansController.send(:parents_symbols=, [:school])
|
131
133
|
end
|
132
|
-
end
|
134
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
class GreatSchool
|
4
4
|
end
|
@@ -22,7 +22,7 @@ class CustomizedBelongsToTest < ActionController::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_expose_the_requested_school_with_chosen_instance_variable_on_index
|
25
|
-
Professor.stubs(:
|
25
|
+
Professor.stubs(:all).returns([mock_professor])
|
26
26
|
get :index, :school_title => 'nice'
|
27
27
|
assert_equal mock_school, assigns(:great_school)
|
28
28
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class Post;
|
4
|
+
def self.human_name; 'Post'; end
|
5
|
+
end
|
6
|
+
|
7
|
+
class PostsController < InheritedResources::Base
|
8
|
+
actions :all, :except => [:show]
|
9
|
+
end
|
10
|
+
|
11
|
+
class RedirectToIndexWithoutShowTest < ActionController::TestCase
|
12
|
+
tests PostsController
|
13
|
+
|
14
|
+
def test_redirect_index_url_after_create
|
15
|
+
Post.stubs(:new).returns(mock_machine(:save => true))
|
16
|
+
assert !PostsController.respond_to?(:show)
|
17
|
+
post :create
|
18
|
+
assert_redirected_to 'http://test.host/posts'
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_redirect_to_index_url_after_update
|
22
|
+
Post.stubs(:find).returns(mock_machine(:update_attributes => true))
|
23
|
+
assert !PostsController.respond_to?(:show)
|
24
|
+
put :update
|
25
|
+
assert_redirected_to 'http://test.host/posts'
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
def mock_machine(stubs={})
|
30
|
+
@mock_machine ||= mock(stubs)
|
31
|
+
end
|
32
|
+
end
|
data/test/defaults_test.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
class Malarz
|
4
4
|
def self.human_name; 'Painter'; end
|
5
|
+
|
6
|
+
def to_param
|
7
|
+
self.slug
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
11
|
class PaintersController < InheritedResources::Base
|
8
12
|
defaults :instance_name => 'malarz', :collection_name => 'malarze',
|
9
|
-
:resource_class => Malarz, :route_prefix => nil
|
13
|
+
:resource_class => Malarz, :route_prefix => nil,
|
14
|
+
:finder => :find_by_slug
|
10
15
|
end
|
11
16
|
|
12
17
|
class DefaultsTest < ActionController::TestCase
|
@@ -18,14 +23,14 @@ class DefaultsTest < ActionController::TestCase
|
|
18
23
|
end
|
19
24
|
|
20
25
|
def test_expose_all_painters_as_instance_variable
|
21
|
-
Malarz.expects(:
|
26
|
+
Malarz.expects(:all).returns([mock_painter])
|
22
27
|
get :index
|
23
28
|
assert_equal [mock_painter], assigns(:malarze)
|
24
29
|
end
|
25
30
|
|
26
31
|
def test_expose_the_requested_painter_on_show
|
27
|
-
Malarz.expects(:
|
28
|
-
get :show, :id => '
|
32
|
+
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
|
33
|
+
get :show, :id => 'forty_two'
|
29
34
|
assert_equal mock_painter, assigns(:malarz)
|
30
35
|
end
|
31
36
|
|
@@ -36,8 +41,8 @@ class DefaultsTest < ActionController::TestCase
|
|
36
41
|
end
|
37
42
|
|
38
43
|
def test_expose_the_requested_painter_on_edit
|
39
|
-
Malarz.expects(:
|
40
|
-
get :edit, :id => '
|
44
|
+
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
|
45
|
+
get :edit, :id => 'forty_two'
|
41
46
|
assert_response :success
|
42
47
|
assert_equal mock_painter, assigns(:malarz)
|
43
48
|
end
|
@@ -49,16 +54,16 @@ class DefaultsTest < ActionController::TestCase
|
|
49
54
|
end
|
50
55
|
|
51
56
|
def test_update_the_requested_object
|
52
|
-
Malarz.expects(:
|
57
|
+
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
|
53
58
|
mock_painter.expects(:update_attributes).with({'these' => 'params'}).returns(true)
|
54
|
-
put :update, :id => '
|
59
|
+
put :update, :id => 'forty_two', :malarz => {:these => 'params'}
|
55
60
|
assert_equal mock_painter, assigns(:malarz)
|
56
61
|
end
|
57
62
|
|
58
63
|
def test_the_requested_painter_is_destroyed
|
59
|
-
Malarz.expects(:
|
64
|
+
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
|
60
65
|
mock_painter.expects(:destroy)
|
61
|
-
delete :destroy, :id => '
|
66
|
+
delete :destroy, :id => 'forty_two'
|
62
67
|
assert_equal mock_painter, assigns(:malarz)
|
63
68
|
end
|
64
69
|
|
@@ -68,3 +73,104 @@ class DefaultsTest < ActionController::TestCase
|
|
68
73
|
end
|
69
74
|
end
|
70
75
|
|
76
|
+
class Professor
|
77
|
+
def self.human_name; 'Einstein'; end
|
78
|
+
end
|
79
|
+
module University; end
|
80
|
+
class University::ProfessorsController < InheritedResources::Base
|
81
|
+
defaults :finder => :find_by_slug
|
82
|
+
end
|
83
|
+
|
84
|
+
class DefaultsNamespaceTest < ActionController::TestCase
|
85
|
+
tests University::ProfessorsController
|
86
|
+
|
87
|
+
def setup
|
88
|
+
@controller.stubs(:resource_url).returns('/')
|
89
|
+
@controller.stubs(:collection_url).returns('/')
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_expose_all_professors_as_instance_variable
|
93
|
+
Professor.expects(:all).returns([mock_professor])
|
94
|
+
get :index
|
95
|
+
assert_equal [mock_professor], assigns(:professors)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_expose_the_requested_painter_on_show
|
99
|
+
Professor.expects(:find_by_slug).with('forty_two').returns(mock_professor)
|
100
|
+
get :show, :id => 'forty_two'
|
101
|
+
assert_equal mock_professor, assigns(:professor)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_expose_a_new_painter
|
105
|
+
Professor.expects(:new).returns(mock_professor)
|
106
|
+
get :new
|
107
|
+
assert_equal mock_professor, assigns(:professor)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_expose_the_requested_painter_on_edit
|
111
|
+
Professor.expects(:find_by_slug).with('forty_two').returns(mock_professor)
|
112
|
+
get :edit, :id => 'forty_two'
|
113
|
+
assert_response :success
|
114
|
+
assert_equal mock_professor, assigns(:professor)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_expose_a_newly_create_professor_when_saved_with_success
|
118
|
+
Professor.expects(:new).with({'these' => 'params'}).returns(mock_professor(:save => true))
|
119
|
+
post :create, :university_professor => {:these => 'params'}
|
120
|
+
assert_equal mock_professor, assigns(:professor)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_update_the_professor
|
124
|
+
Professor.expects(:find_by_slug).with('forty_two').returns(mock_professor)
|
125
|
+
mock_professor.expects(:update_attributes).with({'these' => 'params'}).returns(true)
|
126
|
+
put :update, :id => 'forty_two', :university_professor => {:these => 'params'}
|
127
|
+
assert_equal mock_professor, assigns(:professor)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_the_requested_painter_is_destroyed
|
131
|
+
Professor.expects(:find_by_slug).with('forty_two').returns(mock_professor)
|
132
|
+
mock_professor.expects(:destroy)
|
133
|
+
delete :destroy, :id => 'forty_two'
|
134
|
+
assert_equal mock_professor, assigns(:professor)
|
135
|
+
end
|
136
|
+
|
137
|
+
protected
|
138
|
+
def mock_professor(stubs={})
|
139
|
+
@mock_professor ||= mock(stubs)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
class Group
|
144
|
+
end
|
145
|
+
class AdminGroup
|
146
|
+
end
|
147
|
+
module Admin; end
|
148
|
+
class Admin::Group
|
149
|
+
end
|
150
|
+
class Admin::GroupsController < InheritedResources::Base
|
151
|
+
end
|
152
|
+
class NamespacedModelForNamespacedController < ActionController::TestCase
|
153
|
+
tests Admin::GroupsController
|
154
|
+
|
155
|
+
def test_that_it_picked_the_namespaced_model
|
156
|
+
# make public so we can test it
|
157
|
+
Admin::GroupsController.send(:public, *Admin::GroupsController.protected_instance_methods)
|
158
|
+
assert_equal Admin::Group, @controller.resource_class
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
class Role
|
163
|
+
end
|
164
|
+
class AdminRole
|
165
|
+
end
|
166
|
+
class Admin::RolesController < InheritedResources::Base
|
167
|
+
end
|
168
|
+
class TwoPartNameModelForNamespacedController < ActionController::TestCase
|
169
|
+
tests Admin::RolesController
|
170
|
+
|
171
|
+
def test_that_it_picked_the_camelcased_model
|
172
|
+
# make public so we can test it
|
173
|
+
Admin::RolesController.send(:public, *Admin::RolesController.protected_instance_methods)
|
174
|
+
assert_equal AdminRole, @controller.resource_class
|
175
|
+
end
|
176
|
+
end
|