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
@@ -1,76 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class GreatSchool
|
4
|
-
end
|
5
|
-
|
6
|
-
class Professor
|
7
|
-
def self.human_name; 'Professor'; end
|
8
|
-
end
|
9
|
-
|
10
|
-
class ProfessorsController < InheritedResources::Base
|
11
|
-
belongs_to :school, :parent_class => GreatSchool, :instance_name => :great_school,
|
12
|
-
:finder => :find_by_title!, :param => :school_title
|
13
|
-
end
|
14
|
-
|
15
|
-
class CustomizedBelongsToTest < ActionController::TestCase
|
16
|
-
tests ProfessorsController
|
17
|
-
|
18
|
-
def setup
|
19
|
-
GreatSchool.expects(:find_by_title!).with('nice').returns(mock_school(:professors => Professor))
|
20
|
-
@controller.stubs(:resource_url).returns('/')
|
21
|
-
@controller.stubs(:collection_url).returns('/')
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_expose_the_requested_school_with_chosen_instance_variable_on_index
|
25
|
-
Professor.stubs(:scoped).returns([mock_professor])
|
26
|
-
get :index, :school_title => 'nice'
|
27
|
-
assert_equal mock_school, assigns(:great_school)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_expose_the_requested_school_with_chosen_instance_variable_on_show
|
31
|
-
Professor.stubs(:find).returns(mock_professor)
|
32
|
-
get :show, :school_title => 'nice'
|
33
|
-
assert_equal mock_school, assigns(:great_school)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_expose_the_requested_school_with_chosen_instance_variable_on_new
|
37
|
-
Professor.stubs(:build).returns(mock_professor)
|
38
|
-
get :new, :school_title => 'nice'
|
39
|
-
assert_equal mock_school, assigns(:great_school)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_expose_the_requested_school_with_chosen_instance_variable_on_edit
|
43
|
-
Professor.stubs(:find).returns(mock_professor)
|
44
|
-
get :edit, :school_title => 'nice'
|
45
|
-
assert_equal mock_school, assigns(:great_school)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_expose_the_requested_school_with_chosen_instance_variable_on_create
|
49
|
-
Professor.stubs(:build).returns(mock_professor(:save => true))
|
50
|
-
post :create, :school_title => 'nice'
|
51
|
-
assert_equal mock_school, assigns(:great_school)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_expose_the_requested_school_with_chosen_instance_variable_on_update
|
55
|
-
Professor.stubs(:find).returns(mock_professor(:update_attributes => true))
|
56
|
-
put :update, :school_title => 'nice'
|
57
|
-
assert_equal mock_school, assigns(:great_school)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_expose_the_requested_school_with_chosen_instance_variable_on_destroy
|
61
|
-
Professor.stubs(:find).returns(mock_professor(:destroy => true))
|
62
|
-
delete :destroy, :school_title => 'nice'
|
63
|
-
assert_equal mock_school, assigns(:great_school)
|
64
|
-
end
|
65
|
-
|
66
|
-
protected
|
67
|
-
|
68
|
-
def mock_school(stubs={})
|
69
|
-
@mock_school ||= mock(stubs)
|
70
|
-
end
|
71
|
-
|
72
|
-
def mock_professor(stubs={})
|
73
|
-
@mock_professor ||= mock(stubs)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
@@ -1,32 +0,0 @@
|
|
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
DELETED
@@ -1,197 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class Malarz
|
4
|
-
def self.human_name; 'Painter'; end
|
5
|
-
|
6
|
-
def to_param
|
7
|
-
self.slug
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class PaintersController < InheritedResources::Base
|
12
|
-
defaults :instance_name => 'malarz', :collection_name => 'malarze',
|
13
|
-
:resource_class => Malarz, :route_prefix => nil,
|
14
|
-
:finder => :find_by_slug
|
15
|
-
end
|
16
|
-
|
17
|
-
class DefaultsTest < ActionController::TestCase
|
18
|
-
tests PaintersController
|
19
|
-
|
20
|
-
def setup
|
21
|
-
@controller.stubs(:resource_url).returns('/')
|
22
|
-
@controller.stubs(:collection_url).returns('/')
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_expose_all_painters_as_instance_variable
|
26
|
-
Malarz.expects(:scoped).returns([mock_painter])
|
27
|
-
get :index
|
28
|
-
assert_equal [mock_painter], assigns(:malarze)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_expose_the_requested_painter_on_show
|
32
|
-
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
|
33
|
-
get :show, :id => 'forty_two'
|
34
|
-
assert_equal mock_painter, assigns(:malarz)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_expose_a_new_painter
|
38
|
-
Malarz.expects(:new).returns(mock_painter)
|
39
|
-
get :new
|
40
|
-
assert_equal mock_painter, assigns(:malarz)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_expose_the_requested_painter_on_edit
|
44
|
-
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
|
45
|
-
get :edit, :id => 'forty_two'
|
46
|
-
assert_response :success
|
47
|
-
assert_equal mock_painter, assigns(:malarz)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_expose_a_newly_create_painter_when_saved_with_success
|
51
|
-
Malarz.expects(:new).with({'these' => 'params'}).returns(mock_painter(:save => true))
|
52
|
-
post :create, :malarz => {:these => 'params'}
|
53
|
-
assert_equal mock_painter, assigns(:malarz)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_update_the_requested_object
|
57
|
-
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
|
58
|
-
mock_painter.expects(:update_attributes).with({'these' => 'params'}).returns(true)
|
59
|
-
put :update, :id => 'forty_two', :malarz => {:these => 'params'}
|
60
|
-
assert_equal mock_painter, assigns(:malarz)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_the_requested_painter_is_destroyed
|
64
|
-
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
|
65
|
-
mock_painter.expects(:destroy)
|
66
|
-
delete :destroy, :id => 'forty_two'
|
67
|
-
assert_equal mock_painter, assigns(:malarz)
|
68
|
-
end
|
69
|
-
|
70
|
-
protected
|
71
|
-
def mock_painter(stubs={})
|
72
|
-
@mock_painter ||= mock(stubs)
|
73
|
-
end
|
74
|
-
end
|
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(:scoped).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, :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', :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
|
177
|
-
|
178
|
-
class User
|
179
|
-
end
|
180
|
-
class Admin::UsersController < InheritedResources::Base
|
181
|
-
end
|
182
|
-
class TwoPartNameModelForNamespacedController < ActionController::TestCase
|
183
|
-
tests Admin::UsersController
|
184
|
-
|
185
|
-
def setup
|
186
|
-
# make public so we can test it
|
187
|
-
Admin::UsersController.send(:public, *Admin::UsersController.protected_instance_methods)
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_that_it_picked_the_camelcased_model
|
191
|
-
assert_equal User, @controller.resource_class
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_that_it_got_the_rquest_params_right
|
195
|
-
assert_equal 'user', @controller.resources_configuration[:self][:request_name]
|
196
|
-
end
|
197
|
-
end
|
data/test/locales/en.yml
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
flash:
|
3
|
-
addresses:
|
4
|
-
create:
|
5
|
-
notice: "You created a new address close to <b>{{reference}}</b>."
|
6
|
-
update:
|
7
|
-
notice: "Nice! {{resource_name}} was updated with success!"
|
8
|
-
error: "Oh no! We could not update your address!"
|
9
|
-
admin:
|
10
|
-
actions:
|
11
|
-
create:
|
12
|
-
notice: "Admin notice message."
|
13
|
-
error: "Admin error message."
|
14
|
-
addresses:
|
15
|
-
create:
|
16
|
-
notice: "Admin, you created a new address close to <b>{{reference}}</b>."
|
17
|
-
|
@@ -1,369 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class Student; end
|
4
|
-
class Manager; end
|
5
|
-
class Employee; end
|
6
|
-
|
7
|
-
class Project
|
8
|
-
def self.human_name; "Project"; end
|
9
|
-
end
|
10
|
-
|
11
|
-
class ProjectsController < InheritedResources::Base
|
12
|
-
belongs_to :student, :manager, :employee, :optional => true
|
13
|
-
end
|
14
|
-
|
15
|
-
class MultipleNestedOptionalTest < ActionController::TestCase
|
16
|
-
tests ProjectsController
|
17
|
-
|
18
|
-
def setup
|
19
|
-
@controller.stubs(:resource_url).returns('/')
|
20
|
-
@controller.stubs(:collection_url).returns('/')
|
21
|
-
end
|
22
|
-
|
23
|
-
# INDEX
|
24
|
-
def test_expose_all_projects_as_instance_variable_with_student
|
25
|
-
Student.expects(:find).with('37').returns(mock_student)
|
26
|
-
mock_student.expects(:projects).returns(Project)
|
27
|
-
Project.expects(:scoped).returns([mock_project])
|
28
|
-
get :index, :student_id => '37'
|
29
|
-
assert_equal mock_student, assigns(:student)
|
30
|
-
assert_equal [mock_project], assigns(:projects)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_expose_all_projects_as_instance_variable_with_manager
|
34
|
-
Manager.expects(:find).with('38').returns(mock_manager)
|
35
|
-
mock_manager.expects(:projects).returns(Project)
|
36
|
-
Project.expects(:scoped).returns([mock_project])
|
37
|
-
get :index, :manager_id => '38'
|
38
|
-
assert_equal mock_manager, assigns(:manager)
|
39
|
-
assert_equal [mock_project], assigns(:projects)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_expose_all_projects_as_instance_variable_with_employee
|
43
|
-
Employee.expects(:find).with('666').returns(mock_employee)
|
44
|
-
mock_employee.expects(:projects).returns(Project)
|
45
|
-
Project.expects(:scoped).returns([mock_project])
|
46
|
-
get :index, :employee_id => '666'
|
47
|
-
assert_equal mock_employee, assigns(:employee)
|
48
|
-
assert_equal [mock_project], assigns(:projects)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_expose_all_projects_as_instance_variable_with_manager_and_employee
|
52
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
53
|
-
mock_manager.expects(:employees).returns(Employee)
|
54
|
-
Employee.expects(:find).with('42').returns(mock_employee)
|
55
|
-
mock_employee.expects(:projects).returns(Project)
|
56
|
-
Project.expects(:scoped).returns([mock_project])
|
57
|
-
get :index, :manager_id => '37', :employee_id => '42'
|
58
|
-
assert_equal mock_manager, assigns(:manager)
|
59
|
-
assert_equal mock_employee, assigns(:employee)
|
60
|
-
assert_equal [mock_project], assigns(:projects)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_expose_all_projects_as_instance_variable_without_parents
|
64
|
-
Project.expects(:scoped).returns([mock_project])
|
65
|
-
get :index
|
66
|
-
assert_equal [mock_project], assigns(:projects)
|
67
|
-
end
|
68
|
-
|
69
|
-
# SHOW
|
70
|
-
def test_expose_the_requested_project_with_student
|
71
|
-
Student.expects(:find).with('37').returns(mock_student)
|
72
|
-
mock_student.expects(:projects).returns(Project)
|
73
|
-
Project.expects(:find).with('42').returns(mock_project)
|
74
|
-
get :show, :id => '42', :student_id => '37'
|
75
|
-
assert_equal mock_student, assigns(:student)
|
76
|
-
assert_equal mock_project, assigns(:project)
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_expose_the_requested_project_with_manager
|
80
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
81
|
-
mock_manager.expects(:projects).returns(Project)
|
82
|
-
Project.expects(:find).with('42').returns(mock_project)
|
83
|
-
get :show, :id => '42', :manager_id => '37'
|
84
|
-
assert_equal mock_manager, assigns(:manager)
|
85
|
-
assert_equal mock_project, assigns(:project)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_expose_the_requested_project_with_employee
|
89
|
-
Employee.expects(:find).with('37').returns(mock_employee)
|
90
|
-
mock_employee.expects(:projects).returns(Project)
|
91
|
-
Project.expects(:find).with('42').returns(mock_project)
|
92
|
-
get :show, :id => '42', :employee_id => '37'
|
93
|
-
assert_equal mock_employee, assigns(:employee)
|
94
|
-
assert_equal mock_project, assigns(:project)
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_expose_the_requested_project_with_manager_and_employee
|
98
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
99
|
-
mock_manager.expects(:employees).returns(Employee)
|
100
|
-
Employee.expects(:find).with('42').returns(mock_employee)
|
101
|
-
mock_employee.expects(:projects).returns(Project)
|
102
|
-
Project.expects(:find).with('13').returns(mock_project)
|
103
|
-
get :show, :id => '13', :manager_id => '37', :employee_id => '42'
|
104
|
-
assert_equal mock_manager, assigns(:manager)
|
105
|
-
assert_equal mock_employee, assigns(:employee)
|
106
|
-
assert_equal mock_project, assigns(:project)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_expose_the_requested_project_without_parents
|
110
|
-
Project.expects(:find).with('13').returns(mock_project)
|
111
|
-
get :show, :id => '13'
|
112
|
-
assert_equal mock_project, assigns(:project)
|
113
|
-
end
|
114
|
-
|
115
|
-
# NEW
|
116
|
-
def test_expose_a_new_project_with_student
|
117
|
-
Student.expects(:find).with('37').returns(mock_student)
|
118
|
-
mock_student.expects(:projects).returns(Project)
|
119
|
-
Project.expects(:build).returns(mock_project)
|
120
|
-
get :new, :student_id => '37'
|
121
|
-
assert_equal mock_student, assigns(:student)
|
122
|
-
assert_equal mock_project, assigns(:project)
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_expose_a_new_project_with_manager
|
126
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
127
|
-
mock_manager.expects(:projects).returns(Project)
|
128
|
-
Project.expects(:build).returns(mock_project)
|
129
|
-
get :new, :manager_id => '37'
|
130
|
-
assert_equal mock_manager, assigns(:manager)
|
131
|
-
assert_equal mock_project, assigns(:project)
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_expose_a_new_project_with_employee
|
135
|
-
Employee.expects(:find).with('37').returns(mock_employee)
|
136
|
-
mock_employee.expects(:projects).returns(Project)
|
137
|
-
Project.expects(:build).returns(mock_project)
|
138
|
-
get :new, :employee_id => '37'
|
139
|
-
assert_equal mock_employee, assigns(:employee)
|
140
|
-
assert_equal mock_project, assigns(:project)
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_expose_a_new_project_with_manager_and_employee
|
144
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
145
|
-
mock_manager.expects(:employees).returns(Employee)
|
146
|
-
Employee.expects(:find).with('42').returns(mock_employee)
|
147
|
-
mock_employee.expects(:projects).returns(Project)
|
148
|
-
Project.expects(:build).returns(mock_project)
|
149
|
-
get :new, :manager_id => '37', :employee_id => '42'
|
150
|
-
assert_equal mock_manager, assigns(:manager)
|
151
|
-
assert_equal mock_employee, assigns(:employee)
|
152
|
-
assert_equal mock_project, assigns(:project)
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_expose_a_new_project_without_parents
|
156
|
-
Project.expects(:new).returns(mock_project)
|
157
|
-
get :new
|
158
|
-
assert_equal mock_project, assigns(:project)
|
159
|
-
end
|
160
|
-
|
161
|
-
# EDIT
|
162
|
-
def test_expose_the_requested_project_for_edition_with_student
|
163
|
-
Student.expects(:find).with('37').returns(mock_student)
|
164
|
-
mock_student.expects(:projects).returns(Project)
|
165
|
-
Project.expects(:find).with('42').returns(mock_project)
|
166
|
-
get :edit, :id => '42', :student_id => '37'
|
167
|
-
assert_equal mock_student, assigns(:student)
|
168
|
-
assert_equal mock_project, assigns(:project)
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_expose_the_requested_project_for_edition_with_manager
|
172
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
173
|
-
mock_manager.expects(:projects).returns(Project)
|
174
|
-
Project.expects(:find).with('42').returns(mock_project)
|
175
|
-
get :edit, :id => '42', :manager_id => '37'
|
176
|
-
assert_equal mock_manager, assigns(:manager)
|
177
|
-
assert_equal mock_project, assigns(:project)
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_expose_the_requested_project_for_edition_with_employee
|
181
|
-
Employee.expects(:find).with('37').returns(mock_employee)
|
182
|
-
mock_employee.expects(:projects).returns(Project)
|
183
|
-
Project.expects(:find).with('42').returns(mock_project)
|
184
|
-
get :edit, :id => '42', :employee_id => '37'
|
185
|
-
assert_equal mock_employee, assigns(:employee)
|
186
|
-
assert_equal mock_project, assigns(:project)
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_expose_the_requested_project_for_edition_with_manager_and_employee
|
190
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
191
|
-
mock_manager.expects(:employees).returns(Employee)
|
192
|
-
Employee.expects(:find).with('42').returns(mock_employee)
|
193
|
-
mock_employee.expects(:projects).returns(Project)
|
194
|
-
Project.expects(:find).with('13').returns(mock_project)
|
195
|
-
get :edit, :id => '13', :manager_id => '37', :employee_id => '42'
|
196
|
-
assert_equal mock_manager, assigns(:manager)
|
197
|
-
assert_equal mock_employee, assigns(:employee)
|
198
|
-
assert_equal mock_project, assigns(:project)
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_expose_the_requested_project_for_edition_without_parents
|
202
|
-
Project.expects(:find).with('13').returns(mock_project)
|
203
|
-
get :edit, :id => '13'
|
204
|
-
assert_equal mock_project, assigns(:project)
|
205
|
-
end
|
206
|
-
|
207
|
-
# CREATE
|
208
|
-
def test_expose_a_newly_created_project_with_student
|
209
|
-
Student.expects(:find).with('37').returns(mock_student)
|
210
|
-
mock_student.expects(:projects).returns(Project)
|
211
|
-
Project.expects(:build).with({ 'these' => 'params' }).returns(mock_project(:save => true))
|
212
|
-
post :create, :student_id => '37', :project => { :these => 'params' }
|
213
|
-
assert_equal mock_student, assigns(:student)
|
214
|
-
assert_equal mock_project, assigns(:project)
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_expose_a_newly_created_project_with_manager
|
218
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
219
|
-
mock_manager.expects(:projects).returns(Project)
|
220
|
-
Project.expects(:build).with({ 'these' => 'params' }).returns(mock_project(:save => true))
|
221
|
-
post :create, :manager_id => '37', :project => { :these => 'params' }
|
222
|
-
assert_equal mock_manager, assigns(:manager)
|
223
|
-
assert_equal mock_project, assigns(:project)
|
224
|
-
end
|
225
|
-
|
226
|
-
def test_expose_a_newly_created_project_with_employee
|
227
|
-
Employee.expects(:find).with('37').returns(mock_employee)
|
228
|
-
mock_employee.expects(:projects).returns(Project)
|
229
|
-
Project.expects(:build).with({ 'these' => 'params' }).returns(mock_project(:save => true))
|
230
|
-
post :create, :employee_id => '37', :project => { :these => 'params' }
|
231
|
-
assert_equal mock_employee, assigns(:employee)
|
232
|
-
assert_equal mock_project, assigns(:project)
|
233
|
-
end
|
234
|
-
|
235
|
-
def test_expose_a_newly_created_project_with_manager_and_employee
|
236
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
237
|
-
mock_manager.expects(:employees).returns(Employee)
|
238
|
-
Employee.expects(:find).with('42').returns(mock_employee)
|
239
|
-
mock_employee.expects(:projects).returns(Project)
|
240
|
-
Project.expects(:build).with({ 'these' => 'params' }).returns(mock_project(:save => true))
|
241
|
-
post :create, :manager_id => '37', :employee_id => '42', :project => { :these => 'params' }
|
242
|
-
assert_equal mock_manager, assigns(:manager)
|
243
|
-
assert_equal mock_employee, assigns(:employee)
|
244
|
-
assert_equal mock_project, assigns(:project)
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_expose_a_newly_created_project_without_parents
|
248
|
-
Project.expects(:new).with({ 'these' => 'params' }).returns(mock_project(:save => true))
|
249
|
-
post :create, :project => { :these => 'params' }
|
250
|
-
assert_equal mock_project, assigns(:project)
|
251
|
-
end
|
252
|
-
|
253
|
-
# UPDATE
|
254
|
-
def test_update_the_requested_project_with_student
|
255
|
-
Student.expects(:find).with('37').returns(mock_student)
|
256
|
-
mock_student.expects(:projects).returns(Project)
|
257
|
-
Project.expects(:find).with('42').returns(mock_project)
|
258
|
-
mock_project.expects(:update_attributes).with({ 'these' => 'params' }).returns(true)
|
259
|
-
put :update, :id => '42', :student_id => '37', :project => { :these => 'params' }
|
260
|
-
assert_equal mock_student, assigns(:student)
|
261
|
-
assert_equal mock_project, assigns(:project)
|
262
|
-
end
|
263
|
-
|
264
|
-
def test_update_the_requested_project_with_manager
|
265
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
266
|
-
mock_manager.expects(:projects).returns(Project)
|
267
|
-
Project.expects(:find).with('42').returns(mock_project)
|
268
|
-
mock_project.expects(:update_attributes).with({ 'these' => 'params' }).returns(true)
|
269
|
-
put :update, :id => '42', :manager_id => '37', :project => { :these => 'params' }
|
270
|
-
assert_equal mock_manager, assigns(:manager)
|
271
|
-
assert_equal mock_project, assigns(:project)
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_update_the_requested_project_with_employee
|
275
|
-
Employee.expects(:find).with('37').returns(mock_employee)
|
276
|
-
mock_employee.expects(:projects).returns(Project)
|
277
|
-
Project.expects(:find).with('42').returns(mock_project)
|
278
|
-
mock_project.expects(:update_attributes).with({ 'these' => 'params' }).returns(true)
|
279
|
-
put :update, :id => '42', :employee_id => '37', :project => { :these => 'params' }
|
280
|
-
assert_equal mock_employee, assigns(:employee)
|
281
|
-
assert_equal mock_project, assigns(:project)
|
282
|
-
end
|
283
|
-
|
284
|
-
def test_update_the_requested_project_with_manager_and_employee
|
285
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
286
|
-
mock_manager.expects(:employees).returns(Employee)
|
287
|
-
Employee.expects(:find).with('13').returns(mock_employee)
|
288
|
-
mock_employee.expects(:projects).returns(Project)
|
289
|
-
Project.expects(:find).with('42').returns(mock_project)
|
290
|
-
mock_project.expects(:update_attributes).with({ 'these' => 'params' }).returns(true)
|
291
|
-
put :update, :id => '42', :manager_id => '37', :employee_id => '13', :project => { :these => 'params' }
|
292
|
-
assert_equal mock_manager, assigns(:manager)
|
293
|
-
assert_equal mock_employee, assigns(:employee)
|
294
|
-
assert_equal mock_project, assigns(:project)
|
295
|
-
end
|
296
|
-
|
297
|
-
# DESTROY
|
298
|
-
def test_the_requested_project_is_destroyed_with_student
|
299
|
-
Student.expects(:find).with('37').returns(mock_student)
|
300
|
-
mock_student.expects(:projects).returns(Project)
|
301
|
-
Project.expects(:find).with('42').returns(mock_project)
|
302
|
-
mock_project.expects(:destroy).returns(true)
|
303
|
-
|
304
|
-
delete :destroy, :id => '42', :student_id => '37'
|
305
|
-
assert_equal mock_student, assigns(:student)
|
306
|
-
assert_equal mock_project, assigns(:project)
|
307
|
-
end
|
308
|
-
|
309
|
-
def test_the_requested_project_is_destroyed_with_manager
|
310
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
311
|
-
mock_manager.expects(:projects).returns(Project)
|
312
|
-
Project.expects(:find).with('42').returns(mock_project)
|
313
|
-
mock_project.expects(:destroy).returns(true)
|
314
|
-
|
315
|
-
delete :destroy, :id => '42', :manager_id => '37'
|
316
|
-
assert_equal mock_manager, assigns(:manager)
|
317
|
-
assert_equal mock_project, assigns(:project)
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_the_requested_project_is_destroyed_with_employee
|
321
|
-
Employee.expects(:find).with('37').returns(mock_employee)
|
322
|
-
mock_employee.expects(:projects).returns(Project)
|
323
|
-
Project.expects(:find).with('42').returns(mock_project)
|
324
|
-
mock_project.expects(:destroy).returns(true)
|
325
|
-
|
326
|
-
delete :destroy, :id => '42', :employee_id => '37'
|
327
|
-
assert_equal mock_employee, assigns(:employee)
|
328
|
-
assert_equal mock_project, assigns(:project)
|
329
|
-
end
|
330
|
-
|
331
|
-
def test_the_requested_project_is_destroyed_with_manager_and_employee
|
332
|
-
Manager.expects(:find).with('37').returns(mock_manager)
|
333
|
-
mock_manager.expects(:employees).returns(Employee)
|
334
|
-
Employee.expects(:find).with('13').returns(mock_employee)
|
335
|
-
mock_employee.expects(:projects).returns(Project)
|
336
|
-
Project.expects(:find).with('42').returns(mock_project)
|
337
|
-
mock_project.expects(:destroy).returns(true)
|
338
|
-
|
339
|
-
delete :destroy, :id => '42', :manager_id => '37', :employee_id => '13'
|
340
|
-
assert_equal mock_manager, assigns(:manager)
|
341
|
-
assert_equal mock_employee, assigns(:employee)
|
342
|
-
assert_equal mock_project, assigns(:project)
|
343
|
-
end
|
344
|
-
|
345
|
-
def test_the_requested_project_is_destroyed_without_parents
|
346
|
-
Project.expects(:find).with('42').returns(mock_project)
|
347
|
-
mock_project.expects(:destroy).returns(true)
|
348
|
-
|
349
|
-
delete :destroy, :id => '42'
|
350
|
-
assert_equal mock_project, assigns(:project)
|
351
|
-
end
|
352
|
-
|
353
|
-
protected
|
354
|
-
def mock_manager(stubs={})
|
355
|
-
@mock_manager ||= mock(stubs)
|
356
|
-
end
|
357
|
-
|
358
|
-
def mock_employee(stubs={})
|
359
|
-
@mock_employee ||= mock(stubs)
|
360
|
-
end
|
361
|
-
|
362
|
-
def mock_student(stubs={})
|
363
|
-
@mock_student ||= mock(stubs)
|
364
|
-
end
|
365
|
-
|
366
|
-
def mock_project(stubs={})
|
367
|
-
@mock_project ||= mock(stubs)
|
368
|
-
end
|
369
|
-
end
|