jcfischer / make_resourceful

Hampton Catlins and Nex3's make_resourceful plugin

This URL has Read+Write access

make_resourceful / spec / urls_spec.rb
100644 277 lines (223 sloc) 9.688 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
require File.dirname(__FILE__) + '/spec_helper'
 
describe Resourceful::Default::URLs, " for a controller with no parents or namespaces" do
  include ControllerMocks
  before :each do
    mock_controller Resourceful::Default::URLs
    @object = stub_model('Thing')
    @controller.stubs(:current_object).returns(@object)
    
    @controller.stubs(:current_model_name).returns('Thing')
    @controller.stubs(:parent?).returns(false)
    @controller.stubs(:namespaces).returns([])
  end
 
  it "should return nil for #url_helper_prefix" do
    @controller.url_helper_prefix.should be_nil
  end
 
  it "should return the empty string for #collection_url_prefix" do
    @controller.collection_url_prefix.should == ""
  end
 
  it "should get the path of current_object with #object_path" do
    @controller.expects(:send).with('thing_path', @object)
    @controller.object_path
  end
 
  it "should get the url of current_object with #object_url" do
    @controller.expects(:send).with('thing_url', @object)
    @controller.object_url
  end
 
  it "should get the path of the passed object with #object_path" do
    model = stub_model('Thing')
    @controller.expects(:send).with('thing_path', model)
    @controller.object_path(model)
  end
 
  it "should get the url of the passed object with #object_url" do
    model = stub_model('Thing')
    @controller.expects(:send).with('thing_url', model)
    @controller.object_url(model)
  end
 
  it "should get the path of current_object with #nested_object_path" do
    @controller.expects(:send).with('thing_path', @object)
    @controller.nested_object_path
  end
 
  it "should get the url of current_object with #nested_object_url" do
    @controller.expects(:send).with('thing_url', @object)
    @controller.nested_object_url
  end
 
  it "should get the path of the passed object with #nested_object_path" do
    model = stub_model('Thing')
    @controller.expects(:send).with('thing_path', model)
    @controller.nested_object_path(model)
  end
 
  it "should get the url of the passed object with #nested_object_url" do
    model = stub_model('Thing')
    @controller.expects(:send).with('thing_url', model)
    @controller.nested_object_url(model)
  end
 
  it "should get the edit path of current_object with #edit_object_path" do
    @controller.expects(:send).with('edit_thing_path', @object)
    @controller.edit_object_path
  end
 
  it "should get the edit url of current_object with #edit_object_url" do
    @controller.expects(:send).with('edit_thing_url', @object)
    @controller.edit_object_url
  end
 
  it "should get the edit path of the passed object with #edit_object_path" do
    model = stub_model('Thing')
    @controller.expects(:send).with('edit_thing_path', model)
    @controller.edit_object_path(model)
  end
 
  it "should get the edit url of the passed object with #edit_object_url" do
    model = stub_model('Thing')
    @controller.expects(:send).with('edit_thing_url', model)
    @controller.edit_object_url(model)
  end
 
  it "should get the plural path of the current model with #objects_path" do
    @controller.expects(:send).with('things_path')
    @controller.objects_path
  end
 
  it "should get the plural url of the current model with #objects_url" do
    @controller.expects(:send).with('things_url')
    @controller.objects_url
  end
 
  it "should get the new path of the current model with #new_object_path" do
    @controller.expects(:send).with('new_thing_path')
    @controller.new_object_path
  end
 
  it "should get the new url of the current model with #new_object_url" do
    @controller.expects(:send).with('new_thing_url')
    @controller.new_object_url
  end
end
 
