rc_rails 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/CHANGELOG +355 -0
- data/Gemfile +5 -0
- data/Gemfile.lock.development +117 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +71 -0
- data/Rakefile +33 -0
- data/Todo.txt +1 -0
- data/lib/rc_rails.rb +9 -0
- data/lib/resources_controller/actions.rb +147 -0
- data/lib/resources_controller/active_record/saved.rb +15 -0
- data/lib/resources_controller/helper.rb +123 -0
- data/lib/resources_controller/include_actions.rb +37 -0
- data/lib/resources_controller/named_route_helper.rb +154 -0
- data/lib/resources_controller/railtie.rb +14 -0
- data/lib/resources_controller/request_path_introspection.rb +83 -0
- data/lib/resources_controller/resource_methods.rb +32 -0
- data/lib/resources_controller/singleton_actions.rb +21 -0
- data/lib/resources_controller/specification.rb +119 -0
- data/lib/resources_controller/version.rb +3 -0
- data/lib/resources_controller.rb +849 -0
- data/resources_controller.gemspec +29 -0
- data/spec/app/database.yml +5 -0
- data/spec/app/views/accounts/show.html.erb +0 -0
- data/spec/app/views/addresses/edit.html.erb +0 -0
- data/spec/app/views/addresses/index.html.erb +0 -0
- data/spec/app/views/addresses/new.html.erb +0 -0
- data/spec/app/views/addresses/show.html.erb +0 -0
- data/spec/app/views/admin/forums/create.html.erb +0 -0
- data/spec/app/views/admin/forums/destroy.html.erb +0 -0
- data/spec/app/views/admin/forums/edit.html.erb +0 -0
- data/spec/app/views/admin/forums/index.html.erb +0 -0
- data/spec/app/views/admin/forums/new.html.erb +0 -0
- data/spec/app/views/admin/forums/show.html.erb +0 -0
- data/spec/app/views/admin/forums/update.html.erb +0 -0
- data/spec/app/views/comments/edit.html.erb +0 -0
- data/spec/app/views/comments/index.html.erb +0 -0
- data/spec/app/views/comments/new.html.erb +0 -0
- data/spec/app/views/comments/show.html.erb +0 -0
- data/spec/app/views/forum_posts/edit.html.erb +0 -0
- data/spec/app/views/forum_posts/index.html.erb +0 -0
- data/spec/app/views/forum_posts/new.html.erb +0 -0
- data/spec/app/views/forum_posts/show.html.erb +0 -0
- data/spec/app/views/forums/create.html.erb +0 -0
- data/spec/app/views/forums/destroy.html.erb +0 -0
- data/spec/app/views/forums/edit.html.erb +0 -0
- data/spec/app/views/forums/index.html.erb +0 -0
- data/spec/app/views/forums/new.html.erb +0 -0
- data/spec/app/views/forums/show.html.erb +0 -0
- data/spec/app/views/forums/update.html.erb +0 -0
- data/spec/app/views/infos/edit.html.erb +0 -0
- data/spec/app/views/infos/show.html.erb +0 -0
- data/spec/app/views/interests/index.html.erb +0 -0
- data/spec/app/views/interests/show.html.erb +0 -0
- data/spec/app/views/owners/edit.html.erb +0 -0
- data/spec/app/views/owners/new.html.erb +0 -0
- data/spec/app/views/owners/show.html.erb +0 -0
- data/spec/app/views/tags/index.html.erb +0 -0
- data/spec/app/views/tags/new.html.erb +0 -0
- data/spec/app/views/tags/show.html.erb +0 -0
- data/spec/app/views/users/edit.html.erb +0 -0
- data/spec/app/views/users/index.html.erb +0 -0
- data/spec/app/views/users/show.html.erb +0 -0
- data/spec/app.rb +315 -0
- data/spec/controllers/accounts_controller_spec.rb +77 -0
- data/spec/controllers/addresses_controller_spec.rb +346 -0
- data/spec/controllers/admin_forums_controller_spec.rb +638 -0
- data/spec/controllers/comments_controller_spec.rb +380 -0
- data/spec/controllers/comments_controller_with_models_spec.rb +202 -0
- data/spec/controllers/forum_posts_controller_spec.rb +426 -0
- data/spec/controllers/forums_controller_spec.rb +694 -0
- data/spec/controllers/infos_controller_spec.rb +71 -0
- data/spec/controllers/interests_controller_via_forum_spec.rb +80 -0
- data/spec/controllers/interests_controller_via_user_spec.rb +114 -0
- data/spec/controllers/owners_controller_spec.rb +277 -0
- data/spec/controllers/resource_saved_spec.rb +47 -0
- data/spec/controllers/resource_service_in_forums_controller_spec.rb +37 -0
- data/spec/controllers/resource_service_in_infos_controller_spec.rb +36 -0
- data/spec/controllers/resource_service_in_interests_controller_via_forum_spec.rb +51 -0
- data/spec/controllers/tags_controller_spec.rb +83 -0
- data/spec/controllers/tags_controller_via_account_info_spec.rb +131 -0
- data/spec/controllers/tags_controller_via_forum_post_comment_spec.rb +144 -0
- data/spec/controllers/tags_controller_via_forum_post_spec.rb +133 -0
- data/spec/controllers/tags_controller_via_forum_spec.rb +173 -0
- data/spec/controllers/tags_controller_via_user_address_spec.rb +130 -0
- data/spec/controllers/users_controller_spec.rb +248 -0
- data/spec/lib/action_view_helper_spec.rb +143 -0
- data/spec/lib/bug_0001_spec.rb +22 -0
- data/spec/lib/include_actions_spec.rb +35 -0
- data/spec/lib/load_enclosing_resources_spec.rb +245 -0
- data/spec/lib/request_path_introspection_spec.rb +130 -0
- data/spec/lib/resource_methods_spec.rb +204 -0
- data/spec/lib/resources_controller_spec.rb +57 -0
- data/spec/models/comment_saved_spec.rb +24 -0
- data/spec/rspec_generator_task.rb +105 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/verify_rcov.rb +52 -0
- metadata +193 -0
@@ -0,0 +1,346 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AddressesSpecHelper
|
4
|
+
def setup_mocks
|
5
|
+
@user = mock('User')
|
6
|
+
@user_addresses = mock('Assoc: user_addresses')
|
7
|
+
@user.stub!(:addresses).and_return(@user_addresses)
|
8
|
+
@user.stub!(:to_param).and_return("dave")
|
9
|
+
|
10
|
+
User.stub!(:find_by_login).and_return(@user)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe AddressesController do
|
15
|
+
describe "Routing shortcuts for Addresses (users/dave/addresses/1) should map" do
|
16
|
+
include AddressesSpecHelper
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
setup_mocks
|
20
|
+
@address = mock('Address')
|
21
|
+
@address.stub!(:to_param).and_return('1')
|
22
|
+
@user_addresses.stub!(:find).and_return(@address)
|
23
|
+
|
24
|
+
get :show, :user_id => "dave", :id => "1"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "resources_path to /users/dave/addresses" do
|
28
|
+
controller.resources_path.should == '/users/dave/addresses'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "resource_path to /users/dave/addresses/1" do
|
32
|
+
controller.resource_path.should == '/users/dave/addresses/1'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "resource_path(9) to /users/dave/addresses/9" do
|
36
|
+
controller.resource_path(9).should == '/users/dave/addresses/9'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "edit_resource_path to /users/dave/addresses/1/edit" do
|
40
|
+
controller.edit_resource_path.should == '/users/dave/addresses/1/edit'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "edit_resource_path(9) to /users/dave/addresses/9/edit" do
|
44
|
+
controller.edit_resource_path(9).should == '/users/dave/addresses/9/edit'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "new_resource_path to /users/dave/addresses/new" do
|
48
|
+
controller.new_resource_path.should == '/users/dave/addresses/new'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "resource_service in AddressesController" do
|
53
|
+
|
54
|
+
before(:each) do
|
55
|
+
@user = User.create :login => 'dave'
|
56
|
+
@address = Address.create :user_id => @user.id
|
57
|
+
@other_user = User.create
|
58
|
+
@other_address = Address.create :user_id => @other_user.id
|
59
|
+
|
60
|
+
get :index, :user_id => 'dave'
|
61
|
+
@resource_service = controller.send :resource_service
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should build new address with @user foreign key with new" do
|
65
|
+
resource = @resource_service.new
|
66
|
+
resource.should be_kind_of(Address)
|
67
|
+
resource.user_id.should == @user.id
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should find @address with find(@address.id)" do
|
71
|
+
resource = @resource_service.find(@address.id)
|
72
|
+
resource.should == @address
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise RecordNotFound with find(@other_address.id)" do
|
76
|
+
lambda{ @resource_service.find(@other_address.id) }.should raise_error(ActiveRecord::RecordNotFound)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should find only addresses belonging to @user with find(:all)" do
|
80
|
+
resources = @resource_service.find(:all)
|
81
|
+
resources.should be == Address.find(:all, :conditions => "user_id = #{@user.id}")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Requesting /users/dave/addresses" do
|
86
|
+
include AddressesSpecHelper
|
87
|
+
|
88
|
+
before(:each) do
|
89
|
+
setup_mocks
|
90
|
+
@addresses = mock('Addresses')
|
91
|
+
@user_addresses.stub!(:all).and_return(@addresses)
|
92
|
+
end
|
93
|
+
|
94
|
+
def do_get
|
95
|
+
get :index, :user_id => 'dave'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should find the user" do
|
99
|
+
User.should_receive(:find_by_login).with('dave').and_return(@user)
|
100
|
+
do_get
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should assign the found user for the view" do
|
104
|
+
do_get
|
105
|
+
assigns[:user].should == @user
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should assign the user_addresses association as the addresses resource_service" do
|
109
|
+
@user.should_receive(:addresses).and_return(@user_addresses)
|
110
|
+
do_get
|
111
|
+
@controller.resource_service.should == @user_addresses
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "Requesting /users/dave/addresses using GET" do
|
116
|
+
include AddressesSpecHelper
|
117
|
+
|
118
|
+
before(:each) do
|
119
|
+
setup_mocks
|
120
|
+
@addresses = mock('Addresses')
|
121
|
+
@user_addresses.stub!(:all).and_return(@addresses)
|
122
|
+
end
|
123
|
+
|
124
|
+
def do_get
|
125
|
+
get :index, :user_id => '2'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should be successful" do
|
129
|
+
do_get
|
130
|
+
response.should be_success
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should render index.rhtml" do
|
134
|
+
do_get
|
135
|
+
response.should render_template(:index)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should find all addresses" do
|
139
|
+
@user_addresses.should_receive(:all).and_return(@addresses)
|
140
|
+
do_get
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should assign the found addresses for the view" do
|
144
|
+
do_get
|
145
|
+
assigns[:addresses].should == @addresses
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "Requesting /users/dave/addresses/1 using GET" do
|
150
|
+
include AddressesSpecHelper
|
151
|
+
|
152
|
+
before(:each) do
|
153
|
+
setup_mocks
|
154
|
+
@address = mock('a address')
|
155
|
+
@user_addresses.stub!(:find).and_return(@address)
|
156
|
+
end
|
157
|
+
|
158
|
+
def do_get
|
159
|
+
get :show, :id => "1", :user_id => "dave"
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should be successful" do
|
163
|
+
do_get
|
164
|
+
response.should be_success
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should render show.rhtml" do
|
168
|
+
do_get
|
169
|
+
response.should render_template(:show)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should find the thing requested" do
|
173
|
+
@user_addresses.should_receive(:find).with("1").and_return(@address)
|
174
|
+
do_get
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should assign the found thing for the view" do
|
178
|
+
do_get
|
179
|
+
assigns[:address].should == @address
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "Requesting /users/dave/addresses/new using GET" do
|
184
|
+
include AddressesSpecHelper
|
185
|
+
|
186
|
+
before(:each) do
|
187
|
+
setup_mocks
|
188
|
+
@address = mock('new Address')
|
189
|
+
@user_addresses.stub!(:build).and_return(@address)
|
190
|
+
end
|
191
|
+
|
192
|
+
def do_get
|
193
|
+
get :new, :user_id => "dave"
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should be successful" do
|
197
|
+
do_get
|
198
|
+
response.should be_success
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should render new.rhtml" do
|
202
|
+
do_get
|
203
|
+
response.should render_template(:new)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should create an new thing" do
|
207
|
+
@user_addresses.should_receive(:build).and_return(@address)
|
208
|
+
do_get
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should not save the new thing" do
|
212
|
+
@address.should_not_receive(:save)
|
213
|
+
do_get
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should assign the new thing for the view" do
|
217
|
+
do_get
|
218
|
+
assigns[:address].should == @address
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "Requesting /users/dave/addresses/1/edit using GET" do
|
223
|
+
include AddressesSpecHelper
|
224
|
+
|
225
|
+
before(:each) do
|
226
|
+
setup_mocks
|
227
|
+
@address = mock('Address')
|
228
|
+
@user_addresses.stub!(:find).and_return(@address)
|
229
|
+
end
|
230
|
+
|
231
|
+
def do_get
|
232
|
+
get :edit, :id => "1", :user_id => "dave"
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should be successful" do
|
236
|
+
do_get
|
237
|
+
response.should be_success
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should render edit.rhtml" do
|
241
|
+
do_get
|
242
|
+
response.should render_template(:edit)
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should find the thing requested" do
|
246
|
+
@user_addresses.should_receive(:find).with("1").and_return(@address)
|
247
|
+
do_get
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should assign the found Thing for the view" do
|
251
|
+
do_get
|
252
|
+
assigns(:address).should equal(@address)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe "Requesting /users/dave/addresses using POST" do
|
257
|
+
include AddressesSpecHelper
|
258
|
+
|
259
|
+
before(:each) do
|
260
|
+
setup_mocks
|
261
|
+
@address = mock('Address')
|
262
|
+
@address.stub!(:save).and_return(true)
|
263
|
+
@address.stub!(:to_param).and_return("1")
|
264
|
+
@user_addresses.stub!(:build).and_return(@address)
|
265
|
+
end
|
266
|
+
|
267
|
+
def do_post
|
268
|
+
post :create, :address => {:name => 'Address'}, :user_id => "dave"
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should create a new address" do
|
272
|
+
@user_addresses.should_receive(:build).with({'name' => 'Address'}).and_return(@address)
|
273
|
+
do_post
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should redirect to the new address" do
|
277
|
+
do_post
|
278
|
+
response.should be_redirect
|
279
|
+
response.redirect_url.should == "http://test.host/users/dave/addresses/1"
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "Requesting /users/dave/addresses/1 using PUT" do
|
284
|
+
include AddressesSpecHelper
|
285
|
+
|
286
|
+
before(:each) do
|
287
|
+
setup_mocks
|
288
|
+
@address = mock('Address').as_null_object
|
289
|
+
@address.stub!(:to_param).and_return("1")
|
290
|
+
@user_addresses.stub!(:find).and_return(@address)
|
291
|
+
end
|
292
|
+
|
293
|
+
def do_update
|
294
|
+
put :update, :id => "1", :user_id => "dave"
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should find the address requested" do
|
298
|
+
@user_addresses.should_receive(:find).with("1").and_return(@address)
|
299
|
+
do_update
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should update the found address" do
|
303
|
+
@address.should_receive(:update_attributes).and_return(true)
|
304
|
+
do_update
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should assign the found address for the view" do
|
308
|
+
do_update
|
309
|
+
assigns(:address).should == @address
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should redirect to the address" do
|
313
|
+
do_update
|
314
|
+
response.should be_redirect
|
315
|
+
response.redirect_url.should == "http://test.host/users/dave/addresses/1"
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe "Requesting /users/dave/addresses/1 using DELETE" do
|
320
|
+
include AddressesSpecHelper
|
321
|
+
|
322
|
+
before(:each) do
|
323
|
+
setup_mocks
|
324
|
+
@address = mock('Address', :id => "1").as_null_object
|
325
|
+
@user_addresses.stub!(:find).and_return(@address)
|
326
|
+
@user_addresses.stub!(:destroy)
|
327
|
+
end
|
328
|
+
|
329
|
+
def do_delete
|
330
|
+
delete :destroy, :id => "1", :user_id => "dave"
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should find and destroy the address requested" do
|
334
|
+
@user_addresses.should_receive(:find).with("1").and_return(@address)
|
335
|
+
@user_addresses.should_receive(:destroy).with("1")
|
336
|
+
do_delete
|
337
|
+
assigns(:address).should == @address
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should redirect to the things list" do
|
341
|
+
do_delete
|
342
|
+
response.should be_redirect
|
343
|
+
response.redirect_url.should == "http://test.host/users/dave/addresses"
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|