radiant-shop-extension 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +26 -0
  3. data/Gemfile.lock +75 -0
  4. data/HISTORY.md +77 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +26 -0
  7. data/Rakefile +141 -0
  8. data/VERSION +1 -0
  9. data/app/.DS_Store +0 -0
  10. data/app/controllers/admin/shop/categories_controller.rb +206 -0
  11. data/app/controllers/admin/shop/customers_controller.rb +137 -0
  12. data/app/controllers/admin/shop/orders_controller.rb +171 -0
  13. data/app/controllers/admin/shop/products/images_controller.rb +144 -0
  14. data/app/controllers/admin/shop/products_controller.rb +217 -0
  15. data/app/controllers/admin/shops_controller.rb +9 -0
  16. data/app/controllers/shop/categories_controller.rb +49 -0
  17. data/app/controllers/shop/line_items_controller.rb +165 -0
  18. data/app/controllers/shop/orders_controller.rb +16 -0
  19. data/app/controllers/shop/products_controller.rb +48 -0
  20. data/app/models/form_checkout.rb +245 -0
  21. data/app/models/shop_address.rb +13 -0
  22. data/app/models/shop_addressable.rb +11 -0
  23. data/app/models/shop_category.rb +85 -0
  24. data/app/models/shop_category_page.rb +7 -0
  25. data/app/models/shop_customer.rb +27 -0
  26. data/app/models/shop_line_item.rb +32 -0
  27. data/app/models/shop_order.rb +108 -0
  28. data/app/models/shop_payment.rb +6 -0
  29. data/app/models/shop_payment_method.rb +5 -0
  30. data/app/models/shop_product.rb +87 -0
  31. data/app/models/shop_product_attachment.rb +30 -0
  32. data/app/models/shop_product_page.rb +7 -0
  33. data/app/views/.DS_Store +0 -0
  34. data/app/views/admin/.DS_Store +0 -0
  35. data/app/views/admin/pages/_shop_category.html.haml +4 -0
  36. data/app/views/admin/pages/_shop_product.html.haml +4 -0
  37. data/app/views/admin/shop/categories/edit.html.haml +12 -0
  38. data/app/views/admin/shop/categories/edit/_fields.html.haml +28 -0
  39. data/app/views/admin/shop/categories/edit/_head.html.haml +2 -0
  40. data/app/views/admin/shop/categories/edit/_meta.html.haml +7 -0
  41. data/app/views/admin/shop/categories/edit/_part.html.haml +3 -0
  42. data/app/views/admin/shop/categories/edit/_popup.html.haml +3 -0
  43. data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +5 -0
  44. data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +10 -0
  45. data/app/views/admin/shop/categories/edit/parts/_description.html.haml +1 -0
  46. data/app/views/admin/shop/categories/index/_category.html.haml +16 -0
  47. data/app/views/admin/shop/categories/new.html.haml +10 -0
  48. data/app/views/admin/shop/categories/remove.html.haml +12 -0
  49. data/app/views/admin/shop/customers/index.html.haml +36 -0
  50. data/app/views/admin/shop/orders/index.html.haml +33 -0
  51. data/app/views/admin/shop/products/edit.html.haml +14 -0
  52. data/app/views/admin/shop/products/edit/_fields.html.haml +38 -0
  53. data/app/views/admin/shop/products/edit/_head.html.haml +2 -0
  54. data/app/views/admin/shop/products/edit/_image.html.haml +12 -0
  55. data/app/views/admin/shop/products/edit/_meta.html.haml +8 -0
  56. data/app/views/admin/shop/products/edit/_part.html.haml +3 -0
  57. data/app/views/admin/shop/products/edit/_popup.html.haml +3 -0
  58. data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -0
  59. data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -0
  60. data/app/views/admin/shop/products/edit/meta/_category.html.haml +5 -0
  61. data/app/views/admin/shop/products/edit/meta/_sku.html.haml +5 -0
  62. data/app/views/admin/shop/products/edit/parts/_description.html.haml +1 -0
  63. data/app/views/admin/shop/products/edit/parts/_images.html.haml +5 -0
  64. data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +6 -0
  65. data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +18 -0
  66. data/app/views/admin/shop/products/index.html.haml +10 -0
  67. data/app/views/admin/shop/products/index/_bottom.html.haml +5 -0
  68. data/app/views/admin/shop/products/index/_product.html.haml +13 -0
  69. data/app/views/admin/shop/products/new.html.haml +10 -0
  70. data/app/views/admin/shop/products/remove.html.haml +12 -0
  71. data/app/views/shop/categories/show.html.haml +1 -0
  72. data/app/views/shop/orders/show.html.haml +1 -0
  73. data/app/views/shop/products/index.html.haml +1 -0
  74. data/app/views/shop/products/show.html.haml +1 -0
  75. data/config/locales/en.yml +50 -0
  76. data/config/routes.rb +38 -0
  77. data/config/shop_cart.yml +16 -0
  78. data/cucumber.yml +1 -0
  79. data/db/migrate/20100311053701_initial.rb +153 -0
  80. data/db/migrate/20100520033059_create_layouts.rb +119 -0
  81. data/db/migrate/20100903122123_create_forms.rb +44 -0
  82. data/db/migrate/20100908063639_create_snippets.rb +22 -0
  83. data/features/support/env.rb +16 -0
  84. data/features/support/paths.rb +14 -0
  85. data/lib/shop/controllers/application_controller.rb +39 -0
  86. data/lib/shop/controllers/site_controller.rb +12 -0
  87. data/lib/shop/interface/products.rb +49 -0
  88. data/lib/shop/models/image.rb +14 -0
  89. data/lib/shop/models/page.rb +14 -0
  90. data/lib/shop/tags/address.rb +40 -0
  91. data/lib/shop/tags/cart.rb +49 -0
  92. data/lib/shop/tags/category.rb +83 -0
  93. data/lib/shop/tags/core.rb +12 -0
  94. data/lib/shop/tags/helpers.rb +142 -0
  95. data/lib/shop/tags/item.rb +109 -0
  96. data/lib/shop/tags/product.rb +109 -0
  97. data/lib/shop/tags/responses.rb +34 -0
  98. data/lib/tasks/shop_extension_tasks.rake +54 -0
  99. data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
  100. data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
  101. data/public/images/admin/extensions/shop/products/sort.png +0 -0
  102. data/public/javascripts/admin/extensions/shop/products/edit.js +115 -0
  103. data/public/javascripts/admin/extensions/shop/products/index.js +65 -0
  104. data/public/stylesheets/sass/admin/extensions/shop/edit.sass +86 -0
  105. data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +158 -0
  106. data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +129 -0
  107. data/radiant-shop-extension.gemspec +245 -0
  108. data/shop_extension.rb +62 -0
  109. data/spec/controllers/admin/shop/categories_controller_spec.rb +443 -0
  110. data/spec/controllers/admin/shop/products/images_controller_spec.rb +477 -0
  111. data/spec/controllers/admin/shop/products_controller_spec.rb +394 -0
  112. data/spec/controllers/admin/shops_controller_spec.rb +19 -0
  113. data/spec/controllers/shop/categories_controller_spec.rb +42 -0
  114. data/spec/controllers/shop/line_items_controller_spec.rb +256 -0
  115. data/spec/controllers/shop/orders_controller_specs.rb +37 -0
  116. data/spec/controllers/shop/products_controller_spec.rb +51 -0
  117. data/spec/datasets/forms.rb +153 -0
  118. data/spec/datasets/images.rb +13 -0
  119. data/spec/datasets/shop_addresses.rb +27 -0
  120. data/spec/datasets/shop_categories.rb +13 -0
  121. data/spec/datasets/shop_line_items.rb +9 -0
  122. data/spec/datasets/shop_orders.rb +21 -0
  123. data/spec/datasets/shop_products.rb +34 -0
  124. data/spec/helpers/nested_tag_helper.rb +33 -0
  125. data/spec/lib/shop/models/image_spec.rb +28 -0
  126. data/spec/lib/shop/models/page_spec.rb +38 -0
  127. data/spec/lib/shop/tags/address_spec.rb +196 -0
  128. data/spec/lib/shop/tags/cart_spec.rb +169 -0
  129. data/spec/lib/shop/tags/category_spec.rb +201 -0
  130. data/spec/lib/shop/tags/core_spec.rb +16 -0
  131. data/spec/lib/shop/tags/helpers_spec.rb +381 -0
  132. data/spec/lib/shop/tags/item_spec.rb +313 -0
  133. data/spec/lib/shop/tags/product_spec.rb +334 -0
  134. data/spec/matchers/comparison.rb +72 -0
  135. data/spec/matchers/render_matcher.rb +33 -0
  136. data/spec/models/form_checkout_spec.rb +376 -0
  137. data/spec/models/shop_category_page_spec.rb +10 -0
  138. data/spec/models/shop_category_spec.rb +58 -0
  139. data/spec/models/shop_line_item_spec.rb +42 -0
  140. data/spec/models/shop_order_spec.rb +228 -0
  141. data/spec/models/shop_product_attachment_spec.rb +72 -0
  142. data/spec/models/shop_product_page_spec.rb +10 -0
  143. data/spec/models/shop_product_spec.rb +135 -0
  144. data/spec/spec.opts +6 -0
  145. data/spec/spec_helper.rb +22 -0
  146. data/vendor/plugins/acts_as_list/README +23 -0
  147. data/vendor/plugins/acts_as_list/init.rb +3 -0
  148. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  149. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  150. data/vendor/plugins/json_fields/.gitignore +3 -0
  151. data/vendor/plugins/json_fields/MIT-LICENSE +20 -0
  152. data/vendor/plugins/json_fields/README.rdoc +65 -0
  153. data/vendor/plugins/json_fields/Rakefile +55 -0
  154. data/vendor/plugins/json_fields/init.rb +2 -0
  155. data/vendor/plugins/json_fields/lib/json_fields.rb +99 -0
  156. data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +124 -0
  157. data/vendor/plugins/json_fields/spec/spec.opts +6 -0
  158. data/vendor/plugins/json_fields/spec/spec_helper.rb +29 -0
  159. data/vendor/plugins/json_fields/spec/test_models.rb +12 -0
  160. metadata +324 -0