describe Resourceful::Default::URLs, " for a controller with a parent object" do
  include ControllerMocks
  before :each do
    mock_controller Resourceful::Default::URLs
    @object = stub_model('Thing')
    @controller.stubs(:current_object).returns(@object)
    
    @controller.stubs(:current_model_name).returns('Thing')
 
    @person = stub_model('Person')
    @controller.stubs(:parent_object).returns(@person)
    @controller.stubs(:parent_name).returns('person')
    @controller.stubs(:parent?).returns(true)
    @controller.stubs(:namespaces).returns([])
  end
 
  it "should return nil for #url_helper_prefix" do
    @controller.url_helper_prefix.should be_nil
  end
 
  it "should return the underscored parent name for #collection_url_prefix" do
    @controller.collection_url_prefix.should == "person_"
  end
 
  it "should get the path of current_object with #object_path" do
    @controller.expects(:send).with('thing_path', @object)
    @controller.object_path
  end
 
  it "should get the nested path of current_object with #nested_object_path" do
    @controller.expects(:send).with('person_thing_path', @person, @object)
    @controller.nested_object_path
  end
 
  it "should get the nested url of current_object with #nested_object_url" do
    @controller.expects(:send).with('person_thing_url', @person, @object)
    @controller.nested_object_url
  end
 
  it "should get the nested path of the passed object with #nested_object_path" do
    object = stub_model('Thing')
    @controller.expects(:send).with('person_thing_path', @person, object)
    @controller.nested_object_path object
  end
 
  it "should get the nested url of the passed object with #nested_object_url" do
    object = stub_model('Thing')
    @controller.expects(:send).with('person_thing_url', @person, object)
    @controller.nested_object_url object
  end
 
  it "should get the plural path of the current model and its parent with #objects_path" do
    @controller.expects(:send).with('person_things_path', @person)
    @controller.objects_path
  end
 
  it "should get the edit path of the current model with #edit_object_path" do
    @controller.expects(:send).with('edit_thing_path', @object)
    @controller.edit_object_path
  end
 
  it "should get the new path of the current model and its parent with #new_object_path" do
    @controller.expects(:send).with('new_person_thing_path', @person)
    @controller.new_object_path
  end
 
  it "should get the path of the parent_object with #parent_path" do
    @controller.expects(:send).with('person_path', @person)
    @controller.parent_path
  end
 
  it "should get the url of the parent_object with #parent_url" do
    @controller.expects(:send).with('person_url', @person)
    @controller.parent_url
  end
 
  it "should get the path of the passed object with #parent_path" do
    model = stub_model('Person')
    @controller.expects(:send).with('person_path', model)
    @controller.parent_path model
  end
 
  it "should get the url of the passed object with #parent_url" do
    model = stub_model('Person')
    @controller.expects(:send).with('person_url', model)
    @controller.parent_url model
  end
end
 
describe Resourceful::Default::URLs, " for a controller within a namespace" do
  include ControllerMocks
  before :each do
    mock_controller Resourceful::Default::URLs
    @object = stub_model('Thing')
    @controller.stubs(:current_object).returns(@object)
    
    @controller.stubs(:current_model_name).returns('Thing')
 
    @controller.stubs(:parent?).returns(false)
    @controller.stubs(:namespaces).returns([:admin, :main])
  end
 
  it "should return the underscored list of namespaces for #url_helper_prefix" do
    @controller.url_helper_prefix.should == "admin_main_"
  end
 
  it "should get the namespaced path of current_object with #object_path" do
    @controller.expects(:send).with('admin_main_thing_path', @object)
    @controller.object_path
  end
 
  it "should get the namespaced plural path of the current model with #objects_path" do
    @controller.expects(:send).with('admin_main_things_path')
    @controller.objects_path
  end
 
  it "should get the edit path of the current model with #edit_object_path" do
    @controller.expects(:send).with('edit_admin_main_thing_path', @object)
    @controller.edit_object_path
  end
 
  it "should get the new path of the current model with #new_object_path" do
    @controller.expects(:send).with('new_admin_main_thing_path')
    @controller.new_object_path
  end
end
 
describe Resourceful::Default::URLs, " for a controller with a parent object and within a namespace" do
  include ControllerMocks
  before :each do
    mock_controller Resourceful::Default::URLs
    @object = stub_model('Thing')
    @controller.stubs(:current_object).returns(@object)
    
    @controller.stubs(:current_model_name).returns('Thing')
 
    @person = stub_model('Person')
    @controller.stubs(:parent_object).returns(@person)
    @controller.stubs(:parent_name).returns('person')
    @controller.stubs(:parent?).returns(true)
    @controller.stubs(:namespaces).returns([:admin, :main])
  end
 
  it "should return the underscored list of namespaces for #url_helper_prefix" do
    @controller.url_helper_prefix.should == "admin_main_"
  end
 
  it "should get the namespaced path of current_object with #object_path" do
    @controller.expects(:send).with('admin_main_thing_path', @object)
    @controller.object_path
  end
 
  it "should get the namespaced plural path of the current model and its parent with #objects_path" do
    @controller.expects(:send).with('admin_main_things_path', @person)
    @controller.objects_path
  end
 
  it "should get the edit path of the current model with #edit_object_path" do
    @controller.expects(:send).with('edit_admin_main_thing_path', @object)
    @controller.edit_object_path
  end
 
  it "should get the new path of the current model and its parent with #new_object_path" do
    @controller.expects(:send).with('new_admin_main_thing_path', @person)
    @controller.new_object_path
  end
end