inherited_resources 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inherited_resources/version.rb +1 -1
- metadata +13 -218
- data/.gitignore +0 -1
- data/CHANGELOG +0 -172
- data/Gemfile +0 -10
- data/Gemfile.lock +0 -71
- data/Rakefile +0 -24
- data/inherited_resources.gemspec +0 -25
- data/test/aliases_test.rb +0 -146
- data/test/association_chain_test.rb +0 -125
- data/test/base_test.rb +0 -334
- data/test/belongs_to_test.rb +0 -130
- data/test/belongs_to_with_shallow_test.rb +0 -93
- data/test/class_methods_test.rb +0 -185
- data/test/customized_base_test.rb +0 -168
- data/test/customized_belongs_to_test.rb +0 -76
- data/test/customized_redirect_to_test.rb +0 -32
- data/test/defaults_test.rb +0 -197
- data/test/locales/en.yml +0 -17
- data/test/multiple_nested_optional_belongs_to_test.rb +0 -369
- data/test/nested_belongs_to_test.rb +0 -108
- data/test/nested_belongs_to_with_shallow_test.rb +0 -123
- data/test/nested_model_with_shallow_test.rb +0 -147
- data/test/nested_singleton_test.rb +0 -167
- data/test/optional_belongs_to_test.rb +0 -164
- data/test/polymorphic_test.rb +0 -215
- data/test/redirect_to_test.rb +0 -51
- data/test/singleton_test.rb +0 -87
- data/test/strong_parameters_test.rb +0 -120
- data/test/test_helper.rb +0 -47
- data/test/url_helpers_test.rb +0 -988
- data/test/views/address/edit.html.erb +0 -1
- data/test/views/address/new.html.erb +0 -1
- data/test/views/address/show.html.erb +0 -1
- data/test/views/cars/edit.html.erb +0 -1
- data/test/views/cars/index.html.erb +0 -1
- data/test/views/cars/new.html.erb +0 -1
- data/test/views/cars/show.html.erb +0 -1
- data/test/views/cities/edit.html.erb +0 -1
- data/test/views/cities/index.html.erb +0 -1
- data/test/views/cities/new.html.erb +0 -1
- data/test/views/cities/show.html.erb +0 -1
- data/test/views/comments/edit.html.erb +0 -1
- data/test/views/comments/index.html.erb +0 -1
- data/test/views/comments/new.html.erb +0 -1
- data/test/views/comments/show.html.erb +0 -1
- data/test/views/educations/new.html.erb +0 -0
- data/test/views/employees/edit.html.erb +0 -1
- data/test/views/employees/index.html.erb +0 -1
- data/test/views/employees/new.html.erb +0 -1
- data/test/views/employees/show.html.erb +0 -1
- data/test/views/geolocation/show.html.erb +0 -1
- data/test/views/groups/edit.html.erb +0 -0
- data/test/views/managers/edit.html.erb +0 -1
- data/test/views/managers/new.html.erb +0 -1
- data/test/views/managers/show.html.erb +0 -1
- data/test/views/painters/edit.html.erb +0 -1
- data/test/views/painters/index.html.erb +0 -1
- data/test/views/painters/new.html.erb +0 -1
- data/test/views/painters/show.html.erb +0 -1
- data/test/views/pets/edit.html.erb +0 -1
- data/test/views/pets/index.html.erb +0 -1
- data/test/views/pets/new.html.erb +0 -1
- data/test/views/pets/show.html.erb +0 -1
- data/test/views/photos/index.html.erb +0 -1
- data/test/views/plates/edit.html.erb +0 -1
- data/test/views/plates/index.html.erb +0 -1
- data/test/views/plates/new.html.erb +0 -1
- data/test/views/plates/show.html.erb +0 -1
- data/test/views/products/edit.html.erb +0 -1
- data/test/views/products/index.html.erb +0 -1
- data/test/views/products/new.html.erb +0 -1
- data/test/views/products/show.html.erb +0 -1
- data/test/views/professors/edit.html.erb +0 -1
- data/test/views/professors/index.html.erb +0 -1
- data/test/views/professors/new.html.erb +0 -1
- data/test/views/professors/show.html.erb +0 -1
- data/test/views/projects/edit.html.erb +0 -1
- data/test/views/projects/index.html.erb +0 -1
- data/test/views/projects/index.json.erb +0 -1
- data/test/views/projects/new.html.erb +0 -1
- data/test/views/projects/respond_to_skip_default_template.html.erb +0 -1
- data/test/views/projects/respond_with_resource.html.erb +0 -1
- data/test/views/projects/show.html.erb +0 -1
- data/test/views/students/edit.html.erb +0 -1
- data/test/views/students/new.html.erb +0 -1
- data/test/views/tags/edit.html.erb +0 -1
- data/test/views/tags/index.html.erb +0 -1
- data/test/views/tags/new.html.erb +0 -1
- data/test/views/tags/show.html.erb +0 -1
- data/test/views/trees/edit.html.erb +0 -1
- data/test/views/trees/index.html.erb +0 -1
- data/test/views/trees/new.html.erb +0 -1
- data/test/views/trees/show.html.erb +0 -1
- data/test/views/university/professors/edit.html.erb +0 -1
- data/test/views/university/professors/index.html.erb +0 -1
- data/test/views/university/professors/new.html.erb +0 -1
- data/test/views/university/professors/show.html.erb +0 -1
- data/test/views/users/create.js.erb +0 -1
- data/test/views/users/destroy.js.erb +0 -1
- data/test/views/users/edit.html.erb +0 -1
- data/test/views/users/index.html.erb +0 -1
- data/test/views/users/new.html.erb +0 -1
- data/test/views/users/show.html.erb +0 -1
- data/test/views/users/update.js.erb +0 -1
- data/test/views/venue/show.html.erb +0 -1
- data/test/views/widgets/new.html.erb +0 -0
data/test/belongs_to_test.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class Post
|
4
|
-
extend ActiveModel::Naming
|
5
|
-
end
|
6
|
-
|
7
|
-
class Comment
|
8
|
-
extend ActiveModel::Naming
|
9
|
-
end
|
10
|
-
|
11
|
-
class CommentsController < InheritedResources::Base
|
12
|
-
belongs_to :post
|
13
|
-
end
|
14
|
-
|
15
|
-
class BelongsToTest < ActionController::TestCase
|
16
|
-
tests CommentsController
|
17
|
-
|
18
|
-
def setup
|
19
|
-
Post.expects(:find).with('37').returns(mock_post)
|
20
|
-
mock_post.expects(:comments).returns(Comment)
|
21
|
-
|
22
|
-
@controller.stubs(:resource_url).returns('/')
|
23
|
-
@controller.stubs(:collection_url).returns('/')
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_expose_all_comments_as_instance_variable_on_index
|
27
|
-
Comment.expects(:scoped).returns([mock_comment])
|
28
|
-
get :index, :post_id => '37'
|
29
|
-
assert_equal mock_post, assigns(:post)
|
30
|
-
assert_equal [mock_comment], assigns(:comments)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_expose_the_requested_comment_on_show
|
34
|
-
Comment.expects(:find).with('42').returns(mock_comment)
|
35
|
-
get :show, :id => '42', :post_id => '37'
|
36
|
-
assert_equal mock_post, assigns(:post)
|
37
|
-
assert_equal mock_comment, assigns(:comment)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_expose_a_new_comment_on_new
|
41
|
-
Comment.expects(:build).returns(mock_comment)
|
42
|
-
get :new, :post_id => '37'
|
43
|
-
assert_equal mock_post, assigns(:post)
|
44
|
-
assert_equal mock_comment, assigns(:comment)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_expose_the_requested_comment_on_edit
|
48
|
-
Comment.expects(:find).with('42').returns(mock_comment)
|
49
|
-
get :edit, :id => '42', :post_id => '37'
|
50
|
-
assert_equal mock_post, assigns(:post)
|
51
|
-
assert_equal mock_comment, assigns(:comment)
|
52
|
-
end
|
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
|
-
|
62
|
-
def test_expose_a_newly_create_comment_on_create
|
63
|
-
Comment.expects(:build).with({'these' => 'params'}).returns(mock_comment(:save => true))
|
64
|
-
post :create, :post_id => '37', :comment => {:these => 'params'}
|
65
|
-
assert_equal mock_post, assigns(:post)
|
66
|
-
assert_equal mock_comment, assigns(:comment)
|
67
|
-
end
|
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
|
-
|
77
|
-
def test_update_the_requested_object_on_update
|
78
|
-
Comment.expects(:find).with('42').returns(mock_comment)
|
79
|
-
mock_comment.expects(:update_attributes).with({'these' => 'params'}).returns(true)
|
80
|
-
put :update, :id => '42', :post_id => '37', :comment => {:these => 'params'}
|
81
|
-
assert_equal mock_post, assigns(:post)
|
82
|
-
assert_equal mock_comment, assigns(:comment)
|
83
|
-
end
|
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
|
-
|
94
|
-
def test_the_requested_comment_is_destroyed_on_destroy
|
95
|
-
Comment.expects(:find).with('42').returns(mock_comment)
|
96
|
-
mock_comment.expects(:destroy)
|
97
|
-
delete :destroy, :id => '42', :post_id => '37'
|
98
|
-
assert_equal mock_post, assigns(:post)
|
99
|
-
assert_equal mock_comment, assigns(:comment)
|
100
|
-
end
|
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(:scoped).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
|
-
|
119
|
-
protected
|
120
|
-
|
121
|
-
def mock_post(stubs={})
|
122
|
-
@mock_post ||= mock(stubs)
|
123
|
-
end
|
124
|
-
|
125
|
-
def mock_comment(stubs={})
|
126
|
-
@mock_comment ||= mock(stubs)
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
@@ -1,93 +0,0 @@
|
|
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(:scoped).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
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class Book; end
|
4
|
-
class Folder; end
|
5
|
-
|
6
|
-
class BooksController < InheritedResources::Base
|
7
|
-
custom_actions :collection => :search, :resource => [:delete]
|
8
|
-
actions :index, :show
|
9
|
-
end
|
10
|
-
|
11
|
-
class ReadersController < InheritedResources::Base
|
12
|
-
actions :all, :except => [ :edit, :update ]
|
13
|
-
end
|
14
|
-
|
15
|
-
class FoldersController < InheritedResources::Base
|
16
|
-
end
|
17
|
-
|
18
|
-
class Dean
|
19
|
-
def self.human_name; 'Dean'; end
|
20
|
-
end
|
21
|
-
|
22
|
-
class DeansController < InheritedResources::Base
|
23
|
-
belongs_to :school
|
24
|
-
end
|
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
|
-
|
42
|
-
module Library
|
43
|
-
class Category
|
44
|
-
end
|
45
|
-
|
46
|
-
class Subcategory
|
47
|
-
end
|
48
|
-
|
49
|
-
class SubcategoriesController < InheritedResources::Base
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class ActionsClassMethodTest < ActionController::TestCase
|
54
|
-
tests BooksController
|
55
|
-
|
56
|
-
def test_cannot_render_actions
|
57
|
-
assert_raise AbstractController::ActionNotFound do
|
58
|
-
get :new
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_actions_are_undefined
|
63
|
-
action_methods = BooksController.send(:action_methods).map(&:to_sym)
|
64
|
-
assert_equal 4, action_methods.size
|
65
|
-
|
66
|
-
[:index, :show, :delete, :search].each do |action|
|
67
|
-
assert action_methods.include?(action)
|
68
|
-
end
|
69
|
-
|
70
|
-
instance_methods = BooksController.send(:instance_methods).map(&:to_sym)
|
71
|
-
|
72
|
-
[:new, :edit, :create, :update, :destroy].each do |action|
|
73
|
-
assert !instance_methods.include?(action)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_actions_are_undefined_when_except_option_is_given
|
78
|
-
action_methods = ReadersController.send(:action_methods)
|
79
|
-
assert_equal 5, action_methods.size
|
80
|
-
|
81
|
-
['index', 'new', 'show', 'create', 'destroy'].each do |action|
|
82
|
-
assert action_methods.include? action
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
class DefaultsClassMethodTest < ActiveSupport::TestCase
|
89
|
-
def test_resource_class_is_set_to_nil_when_resource_model_cannot_be_found
|
90
|
-
assert_nil ReadersController.send(:resource_class)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_defaults_are_set
|
94
|
-
assert_equal Folder, FoldersController.send(:resource_class)
|
95
|
-
assert_equal :folder, FoldersController.send(:resources_configuration)[:self][:instance_name]
|
96
|
-
assert_equal :folders, FoldersController.send(:resources_configuration)[:self][:collection_name]
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_defaults_can_be_overwriten
|
100
|
-
BooksController.send(:defaults, :resource_class => String, :instance_name => 'string', :collection_name => 'strings')
|
101
|
-
|
102
|
-
assert_equal String, BooksController.send(:resource_class)
|
103
|
-
assert_equal :string, BooksController.send(:resources_configuration)[:self][:instance_name]
|
104
|
-
assert_equal :strings, BooksController.send(:resources_configuration)[:self][:collection_name]
|
105
|
-
|
106
|
-
BooksController.send(:defaults, :class_name => 'Fixnum', :instance_name => :fixnum, :collection_name => :fixnums)
|
107
|
-
|
108
|
-
assert_equal Fixnum, BooksController.send(:resource_class)
|
109
|
-
assert_equal :fixnum, BooksController.send(:resources_configuration)[:self][:instance_name]
|
110
|
-
assert_equal :fixnums, BooksController.send(:resources_configuration)[:self][:collection_name]
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_defaults_raises_invalid_key
|
114
|
-
assert_raise ArgumentError do
|
115
|
-
BooksController.send(:defaults, :boom => String)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_url_helpers_are_recreated_when_defaults_change
|
120
|
-
BooksController.expects(:create_resources_url_helpers!).returns(true).once
|
121
|
-
BooksController.send(:defaults, :instance_name => 'string', :collection_name => 'strings')
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
class BelongsToErrorsTest < ActiveSupport::TestCase
|
126
|
-
def test_belongs_to_raise_errors_with_invalid_arguments
|
127
|
-
assert_raise ArgumentError do
|
128
|
-
DeansController.send(:belongs_to)
|
129
|
-
end
|
130
|
-
|
131
|
-
assert_raise ArgumentError do
|
132
|
-
DeansController.send(:belongs_to, :nice, :invalid_key => '')
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_belongs_to_raises_an_error_when_multiple_associations_are_given_with_options
|
137
|
-
assert_raise ArgumentError do
|
138
|
-
DeansController.send(:belongs_to, :arguments, :with_options, :parent_class => Book)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_url_helpers_are_recreated_just_once_when_belongs_to_is_called_with_block
|
143
|
-
DeansController.expects(:create_resources_url_helpers!).returns(true).once
|
144
|
-
DeansController.send(:belongs_to, :school) do
|
145
|
-
belongs_to :association
|
146
|
-
end
|
147
|
-
ensure
|
148
|
-
DeansController.send(:parents_symbols=, [:school])
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_url_helpers_are_recreated_just_once_when_belongs_to_is_called_with_multiple_blocks
|
152
|
-
DeansController.expects(:create_resources_url_helpers!).returns(true).once
|
153
|
-
DeansController.send(:belongs_to, :school) do
|
154
|
-
belongs_to :association do
|
155
|
-
belongs_to :nested
|
156
|
-
end
|
157
|
-
end
|
158
|
-
ensure
|
159
|
-
DeansController.send(:parents_symbols=, [:school])
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_belongs_to_for_namespaced_controller_and_namespaced_model_fetches_model_in_the_namespace_firstly
|
163
|
-
Library::SubcategoriesController.send(:belongs_to, :category)
|
164
|
-
assert_equal Library::Category, Library::SubcategoriesController.resources_configuration[:category][:parent_class]
|
165
|
-
end
|
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
|
-
|
172
|
-
def test_belongs_to_without_namespace_sets_parent_class_properly
|
173
|
-
FoldersController.send(:belongs_to, :book)
|
174
|
-
assert_equal Book, FoldersController.resources_configuration[:book][:parent_class]
|
175
|
-
end
|
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
|
@@ -1,168 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class Car
|
4
|
-
extend ActiveModel::Naming
|
5
|
-
end
|
6
|
-
|
7
|
-
class CarsController < InheritedResources::Base
|
8
|
-
respond_to :html
|
9
|
-
|
10
|
-
protected
|
11
|
-
|
12
|
-
def collection
|
13
|
-
@cars ||= Car.get_all
|
14
|
-
end
|
15
|
-
|
16
|
-
def build_resource
|
17
|
-
@car ||= Car.create_new(params[:car])
|
18
|
-
end
|
19
|
-
|
20
|
-
def resource
|
21
|
-
@car ||= Car.get(params[:id])
|
22
|
-
end
|
23
|
-
|
24
|
-
def create_resource(resource)
|
25
|
-
resource.save_successfully
|
26
|
-
end
|
27
|
-
|
28
|
-
def update_resource(resource, attributes)
|
29
|
-
resource.update_successfully(*attributes)
|
30
|
-
end
|
31
|
-
|
32
|
-
def destroy_resource(resource)
|
33
|
-
resource.destroy_successfully
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
module CarTestHelper
|
38
|
-
def setup
|
39
|
-
@controller = CarsController.new
|
40
|
-
@controller.request = @request = ActionController::TestRequest.new
|
41
|
-
@controller.response = @response = ActionController::TestResponse.new
|
42
|
-
@controller.stubs(:car_url).returns("/")
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
def mock_car(expectations={})
|
47
|
-
@mock_car ||= begin
|
48
|
-
car = mock(expectations.except(:errors))
|
49
|
-
car.stubs(:class).returns(Car)
|
50
|
-
car.stubs(:errors).returns(expectations.fetch(:errors, {}))
|
51
|
-
car
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class IndexActionCustomizedBaseTest < ActionController::TestCase
|
57
|
-
include CarTestHelper
|
58
|
-
|
59
|
-
def test_expose_all_users_as_instance_variable
|
60
|
-
Car.expects(:get_all).returns([mock_car])
|
61
|
-
get :index
|
62
|
-
assert_equal [mock_car], assigns(:cars)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class ShowActionCustomizedBaseTest < ActionController::TestCase
|
67
|
-
include CarTestHelper
|
68
|
-
|
69
|
-
def test_expose_the_requested_user
|
70
|
-
Car.expects(:get).with('42').returns(mock_car)
|
71
|
-
get :show, :id => '42'
|
72
|
-
assert_equal mock_car, assigns(:car)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class NewActionCustomizedBaseTest < ActionController::TestCase
|
77
|
-
include CarTestHelper
|
78
|
-
|
79
|
-
def test_expose_a_new_user
|
80
|
-
Car.expects(:create_new).returns(mock_car)
|
81
|
-
get :new
|
82
|
-
assert_equal mock_car, assigns(:car)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
class EditActionCustomizedBaseTest < ActionController::TestCase
|
87
|
-
include CarTestHelper
|
88
|
-
|
89
|
-
def test_expose_the_requested_user
|
90
|
-
Car.expects(:get).with('42').returns(mock_car)
|
91
|
-
get :edit, :id => '42'
|
92
|
-
assert_response :success
|
93
|
-
assert_equal mock_car, assigns(:car)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
class CreateActionCustomizedBaseTest < ActionController::TestCase
|
98
|
-
include CarTestHelper
|
99
|
-
|
100
|
-
def test_expose_a_newly_create_user_when_saved_with_success
|
101
|
-
Car.expects(:create_new).with({'these' => 'params'}).returns(mock_car(:save_successfully => true))
|
102
|
-
post :create, :car => {:these => 'params'}
|
103
|
-
assert_equal mock_car, assigns(:car)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_redirect_to_the_created_user
|
107
|
-
Car.stubs(:create_new).returns(mock_car(:save_successfully => true))
|
108
|
-
@controller.expects(:resource_url).returns('http://test.host/')
|
109
|
-
post :create
|
110
|
-
assert_redirected_to 'http://test.host/'
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_render_new_template_when_user_cannot_be_saved
|
114
|
-
Car.stubs(:create_new).returns(mock_car(:save_successfully => false, :errors => {:some => :error}))
|
115
|
-
post :create
|
116
|
-
assert_response :success
|
117
|
-
assert_equal "New HTML", @response.body.strip
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
class UpdateActionCustomizedBaseTest < ActionController::TestCase
|
122
|
-
include CarTestHelper
|
123
|
-
|
124
|
-
def test_update_the_requested_object
|
125
|
-
Car.expects(:get).with('42').returns(mock_car)
|
126
|
-
mock_car.expects(:update_successfully).with({'these' => 'params'}).returns(true)
|
127
|
-
put :update, :id => '42', :car => {:these => 'params'}
|
128
|
-
assert_equal mock_car, assigns(:car)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_redirect_to_the_created_user
|
132
|
-
Car.stubs(:get).returns(mock_car(:update_successfully => true))
|
133
|
-
@controller.expects(:resource_url).returns('http://test.host/')
|
134
|
-
put :update
|
135
|
-
assert_redirected_to 'http://test.host/'
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_render_edit_template_when_user_cannot_be_saved
|
139
|
-
Car.stubs(:get).returns(mock_car(:update_successfully => false, :errors => {:some => :error}))
|
140
|
-
put :update
|
141
|
-
assert_response :success
|
142
|
-
assert_equal "Edit HTML", @response.body.strip
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
class DestroyActionCustomizedBaseTest < ActionController::TestCase
|
147
|
-
include CarTestHelper
|
148
|
-
|
149
|
-
def test_the_requested_user_is_destroyed
|
150
|
-
Car.expects(:get).with('42').returns(mock_car)
|
151
|
-
mock_car.expects(:destroy_successfully)
|
152
|
-
delete :destroy, :id => '42'
|
153
|
-
assert_equal mock_car, assigns(:car)
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_show_flash_message_when_user_can_be_deleted
|
157
|
-
Car.stubs(:get).returns(mock_car(:destroy_successfully => true))
|
158
|
-
delete :destroy
|
159
|
-
assert_equal flash[:notice], 'Car was successfully destroyed.'
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_show_flash_message_when_cannot_be_deleted
|
163
|
-
Car.stubs(:get).returns(mock_car(:destroy_successfully => false, :errors => { :fail => true }))
|
164
|
-
delete :destroy
|
165
|
-
assert_equal flash[:alert], 'Car could not be destroyed.'
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|