resource_full 0.7.6

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 (35) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +100 -0
  3. data/Rakefile +19 -0
  4. data/lib/resource_full/base.rb +140 -0
  5. data/lib/resource_full/controllers/resources.rb +16 -0
  6. data/lib/resource_full/controllers/resources_controller.rb +26 -0
  7. data/lib/resource_full/controllers/routes_controller.rb +16 -0
  8. data/lib/resource_full/core_extensions/api.rb +26 -0
  9. data/lib/resource_full/core_extensions/exception.rb +25 -0
  10. data/lib/resource_full/core_extensions/from_json.rb +13 -0
  11. data/lib/resource_full/core_extensions/module.rb +13 -0
  12. data/lib/resource_full/dispatch.rb +196 -0
  13. data/lib/resource_full/models/resourced_route.rb +84 -0
  14. data/lib/resource_full/query.rb +337 -0
  15. data/lib/resource_full/render/html.rb +74 -0
  16. data/lib/resource_full/render/json.rb +107 -0
  17. data/lib/resource_full/render/xml.rb +106 -0
  18. data/lib/resource_full/render.rb +63 -0
  19. data/lib/resource_full/retrieve.rb +87 -0
  20. data/lib/resource_full/version.rb +9 -0
  21. data/lib/resource_full.rb +31 -0
  22. data/spec/resource_full/base_spec.rb +88 -0
  23. data/spec/resource_full/controllers/resources_spec.rb +30 -0
  24. data/spec/resource_full/dispatch_spec.rb +274 -0
  25. data/spec/resource_full/models/resourced_route_spec.rb +62 -0
  26. data/spec/resource_full/query/parameter_spec.rb +61 -0
  27. data/spec/resource_full/query_spec.rb +462 -0
  28. data/spec/resource_full/render/html_spec.rb +4 -0
  29. data/spec/resource_full/render/json_spec.rb +258 -0
  30. data/spec/resource_full/render/xml_spec.rb +378 -0
  31. data/spec/resource_full/render_spec.rb +5 -0
  32. data/spec/resource_full/retrieve_spec.rb +184 -0
  33. data/spec/spec.opts +4 -0
  34. data/spec/spec_helper.rb +134 -0
  35. metadata +156 -0