@@ -0,0 +1,477 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Admin::Shop::Products::ImagesController do
4
+
5
+ dataset :users
6
+
7
+ before(:each) do
8
+ login_as :admin
9
+
10
+ @shop_product = Object.new
11
+ stub(@shop_product).id { 1 }
12
+ mock(ShopProduct).find('1') { @shop_product }
13
+
14
+ @image = Object.new
15
+ @images = [ @image ]
16
+ end
17
+
18
+ describe '#index' do
19
+ context 'product has no images' do
20
+ before :each do
21
+ stub(@shop_product).images { [] }
22
+ end
23
+
24
+ context 'html' do
25
+ it 'should assign an error and redirect to edit_shop_product path' do
26
+ get :index, :product_id => @shop_product.id
27
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
28
+ flash.now[:error].should_not be_nil
29
+ end
30
+ end
31
+
32
+ context 'js' do
33
+ it 'should return an error string and unprocessable status' do
34
+ get :index, :product_id => @shop_product.id, :format => 'js'
35
+ response.should_not be_success
36
+ response.body.should === 'This Product has no Images.'
37
+ end
38
+ end
39
+
40
+ context 'json' do
41
+ it 'should return a json error object and unprocessable status' do
42
+ get :index, :product_id => @shop_product.id, :format => 'json'
43
+ response.should_not be_success
44
+ JSON.parse(response.body)['error'].should === 'This Product has no Images.'
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'product has images' do
50
+ before :each do
51
+ stub(@shop_product).images { @images }
52
+ end
53
+
54
+ context 'html' do
55
+ before :each do
56
+ get :index, :product_id => @shop_product.id
57
+ end
58
+
59
+ it 'should not assign an error or notice and redirect to edit_shop_product path' do
60
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
61
+ flash.now[:error].should be_nil
62
+ flash.now[:notice].should be_nil
63
+ end
64
+
65
+ it 'should assign the shop_product_images instance variable' do
66
+ assigns(:shop_product_images).should === @images
67
+ end
68
+ end
69
+
70
+ context 'js' do
71
+ before :each do
72
+ get :index, :product_id => @shop_product.id, :format => 'js'
73
+ end
74
+
75
+ it 'should render the collection partial and success status' do
76
+ response.should be_success
77
+ response.should render_template('/admin/shop/products/edit/_image')
78
+ end
79
+
80
+ it 'should assign the shop_product_images instance variable' do
81
+ assigns(:shop_product_images).should === @images
82
+ end
83
+ end
84
+
85
+ context 'json' do
86
+ before :each do
87
+ get :index, :product_id => @shop_product.id, :format => 'json'
88
+ end
89
+
90
+ it 'should return a json object of the array and success status' do
91
+ response.should be_success
92
+ response.body.should === @images.to_json(ShopProductAttachment.params)
93
+ end
94
+
95
+ it 'should assign the shop_product_images instance variable' do
96
+ assigns(:shop_product_images).should === @images
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ describe '#sort' do
103
+
104
+ before :each do
105
+ @attachments = [
106
+ 'product_attachments[]=2',
107
+ 'product_attachments[]=1'
108
+ ].join('&')
109
+ end
110
+
111
+ context 'could not sort' do
112
+ before :each do
113
+ stub(@shop_product).attachments.stub!.find('2').stub!.update_attributes!({ :position => 1 }) { raise ActiveRecord::RecordNotFound }
114
+
115
+ stub(@shop_product).images { @images }
116
+ end
117
+
118
+ context 'html' do
119
+ it 'should assign an error and redirect to edit_shop_product path' do
120
+ put :sort, :product_id => @shop_product.id, :attachments => @attachments
121
+ flash.now[:error].should_not be_nil
122
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
123
+ end
124
+ end
125
+
126
+ context 'js' do
127
+ it 'should return an error string and unprocessable status' do
128
+ put :sort, :product_id => @shop_product.id, :attachments => @attachments, :format => 'js'
129
+ response.should_not be_success
130
+ response.body.should === 'Could not sort Images.'
131
+ end
132
+ end
133
+
134
+ context 'json' do
135
+ it 'should return a json error object and unprocessable status' do
136
+ put :sort, :product_id => @shop_product.id, :attachments => @attachments, :format => 'json'
137
+ response.should_not be_success
138
+ JSON.parse(response.body)['error'].should === 'Could not sort Images.'
139
+ end
140
+ end
141
+ end
142
+
143
+ context 'successfully sorted' do
144
+ before :each do
145
+ mock(ShopProductAttachment).find('2').stub!.update_attributes!({:position => 1}) { true }
146
+ mock(ShopProductAttachment).find('1').stub!.update_attributes!({:position => 2}) { true }
147
+
148
+ stub(@shop_product).images { @images }
149
+ end
150
+
151
+ context 'html' do
152
+ before :each do
153
+ put :sort, :product_id => @shop_product.id, :attachments => @attachments
154
+ end
155
+
156
+ it 'should assign a notice and redirect to edit_shop_product path' do
157
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
158
+ flash.now[:notice].should_not be_nil
159
+ end
160
+
161
+ it 'should have ordered the images based on input' do
162
+ assigns(:images).first.should === '2'
163
+ assigns(:images).last.should === '1'
164
+ end
165
+ end
166
+
167
+ context 'js' do
168
+ before :each do
169
+ put :sort, :product_id => @shop_product.id, :attachments => @attachments, :format => 'js'
170
+ end
171
+
172
+ it 'should render the collection partial and success status' do
173
+ response.should be_success
174
+ response.should render_template('/admin/shop/products/edit/_image')
175
+ end
176
+
177
+ it 'should have ordered the images based on input' do
178
+ assigns(:images).first.should === '2'
179
+ assigns(:images).last.should === '1'
180
+ end
181
+ end
182
+
183
+ context 'json' do
184
+ before :each do
185
+ put :sort, :product_id => @shop_product.id, :attachments => @attachments, :format => 'json'
186
+ end
187
+
188
+ it 'should return a json object of the array and success status' do
189
+ response.should be_success
190
+ response.body.should == @images.to_json(ShopProductAttachment.params)
191
+ end
192
+
193
+ it 'should have ordered the images based on input' do
194
+ assigns(:images).first.should === '2'
195
+ assigns(:images).last.should === '1'
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ describe '#create' do
202
+ context 'new image' do
203
+ context 'could not create image' do
204
+ before :each do
205
+ mock(Image).create!('FileObject') { raise 'Could not create Image' }
206
+ end
207
+
208
+ context 'html' do
209
+ it 'should assign an error and redirect to edit_shop_product path' do
210
+ post :create, :product_id => @shop_product.id, :image => 'FileObject'
211
+ flash.now[:error].should_not be_nil
212
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
213
+ end
214
+ end
215
+
216
+ context 'js' do
217
+ it 'should return an error string and unprocessable status' do
218
+ post :create, :product_id => @shop_product.id, :image => 'FileObject', :format => 'js'
219
+ response.should_not be_success
220
+ response.body.should == 'Unable to create Image.'
221
+ end
222
+ end
223
+
224
+ context 'json' do
225
+ it 'should return a json error object and unprocessable status' do
226
+ post :create, :product_id => @shop_product.id, :image => 'FileObject', :format => 'json'
227
+ response.should_not be_success
228
+ JSON.parse(response.body)['error'].should === 'Unable to create Image.'
229
+ end
230
+ end
231
+
232
+ end
233
+
234
+ context 'successfully created image' do
235
+ before :each do
236
+ mock(Image).create!('FileObject') { @image }
237
+ end
238
+
239
+ context 'could not create attachment' do
240
+ before :each do
241
+ stub(@shop_product).attachments.stub!.create!({ :image => @image }) { raise ActiveRecord::RecordNotSaved }
242
+ end
243
+
244
+ context 'html' do
245
+ it 'should assign an error and redirect to edit_shop_product path' do
246
+ post :create, :product_id => @shop_product.id, :image => 'FileObject'
247
+ flash.now[:error].should_not be_nil
248
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
249
+ end
250
+ end
251
+
252
+ context 'js' do
253
+ it 'should return an error string and unprocessable status' do
254
+ post :create, :product_id => @shop_product.id, :image => 'FileObject', :format => 'js'
255
+ response.should_not be_success
256
+ response.body.should == 'Unable to create Image.'
257
+ end
258
+ end
259
+
260
+ context 'json' do
261
+ it 'should return a json error object and unprocessable status' do
262
+ post :create, :product_id => @shop_product.id, :image => 'FileObject', :format => 'json'
263
+ response.should_not be_success
264
+ JSON.parse(response.body)['error'].should === 'Unable to create Image.'
265
+ end
266
+ end
267
+ end
268
+
269
+ context 'successfully created attachment' do
270
+ before :each do
271
+ @attachment = Object.new
272
+ stub(@shop_product).attachments.stub!.create!({ :image => @image }) { @attachment }
273
+ end
274
+
275
+ context 'html' do
276
+ it 'should assign a notice and redirect to edit_shop_product path' do
277
+ post :create, :product_id => @shop_product.id, :image => 'FileObject'
278
+ flash.now[:notice].should_not be_nil
279
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
280
+ end
281
+ end
282
+
283
+ context 'js' do
284
+ it 'should render the collection partial and success status' do
285
+ post :create, :product_id => @shop_product.id, :image => 'FileObject', :format => 'js'
286
+ response.should be_success
287
+ assigns(:shop_product_attachment).should == @attachment
288
+ response.should render_template('/admin/shop/products/edit/_image')
289
+ end
290
+ end
291
+
292
+ context 'json' do
293
+ it 'should return a json object of the array and success status' do
294
+ post :create, :product_id => @shop_product.id, :image => 'FileObject', :format => 'json'
295
+ response.should be_success
296
+ response.body.should == @attachment.to_json(ShopProductAttachment.params)
297
+ end
298
+ end
299
+ end
300
+ end
301
+ end
302
+
303
+ context 'existing image' do
304
+ context 'could not find image' do
305
+ before :each do
306
+ mock(Image).find('1') { raise 'Could not find Image' }
307
+ end
308
+
309
+ context 'html' do
310
+ it 'should assign an error and redirect to edit_shop_product path' do
311
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }
312
+ flash.now[:error].should_not be_nil
313
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
314
+ end
315
+ end
316
+
317
+ context 'js' do
318
+ it 'should return an error string and unprocessable status' do
319
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }, :format => 'js'
320
+ response.should_not be_success
321
+ response.body.should == 'Unable to create Image.'
322
+ end
323
+ end
324
+
325
+ context 'json' do
326
+ it 'should return a json error object and unprocessable status' do
327
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }, :format => 'json'
328
+ response.should_not be_success
329
+ JSON.parse(response.body)['error'].should == 'Unable to create Image.'
330
+ end
331
+ end
332
+ end
333
+
334
+ context 'successfully found image' do
335
+ before :each do
336
+ mock(Image).find('1') { @image }
337
+ end
338
+
339
+ context 'could not create attachment' do
340
+ before :each do
341
+ stub(@shop_product).attachments.stub!.create!({ :image => @image }) { raise ActiveRecord::RecordNotSaved }
342
+ end
343
+
344
+ context 'html' do
345
+ it 'should assign an error and redirect to edit_shop_product path' do
346
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }
347
+ flash.now[:error].should_not be_nil
348
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
349
+ end
350
+ end
351
+
352
+ context 'js' do
353
+ it 'should return an error string and unprocessable status' do
354
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }, :format => 'js'
355
+ response.should_not be_success
356
+ response.body.should == 'Unable to create Image.'
357
+ end
358
+ end
359
+
360
+ context 'json' do
361
+ it 'should return a json error object and unprocessable status' do
362
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }, :format => 'json'
363
+ response.should_not be_success
364
+ JSON.parse(response.body)['error'].should == 'Unable to create Image.'
365
+ end
366
+ end
367
+ end
368
+
369
+ context 'successfully created attachment' do
370
+ before :each do
371
+ @attachment = Object.new
372
+ stub(@shop_product).attachments.stub!.create!({ :image => @image }) { @attachment }
373
+ end
374
+
375
+ context 'html' do
376
+ it 'should assign a notice and redirect to edit_shop_product path' do
377
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }
378
+ flash.now[:notice].should_not be_nil
379
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
380
+ end
381
+ end
382
+
383
+ context 'js' do
384
+ it 'should render the collection partial and success status' do
385
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }, :format => 'js'
386
+ response.should be_success
387
+ assigns(:shop_product_attachment).should === @attachment
388
+ response.should render_template('/admin/shop/products/edit/_image')
389
+ end
390
+ end
391
+
392
+ context 'json' do
393
+ it 'should return a json object of the array and success status' do
394
+ post :create, :product_id => @shop_product.id, :attachment => { :image_id => '1' }, :format => 'json'
395
+ response.should be_success
396
+ response.body.should == @attachment.to_json(ShopProductAttachment.params)
397
+ end
398
+ end
399
+ end
400
+ end
401
+ end
402
+ end
403
+
404
+ describe '#destroy' do
405
+ context 'Attachment does not exist' do
406
+ # Resource controller handles this
407
+ end
408
+ context 'Attachment exists' do
409
+ before :each do
410
+ mock(ShopProductAttachment).find('1') { @image }
411
+ stub(@image).id { 1 }
412
+ end
413
+ context 'could not destroy attachment' do
414
+ before :each do
415
+ stub(@image).destroy { raise 'Could not destroy attachment' }
416
+ stub(@image).image { nil }
417
+ end
418
+
419
+ context 'html' do
420
+ it 'should assign an error and redirect to edit_shop_product path' do
421
+ delete :destroy, :id => @image.id, :product_id => @shop_product.id
422
+ flash.now[:error].should_not be_nil
423
+ response.should render_template(:remove)
424
+ end
425
+ end
426
+
427
+ context 'js' do
428
+ it 'should return an error string and unprocessable status' do
429
+ delete :destroy, :id => @image.id, :product_id => @shop_product.id, :format => 'js'
430
+ response.should_not be_success
431
+ response.body.should == 'Unable to delete Image.'
432
+ end
433
+ end
434
+
435
+ context 'json' do
436
+ it 'should return a json error object and unprocessable status' do
437
+ delete :destroy, :id => @image.id, :product_id => @shop_product.id, :format => 'json'
438
+ response.should_not be_success
439
+ JSON.parse(response.body)['error'].should === 'Unable to delete Image.'
440
+ end
441
+ end
442
+ end
443
+ context 'Successfully destroy attachment' do
444
+ before :each do
445
+ stub(@image).destroy { true }
446
+ stub(@image).image { nil }
447
+ end
448
+
449
+ context 'html' do
450
+ it 'should assign a notice and redirect to edit_shop_product path' do
451
+ delete :destroy, :id => @image.id, :product_id => @shop_product.id
452
+ flash.now[:notice].should_not be_nil
453
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
454
+ end
455
+ end
456
+
457
+ context 'js' do
458
+ it 'should render the collection partial and success status' do
459
+ delete :destroy, :id => @image.id, :product_id => @shop_product.id, :format => 'js'
460
+ response.should be_success
461
+ assigns(:shop_product_attachment).should == @image
462
+ response.should render_template('/admin/shop/products/edit/_image')
463
+ end
464
+ end
465
+
466
+ context 'json' do
467
+ it 'should return a json object of the array and success status' do
468
+ delete :destroy, :id => @image.id, :product_id => @shop_product.id, :format => 'json'
469
+ response.should be_success
470
+ JSON.parse(response.body)['notice'].should === 'Image deleted successfully.'
471
+ end
472
+ end
473
+ end
474
+ end
475
+ end
476
+
477
+ end