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,394 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Admin::Shop::ProductsController do
4
+
5
+ dataset :users
6
+
7
+ before(:each) do
8
+ login_as :admin
9
+
10
+ @shop_category = ShopCategory.new
11
+ @shop_categories = [ @shop_category ]
12
+
13
+ @shop_product = ShopProduct.new
14
+ @shop_products = [ @shop_product ]
15
+
16
+ stub(@shop_category).id { 1 }
17
+ stub(@shop_product).id { 1 }
18
+ stub(@shop_product).products { @shop_products }
19
+ end
20
+
21
+ describe '#index' do
22
+ before :each do
23
+ mock(ShopCategory).all { @shop_categories }
24
+ mock(ShopProduct).find(:all) { @shop_products } # Resource Controller
25
+ mock(ShopProduct).search('search') { @shop_products }
26
+ end
27
+
28
+ context 'html' do
29
+ before :each do
30
+ get :index, :search => 'search'
31
+ end
32
+
33
+ it 'should render index' do
34
+ response.should render_template(:index)
35
+ end
36
+
37
+ it 'should assign the shop_products and shop_categories instance variables' do
38
+ assigns(:shop_products).should === @shop_products
39
+ assigns(:shop_categories).should === @shop_categories
40
+ end
41
+ end
42
+
43
+ context 'js' do
44
+ before :each do
45
+ get :index, :search => 'search', :format => 'js'
46
+ end
47
+
48
+ it 'should render the collection partial and success status' do
49
+ response.should be_success
50
+ response.should render_template('/admin/shop/products/index/_product')
51
+ end
52
+
53
+ it 'should assign the shop_products instance variable' do
54
+ assigns(:shop_products).should === @shop_products
55
+ end
56
+ end
57
+
58
+ context 'json' do
59
+ before :each do
60
+ get :index, :search => 'search', :format => 'json'
61
+ end
62
+
63
+ it 'should return a json object of the array and success status' do
64
+ response.should be_success
65
+ response.body.should === @shop_products.to_json(ShopProduct.params)
66
+ end
67
+
68
+ it 'should assign the shop_product_images instance variable' do
69
+ assigns(:shop_products).should === @shop_products
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ describe '#sort' do
76
+ before :each do
77
+ @products = [
78
+ 'shop_category_1_products[]=2',
79
+ 'shop_category_1_products[]=1'
80
+ ].join('&')
81
+ end
82
+
83
+ context 'products are not passed' do
84
+ context 'html' do
85
+ it 'should assign an error and redirect to admin_shop_products_path path' do
86
+ put :sort
87
+ flash.now[:error].should_not be_nil
88
+ response.should redirect_to(admin_shop_products_path)
89
+ end
90
+ end
91
+
92
+ context 'js' do
93
+ it 'should return an error string and failure status' do
94
+ put :sort, :format => 'js'
95
+ response.should_not be_success
96
+ response.body.should === 'Could not sort Products.'
97
+ end
98
+ end
99
+
100
+ context 'json' do
101
+ it 'should return a json error object and failure status' do
102
+ put :sort, :format => 'json'
103
+ response.should_not be_success
104
+ JSON.parse(response.body)['error'].should === 'Could not sort Products.'
105
+ end
106
+ end
107
+ end
108
+
109
+ context 'products are passed' do
110
+ before :each do
111
+ mock(ShopCategory).find('1') { @shop_category }
112
+ end
113
+ context 'could not sort' do
114
+ before :each do
115
+ mock(ShopProduct).find('2').stub!.update_attributes!(anything) { raise 'No Sorting' }
116
+ end
117
+
118
+ context 'html' do
119
+ it 'should assign an error and redirect to admin_shop_products_path path' do
120
+ put :sort, :products => @products, :category_id => 1
121
+ flash.now[:error].should === 'Could not sort Products.'
122
+ response.should redirect_to(admin_shop_products_path)
123
+ end
124
+ end
125
+
126
+ context 'js' do
127
+ it 'should return an error string and failure status' do
128
+ put :sort, :products => @products, :category_id => 1, :format => 'js'
129
+ response.should_not be_success
130
+ response.body.should === 'Could not sort Products.'
131
+ end
132
+ end
133
+
134
+ context 'json' do
135
+ it 'should return a json error object and failure status' do
136
+ put :sort, :products => @products, :category_id => 1, :format => 'json'
137
+ response.should_not be_success
138
+ JSON.parse(response.body)['error'].should === 'Could not sort Products.'
139
+ end
140
+ end
141
+ end
142
+
143
+ context 'successfully sorted' do
144
+ before :each do
145
+ mock(ShopProduct).find(anything).times(2).stub!.update_attributes!(anything) { true }
146
+ end
147
+
148
+ context 'html' do
149
+ it 'should assign a notice and redirect to admin_shop_products_path path' do
150
+ put :sort, :products => @products, :category_id => 1
151
+ flash.now[:notice].should === 'Products successfully sorted.'
152
+ response.should redirect_to(admin_shop_products_path)
153
+ end
154
+ end
155
+
156
+ context 'js' do
157
+ it 'should return success string and success status' do
158
+ put :sort, :products => @products, :category_id => 1, :format => 'js'
159
+ response.should be_success
160
+ response.body.should === 'Products successfully sorted.'
161
+ end
162
+ end
163
+
164
+ context 'json' do
165
+ it 'should return a json success object and success status' do
166
+ put :sort, :products => @products, :category_id => 1, :format => 'json'
167
+ response.should be_success
168
+ JSON.parse(response.body)['notice'].should === 'Products successfully sorted.'
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ describe '#create' do
176
+ context 'product could not be created' do
177
+ before :each do
178
+ mock(ShopProduct).new() { @shop_product }
179
+ stub(@shop_product).save! { raise ActiveRecord::RecordNotSaved }
180
+ end
181
+
182
+ context 'html' do
183
+ it 'should assign a flash error and render new' do
184
+ post :create, :shop_product => {}
185
+
186
+ response.should render_template(:new)
187
+ flash.now[:error].should === 'Could not create Product.'
188
+ end
189
+ end
190
+
191
+ context 'js' do
192
+ it 'should return error notice and failure status' do
193
+ post :create, :shop_product => {}, :format => 'js'
194
+
195
+ response.body.should === 'Could not create Product.'
196
+ response.should_not be_success
197
+ end
198
+ end
199
+
200
+ context 'json' do
201
+ it 'should return an error json object and failure status' do
202
+ post :create, :shop_product => {}, :format => 'json'
203
+
204
+ JSON.parse(response.body)['error'].should === 'Could not create Product.'
205
+ response.should_not be_success
206
+ end
207
+ end
208
+ end
209
+
210
+ context 'product successfully created' do
211
+ before :each do
212
+ mock(ShopProduct).new() { @shop_product }
213
+ stub(@shop_product).save! { true }
214
+ end
215
+
216
+ context 'html' do
217
+ context 'not continue' do
218
+ it 'should assign a notice and redirect to edit_shop_product path' do
219
+ post :create, :shop_product => {}
220
+ flash.now[:notice].should === 'Product created successfully.'
221
+ response.should redirect_to(admin_shop_products_path)
222
+ end
223
+ end
224
+ context 'continue' do
225
+ it 'should assign a notice and redirect to edit_shop_product path' do
226
+ post :create, :shop_product => {}, :continue => true
227
+ flash.now[:notice].should === 'Product created successfully.'
228
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
229
+ end
230
+ end
231
+ end
232
+
233
+ context 'js' do
234
+ it 'should render the collection partial and success status' do
235
+ post :create, :shop_product => {}, :format => 'js'
236
+ response.should be_success
237
+ assigns(:shop_product).should === @shop_product
238
+ response.should render_template('/admin/shop/products/index/_product')
239
+ end
240
+ end
241
+
242
+ context 'json' do
243
+ it 'should render the json object and redirect to json show' do
244
+ post :create ,:shop_product => {}, :format => 'json'
245
+ response.should be_success
246
+ response.body.should === @shop_product.to_json(ShopProduct.params)
247
+ end
248
+ end
249
+ end
250
+ end
251
+
252
+ describe '#update' do
253
+ before :each do
254
+ mock(ShopProduct).find('1') { @shop_product }
255
+ end
256
+
257
+ context 'could not update' do
258
+ before :each do
259
+ stub(@shop_product).update_attributes!({}) { raise ActiveRecord::RecordNotSaved }
260
+ end
261
+
262
+ context 'html' do
263
+ it 'should assign a flash error and render edit' do
264
+ put :update, :id => @shop_product.id, :shop_product => {}
265
+ response.should render_template(:edit)
266
+ flash.now[:error].should === 'Could not update Product.'
267
+ end
268
+ end
269
+
270
+ context 'js' do
271
+ it 'should render the error and failure status' do
272
+ put :update, :id => @shop_product.id, :shop_product => {}, :format => 'js'
273
+ response.should_not be_success
274
+ response.body.should === 'Could not update Product.'
275
+ end
276
+ end
277
+
278
+ context 'json' do
279
+ it 'should assign an error json object and failure status' do
280
+ put :update, :id => @shop_product.id, :shop_product => {}, :format => 'json'
281
+ response.should_not be_success
282
+ JSON.parse(response.body)['error'].should === 'Could not update Product.'
283
+ end
284
+ end
285
+ end
286
+
287
+ context 'successfully updated' do
288
+ before :each do
289
+ stub(@shop_product).update_attributes!({}) { true }
290
+ end
291
+
292
+ context 'html' do
293
+ context 'not continue' do
294
+ it 'should assign a notice and redirect to edit_shop_product path' do
295
+ put :update, :id => @shop_product.id, :shop_product => {}
296
+ flash.now[:notice].should === 'Product updated successfully.'
297
+ response.should redirect_to(admin_shop_products_path)
298
+ end
299
+ end
300
+ context 'continue' do
301
+ it 'should assign a notice and redirect to edit_shop_product path' do
302
+ put :update, :id => @shop_product.id, :shop_product => {}, :continue => true
303
+ flash.now[:notice].should === 'Product updated successfully.'
304
+ response.should redirect_to(edit_admin_shop_product_path(@shop_product))
305
+ end
306
+ end
307
+ end
308
+
309
+ context 'js' do
310
+ it 'should render the partial and success status' do
311
+ put :update, :id => @shop_product.id, :shop_product => {}, :format => 'js'
312
+ response.should be_success
313
+ response.should render_template('/admin/shop/products/index/_product')
314
+ end
315
+ end
316
+
317
+ context 'json' do
318
+ it 'should assign the json object and success status' do
319
+ put :update, :id => @shop_product.id, :shop_product => {}, :format => 'json'
320
+ response.should be_success
321
+ response.body.should === @shop_product.to_json(ShopProduct.params)
322
+ end
323
+ end
324
+ end
325
+ end
326
+
327
+ describe '#destroy' do
328
+ before :each do
329
+ mock(ShopProduct).find('1') { @shop_product }
330
+ end
331
+
332
+ context 'product not destroyed' do
333
+ before :each do
334
+ stub(@shop_product).destroy { raise ActiveRecord::RecordNotFound }
335
+ end
336
+
337
+ context 'html' do
338
+ it 'should assign a flash error and render remove' do
339
+ delete :destroy, :id => 1
340
+ flash.now[:error].should === 'Could not delete Product.'
341
+ response.should render_template(:remove)
342
+ end
343
+ end
344
+
345
+ context 'js' do
346
+ it 'should render an error and failure status' do
347
+ delete :destroy, :id => 1, :format => 'js'
348
+ response.body.should === 'Could not delete Product.'
349
+ response.should_not be_success
350
+ end
351
+ end
352
+
353
+ context 'json' do
354
+ it 'should render an error and failure status' do
355
+ delete :destroy, :id => 1, :format => 'json'
356
+ JSON.parse(response.body)['error'].should === 'Could not delete Product.'
357
+ response.should_not be_success
358
+ end
359
+ end
360
+
361
+ end
362
+
363
+ context 'product successfully destroyed' do
364
+ before :each do
365
+ stub(@shop_product).destroy { true }
366
+ end
367
+
368
+ context 'html' do
369
+ it 'should assign a flash notice and redirect to shop_products path' do
370
+ delete :destroy, :id => 1
371
+ flash.now[:notice].should === 'Product deleted successfully.'
372
+ response.should redirect_to(admin_shop_products_path)
373
+ end
374
+ end
375
+
376
+ context 'js' do
377
+ it 'should render success message and success status' do
378
+ delete :destroy, :id => 1, :format => 'js'
379
+ response.body.should === 'Product deleted successfully.'
380
+ response.should be_success
381
+ end
382
+ end
383
+
384
+ context 'json' do
385
+ it 'should return a success json object and success status' do
386
+ delete :destroy, :id => 1, :format => 'json'
387
+ JSON.parse(response.body)['notice'].should === 'Product deleted successfully.'
388
+ response.should be_success
389
+ end
390
+ end
391
+ end
392
+ end
393
+
394
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Admin::ShopsController do
4
+ dataset :users
5
+
6
+ before :each do
7
+ login_as :admin
8
+ end
9
+
10
+ describe '#index' do
11
+
12
+ it 'should redirect to shop products' do
13
+ get :index
14
+
15
+ response.should redirect_to(admin_shop_products_path)
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Shop::CategoriesController do
4
+ before(:each) do
5
+ @shop_category = Object.new
6
+ stub(@shop_category).handle { 'a' }
7
+ stub(@shop_category).layout.stub!.name { 'Layout' }
8
+ stub(@shop_category).name { 'Bob' }
9
+ @shop_categories = []
10
+ end
11
+
12
+ describe 'index' do
13
+ it 'should expose categories list' do
14
+ mock(ShopCategory).search(nil).returns(@shop_categories)
15
+ get :index
16
+
17
+ response.should be_success
18
+ assigns(:shop_categories).should === @shop_categories
19
+ end
20
+ end
21
+
22
+ describe '#show' do
23
+ it 'should expose category' do
24
+ mock(ShopCategory).find(:first, :conditions => { :handle => @shop_category.handle}) { @shop_category }
25
+
26
+ get :show, :handle => @shop_category.handle
27
+
28
+ response.should be_success
29
+ assigns(:shop_category).should === @shop_category
30
+ assigns(:title).should === 'Bob'
31
+ assigns(:radiant_layout).should === 'Layout'
32
+ end
33
+
34
+ it 'should return 404 if product empty' do
35
+ mock(ShopCategory).find(:first, :conditions => { :handle => @shop_category.handle}) { false }
36
+ get :show, :handle => @shop_category.handle
37
+
38
+ response.should render_template('site/not_found')
39
+ end
40
+ end
41
+
42
+ end