@@ -0,0 +1,258 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "ResourceFull::Render::JSON", :type => :controller do
4
+ controller_name "resource_full_mock_users"
5
+
6
+ class SomeNonsenseException < Exception; end
7
+
8
+ before :each do
9
+ rescue_action_in_public!
10
+ ResourceFullMockUser.delete_all
11
+ ResourceFullMockUsersController.resource_identifier = :id
12
+ end
13
+
14
+ describe "index" do
15
+ it "renders all model objects" do
16
+ 2.times { ResourceFullMockUser.create! }
17
+
18
+ get :index, :format => 'json'
19
+
20
+ hash = Hash.from_json(response.body)
21
+ hash.size.should == 2
22
+ response.code.should == '200'
23
+ end
24
+
25
+ it "rescues all unhandled exceptions with an JSON response" do
26
+ ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
27
+
28
+ get :index, :format => 'json'
29
+
30
+ response.code.should == '500'
31
+ hash = Hash.from_json(response.body)
32
+ hash["error"]["text"].should == "sparrow farts"
33
+ end
34
+
35
+ it "it sends an exception notification email if ExceptionNotifier is enabled and still renders the JSON error response" do
36
+ cleanup = unless defined? ExceptionNotifier
37
+ module ExceptionNotifier; end
38
+ module ExceptionNotifiable; end
39
+ true
40
+ end
41
+
42
+ ResourceFullMockUsersController.send :include, ExceptionNotifiable
43
+ ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
44
+ ResourceFullMockUsersController.stubs(:exception_data).returns(nil)
45
+ ResourceFullMockUsersController.any_instance.stubs(:consider_all_requests_local).returns(false)
46
+ ResourceFullMockUsersController.any_instance.stubs(:local_request?).returns(false)
47
+ ExceptionNotifier.expects(:deliver_exception_notification)
48
+
49
+ get :index, :format => 'json'
50
+
51
+ response.code.should == '500'
52
+ hash = Hash.from_json(response.body)
53
+ hash["error"]["text"].should == "sparrow farts"
54
+
55
+ if cleanup
56
+ Object.send :remove_const, :ExceptionNotifier
57
+ Object.send :remove_const, :ExceptionNotifiable
58
+ end
59
+ end
60
+
61
+ it "retains the generic error 500 when re-rendering unhandled exceptions" do
62
+ ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
63
+
64
+ get :index, :format => 'json'
65
+
66
+ response.code.should == '500'
67
+ hash = Hash.from_json(response.body)
68
+ hash["error"]["text"].should == "sparrow farts"
69
+ end
70
+ end
71
+
72
+ describe "show" do
73
+ it "renders the model object" do
74
+ user = ResourceFullMockUser.create!
75
+
76
+ get :show, :id => user.id, :format => 'json'
77
+
78
+ response.code.should == '200'
79
+ hash = Hash.from_json(response.body)
80
+ hash.should have_key("resource_full_mock_user")
81
+ end
82
+
83
+ it "renders the appropriate error message if it can't find the model object" do
84
+ get :show, :id => 1, :format => 'json'
85
+
86
+ response.code.should == '404'
87
+ hash = Hash.from_json(response.body)
88
+ hash["error"]["text"].should == "Couldn't find ResourceFullMockUser with id=1"
89
+ end
90
+
91
+ it "renders appropriate errors if a generic exception occurs" do
92
+ mock_user = ResourceFullMockUser.create!
93
+ ResourceFullMockUser.send :define_method, :to_json do
94
+ raise SomeNonsenseException, "sparrow farts"
95
+ end
96
+
97
+ begin
98
+ get :show, :id => mock_user.id.to_s, :format => 'json'
99
+
100
+ response.code.should == '500'
101
+ hash = Hash.from_json(response.body)
102
+ hash["error"]["text"].should == "sparrow farts"
103
+ ensure
104
+ ResourceFullMockUser.send :remove_method, :to_json
105
+ end
106
+ end
107
+ end
108
+
109
+ describe "new" do
110
+ it "renders the JSON for a new model object" do
111
+ get :new, :format => 'json'
112
+
113
+ response.body.should == ResourceFullMockUser.new.to_json
114
+ end
115
+ end
116
+
117
+ describe "create" do
118
+ it "creates and renders a new model object with an empty body" do
119
+ put :create, :resource_full_mock_user => { 'first_name' => 'brian' }, :format => 'json'
120
+
121
+ response.body.should == ResourceFullMockUser.find(:first).to_json
122
+ ResourceFullMockUser.find(:first).first_name.should == 'brian'
123
+ end
124
+
125
+ it "creates a new model object and returns a status code of 201 (created)" do
126
+ put :create, :resource_full_mock_user => { 'first_name' => 'brian' }, :format => 'json'
127
+
128
+ response.code.should == '201'
129
+ end
130
+
131
+ it "creates a new model object and places the location of the new object in the Location header" do
132
+ put :create, :resource_full_mock_user => {}, :format => 'json'
133
+
134
+ response.headers['Location'].should == resource_full_mock_user_url(ResourceFullMockUser.find(:first))
135
+ end
136
+
137
+ it "renders appropriate errors if a model validation fails" do
138
+ ResourceFullMockUser.send :define_method, :validate do
139
+ errors.add :first_name, "can't be blank" if self.first_name.blank?
140
+ end
141
+
142
+ begin
143
+ put :create, :resource_full_mock_user => {}, :format => 'json'
144
+
145
+ hash = Hash.from_json(response.body)
146
+ hash["resource_full_mock_user"]["errors"]["full_messages"][0].should == "First name can't be blank"
147
+ ensure
148
+ ResourceFullMockUser.send :remove_method, :validate
149
+ end
150
+ end
151
+
152
+ it "renders appropriate errors if a generic exception is raised" do
153
+ ResourceFullMockUser.send :define_method, :validate do
154
+ raise SomeNonsenseException, "sparrow farts"
155
+ end
156
+
157
+ begin
158
+ put :create, :resource_full_mock_user => {}, :format => 'json'
159
+
160
+ response.code.should == '500'
161
+ hash = Hash.from_json(response.body)
162
+ hash["error"]["text"].should == "sparrow farts"
163
+ ensure
164
+ ResourceFullMockUser.send :remove_method, :validate
165
+ end
166
+ end
167
+ end
168
+
169
+ describe "edit" do
170
+ end
171
+
172
+ describe "update" do
173
+ it "renders appropriate errors if a model could not be found" do
174
+ put :update, :id => 1, :format => 'json'
175
+
176
+ response.code.should == '404'
177
+ hash = Hash.from_json(response.body)
178
+ hash["error"]["text"].should == "Couldn't find ResourceFullMockUser with id=1"
179
+ end
180
+
181
+ it "renders appropriate errors if a model validation fails" do
182
+ mock_user = ResourceFullMockUser.create!
183
+ ResourceFullMockUser.send :define_method, :validate do
184
+ errors.add :first_name, "can't be blank" if self.first_name.blank?
185
+ end
186
+
187
+ begin
188
+ put :update, :id => mock_user.id.to_s, :resource_full_mock_user => {:first_name => ''}, :format => 'json'
189
+
190
+ response.code.should == '422'
191
+ hash = Hash.from_json(response.body)
192
+ hash["resource_full_mock_user"]["errors"]["full_messages"].should == ["First name can't be blank"]
193
+ ensure
194
+ ResourceFullMockUser.send :remove_method, :validate
195
+ end
196
+ end
197
+
198
+ it "renders appropriate errors if a generic exception is raised" do
199
+ mock_user = ResourceFullMockUser.create!
200
+ ResourceFullMockUser.send :define_method, :validate do
201
+ raise SomeNonsenseException, "sparrow farts"
202
+ end
203
+
204
+ begin
205
+ put :update, :id => mock_user.id.to_s, :format => 'json'
206
+
207
+ response.code.should == '500'
208
+ hash = Hash.from_json(response.body)
209
+ hash["error"]["text"].should == "sparrow farts"
210
+ ensure
211
+ ResourceFullMockUser.send :remove_method, :validate
212
+ end
213
+ end
214
+ end
215
+
216
+ describe "destroy" do
217
+ it "renders appropriate errors if a model could not be found" do
218
+ delete :destroy, :id => 1, :format => 'json'
219
+
220
+ response.code.should == '404'
221
+ hash = Hash.from_json(response.body)
222
+ hash["error"]["text"].should == "Couldn't find ResourceFullMockUser with id=1"
223
+ end
224
+
225
+ it "renders appropriate errors if a generic exception is raised" do
226
+ mock_user = ResourceFullMockUser.create!
227
+ ResourceFullMockUser.send :define_method, :destroy do
228
+ errors.add_to_base("Cannot delete")
229
+ raise ActiveRecord::RecordInvalid.new(self)
230
+ end
231
+
232
+ begin
233
+ delete :destroy, :id => mock_user.id.to_s, :format => 'json'
234
+
235
+ response.code.should == '422'
236
+ hash = Hash.from_json(response.body)
237
+ hash["error"]["text"].should == "Validation failed: Cannot delete"
238
+ ensure
239
+ ResourceFullMockUser.send :remove_method, :destroy
240
+ end
241
+ end
242
+
243
+ it "renders error if the model could not be destroyed"
244
+ end
245
+
246
+ if ([Rails::VERSION::MAJOR, Rails::VERSION::MINOR] <=> [2,1]) >= 0 # if the rails version is 2.1 or greater...
247
+ it "renders the model object" do
248
+ user = ResourceFullMockUser.create!
249
+
250
+ get :show, :id => user.id, :format => 'json'
251
+
252
+ user.to_json.should == response.body
253
+ hash = Hash.from_json(response.body)
254
+ hash["resource_full_mock_user"].should_not be_nil
255
+ response.code.should == '200'
256
+ end
257
+ end
258
+ end
@@ -0,0 +1,378 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+
4
+ describe "ResourceFull::Render::XML" , :type => :controller do
5
+ describe ResourceFullNamespacedMockRecordsController do
6
+ describe "index" do
7
+ it "renders all model objects using simple model_name when model_class is namespaced" do
8
+ 2.times { ResourceFullSpec::ResourceFullNamespacedMockRecord.create! }
9
+
10
+ get :index, :format => 'xml'
11
+
12
+ response.code.should == '200'
13
+ response_hash = Hash.from_xml(response.body)['resource_full_namespaced_mock_records']
14
+ response_hash.size.should == 2
15
+ end
16
+ end
17
+ describe "show" do
18
+ it "renders the model object" do
19
+ record = ResourceFullSpec::ResourceFullNamespacedMockRecord.create!
20
+
21
+ get :show, :id => record.id, :format => 'xml'
22
+
23
+ response.code.should == '200'
24
+ response.body.should have_tag("resource-full-namespaced-mock-record")
25
+ end
26
+ end
27
+ describe "new" do
28
+ it "renders the XML for a new model object" do
29
+ get :new, :format => 'xml'
30
+
31
+ response.code.should == '200'
32
+ response.body.should == ResourceFullSpec::ResourceFullNamespacedMockRecord.new.to_xml(:root => :resource_full_namespaced_mock_record)
33
+ end
34
+ end
35
+
36
+ describe "create" do
37
+ it "creates and renders a new model object with an empty body" do
38
+ put :create, :resource_full_namespaced_mock_record => { 'name' => 'brian' }, :format => 'xml'
39
+
40
+ response.code.should == '201'
41
+ response.body.should == ResourceFullSpec::ResourceFullNamespacedMockRecord.find(:first).to_xml(:root => :resource_full_namespaced_mock_record)
42
+ ResourceFullSpec::ResourceFullNamespacedMockRecord.find(:first).name.should == 'brian'
43
+ end
44
+
45
+ it "creates a new model object and returns a status code of 201 (created)" do
46
+ put :create, :resource_full_namespaced_mock_record => { 'name' => 'brian' }, :format => 'xml'
47
+
48
+ response.code.should == '201'
49
+ end
50
+
51
+ it "creates a new model object and places the location of the new object in the Location header" do
52
+ put :create, :resource_full_namespaced_mock_record => {}, :format => 'xml'
53
+
54
+ response.headers['Location'].should == resource_full_namespaced_mock_record_url(ResourceFullSpec::ResourceFullNamespacedMockRecord.find(:first))
55
+ end
56
+ end
57
+
58
+ describe "update" do
59
+ it "updates and renders the model object" do
60
+ record = ResourceFullSpec::ResourceFullNamespacedMockRecord.create!
61
+
62
+ put :update, :id => record.id, :format => 'xml', :resource_full_namespaced_mock_record => {:name => 'the new name'}
63
+
64
+ response.code.should == '200'
65
+ response.body.should have_tag("resource-full-namespaced-mock-record") do
66
+ with_tag "name", "the new name"
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ describe ResourceFullNamespacedMockRecordWithXmlOverridesController do
73
+ describe "index" do
74
+ it "renders all model objects using simple model_name when model_class is namespaced" do
75
+ 2.times { ResourceFullSpec::ResourceFullNamespacedMockRecord.create! }
76
+
77
+ get :index, :format => 'xml'
78
+
79
+ response.code.should == '200'
80
+ response_hash = Hash.from_xml(response.body)['my_index_roots']
81
+ response_hash.size.should == 2
82
+ end
83
+ end
84
+ describe "show" do
85
+ it "renders the model object" do
86
+ record = ResourceFullSpec::ResourceFullNamespacedMockRecord.create!
87
+
88
+ get :show, :id => record.id, :format => 'xml'
89
+
90
+ response.code.should == '200'
91
+ response.body.should have_tag("my-show-root")
92
+ end
93
+ end
94
+ describe "new" do
95
+ it "renders the XML for a new model object" do
96
+ get :new, :format => 'xml'
97
+
98
+ response.code.should == '200'
99
+ response.body.should == ResourceFullSpec::ResourceFullNamespacedMockRecord.new.to_xml(:root => 'my_new_root')
100
+ end
101
+ end
102
+
103
+ describe "create" do
104
+ it "creates and renders a new model object with an empty body" do
105
+ put :create, :resource_full_namespaced_mock_record => { 'name' => 'brian' }, :format => 'xml'
106
+
107
+ response.code.should == '201'
108
+ response.body.should == ResourceFullSpec::ResourceFullNamespacedMockRecord.find(:first).to_xml(:root => 'my_create_root')
109
+ ResourceFullSpec::ResourceFullNamespacedMockRecord.find(:first).name.should == 'brian'
110
+ end
111
+
112
+ it "creates a new model object and returns a status code of 201 (created)" do
113
+ put :create, :resource_full_namespaced_mock_record => { 'name' => 'brian' }, :format => 'xml'
114
+
115
+ response.code.should == '201'
116
+ end
117
+
118
+ it "creates a new model object and places the location of the new object in the Location header" do
119
+ put :create, :resource_full_namespaced_mock_record => {}, :format => 'xml'
120
+
121
+ response.headers['Location'].should == resource_full_namespaced_mock_record_url(ResourceFullSpec::ResourceFullNamespacedMockRecord.find(:first))
122
+ end
123
+ end
124
+
125
+ describe "update" do
126
+ it "updates and renders the model object" do
127
+ record = ResourceFullSpec::ResourceFullNamespacedMockRecord.create!
128
+
129
+ put :update, :id => record.id, :format => 'xml', :resource_full_namespaced_mock_record => {:name => 'the new name'}
130
+
131
+ response.code.should == '200'
132
+ response.body.should have_tag("my-update-root") do
133
+ with_tag "name", "the new name"
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ describe ResourceFullMockUsersController do
140
+
141
+ class SomeNonsenseException < Exception; end
142
+
143
+ before :each do
144
+ rescue_action_in_public!
145
+ ResourceFullMockUser.delete_all
146
+ ResourceFullMockUsersController.resource_identifier = :id
147
+ end
148
+
149
+ describe "index" do
150
+ it "renders all model objects" do
151
+ 2.times { ResourceFullMockUser.create! }
152
+
153
+ get :index, :format => 'xml'
154
+
155
+ Hash.from_xml(response.body)['resource_full_mock_users'].size.should == 2
156
+ response.code.should == '200'
157
+ end
158
+
159
+ it "renders all model objects using sub-class name" do
160
+ 2.times { ResourceFullMockSubUser.create! }
161
+
162
+ get :index, :format => 'xml'
163
+ Hash.from_xml(response.body)['resource_full_mock_sub_users'].size.should == 2
164
+ response.code.should == '200'
165
+ end
166
+
167
+ it "rescues all unhandled exceptions with an XML response" do
168
+ ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
169
+
170
+ get :index, :format => 'xml'
171
+
172
+ response.code.should == '500'
173
+ response.should have_tag("errors") { with_tag("error", "sparrow farts") }
174
+ end
175
+
176
+ it "it sends an exception notification email if ExceptionNotifier is enabled and still renders the XML error response" do
177
+ cleanup = unless defined? ExceptionNotifier
178
+ module ExceptionNotifier; end
179
+ module ExceptionNotifiable; end
180
+ true
181
+ end
182
+
183
+ ResourceFullMockUsersController.send :include, ExceptionNotifiable
184
+ ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
185
+ ResourceFullMockUsersController.stubs(:exception_data).returns(nil)
186
+ ResourceFullMockUsersController.any_instance.stubs(:consider_all_requests_local).returns(false)
187
+ ResourceFullMockUsersController.any_instance.stubs(:local_request?).returns(false)
188
+ ExceptionNotifier.expects(:deliver_exception_notification)
189
+
190
+ get :index, :format => 'xml'
191
+
192
+ response.code.should == '500'
193
+ response.should have_tag("errors") { with_tag("error", "sparrow farts") }
194
+
195
+ if cleanup
196
+ Object.send :remove_const, :ExceptionNotifier
197
+ Object.send :remove_const, :ExceptionNotifiable
198
+ end
199
+ end
200
+
201
+ it "retains the generic error 500 when re-rendering unhandled exceptions" do
202
+ ResourceFullMockUser.expects(:find).raises SomeNonsenseException, "sparrow farts"
203
+
204
+ get :index, :format => 'xml'
205
+
206
+ response.code.should == '500'
207
+ response.should have_tag("errors") { with_tag("error", "sparrow farts") }
208
+ end
209
+ end
210
+
211
+ describe "show" do
212
+ it "renders the model object" do
213
+ user = ResourceFullMockUser.create!
214
+
215
+ get :show, :id => user.id, :format => 'xml'
216
+
217
+ response.code.should == '200'
218
+ response.body.should have_tag("resource-full-mock-user")
219
+ end
220
+
221
+ it "renders the appropriate error message if it can't find the model object" do
222
+ get :show, :id => 1, :format => 'xml'
223
+
224
+ response.code.should == '404'
225
+ response.body.should have_tag("errors") { with_tag("error", "Couldn't find ResourceFullMockUser with id=1") }
226
+ end
227
+
228
+ it "renders appropriate errors if a generic exception occurs" do
229
+ mock_user = ResourceFullMockUser.create!
230
+ ResourceFullMockUser.send :define_method, :to_xml do
231
+ raise SomeNonsenseException, "sparrow farts"
232
+ end
233
+
234
+ begin
235
+ get :show, :id => mock_user.id.to_s, :format => 'xml'
236
+
237
+ response.code.should == '500'
238
+ response.should have_tag("errors") { with_tag("error", "sparrow farts")}
239
+ ensure
240
+ ResourceFullMockUser.send :remove_method, :to_xml
241
+ end
242
+ end
243
+ end
244
+
245
+ describe "new" do
246
+ it "renders the XML for a new model object" do
247
+ get :new, :format => 'xml'
248
+
249
+ response.code.should == '200'
250
+ response.body.should == ResourceFullMockUser.new.to_xml
251
+ end
252
+ end
253
+
254
+ describe "create" do
255
+ it "creates and renders a new model object with an empty body" do
256
+ put :create, :resource_full_mock_user => { 'first_name' => 'brian' }, :format => 'xml'
257
+
258
+ response.code.should == '201'
259
+ response.body.should == ResourceFullMockUser.find(:first).to_xml
260
+ ResourceFullMockUser.find(:first).first_name.should == 'brian'
261
+ end
262
+
263
+ it "creates a new model object and returns a status code of 201 (created)" do
264
+ put :create, :resource_full_mock_user => { 'first_name' => 'brian' }, :format => 'xml'
265
+
266
+ response.code.should == '201'
267
+ end
268
+
269
+ it "creates a new model object and places the location of the new object in the Location header" do
270
+ put :create, :resource_full_mock_user => {}, :format => 'xml'
271
+
272
+ response.headers['Location'].should == resource_full_mock_user_url(ResourceFullMockUser.find(:first))
273
+ end
274
+
275
+ it "renders appropriate errors if a model validation fails" do
276
+ ResourceFullMockUser.send :define_method, :validate do
277
+ errors.add :first_name, "can't be blank" if self.first_name.blank?
278
+ end
279
+
280
+ begin
281
+ put :create, :resource_full_mock_user => {}, :format => 'xml'
282
+
283
+ response.code.should == '422'
284
+ response.should have_tag("errors") { with_tag("error", "First name can't be blank")}
285
+ ensure
286
+ ResourceFullMockUser.send :remove_method, :validate
287
+ end
288
+ end
289
+
290
+ it "renders appropriate errors if a generic exception is raised" do
291
+ ResourceFullMockUser.send :define_method, :validate do
292
+ raise SomeNonsenseException, "sparrow farts"
293
+ end
294
+
295
+ begin
296
+ put :create, :resource_full_mock_user => {}, :format => 'xml'
297
+
298
+ response.code.should == '500'
299
+ response.should have_tag("errors") { with_tag("error", "sparrow farts")}
300
+ ensure
301
+ ResourceFullMockUser.send :remove_method, :validate
302
+ end
303
+ end
304
+ end
305
+
306
+ describe "edit" do
307
+ end
308
+
309
+ describe "update" do
310
+ it "renders appropriate errors if a model could not be found" do
311
+ put :update, :id => 1, :format => 'xml'
312
+
313
+ response.code.should == '404'
314
+ response.should have_tag("errors") { with_tag("error", "Couldn't find ResourceFullMockUser with id=1")}
315
+ end
316
+
317
+ it "renders appropriate errors if a model validation fails" do
318
+ mock_user = ResourceFullMockUser.create!
319
+ ResourceFullMockUser.send :define_method, :validate do
320
+ errors.add :first_name, "can't be blank" if self.first_name.blank?
321
+ end
322
+
323
+ begin
324
+ put :update, :id => mock_user.id.to_s, :resource_full_mock_user => {:first_name => ''}, :format => 'xml'
325
+
326
+ response.code.should == '422'
327
+ response.should have_tag("errors") { with_tag("error", "First name can't be blank")}
328
+ ensure
329
+ ResourceFullMockUser.send :remove_method, :validate
330
+ end
331
+ end
332
+
333
+ it "renders appropriate errors if a generic exception is raised" do
334
+ mock_user = ResourceFullMockUser.create!
335
+ ResourceFullMockUser.send :define_method, :validate do
336
+ raise SomeNonsenseException, "sparrow farts"
337
+ end
338
+
339
+ begin
340
+ put :update, :id => mock_user.id.to_s, :format => 'xml'
341
+
342
+ response.code.should == '500'
343
+ response.should have_tag("errors") { with_tag("error", "sparrow farts") }
344
+ ensure
345
+ ResourceFullMockUser.send :remove_method, :validate
346
+ end
347
+ end
348
+ end
349
+
350
+ describe "destroy" do
351
+ it "renders appropriate errors if a model could not be found" do
352
+ delete :destroy, :id => 1, :format => 'xml'
353
+
354
+ response.code.should == '404'
355
+ response.should have_tag("errors") { with_tag("error", "Couldn't find ResourceFullMockUser with id=1")}
356
+ end
357
+
358
+ it "renders appropriate errors if a generic exception is raised" do
359
+ mock_user = ResourceFullMockUser.create!
360
+ ResourceFullMockUser.send :define_method, :destroy do
361
+ errors.add_to_base("Cannot delete")
362
+ raise ActiveRecord::RecordInvalid.new(self)
363
+ end
364
+
365
+ begin
366
+ delete :destroy, :id => mock_user.id.to_s, :format => 'xml'
367
+
368
+ response.code.should == '422'
369
+ response.should have_tag("errors") { with_tag("error", "Validation failed: Cannot delete") }
370
+ ensure
371
+ ResourceFullMockUser.send :remove_method, :destroy
372
+ end
373
+ end
374
+
375
+ it "renders error if the model could not be destroyed"
376
+ end
377
+ end
378
+ end
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "ResourceFull::Render", :type => :controller do
4
+ end
5
+