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,108 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class Country
|
4
|
-
end
|
5
|
-
|
6
|
-
class State
|
7
|
-
end
|
8
|
-
|
9
|
-
class City
|
10
|
-
def self.human_name; 'City'; end
|
11
|
-
end
|
12
|
-
|
13
|
-
class CitiesController < InheritedResources::Base
|
14
|
-
belongs_to :country, :state
|
15
|
-
end
|
16
|
-
|
17
|
-
class NestedBelongsToTest < ActionController::TestCase
|
18
|
-
tests CitiesController
|
19
|
-
|
20
|
-
def setup
|
21
|
-
Country.expects(:find).with('13').returns(mock_country)
|
22
|
-
mock_country.expects(:states).returns(State)
|
23
|
-
State.expects(:find).with('37').returns(mock_state)
|
24
|
-
mock_state.expects(:cities).returns(City)
|
25
|
-
|
26
|
-
@controller.stubs(:resource_url).returns('/')
|
27
|
-
@controller.stubs(:collection_url).returns('/')
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_assigns_country_and_state_and_city_on_create
|
31
|
-
City.expects(:find).with(:all).returns([mock_city])
|
32
|
-
get :index, :state_id => '37', :country_id => '13'
|
33
|
-
|
34
|
-
assert_equal mock_country, assigns(:country)
|
35
|
-
assert_equal mock_state, assigns(:state)
|
36
|
-
assert_equal [mock_city], assigns(:cities)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_assigns_country_and_state_and_city_on_show
|
40
|
-
City.expects(:find).with('42').returns(mock_city)
|
41
|
-
get :show, :id => '42', :state_id => '37', :country_id => '13'
|
42
|
-
|
43
|
-
assert_equal mock_country, assigns(:country)
|
44
|
-
assert_equal mock_state, assigns(:state)
|
45
|
-
assert_equal mock_city, assigns(:city)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_assigns_country_and_state_and_city_on_new
|
49
|
-
City.expects(:build).returns(mock_city)
|
50
|
-
get :new, :state_id => '37', :country_id => '13'
|
51
|
-
|
52
|
-
assert_equal mock_country, assigns(:country)
|
53
|
-
assert_equal mock_state, assigns(:state)
|
54
|
-
assert_equal mock_city, assigns(:city)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_assigns_country_and_state_and_city_on_edit
|
58
|
-
City.expects(:find).with('42').returns(mock_city)
|
59
|
-
get :edit, :id => '42', :state_id => '37', :country_id => '13'
|
60
|
-
|
61
|
-
assert_equal mock_country, assigns(:country)
|
62
|
-
assert_equal mock_state, assigns(:state)
|
63
|
-
assert_equal mock_city, assigns(:city)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_assigns_country_and_state_and_city_on_create
|
67
|
-
City.expects(:build).with({'these' => 'params'}).returns(mock_city)
|
68
|
-
mock_city.expects(:save).returns(true)
|
69
|
-
post :create, :state_id => '37', :country_id => '13', :city => {:these => 'params'}
|
70
|
-
|
71
|
-
assert_equal mock_country, assigns(:country)
|
72
|
-
assert_equal mock_state, assigns(:state)
|
73
|
-
assert_equal mock_city, assigns(:city)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_assigns_country_and_state_and_city_on_update
|
77
|
-
City.expects(:find).with('42').returns(mock_city)
|
78
|
-
mock_city.expects(:update_attributes).returns(true)
|
79
|
-
put :update, :id => '42', :state_id => '37', :country_id => '13', :city => {:these => 'params'}
|
80
|
-
|
81
|
-
assert_equal mock_country, assigns(:country)
|
82
|
-
assert_equal mock_state, assigns(:state)
|
83
|
-
assert_equal mock_city, assigns(:city)
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_assigns_country_and_state_and_city_on_destroy
|
87
|
-
City.expects(:find).with('42').returns(mock_city)
|
88
|
-
mock_city.expects(:destroy)
|
89
|
-
delete :destroy, :id => '42', :state_id => '37', :country_id => '13'
|
90
|
-
|
91
|
-
assert_equal mock_country, assigns(:country)
|
92
|
-
assert_equal mock_state, assigns(:state)
|
93
|
-
assert_equal mock_city, assigns(:city)
|
94
|
-
end
|
95
|
-
|
96
|
-
protected
|
97
|
-
def mock_country(stubs={})
|
98
|
-
@mock_country ||= mock(stubs)
|
99
|
-
end
|
100
|
-
|
101
|
-
def mock_state(stubs={})
|
102
|
-
@mock_state ||= mock(stubs)
|
103
|
-
end
|
104
|
-
|
105
|
-
def mock_city(stubs={})
|
106
|
-
@mock_city ||= mock(stubs)
|
107
|
-
end
|
108
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class Dresser
|
4
|
-
end
|
5
|
-
|
6
|
-
class Shelf
|
7
|
-
end
|
8
|
-
|
9
|
-
class Plate
|
10
|
-
end
|
11
|
-
|
12
|
-
class PlatesController < InheritedResources::Base
|
13
|
-
belongs_to :dresser, :shelf, :shallow => true
|
14
|
-
end
|
15
|
-
|
16
|
-
class NestedBelongsToWithShallowTest < ActionController::TestCase
|
17
|
-
tests PlatesController
|
18
|
-
|
19
|
-
def setup
|
20
|
-
mock_shelf.expects(:dresser).returns(mock_dresser)
|
21
|
-
mock_dresser.expects(:to_param).returns('13')
|
22
|
-
|
23
|
-
Dresser.expects(:find).with('13').returns(mock_dresser)
|
24
|
-
mock_dresser.expects(:shelves).returns(Shelf)
|
25
|
-
mock_shelf.expects(:plates).returns(Plate)
|
26
|
-
|
27
|
-
@controller.stubs(:resource_url).returns('/')
|
28
|
-
@controller.stubs(:collection_url).returns('/')
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_assigns_dresser_and_shelf_and_plate_on_index
|
32
|
-
Shelf.expects(:find).with('37').twice.returns(mock_shelf)
|
33
|
-
Plate.expects(:scoped).returns([mock_plate])
|
34
|
-
get :index, :shelf_id => '37'
|
35
|
-
|
36
|
-
assert_equal mock_dresser, assigns(:dresser)
|
37
|
-
assert_equal mock_shelf, assigns(:shelf)
|
38
|
-
assert_equal [mock_plate], assigns(:plates)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_assigns_dresser_and_shelf_and_plate_on_show
|
42
|
-
should_find_parents
|
43
|
-
get :show, :id => '42'
|
44
|
-
|
45
|
-
assert_equal mock_dresser, assigns(:dresser)
|
46
|
-
assert_equal mock_shelf, assigns(:shelf)
|
47
|
-
assert_equal mock_plate, assigns(:plate)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_assigns_dresser_and_shelf_and_plate_on_new
|
51
|
-
Plate.expects(:build).returns(mock_plate)
|
52
|
-
Shelf.expects(:find).with('37').twice.returns(mock_shelf)
|
53
|
-
get :new, :shelf_id => '37'
|
54
|
-
|
55
|
-
assert_equal mock_dresser, assigns(:dresser)
|
56
|
-
assert_equal mock_shelf, assigns(:shelf)
|
57
|
-
assert_equal mock_plate, assigns(:plate)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_assigns_dresser_and_shelf_and_plate_on_edit
|
61
|
-
should_find_parents
|
62
|
-
get :edit, :id => '42'
|
63
|
-
|
64
|
-
assert_equal mock_dresser, assigns(:dresser)
|
65
|
-
assert_equal mock_shelf, assigns(:shelf)
|
66
|
-
assert_equal mock_plate, assigns(:plate)
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
def test_assigns_dresser_and_shelf_and_plate_on_create
|
71
|
-
Shelf.expects(:find).with('37').twice.returns(mock_shelf)
|
72
|
-
|
73
|
-
Plate.expects(:build).with({'these' => 'params'}).returns(mock_plate)
|
74
|
-
mock_plate.expects(:save).returns(true)
|
75
|
-
post :create, :shelf_id => '37', :plate => {:these => 'params'}
|
76
|
-
|
77
|
-
assert_equal mock_dresser, assigns(:dresser)
|
78
|
-
assert_equal mock_shelf, assigns(:shelf)
|
79
|
-
assert_equal mock_plate, assigns(:plate)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_assigns_dresser_and_shelf_and_plate_on_update
|
83
|
-
should_find_parents
|
84
|
-
mock_plate.expects(:update_attributes).returns(true)
|
85
|
-
put :update, :id => '42', :plate => {:these => 'params'}
|
86
|
-
|
87
|
-
assert_equal mock_dresser, assigns(:dresser)
|
88
|
-
assert_equal mock_shelf, assigns(:shelf)
|
89
|
-
assert_equal mock_plate, assigns(:plate)
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_assigns_dresser_and_shelf_and_plate_on_destroy
|
93
|
-
should_find_parents
|
94
|
-
mock_plate.expects(:destroy)
|
95
|
-
delete :destroy, :id => '42'
|
96
|
-
|
97
|
-
assert_equal mock_dresser, assigns(:dresser)
|
98
|
-
assert_equal mock_shelf, assigns(:shelf)
|
99
|
-
assert_equal mock_plate, assigns(:plate)
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
protected
|
104
|
-
def should_find_parents
|
105
|
-
Plate.expects(:find).with('42').returns(mock_plate)
|
106
|
-
mock_plate.expects(:shelf).returns(mock_shelf)
|
107
|
-
mock_shelf.expects(:to_param).returns('37')
|
108
|
-
Plate.expects(:find).with('42').returns(mock_plate)
|
109
|
-
Shelf.expects(:find).with('37').returns(mock_shelf)
|
110
|
-
end
|
111
|
-
|
112
|
-
def mock_dresser(stubs={})
|
113
|
-
@mock_dresser ||= mock(stubs)
|
114
|
-
end
|
115
|
-
|
116
|
-
def mock_shelf(stubs={})
|
117
|
-
@mock_shelf ||= mock(stubs)
|
118
|
-
end
|
119
|
-
|
120
|
-
def mock_plate(stubs={})
|
121
|
-
@mock_plate ||= mock(stubs)
|
122
|
-
end
|
123
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class Subfaculty
|
4
|
-
end
|
5
|
-
|
6
|
-
class Speciality
|
7
|
-
end
|
8
|
-
|
9
|
-
module Plan
|
10
|
-
class Group
|
11
|
-
end
|
12
|
-
|
13
|
-
class Education
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class GroupsController < InheritedResources::Base
|
18
|
-
defaults :resource_class => Plan::Group, :finder => :find_by_slug
|
19
|
-
belongs_to :subfaculty, :shallow => true do
|
20
|
-
belongs_to :speciality
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class EducationsController < InheritedResources::Base
|
25
|
-
defaults :resource_class => Plan::Education
|
26
|
-
belongs_to :subfaculty, :shallow => true do
|
27
|
-
belongs_to :speciality do
|
28
|
-
belongs_to :group, :parent_class => Plan::Group,
|
29
|
-
:instance_name => :plan_group,
|
30
|
-
:param => :group_id,
|
31
|
-
:finder => :find_by_slug
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class NestedModelWithShallowTest < ActionController::TestCase
|
37
|
-
tests GroupsController
|
38
|
-
|
39
|
-
def setup
|
40
|
-
mock_speciality.expects(:subfaculty).returns(mock_subfaculty)
|
41
|
-
mock_subfaculty.expects(:to_param).returns('13')
|
42
|
-
|
43
|
-
Subfaculty.expects(:find).with('13').returns(mock_subfaculty)
|
44
|
-
mock_subfaculty.expects(:specialities).returns(Speciality)
|
45
|
-
mock_speciality.expects(:groups).returns(Plan::Group)
|
46
|
-
|
47
|
-
@controller.stubs(:resource_url).returns('/')
|
48
|
-
@controller.stubs(:collection_url).returns('/')
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_assigns_subfaculty_and_speciality_and_group_on_edit
|
52
|
-
should_find_parents
|
53
|
-
get :edit, :id => 'forty_two'
|
54
|
-
|
55
|
-
assert_equal mock_subfaculty, assigns(:subfaculty)
|
56
|
-
assert_equal mock_speciality, assigns(:speciality)
|
57
|
-
assert_equal mock_group, assigns(:group)
|
58
|
-
end
|
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
|
-
|
74
|
-
protected
|
75
|
-
def should_find_parents
|
76
|
-
Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
|
77
|
-
mock_group.expects(:speciality).returns(mock_speciality)
|
78
|
-
mock_speciality.expects(:to_param).returns('37')
|
79
|
-
Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
|
80
|
-
Speciality.expects(:find).with('37').returns(mock_speciality)
|
81
|
-
end
|
82
|
-
|
83
|
-
def mock_group(stubs={})
|
84
|
-
@mock_group ||= mock(stubs)
|
85
|
-
end
|
86
|
-
|
87
|
-
def mock_speciality(stubs={})
|
88
|
-
@mock_speciality ||= mock(stubs)
|
89
|
-
end
|
90
|
-
|
91
|
-
def mock_subfaculty(stubs={})
|
92
|
-
@mock_subfaculty ||= mock(stubs)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
class TwoNestedModelWithShallowTest < ActionController::TestCase
|
97
|
-
tests EducationsController
|
98
|
-
|
99
|
-
def setup
|
100
|
-
mock_speciality.expects(:subfaculty).returns(mock_subfaculty)
|
101
|
-
mock_subfaculty.expects(:to_param).returns('13')
|
102
|
-
Subfaculty.expects(:find).with('13').returns(mock_subfaculty)
|
103
|
-
mock_subfaculty.expects(:specialities).returns(Speciality)
|
104
|
-
mock_speciality.expects(:groups).returns(Plan::Group)
|
105
|
-
|
106
|
-
@controller.stubs(:resource_url).returns('/')
|
107
|
-
@controller.stubs(:collection_url).returns('/')
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_assigns_subfaculty_and_speciality_and_group_on_new
|
111
|
-
should_find_parents
|
112
|
-
get :new, :group_id => 'forty_two'
|
113
|
-
|
114
|
-
assert_equal mock_subfaculty, assigns(:subfaculty)
|
115
|
-
assert_equal mock_speciality, assigns(:speciality)
|
116
|
-
assert_equal mock_group, assigns(:plan_group)
|
117
|
-
assert_equal mock_education, assigns(:education)
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
protected
|
122
|
-
def should_find_parents
|
123
|
-
Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
|
124
|
-
mock_group.expects(:speciality).returns(mock_speciality)
|
125
|
-
mock_group.expects(:educations).returns(mock_education)
|
126
|
-
mock_education.expects(:build).returns(mock_education)
|
127
|
-
mock_speciality.expects(:to_param).returns('37')
|
128
|
-
Plan::Group.expects(:find_by_slug).with('forty_two').returns(mock_group)
|
129
|
-
Speciality.expects(:find).with('37').returns(mock_speciality)
|
130
|
-
end
|
131
|
-
|
132
|
-
def mock_group(stubs={})
|
133
|
-
@mock_group ||= mock(stubs)
|
134
|
-
end
|
135
|
-
|
136
|
-
def mock_education(stubs={})
|
137
|
-
@mock_education ||= mock(stubs)
|
138
|
-
end
|
139
|
-
|
140
|
-
def mock_speciality(stubs={})
|
141
|
-
@mock_speciality ||= mock(stubs)
|
142
|
-
end
|
143
|
-
|
144
|
-
def mock_subfaculty(stubs={})
|
145
|
-
@mock_subfaculty ||= mock(stubs)
|
146
|
-
end
|
147
|
-
end
|
@@ -1,167 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
# This test file is instead to test the how controller flow and actions
|
4
|
-
# using a belongs_to association. This is done using mocks a la rspec.
|
5
|
-
#
|
6
|
-
class Party
|
7
|
-
extend ActiveModel::Naming
|
8
|
-
end
|
9
|
-
|
10
|
-
class Venue
|
11
|
-
extend ActiveModel::Naming
|
12
|
-
end
|
13
|
-
|
14
|
-
class Address
|
15
|
-
extend ActiveModel::Naming
|
16
|
-
end
|
17
|
-
|
18
|
-
ActiveSupport::Inflector.inflections do |inflect|
|
19
|
-
inflect.singular "address", "address"
|
20
|
-
inflect.plural "address", "addresses"
|
21
|
-
end
|
22
|
-
|
23
|
-
class VenueController < InheritedResources::Base
|
24
|
-
defaults :singleton => true
|
25
|
-
belongs_to :party
|
26
|
-
end
|
27
|
-
|
28
|
-
# for the slightly pathological
|
29
|
-
# /party/37/venue/address case
|
30
|
-
class AddressController < InheritedResources::Base
|
31
|
-
defaults :singleton => true
|
32
|
-
belongs_to :venue, :singleton => true do
|
33
|
-
belongs_to :party
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
#and the more pathological case
|
38
|
-
class GeolocationController < InheritedResources::Base
|
39
|
-
defaults :singleton => true
|
40
|
-
belongs_to :address, :singleton => true do
|
41
|
-
belongs_to :venue, :singleton => true do
|
42
|
-
belongs_to :party
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class NestedSingletonTest < ActionController::TestCase
|
48
|
-
tests AddressController
|
49
|
-
|
50
|
-
def setup
|
51
|
-
@controller.stubs(:resource_url).returns('/')
|
52
|
-
@controller.stubs(:collection_url).returns('/')
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_does_not_break_parent_controller
|
56
|
-
#this is kind of tacky, but seems to work
|
57
|
-
old_controller = @controller
|
58
|
-
@controller = VenueController.new
|
59
|
-
Party.expects(:find).with('37').returns(mock_party)
|
60
|
-
mock_party.expects(:venue).returns(mock_venue)
|
61
|
-
get :show, :party_id => '37'
|
62
|
-
assert_equal mock_party, assigns(:party)
|
63
|
-
assert_equal mock_venue, assigns(:venue)
|
64
|
-
ensure
|
65
|
-
@controller = old_controller
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_does_not_break_child_controller
|
69
|
-
#this is kind of tacky, but seems to work
|
70
|
-
old_controller = @controller
|
71
|
-
@controller = GeolocationController.new
|
72
|
-
Party.expects(:find).with('37').returns(mock_party)
|
73
|
-
mock_party.expects(:venue).returns(mock_venue)
|
74
|
-
mock_venue.expects(:address).returns(mock_address)
|
75
|
-
mock_address.expects(:geolocation).returns(mock_geolocation)
|
76
|
-
get :show, :party_id => '37'
|
77
|
-
assert_equal mock_party, assigns(:party)
|
78
|
-
assert_equal mock_venue, assigns(:venue)
|
79
|
-
assert_equal mock_address, assigns(:address)
|
80
|
-
assert_equal mock_geolocation, assigns(:geolocation)
|
81
|
-
ensure
|
82
|
-
@controller = old_controller
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
def test_expose_a_new_address_on_new
|
87
|
-
Party.expects(:find).with('37').returns(mock_party)
|
88
|
-
mock_party.expects(:venue).returns(mock_venue)
|
89
|
-
mock_venue.expects(:build_address).returns(mock_address)
|
90
|
-
get :new, :party_id => '37'
|
91
|
-
assert_equal mock_party, assigns(:party)
|
92
|
-
assert_equal mock_venue, assigns(:venue)
|
93
|
-
assert_equal mock_address, assigns(:address)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_expose_the_address_on_edit
|
97
|
-
Party.expects(:find).with('37').returns(mock_party)
|
98
|
-
mock_party.expects(:venue).returns(mock_venue)
|
99
|
-
mock_venue.expects(:address).returns(mock_address)
|
100
|
-
get :edit, :party_id => '37'
|
101
|
-
assert_equal mock_party, assigns(:party)
|
102
|
-
assert_equal mock_venue, assigns(:venue)
|
103
|
-
assert_equal mock_address, assigns(:address)
|
104
|
-
assert_response :success
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_expose_the_address_on_show
|
108
|
-
Party.expects(:find).with('37').returns(mock_party)
|
109
|
-
mock_party.expects(:venue).returns(mock_venue)
|
110
|
-
mock_venue.expects(:address).returns(mock_address)
|
111
|
-
get :show, :party_id => '37'
|
112
|
-
assert_equal mock_party, assigns(:party)
|
113
|
-
assert_equal mock_venue, assigns(:venue)
|
114
|
-
assert_equal mock_address, assigns(:address)
|
115
|
-
assert_response :success
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_expose_a_newly_create_address_on_create
|
119
|
-
Party.expects(:find).with('37').returns(mock_party)
|
120
|
-
mock_party.expects(:venue).returns(mock_venue)
|
121
|
-
mock_venue.expects(:build_address).with({'these' => 'params'}).returns(mock_address(:save => true))
|
122
|
-
post :create, :party_id => '37', :address => {:these => 'params'}
|
123
|
-
assert_equal mock_party, assigns(:party)
|
124
|
-
assert_equal mock_venue, assigns(:venue)
|
125
|
-
assert_equal mock_address, assigns(:address)
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_update_the_requested_object_on_update
|
129
|
-
Party.expects(:find).with('37').returns(mock_party)
|
130
|
-
mock_party.expects(:venue).returns(mock_venue(:address => mock_address))
|
131
|
-
mock_address.expects(:update_attributes).with({'these' => 'params'}).returns(mock_address(:save => true))
|
132
|
-
post :update, :party_id => '37', :address => {:these => 'params'}
|
133
|
-
assert_equal mock_party, assigns(:party)
|
134
|
-
assert_equal mock_venue, assigns(:venue)
|
135
|
-
assert_equal mock_address, assigns(:address)
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_the_requested_manager_is_destroyed_on_destroy
|
139
|
-
Party.expects(:find).with('37').returns(mock_party)
|
140
|
-
mock_party.expects(:venue).returns(mock_venue)
|
141
|
-
mock_venue.expects(:address).returns(mock_address)
|
142
|
-
@controller.expects(:parent_url).returns('http://test.host/')
|
143
|
-
mock_address.expects(:destroy)
|
144
|
-
delete :destroy, :party_id => '37'
|
145
|
-
assert_equal mock_party, assigns(:party)
|
146
|
-
assert_equal mock_venue, assigns(:venue)
|
147
|
-
assert_equal mock_address, assigns(:address)
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
protected
|
152
|
-
def mock_party(stubs={})
|
153
|
-
@mock_party ||= mock('party',stubs)
|
154
|
-
end
|
155
|
-
|
156
|
-
def mock_venue(stubs={})
|
157
|
-
@mock_venue ||= mock('venue',stubs)
|
158
|
-
end
|
159
|
-
|
160
|
-
def mock_address(stubs={})
|
161
|
-
@mock_address ||= mock('address',stubs)
|
162
|
-
end
|
163
|
-
|
164
|
-
def mock_geolocation(stubs={})
|
165
|
-
@mock_geolocation ||= mock('geolocation', stubs)
|
166
|
-
end
|
167
|
-
end
|