easy_admin_ui 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. data/README +4 -15
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/{assets/icons → app/assets/images/easy_admin_ui}/classify.png +0 -0
  5. data/{assets/icons → app/assets/images/easy_admin_ui}/connect.png +0 -0
  6. data/{assets/icons → app/assets/images/easy_admin_ui}/delete.png +0 -0
  7. data/{assets/icons → app/assets/images/easy_admin_ui}/disconnect.png +0 -0
  8. data/{assets/icons → app/assets/images/easy_admin_ui}/pencil.png +0 -0
  9. data/{assets/icons → app/assets/images/easy_admin_ui}/show.png +0 -0
  10. data/app/assets/stylesheets/easy_admin_ui/easy_admin_ui.sass +47 -0
  11. data/app/views/easy_admin_ui/destroy.js.erb +1 -0
  12. data/{templates → app/views}/easy_admin_ui/edit.html.erb +0 -0
  13. data/{templates → app/views}/easy_admin_ui/index.html.erb +0 -0
  14. data/{templates → app/views}/easy_admin_ui/new.html.erb +0 -0
  15. data/{templates → app/views}/easy_admin_ui/show.html.erb +0 -0
  16. data/easy_admin_ui.gemspec +80 -21
  17. data/lib/easy_admin_ui/core_ext.rb +1 -3
  18. data/lib/easy_admin_ui/rails/engine.rb +10 -0
  19. data/lib/easy_admin_ui/tasks.rb +0 -10
  20. data/lib/easy_admin_ui/view_helpers.rb +3 -3
  21. data/lib/easy_admin_ui.rb +1 -9
  22. data/vendor/plugins/make_resourceful/.gitignore +1 -0
  23. data/vendor/plugins/make_resourceful/DEFAULTS +148 -0
  24. data/vendor/plugins/make_resourceful/LICENSE +7 -0
  25. data/vendor/plugins/make_resourceful/README.rdoc +239 -0
  26. data/vendor/plugins/make_resourceful/Rakefile +31 -0
  27. data/vendor/plugins/make_resourceful/VERSION +1 -0
  28. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/resourceful_scaffold_generator.rb +87 -0
  29. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/controller.rb +5 -0
  30. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/fixtures.yml +10 -0
  31. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/functional_test.rb +50 -0
  32. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/helper.rb +2 -0
  33. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/migration.rb +13 -0
  34. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/model.rb +2 -0
  35. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/unit_test.rb +7 -0
  36. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view__form.haml +5 -0
  37. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_edit.haml +11 -0
  38. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_index.haml +5 -0
  39. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_new.haml +9 -0
  40. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_partial.haml +12 -0
  41. data/vendor/plugins/make_resourceful/generators/resourceful_scaffold/templates/view_show.haml +14 -0
  42. data/vendor/plugins/make_resourceful/init.rb +3 -0
  43. data/vendor/plugins/make_resourceful/lib/resourceful/base.rb +63 -0
  44. data/vendor/plugins/make_resourceful/lib/resourceful/builder.rb +385 -0
  45. data/vendor/plugins/make_resourceful/lib/resourceful/default/accessors.rb +402 -0
  46. data/vendor/plugins/make_resourceful/lib/resourceful/default/actions.rb +101 -0
  47. data/vendor/plugins/make_resourceful/lib/resourceful/default/callbacks.rb +51 -0
  48. data/vendor/plugins/make_resourceful/lib/resourceful/default/responses.rb +118 -0
  49. data/vendor/plugins/make_resourceful/lib/resourceful/default/urls.rb +137 -0
  50. data/vendor/plugins/make_resourceful/lib/resourceful/maker.rb +84 -0
  51. data/vendor/plugins/make_resourceful/lib/resourceful/response.rb +33 -0
  52. data/vendor/plugins/make_resourceful/lib/resourceful/serialize.rb +185 -0
  53. data/vendor/plugins/make_resourceful/spec/accessors_spec.rb +474 -0
  54. data/vendor/plugins/make_resourceful/spec/actions_spec.rb +310 -0
  55. data/vendor/plugins/make_resourceful/spec/base_spec.rb +12 -0
  56. data/vendor/plugins/make_resourceful/spec/builder_spec.rb +332 -0
  57. data/vendor/plugins/make_resourceful/spec/callbacks_spec.rb +71 -0
  58. data/vendor/plugins/make_resourceful/spec/integration_spec.rb +394 -0
  59. data/vendor/plugins/make_resourceful/spec/maker_spec.rb +91 -0
  60. data/vendor/plugins/make_resourceful/spec/response_spec.rb +37 -0
  61. data/vendor/plugins/make_resourceful/spec/responses_spec.rb +314 -0
  62. data/vendor/plugins/make_resourceful/spec/rspec-rails/LICENSE +37 -0
  63. data/vendor/plugins/make_resourceful/spec/rspec-rails/redirect_to.rb +113 -0
  64. data/vendor/plugins/make_resourceful/spec/rspec-rails/render_template.rb +90 -0
  65. data/vendor/plugins/make_resourceful/spec/serialize_spec.rb +133 -0
  66. data/vendor/plugins/make_resourceful/spec/spec_helper.rb +319 -0
  67. data/vendor/plugins/make_resourceful/spec/urls_spec.rb +282 -0
  68. data/vendor/plugins/make_resourceful/spec/views/things/create.rjs +1 -0
  69. data/vendor/plugins/make_resourceful/spec/views/things/destroy.rjs +1 -0
  70. data/vendor/plugins/make_resourceful/spec/views/things/edit.html.erb +4 -0
  71. data/vendor/plugins/make_resourceful/spec/views/things/edit.rjs +1 -0
  72. data/vendor/plugins/make_resourceful/spec/views/things/index.html.erb +4 -0
  73. data/vendor/plugins/make_resourceful/spec/views/things/index.rjs +1 -0
  74. data/vendor/plugins/make_resourceful/spec/views/things/new.html.erb +4 -0
  75. data/vendor/plugins/make_resourceful/spec/views/things/new.rjs +1 -0
  76. data/vendor/plugins/make_resourceful/spec/views/things/show.html.erb +4 -0
  77. data/vendor/plugins/make_resourceful/spec/views/things/show.rjs +1 -0
  78. data/vendor/plugins/make_resourceful/spec/views/things/update.rjs +1 -0
  79. metadata +75 -16
  80. data/assets/css/easy_admin_ui.css +0 -69
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Resourceful::Default::Callbacks, " with a few callbacks" do
4
+ include ControllerMocks
5
+ before :each do
6
+ mock_controller Resourceful::Default::Callbacks
7
+ end
8
+
9
+ it "should fire the :before callback with the given name when #before is called" do
10
+ callbacks[:before] = { :create => [ should_be_called ] }
11
+ @controller.before(:create)
12
+ end
13
+
14
+ it "should fire the :after callback with the given name when #after is called" do
15
+ callbacks[:after] = { :index => [ should_be_called ] }
16
+ @controller.after("index")
17
+ end
18
+ end
19
+
20
+ describe Resourceful::Default::Callbacks, " with a few responses" do
21
+ include ControllerMocks
22
+ before :each do
23
+ mock_controller Resourceful::Default::Callbacks
24
+ responses[:create_failed] = [[:html, nil], [:js, nil]]
25
+ responses[:create] = [[:html, proc { "create html" }], [:xml, proc { @xml }]]
26
+ @controller.instance_variable_set('@xml', 'create XML')
27
+ @response = Resourceful::Response.new
28
+ end
29
+
30
+ it "should respond to each format with a call to the given block when #response_for is called" do
31
+ @controller.expects(:respond_to).yields(@response)
32
+ @controller.response_for(:create_failed)
33
+ @response.formats[0][0].should == :html
34
+ @response.formats[0][1].call.should be_nil
35
+
36
+ @response.formats[1][0].should == :js
37
+ @response.formats[1][1].call.should be_nil
38
+ end
39
+
40
+ it "should properly scope blocks when #response_for is called" do
41
+ @controller.expects(:respond_to).yields(@response)
42
+ @controller.response_for(:create)
43
+ @response.formats[0][0].should == :html
44
+ @response.formats[0][1].call.should == "create html"
45
+
46
+ @response.formats[1][0].should == :xml
47
+
48
+ # This value comes from the instance variable in @controller.
49
+ # Having it be "create XML" ensures that the block was properly scoped.
50
+ @response.formats[1][1].call.should == "create XML"
51
+ end
52
+ end
53
+
54
+ describe Resourceful::Default::Callbacks, "#scope" do
55
+ include ControllerMocks
56
+ before(:each) { mock_controller Resourceful::Default::Callbacks }
57
+
58
+ it "should re-bind the block to the controller's context" do
59
+ block = proc { @var }
60
+ @controller.instance_variable_set('@var', 'value')
61
+
62
+ block.call.should == nil
63
+ @controller.scope(block).call.should == 'value'
64
+ end
65
+
66
+ it "should make the block empty if it's passed in as nil" do
67
+ @controller.scope(nil).call.should == nil
68
+ end
69
+ end
70
+
71
+
@@ -0,0 +1,394 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "ThingsController", "with all the resourceful actions" do
4
+
5
+ before :each do
6
+ mock_resourceful do
7
+ actions :all
8
+ end
9
+ @objects = stub_list(5, 'Thing') do |t|
10
+ [:destroy, :save, :update_attributes].each { |m| t.stubs(m).returns(true) }
11
+ t.stubs(:to_param).returns('12')
12
+ end
13
+ @object = @objects.first
14
+ Thing.stubs(:find).returns(@object)
15
+ Thing.stubs(:new).returns(@object)
16
+ end
17
+
18
+ ## Default responses
19
+
20
+ (Resourceful::ACTIONS - Resourceful::MODIFYING_ACTIONS).each(&method(:should_render_html))
21
+ Resourceful::ACTIONS.each(&method(:should_render_js))
22
+ Resourceful::ACTIONS.each(&method(:shouldnt_render_xml))
23
+
24
+ ## Specs for #index
25
+
26
+ it "should find all records on GET /things" do
27
+ Thing.expects(:find).with(:all).returns(@objects)
28
+ get :index
29
+ end
30
+
31
+ it "should return a list of objects for #current_objects after GET /things" do
32
+ Thing.stubs(:find).returns(@objects)
33
+ get :index
34
+ current_objects.should == @objects
35
+ end
36
+
37
+ it "should assign @things to a list of objects for GET /things" do
38
+ Thing.stubs(:find).returns(@objects)
39
+ get :index
40
+ assigns(:things).should == @objects
41
+ end
42
+
43
+ ## Specs for #show
44
+
45
+ it "should find the record with id 12 on GET /things/12" do
46
+ Thing.expects(:find).with('12').returns(@object)
47
+ get :show, :id => 12
48
+ end
49
+
50
+ it "should return an object for #current_object after GET /things/12" do
51
+ Thing.stubs(:find).returns(@object)
52
+ get :show, :id => 12
53
+ current_object.should == @object
54
+ end
55
+
56
+ it "should assign @thing to an object for GET /things/12" do
57
+ Thing.stubs(:find).returns(@object)
58
+ get :show, :id => 12
59
+ assigns(:thing).should == @object
60
+ end
61
+
62
+ ## Specs for #edit
63
+
64
+ it "should find the record with id 12 on GET /things/12/edit" do
65
+ Thing.expects(:find).with('12').returns(@object)
66
+ get :edit, :id => 12
67
+ end
68
+
69
+ it "should return an object for #current_object after GET /things/12/edit" do
70
+ Thing.stubs(:find).returns(@object)
71
+ get :edit, :id => 12
72
+ current_object.should == @object
73
+ end
74
+
75
+ it "should assign @thing to an object for GET /things/12/edit" do
76
+ Thing.stubs(:find).returns(@object)
77
+ get :edit, :id => 12
78
+ assigns(:thing).should == @object
79
+ end
80
+
81
+ ## Specs for #new
82
+
83
+ it "should create a new object from params[:thing] for GET /things/new" do
84
+ Thing.expects(:new).with('name' => "Herbert the thing").returns(@object)
85
+ get :new, :thing => {:name => "Herbert the thing"}
86
+ end
87
+
88
+ it "should create a new object even if there aren't any params for GET /things/new" do
89
+ Thing.expects(:new).with(nil).returns(@object)
90
+ get :new
91
+ end
92
+
93
+ it "should return the new object for #current_object after GET /things/new" do
94
+ Thing.stubs(:new).returns(@object)
95
+ get :new
96
+ current_object.should == @object
97
+ end
98
+
99
+ it "should assign @thing to the new object for GET /things/new" do
100
+ Thing.stubs(:new).returns(@object)
101
+ get :new
102
+ assigns(:thing).should == @object
103
+ end
104
+
105
+ ## Specs for #create
106
+
107
+ it "should create a new object from params[:thing] for POST /things" do
108
+ Thing.expects(:new).with('name' => "Herbert the thing").returns(@object)
109
+ post :create, :thing => {:name => "Herbert the thing"}
110
+ end
111
+
112
+ it "should create a new object even if there aren't any params for POST /things" do
113
+ Thing.expects(:new).with(nil).returns(@object)
114
+ post :create
115
+ end
116
+
117
+ it "should return the new object for #current_object after POST /things" do
118
+ Thing.stubs(:new).returns(@object)
119
+ post :create
120
+ current_object.should == @object
121
+ end
122
+
123
+ it "should assign @thing to the new object for POST /things" do
124
+ Thing.stubs(:new).returns(@object)
125
+ post :create
126
+ assigns(:thing).should == @object
127
+ end
128
+
129
+ it "should save the new object for POST /things" do
130
+ Thing.stubs(:new).returns(@object)
131
+ @object.expects(:save)
132
+ post :create
133
+ end
134
+
135
+ it "should set an appropriate flash notice for a successful POST /things" do
136
+ Thing.stubs(:new).returns(@object)
137
+ post :create
138
+ flash[:notice].should == "Create successful!"
139
+ end
140
+
141
+ it "should redirect to the new object for a successful POST /things" do
142
+ Thing.stubs(:new).returns(@object)
143
+ post :create
144
+ response.should redirect_to('/things/12')
145
+ end
146
+
147
+ it "should set an appropriate flash error for an unsuccessful POST /things" do
148
+ Thing.stubs(:new).returns(@object)
149
+ @object.stubs(:save).returns(false)
150
+ post :create
151
+ flash[:error].should == "There was a problem!"
152
+ end
153
+
154
+ it "should give a failing response for an unsuccessful POST /things" do
155
+ Thing.stubs(:new).returns(@object)
156
+ @object.stubs(:save).returns(false)
157
+ post :create
158
+ response.should_not be_success
159
+ response.code.should == '422'
160
+ end
161
+
162
+ it "should render the #new template for an unsuccessful POST /things" do
163
+ Thing.stubs(:new).returns(@object)
164
+ @object.stubs(:save).returns(false)
165
+ post :create
166
+ response.body.should include('New object')
167
+ end
168
+
169
+ ## Specs for #update
170
+
171
+ it "should find the record with id 12 on PUT /things/12" do
172
+ Thing.expects(:find).with('12').returns(@object)
173
+ put :update, :id => 12
174
+ end
175
+
176
+ it "should return an object for #current_object after PUT /things/12" do
177
+ Thing.stubs(:find).returns(@object)
178
+ put :update, :id => 12
179
+ current_object.should == @object
180
+ end
181
+
182
+ it "should assign @thing to an object for PUT /things/12" do
183
+ Thing.stubs(:find).returns(@object)
184
+ put :update, :id => 12
185
+ assigns(:thing).should == @object
186
+ end
187
+
188
+ it "should update the new object for PUT /things/12" do
189
+ Thing.stubs(:find).returns(@object)
190
+ @object.expects(:update_attributes).with('name' => "Jorje")
191
+ put :update, :id => 12, :thing => {:name => "Jorje"}
192
+ end
193
+
194
+ it "should set an appropriate flash notice for a successful PUT /things/12" do
195
+ Thing.stubs(:find).returns(@object)
196
+ put :update, :id => 12
197
+ flash[:notice].should == "Save successful!"
198
+ end
199
+
200
+ it "should redirect to the updated object for a successful PUT /things/12" do
201
+ Thing.stubs(:find).returns(@object)
202
+ put :update, :id => 12
203
+ response.should redirect_to('/things/12')
204
+ end
205
+
206
+ it "should set an appropriate flash error for an unsuccessful PUT /things/12" do
207
+ Thing.stubs(:find).returns(@object)
208
+ @object.stubs(:update_attributes).returns(false)
209
+ put :update, :id => 12
210
+ flash[:error].should == "There was a problem saving!"
211
+ end
212
+
213
+ it "should give a failing response for an unsuccessful PUT /things/12" do
214
+ Thing.stubs(:find).returns(@object)
215
+ @object.stubs(:update_attributes).returns(false)
216
+ put :update, :id => 12
217
+ response.should_not be_success
218
+ response.code.should == '422'
219
+ end
220
+
221
+ it "should render the #edit template for an unsuccessful PUT /things/12" do
222
+ Thing.stubs(:find).returns(@object)
223
+ @object.stubs(:update_attributes).returns(false)
224
+ put :update, :id => 12
225
+ response.body.should include('Editting object')
226
+ end
227
+
228
+ ## Specs for #destroy
229
+
230
+ it "should find the record with id 12 on DELETE /things/12" do
231
+ Thing.expects(:find).with('12').returns(@object)
232
+ delete :destroy, :id => 12
233
+ end
234
+
235
+ it "should return an object for #current_object after DELETE /things/12" do
236
+ Thing.stubs(:find).returns(@object)
237
+ delete :destroy, :id => 12
238
+ current_object.should == @object
239
+ end
240
+
241
+ it "should assign @thing to an object for DELETE /things/12" do
242
+ Thing.stubs(:find).returns(@object)
243
+ delete :destroy, :id => 12
244
+ assigns(:thing).should == @object
245
+ end
246
+
247
+ it "should destroy the new object for DELETE /things/12" do
248
+ Thing.stubs(:find).returns(@object)
249
+ @object.expects(:destroy)
250
+ delete :destroy, :id => 12
251
+ end
252
+
253
+ it "should set an appropriate flash notice for a successful DELETE /things/12" do
254
+ Thing.stubs(:find).returns(@object)
255
+ delete :destroy, :id => 12
256
+ flash[:notice].should == "Record deleted!"
257
+ end
258
+
259
+ it "should redirect to the object list for a successful DELETE /things/12" do
260
+ Thing.stubs(:find).returns(@object)
261
+ delete :destroy, :id => 12
262
+ response.should redirect_to('/things')
263
+ end
264
+
265
+ it "should set an appropriate flash error for an unsuccessful DELETE /things/12" do
266
+ Thing.stubs(:find).returns(@object)
267
+ @object.stubs(:destroy).returns(false)
268
+ delete :destroy, :id => 12
269
+ flash[:error].should == "There was a problem deleting!"
270
+ end
271
+
272
+ it "should give a failing response for an unsuccessful DELETE /things/12" do
273
+ Thing.stubs(:find).returns(@object)
274
+ @object.stubs(:destroy).returns(false)
275
+ delete :destroy, :id => 12
276
+ response.should_not be_success
277
+ end
278
+
279
+ it "should redirect to the previous page for an unsuccessful DELETE /things/12" do
280
+ Thing.stubs(:find).returns(@object)
281
+ @object.stubs(:destroy).returns(false)
282
+ delete :destroy, :id => 12
283
+ response.should redirect_to(:back)
284
+ end
285
+ end
286
+
287
+ describe "ThingsController", "with several parent objects", :type => :integration do
288
+ before :each do
289
+ mock_resourceful do
290
+ actions :all
291
+ belongs_to :person, :category
292
+ end
293
+ stub_const 'Person'
294
+ stub_const 'Category'
295
+
296
+ @objects = stub_list(5, 'Thing') do |t|
297
+ t.stubs(:save).returns(true)
298
+ end
299
+ @object = @objects.first
300
+ @person = stub('Person')
301
+ @category = stub('Category')
302
+ @fake_model = stub('parent_object.things')
303
+ end
304
+
305
+ ## No parent ids
306
+
307
+ it "should find all things on GET /things" do
308
+ Thing.expects(:find).with(:all).returns(@objects)
309
+ get :index
310
+ current_objects.should == @objects
311
+ end
312
+
313
+ it "should find the thing with id 12 regardless of scoping on GET /things/12" do
314
+ Thing.expects(:find).with('12').returns(@object)
315
+ get :show, :id => 12
316
+ current_object.should == @object
317
+ end
318
+
319
+ it "should create a new thing without a person on POST /things" do
320
+ Thing.expects(:new).with('name' => "Lamp").returns(@object)
321
+ post :create, :thing => {:name => "Lamp"}
322
+ current_object.should == @object
323
+ end
324
+
325
+ ## Person ids
326
+
327
+ it "should assign the proper parent variables and accessors to the person with id 4 for GET /people/4/things" do
328
+ Person.stubs(:find).returns(@person)
329
+ @person.stubs(:things).returns(@fake_model)
330
+ @fake_model.stubs(:find).with(:all).returns(@objects)
331
+ get :index, :person_id => 4
332
+ controller.instance_eval("parent_object").should == @person
333
+ assigns(:person).should == @person
334
+ end
335
+
336
+ it "should find all the things belonging to the person with id 4 on GET /people/4/things" do
337
+ Person.expects(:find).with('4').returns(@person)
338
+ @person.expects(:things).at_least_once.returns(@fake_model)
339
+ @fake_model.expects(:find).with(:all).returns(@objects)
340
+ get :index, :person_id => 4
341
+ current_objects.should == @objects
342
+ end
343
+
344
+ it "should find the thing with id 12 if it belongs to the person with id 4 on GET /person/4/things/12" do
345
+ Person.expects(:find).with('4').returns(@person)
346
+ @person.expects(:things).at_least_once.returns(@fake_model)
347
+ @fake_model.expects(:find).with('12').returns(@object)
348
+ get :show, :person_id => 4, :id => 12
349
+ current_object.should == @object
350
+ end
351
+
352
+ it "should create a new thing belonging to the person with id 4 on POST /person/4/things" do
353
+ Person.expects(:find).with('4').returns(@person)
354
+ @person.expects(:things).at_least_once.returns(@fake_model)
355
+ @fake_model.expects(:build).with('name' => 'Lamp').returns(@object)
356
+ post :create, :person_id => 4, :thing => {:name => "Lamp"}
357
+ current_object.should == @object
358
+ end
359
+
360
+ ## Category ids
361
+
362
+ it "should assign the proper parent variables and accessors to the category with id 4 for GET /people/4/things" do
363
+ Category.stubs(:find).returns(@category)
364
+ @category.stubs(:things).returns(@fake_model)
365
+ @fake_model.stubs(:find).with(:all).returns(@objects)
366
+ get :index, :category_id => 4
367
+ controller.instance_eval("parent_object").should == @category
368
+ assigns(:category).should == @category
369
+ end
370
+
371
+ it "should find all the things belonging to the category with id 4 on GET /people/4/things" do
372
+ Category.expects(:find).with('4').returns(@category)
373
+ @category.expects(:things).at_least_once.returns(@fake_model)
374
+ @fake_model.expects(:find).with(:all).returns(@objects)
375
+ get :index, :category_id => 4
376
+ current_objects.should == @objects
377
+ end
378
+
379
+ it "should find the thing with id 12 if it belongs to the category with id 4 on GET /category/4/things/12" do
380
+ Category.expects(:find).with('4').returns(@category)
381
+ @category.expects(:things).at_least_once.returns(@fake_model)
382
+ @fake_model.expects(:find).with('12').returns(@object)
383
+ get :show, :category_id => 4, :id => 12
384
+ current_object.should == @object
385
+ end
386
+
387
+ it "should create a new thing belonging to the category with id 4 on POST /category/4/things" do
388
+ Category.expects(:find).with('4').returns(@category)
389
+ @category.expects(:things).at_least_once.returns(@fake_model)
390
+ @fake_model.expects(:build).with('name' => 'Lamp').returns(@object)
391
+ post :create, :category_id => 4, :thing => {:name => "Lamp"}
392
+ current_object.should == @object
393
+ end
394
+ end
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Resourceful::Maker, "when extended" do
4
+ include ControllerMocks
5
+ before(:each) { mock_kontroller }
6
+
7
+ it "should create an empty, inheritable callbacks hash" do
8
+ @kontroller.read_inheritable_attribute(:resourceful_callbacks).should == {}
9
+ end
10
+
11
+ it "should create an empty, inheritable responses hash" do
12
+ @kontroller.read_inheritable_attribute(:resourceful_responses).should == {}
13
+ end
14
+
15
+ it "should create an empty, inheritable parents array" do
16
+ @kontroller.read_inheritable_attribute(:parents).should == []
17
+ end
18
+
19
+ it "should create a made_resourceful variable set to false" do
20
+ @kontroller.read_inheritable_attribute(:made_resourceful).should be_false
21
+ end
22
+
23
+ it "should create a made_resourceful? method on the controller that returns the variable" do
24
+ @kontroller.should_not be_made_resourceful
25
+ @kontroller.write_inheritable_attribute(:made_resourceful, true)
26
+ @kontroller.should be_made_resourceful
27
+ end
28
+ end
29
+
30
+ describe Resourceful::Maker, "when made_resourceful" do
31
+ include ControllerMocks
32
+ before(:each) do
33
+ mock_kontroller
34
+ mock_builder
35
+ end
36
+
37
+ it "should include Resourceful::Base" do
38
+ @kontroller.expects(:include).with(Resourceful::Base)
39
+ @kontroller.make_resourceful {}
40
+ end
41
+
42
+ it "should use Resourceful::Builder to build the controller" do
43
+ Resourceful::Builder.expects(:new).with(@kontroller).returns(@builder)
44
+ @kontroller.make_resourceful {}
45
+ end
46
+
47
+ it "should evaluate the made_resourceful callbacks in the context of the builder" do
48
+ procs = (1..5).map { should_be_called { with(@builder) } }
49
+ Resourceful::Base.stubs(:made_resourceful).returns(procs)
50
+ @kontroller.make_resourceful {}
51
+ end
52
+
53
+ it "should evaluate the :include callback in the context of the builder" do
54
+ @kontroller.make_resourceful(:include => should_be_called { with(@builder) }) {}
55
+ end
56
+
57
+ it "should evaluate the given block in the context of the builder" do
58
+ @kontroller.make_resourceful(&(should_be_called { with(@builder) }))
59
+ end
60
+ end
61
+
62
+ describe Resourceful::Maker, "when made_resourceful with an inherited controller" do
63
+ include ControllerMocks
64
+ before(:each) do
65
+ mock_kontroller
66
+ mock_builder :inherited
67
+ end
68
+
69
+ it "should include Resourceful::Base" do
70
+ @kontroller.expects(:include).with(Resourceful::Base)
71
+ @kontroller.make_resourceful {}
72
+ end
73
+
74
+ it "should use Resourceful::Builder to build the controller" do
75
+ Resourceful::Builder.expects(:new).with(@kontroller).returns(@builder)
76
+ @kontroller.make_resourceful {}
77
+ end
78
+
79
+ it "should not evaluate the made_resourceful callbacks in the context of the builder" do
80
+ Resourceful::Base.expects(:made_resourceful).never
81
+ @kontroller.make_resourceful {}
82
+ end
83
+
84
+ it "should evaluate the :include callback in the context of the builder" do
85
+ @kontroller.make_resourceful(:include => should_be_called { with(@builder) }) {}
86
+ end
87
+
88
+ it "should evaluate the given block in the context of the builder" do
89
+ @kontroller.make_resourceful(&(should_be_called { with(@builder) }))
90
+ end
91
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Resourceful::Response, "when first created" do
4
+ before(:each) { @response = Resourceful::Response.new }
5
+
6
+ it "should have an empty formats array" do
7
+ @response.formats.should == []
8
+ end
9
+ end
10
+
11
+ describe Resourceful::Response, "with a few formats" do
12
+ before :each do
13
+ @response = Resourceful::Response.new
14
+ @response.html
15
+ @response.js {'javascript'}
16
+ @response.xml {'xml'}
17
+ end
18
+
19
+ it "should store the formats and blocks" do
20
+ @response.formats.should have_any {|f,p| f == :js && p.call == 'javascript'}
21
+ @response.formats.should have_any {|f,p| f == :xml && p.call == 'xml'}
22
+ end
23
+
24
+ it "should give formats without a block an empty block" do
25
+ @response.formats.should have_any {|f,p| f == :html && Proc === p && p.call.nil?}
26
+ end
27
+
28
+ it "shouldn't allow duplicate formats" do
29
+ @response.js {'not javascript'}
30
+ @response.formats.should have_any {|f,p| f == :js && p.call == 'javascript'}
31
+ @response.formats.should_not have_any {|f,p| f == :js && p.call == 'not javascript'}
32
+ end
33
+
34
+ it "should keep the formats in sorted order" do
35
+ @response.formats.map(&:first).should == [:html, :js, :xml]
36
+ end
37
+ end