radiant-shop-extension 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (272) hide show
  1. data/README.md +5 -1
  2. data/VERSION +1 -1
  3. data/app/controllers/admin/shop/categories_controller.rb +32 -65
  4. data/app/controllers/admin/shop/customers_controller.rb +8 -7
  5. data/app/controllers/admin/shop/orders_controller.rb +37 -159
  6. data/app/controllers/admin/shop/packages/packings_controller.rb +90 -0
  7. data/app/controllers/admin/shop/packages_controller.rb +65 -0
  8. data/app/controllers/admin/shop/products/images_controller.rb +5 -8
  9. data/app/controllers/admin/shop/products/variant_templates_controller.rb +27 -0
  10. data/app/controllers/admin/shop/products/variants_controller.rb +60 -0
  11. data/app/controllers/admin/shop/products_controller.rb +67 -64
  12. data/app/controllers/admin/shop/variants_controller.rb +49 -0
  13. data/app/helpers/shop_helper.rb +5 -0
  14. data/app/models/form_address.rb +144 -0
  15. data/app/models/form_checkout.rb +200 -307
  16. data/app/models/form_line_item.rb +60 -0
  17. data/app/models/shop_address.rb +2 -2
  18. data/app/models/shop_category.rb +48 -51
  19. data/app/models/shop_customer.rb +25 -5
  20. data/app/models/shop_group.rb +15 -0
  21. data/app/models/shop_grouping.rb +6 -0
  22. data/app/models/shop_line_item.rb +7 -6
  23. data/app/models/shop_order.rb +44 -16
  24. data/app/models/shop_package.rb +74 -0
  25. data/app/models/shop_packing.rb +22 -0
  26. data/app/models/shop_page.rb +7 -0
  27. data/app/models/shop_payment.rb +5 -1
  28. data/app/models/shop_product.rb +86 -48
  29. data/app/models/shop_product_attachment.rb +5 -2
  30. data/app/models/shop_product_variant.rb +31 -0
  31. data/app/models/shop_variant.rb +25 -0
  32. data/app/views/admin/shop/categories/edit.html.haml +9 -10
  33. data/app/views/admin/shop/categories/edit/_foot.html.haml +9 -0
  34. data/app/views/admin/shop/categories/edit/_form.html.haml +14 -0
  35. data/app/views/admin/shop/categories/edit/_head.html.haml +4 -2
  36. data/app/views/admin/shop/categories/edit/_inputs.html.haml +2 -0
  37. data/app/views/admin/shop/categories/edit/_meta.html.haml +8 -7
  38. data/app/views/admin/shop/categories/edit/_parts.html.haml +9 -0
  39. data/app/views/admin/shop/categories/edit/_popups.html.haml +4 -0
  40. data/app/views/admin/shop/categories/edit/inputs/_name.html.haml +4 -0
  41. data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +6 -5
  42. data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +6 -5
  43. data/app/views/admin/shop/categories/edit/meta/_page.html.haml +3 -0
  44. data/app/views/admin/shop/categories/edit/parts/_description.html.haml +4 -1
  45. data/app/views/admin/shop/categories/index/_category.html.haml +11 -10
  46. data/app/views/admin/shop/categories/new.html.haml +10 -9
  47. data/app/views/admin/shop/customers/edit.html.haml +8 -10
  48. data/app/views/admin/shop/customers/edit/_foot.html.haml +9 -0
  49. data/app/views/admin/shop/customers/edit/_form.html.haml +13 -0
  50. data/app/views/admin/shop/customers/edit/_head.html.haml +4 -2
  51. data/app/views/admin/shop/customers/edit/_inputs.html.haml +2 -0
  52. data/app/views/admin/shop/customers/edit/_parts.html.haml +9 -4
  53. data/app/views/admin/shop/customers/edit/inputs/_email.html.haml +3 -0
  54. data/app/views/admin/shop/customers/edit/inputs/_name.html.haml +3 -0
  55. data/app/views/admin/shop/customers/edit/parts/_orders.html.haml +10 -6
  56. data/app/views/admin/shop/customers/index.html.haml +4 -1
  57. data/app/views/admin/shop/customers/index/_customer.html.haml +3 -3
  58. data/app/views/admin/shop/customers/index/_foot.html.haml +4 -0
  59. data/app/views/admin/shop/customers/index/_head.html.haml +4 -0
  60. data/app/views/admin/shop/customers/new.html.haml +9 -9
  61. data/app/views/admin/shop/orders/edit.html.haml +11 -0
  62. data/app/views/admin/shop/orders/edit/_foot.html.haml +9 -0
  63. data/app/views/admin/shop/orders/edit/_form.html.haml +13 -0
  64. data/app/views/admin/shop/orders/edit/_head.html.haml +4 -0
  65. data/app/views/admin/shop/orders/edit/_inputs.html.haml +2 -0
  66. data/app/views/admin/shop/orders/edit/_meta.html.haml +8 -0
  67. data/app/views/admin/shop/orders/edit/_parts.html.haml +9 -0
  68. data/app/views/admin/shop/orders/edit/_popups.html.haml +4 -0
  69. data/app/views/admin/shop/orders/edit/parts/_address.html.haml +7 -0
  70. data/app/views/admin/shop/orders/edit/parts/_addresses.html.haml +9 -0
  71. data/app/views/admin/shop/orders/edit/parts/_customer.html.haml +3 -0
  72. data/app/views/admin/shop/orders/edit/parts/_items.html.haml +8 -0
  73. data/app/views/admin/shop/orders/index.html.haml +10 -30
  74. data/app/views/admin/shop/orders/index/_foot.html.haml +3 -0
  75. data/app/views/admin/shop/orders/index/_head.html.haml +4 -0
  76. data/app/views/admin/shop/orders/index/_order.html.haml +13 -0
  77. data/app/views/admin/shop/orders/index/buttons/_all.html.haml +1 -0
  78. data/app/views/admin/shop/orders/index/buttons/_new.html.haml +1 -0
  79. data/app/views/admin/shop/orders/index/buttons/_paid.html.haml +1 -0
  80. data/app/views/admin/shop/orders/index/buttons/_shipped.html.haml +1 -0
  81. data/app/views/admin/shop/packages/edit.html.haml +11 -0
  82. data/app/views/admin/shop/packages/edit/_foot.html.haml +17 -0
  83. data/app/views/admin/shop/packages/edit/_form.html.haml +15 -0
  84. data/app/views/admin/shop/packages/edit/_head.html.haml +4 -0
  85. data/app/views/admin/shop/packages/edit/_inputs.html.haml +2 -0
  86. data/app/views/admin/shop/packages/edit/_meta.html.haml +8 -0
  87. data/app/views/admin/shop/packages/edit/_parts.html.haml +9 -0
  88. data/app/views/admin/shop/packages/edit/_popups.html.haml +4 -0
  89. data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +1 -0
  90. data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +3 -0
  91. data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +3 -0
  92. data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +5 -0
  93. data/app/views/admin/shop/packages/edit/parts/_description.html.haml +1 -0
  94. data/app/views/admin/shop/packages/edit/parts/_products.html.haml +3 -0
  95. data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +7 -0
  96. data/app/views/admin/shop/packages/edit/shared/_product.html.haml +8 -0
  97. data/app/views/admin/shop/packages/index.html.haml +13 -0
  98. data/app/views/admin/shop/packages/index/_foot.html.haml +7 -0
  99. data/app/views/admin/shop/packages/index/_head.html.haml +4 -0
  100. data/app/views/admin/shop/packages/index/_package.html.haml +9 -0
  101. data/app/views/admin/shop/packages/new.html.haml +11 -0
  102. data/app/views/admin/shop/packages/remove.html.haml +12 -0
  103. data/app/views/admin/shop/products/edit.html.haml +9 -12
  104. data/app/views/admin/shop/products/edit/_foot.html.haml +19 -0
  105. data/app/views/admin/shop/products/edit/_form.html.haml +15 -0
  106. data/app/views/admin/shop/products/edit/_head.html.haml +4 -2
  107. data/app/views/admin/shop/products/edit/_inputs.html.haml +2 -0
  108. data/app/views/admin/shop/products/edit/_meta.html.haml +8 -8
  109. data/app/views/admin/shop/products/edit/_parts.html.haml +9 -0
  110. data/app/views/admin/shop/products/edit/_popups.html.haml +4 -0
  111. data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -1
  112. data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +1 -0
  113. data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -1
  114. data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +1 -0
  115. data/app/views/admin/shop/products/edit/inputs/_name.html.haml +4 -0
  116. data/app/views/admin/shop/products/edit/inputs/_price.html.haml +3 -0
  117. data/app/views/admin/shop/products/edit/meta/_category.html.haml +6 -5
  118. data/app/views/admin/shop/products/edit/meta/_page.html.haml +2 -0
  119. data/app/views/admin/shop/products/edit/meta/_sku.html.haml +6 -5
  120. data/app/views/admin/shop/products/edit/parts/_customers.html.haml +5 -0
  121. data/app/views/admin/shop/products/edit/parts/_description.html.haml +4 -1
  122. data/app/views/admin/shop/products/edit/parts/_images.html.haml +1 -1
  123. data/app/views/admin/shop/products/edit/parts/_variants.html.haml +3 -0
  124. data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +1 -1
  125. data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +6 -0
  126. data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +4 -4
  127. data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +16 -0
  128. data/app/views/admin/shop/products/edit/{_image.html.haml → shared/_image.html.haml} +0 -0
  129. data/app/views/admin/shop/products/edit/shared/_template.html.haml +6 -0
  130. data/app/views/admin/shop/products/edit/shared/_variant.html.haml +10 -0
  131. data/app/views/admin/shop/products/index.html.haml +6 -3
  132. data/app/views/admin/shop/products/index/_foot.html.haml +10 -0
  133. data/app/views/admin/shop/products/index/_head.html.haml +4 -0
  134. data/app/views/admin/shop/products/index/_product.html.haml +18 -10
  135. data/app/views/admin/shop/products/index/buttons/_discounts.html.haml +1 -0
  136. data/app/views/admin/shop/products/index/buttons/_packages.html.haml +1 -0
  137. data/app/views/admin/shop/products/index/buttons/_variants.html.haml +1 -0
  138. data/app/views/admin/shop/products/new.html.haml +10 -9
  139. data/app/views/admin/shop/variants/edit.html.haml +11 -0
  140. data/app/views/admin/shop/variants/edit/_foot.html.haml +9 -0
  141. data/app/views/admin/shop/variants/edit/_form.html.haml +13 -0
  142. data/app/views/admin/shop/variants/edit/_head.html.haml +4 -0
  143. data/app/views/admin/shop/variants/edit/_inputs.html.haml +2 -0
  144. data/app/views/admin/shop/variants/edit/_meta.html.haml +8 -0
  145. data/app/views/admin/shop/variants/edit/_parts.html.haml +9 -0
  146. data/app/views/admin/shop/variants/edit/_popups.html.haml +4 -0
  147. data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +3 -0
  148. data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +3 -0
  149. data/app/views/admin/shop/variants/index.html.haml +13 -0
  150. data/app/views/admin/shop/variants/index/_foot.html.haml +4 -0
  151. data/app/views/admin/shop/variants/index/_head.html.haml +4 -0
  152. data/app/views/admin/shop/variants/index/_variant.html.haml +9 -0
  153. data/app/views/admin/shop/variants/new.html.haml +11 -0
  154. data/app/views/admin/shop/variants/remove.html.haml +12 -0
  155. data/config/locales/en.yml +8 -1
  156. data/config/routes.rb +11 -22
  157. data/db/migrate/20100929011106_fix_relationship_foreign_keys.rb +101 -0
  158. data/db/migrate/20100929011607_drop_shop_addressables.rb +25 -0
  159. data/db/migrate/20100929030510_create_shop_groups.rb +19 -0
  160. data/db/migrate/20100929080301_shop_groups_change_add_description.rb +11 -0
  161. data/db/migrate/20100929081200_create_variants.rb +20 -0
  162. data/db/migrate/20100929143531_change_variants_add_updated_by.rb +25 -0
  163. data/db/migrate/20100929145641_change_created_by_to_id.rb +75 -0
  164. data/db/migrate/20100929235221_change_category_add_variant_id.rb +9 -0
  165. data/db/migrate/20100930235221_create_packages.rb +31 -0
  166. data/db/migrate/20101005231713_create_page_ids.rb +11 -0
  167. data/db/migrate/20101006051214_create_pages_for_products_and_categories.rb +73 -0
  168. data/db/migrate/20101007111845_add_default_position_to_attachment.rb +9 -0
  169. data/lib/shop/controllers/application_controller.rb +1 -1
  170. data/lib/shop/interface/categories.rb +29 -0
  171. data/lib/shop/interface/customers.rb +15 -15
  172. data/lib/shop/interface/orders.rb +34 -0
  173. data/lib/shop/interface/packages.rb +34 -0
  174. data/lib/shop/interface/products.rb +18 -31
  175. data/lib/shop/interface/variants.rb +34 -0
  176. data/lib/shop/models/form_extension.rb +23 -0
  177. data/lib/shop/models/page.rb +3 -2
  178. data/lib/shop/tags/address.rb +3 -3
  179. data/lib/shop/tags/cart.rb +12 -16
  180. data/lib/shop/tags/category.rb +4 -6
  181. data/lib/shop/tags/helpers.rb +131 -30
  182. data/lib/shop/tags/item.rb +16 -33
  183. data/lib/shop/tags/package.rb +95 -0
  184. data/lib/shop/tags/product.rb +11 -16
  185. data/lib/shop/tags/product_variant.rb +52 -0
  186. data/mockups/discounts/new-edit.bmml +492 -0
  187. data/public/javascripts/admin/extensions/shop/edit.js +20 -0
  188. data/public/javascripts/admin/extensions/shop/packages/edit.js +109 -0
  189. data/public/javascripts/admin/extensions/shop/products/edit.js +64 -65
  190. data/public/javascripts/admin/extensions/shop/products/index.js +31 -36
  191. data/public/stylesheets/sass/admin/extensions/shop/edit.sass +58 -11
  192. data/public/stylesheets/sass/admin/extensions/shop/index.sass +104 -53
  193. data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +162 -0
  194. data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +115 -36
  195. data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +12 -20
  196. data/radiant-shop-extension.gemspec +182 -38
  197. data/shop_extension.rb +29 -25
  198. data/spec/controllers/admin/shop/categories_controller_spec.rb +76 -191
  199. data/spec/controllers/admin/shop/customers_controller_spec.rb +67 -0
  200. data/spec/controllers/admin/shop/orders_controller_spec.rb +85 -0
  201. data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +188 -0
  202. data/spec/controllers/admin/shop/packages_controller_spec.rb +32 -0
  203. data/spec/controllers/admin/shop/products/images_controller_spec.rb +10 -15
  204. data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +53 -0
  205. data/spec/controllers/admin/shop/products/variants_controller_spec.rb +116 -0
  206. data/spec/controllers/admin/shop/products_controller_spec.rb +80 -148
  207. data/spec/controllers/admin/shop/variants_controller_spec.rb +67 -0
  208. data/spec/datasets/forms.rb +23 -8
  209. data/spec/datasets/shop_addresses.rb +1 -4
  210. data/spec/datasets/shop_categories.rb +25 -4
  211. data/spec/datasets/shop_groups.rb +15 -0
  212. data/spec/datasets/shop_line_items.rb +4 -3
  213. data/spec/datasets/shop_orders.rb +6 -15
  214. data/spec/datasets/shop_packages.rb +25 -0
  215. data/spec/datasets/shop_payments.rb +12 -0
  216. data/spec/datasets/{images.rb → shop_product_attachments.rb} +9 -1
  217. data/spec/datasets/shop_product_variants.rb +22 -0
  218. data/spec/datasets/shop_products.rb +28 -18
  219. data/spec/datasets/shop_variants.rb +17 -0
  220. data/spec/lib/shop/models/image_spec.rb +4 -4
  221. data/spec/lib/shop/tags/address_spec.rb +3 -3
  222. data/spec/lib/shop/tags/cart_spec.rb +32 -43
  223. data/spec/lib/shop/tags/category_spec.rb +58 -93
  224. data/spec/lib/shop/tags/helpers_spec.rb +162 -69
  225. data/spec/lib/shop/tags/item_spec.rb +116 -158
  226. data/spec/lib/shop/tags/package_spec.rb +342 -0
  227. data/spec/lib/shop/tags/product_spec.rb +29 -26
  228. data/spec/lib/shop/tags/product_variant_spec.rb +175 -0
  229. data/spec/models/form_address_spec.rb +166 -0
  230. data/spec/models/form_checkout_spec.rb +27 -157
  231. data/spec/models/shop_address_spec.rb +81 -0
  232. data/spec/models/shop_category_spec.rb +114 -31
  233. data/spec/models/shop_customer_spec.rb +105 -0
  234. data/spec/models/shop_group_spec.rb +38 -0
  235. data/spec/models/shop_line_item_spec.rb +5 -5
  236. data/spec/models/shop_order_spec.rb +89 -83
  237. data/spec/models/shop_package_spec.rb +117 -0
  238. data/spec/models/shop_packing_spec.rb +67 -0
  239. data/spec/models/shop_payment_spec.rb +19 -0
  240. data/spec/models/shop_product_attachment_spec.rb +4 -3
  241. data/spec/models/shop_product_spec.rb +171 -92
  242. data/spec/models/shop_product_variant_spec.rb +92 -0
  243. data/spec/models/shop_variant_spec.rb +47 -0
  244. metadata +183 -39
  245. data/app/controllers/shop/categories_controller.rb +0 -45
  246. data/app/controllers/shop/line_items_controller.rb +0 -165
  247. data/app/controllers/shop/orders_controller.rb +0 -16
  248. data/app/controllers/shop/products_controller.rb +0 -48
  249. data/app/models/shop_addressable.rb +0 -11
  250. data/app/views/admin/shop/categories/edit/_fields.html.haml +0 -28
  251. data/app/views/admin/shop/categories/edit/_part.html.haml +0 -3
  252. data/app/views/admin/shop/categories/edit/_popup.html.haml +0 -3
  253. data/app/views/admin/shop/customers/edit/_fields.html.haml +0 -33
  254. data/app/views/admin/shop/customers/index/_bottom.html.haml +0 -4
  255. data/app/views/admin/shop/products/edit/_fields.html.haml +0 -38
  256. data/app/views/admin/shop/products/edit/_part.html.haml +0 -3
  257. data/app/views/admin/shop/products/edit/_popup.html.haml +0 -3
  258. data/app/views/admin/shop/products/index/_bottom.html.haml +0 -5
  259. data/spec/controllers/shop/categories_controller_spec.rb +0 -42
  260. data/spec/controllers/shop/line_items_controller_spec.rb +0 -256
  261. data/spec/controllers/shop/orders_controller_specs.rb +0 -37
  262. data/spec/controllers/shop/products_controller_spec.rb +0 -51
  263. data/vendor/plugins/json_fields/.gitignore +0 -3
  264. data/vendor/plugins/json_fields/MIT-LICENSE +0 -20
  265. data/vendor/plugins/json_fields/README.rdoc +0 -65
  266. data/vendor/plugins/json_fields/Rakefile +0 -55
  267. data/vendor/plugins/json_fields/init.rb +0 -2
  268. data/vendor/plugins/json_fields/lib/json_fields.rb +0 -99
  269. data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +0 -124
  270. data/vendor/plugins/json_fields/spec/spec.opts +0 -6
  271. data/vendor/plugins/json_fields/spec/spec_helper.rb +0 -29
  272. data/vendor/plugins/json_fields/spec/test_models.rb +0 -12
@@ -0,0 +1,53 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Admin::Shop::Products::VariantTemplatesController do
4
+
5
+ dataset :users, :shop_variants, :shop_product_variants
6
+
7
+ before :each do
8
+ login_as :admin
9
+ end
10
+
11
+ describe '#create' do
12
+ before :each do
13
+ @product = shop_products(:crusty_bread)
14
+ @variant = shop_variants(:milk_states)
15
+ @initial_product_variants = @product.variants.all
16
+ end
17
+ context 'successfully created' do
18
+ before :each do
19
+ stub(ShopProduct).find.with_any_args { @product }
20
+ put :update, :product_id => @product.id, :id => @variant.id
21
+ end
22
+ it 'should add the variant templates to product' do
23
+ final_variants = @product.variants.all
24
+ final_variants.should_not == @initial_product_variants
25
+
26
+ names = final_variants.map(&:name)
27
+ @variant.options.each do |name|
28
+ names.include?(name).should be_true
29
+ end
30
+ end
31
+ it 'should redirect to edit product path' do
32
+ response.should redirect_to(edit_admin_shop_product_path(@product))
33
+ end
34
+ end
35
+ context 'could not create' do
36
+ before :each do
37
+ stub(ShopProduct).find.with_any_args { @product }
38
+ mock(@product).apply_variant_template(@variant) { false }
39
+ put :update, :product_id => @product.id, :id => @variant.id
40
+ end
41
+ it 'should not add the variant templates to product' do
42
+ @product.variants.all.should == @initial_product_variants
43
+ end
44
+ it 'should assign flash error' do
45
+ flash.now[:error].should_not be_nil
46
+ end
47
+ it 'should redirect to edit product path' do
48
+ response.should redirect_to(edit_admin_shop_product_path(@product))
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Admin::Shop::Products::VariantsController do
4
+
5
+ dataset :users, :shop_variants, :shop_product_variants
6
+
7
+ before :each do
8
+ login_as :admin
9
+ end
10
+
11
+ describe '#create' do
12
+ before :all do
13
+ @product = shop_products(:crusty_bread)
14
+ end
15
+ context 'successfully created' do
16
+ before :each do
17
+ mock.instance_of(ShopProductVariant).save! { true }
18
+ end
19
+ context 'html' do
20
+ before :each do
21
+ post :create, :product_id => @product.id, :shop_product_variant => { }
22
+ end
23
+ it 'should redirect to product path' do
24
+ response.should redirect_to(edit_admin_shop_product_path(@product))
25
+ end
26
+ end
27
+ context 'js' do
28
+ before :each do
29
+ post :create, :product_id => @product.id, :shop_product_variant => { }, :format => 'js'
30
+ end
31
+ it 'should render the partial' do
32
+ response.should render_template('/admin/shop/products/edit/shared/_variant')
33
+ end
34
+ end
35
+ end
36
+ context 'could not be created' do
37
+ before :each do
38
+ mock.instance_of(ShopProductVariant).save! { raise ActiveRecord::RecordNotSaved }
39
+ end
40
+ context 'html' do
41
+ before :each do
42
+ post :create, :product_id => @product.id, :shop_product_variant => { }
43
+ end
44
+ it 'should assign flash error' do
45
+ flash.now[:error].should_not be_nil
46
+ end
47
+ it 'should redirect to product path' do
48
+ response.should redirect_to(edit_admin_shop_product_path(@product))
49
+ end
50
+ end
51
+ context 'js' do
52
+ before :each do
53
+ post :create, :product_id => @product.id, :shop_product_variant => { }, :format => 'js'
54
+ end
55
+ it 'should not be success' do
56
+ response.should_not be_success
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#destroy' do
63
+ before :each do
64
+ @product = shop_products(:crusty_bread)
65
+ @product_variant = shop_product_variants(:mouldy_crusty_bread)
66
+ end
67
+ describe 'successfully destroyed' do
68
+ before :each do
69
+ mock(ShopProductVariant).find(@product_variant.id.to_s) { @product_variant }
70
+ stub(@product_variant).destroy { true }
71
+ end
72
+ context 'html' do
73
+ before :each do
74
+ delete :destroy, :product_id => @product.id, :id => @product_variant.id
75
+ end
76
+ it 'should redirect to product path' do
77
+ response.should redirect_to(edit_admin_shop_product_path(@product_variant.product))
78
+ end
79
+ end
80
+ context 'js' do
81
+ before :each do
82
+ delete :destroy, :product_id => @product.id, :id => @product_variant.id, :format => 'js'
83
+ end
84
+ it 'should render the partial' do
85
+ response.should be_success
86
+ end
87
+ end
88
+ end
89
+ describe 'could not be destroyed' do
90
+ before :each do
91
+ mock(ShopProductVariant).find(@product_variant.id.to_s) { @product_variant }
92
+ stub(@product_variant).destroy { false }
93
+ end
94
+ context 'html' do
95
+ before :each do
96
+ delete :destroy, :product_id => @product.id, :id => @product_variant.id
97
+ end
98
+ it 'should assign flash error' do
99
+ flash.now[:error].should_not be_nil
100
+ end
101
+ it 'should redirect to product path' do
102
+ response.should redirect_to(edit_admin_shop_product_path(@product_variant.product))
103
+ end
104
+ end
105
+ context 'js' do
106
+ before :each do
107
+ delete :destroy, :product_id => @product.id, :id => @product_variant.id, :format => 'js'
108
+ end
109
+ it 'should not be success' do
110
+ response.should_not be_success
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ end
@@ -2,71 +2,45 @@ require 'spec/spec_helper'
2
2
 
3
3
  describe Admin::Shop::ProductsController do
4
4
 
5
- dataset :users
5
+ dataset :users, :shop_categories, :shop_products
6
6
 
7
7
  before(:each) do
8
8
  login_as :admin
9
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 }
10
+ @product = shop_products(:crusty_bread)
11
+ @products = @product.category.products
19
12
  end
20
13
 
21
14
  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
15
  context 'html' do
29
- before :each do
30
- get :index, :search => 'search'
31
- end
32
-
33
16
  it 'should render index' do
17
+ get :index
18
+
34
19
  response.should render_template(:index)
35
20
  end
36
21
 
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
22
+ it 'should also assign shop_categories' do
23
+ get :index
24
+
25
+ assigns(:shop_categories).should == ShopCategory.all
40
26
  end
41
27
  end
42
28
 
43
29
  context 'js' do
44
- before :each do
45
- get :index, :search => 'search', :format => 'js'
46
- end
47
-
48
30
  it 'should render the collection partial and success status' do
31
+ get :index, :format => 'js'
32
+
49
33
  response.should be_success
50
34
  response.should render_template('/admin/shop/products/index/_product')
51
35
  end
52
-
53
- it 'should assign the shop_products instance variable' do
54
- assigns(:shop_products).should === @shop_products
55
- end
56
36
  end
57
37
 
58
38
  context 'json' do
59
- before :each do
60
- get :index, :search => 'search', :format => 'json'
61
- end
62
-
63
39
  it 'should return a json object of the array and success status' do
40
+ get :index, :format => 'json'
41
+
64
42
  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
43
+ response.body.should === assigns(:shop_products).to_json
70
44
  end
71
45
  end
72
46
 
@@ -74,16 +48,18 @@ describe Admin::Shop::ProductsController do
74
48
 
75
49
  describe '#sort' do
76
50
  before :each do
77
- @products = [
78
- 'shop_category_1_products[]=2',
79
- 'shop_category_1_products[]=1'
51
+ @params = [
52
+ "category_#{@product.category.id}_products[]=2",
53
+ "category_#{@product.category.id}_products[]=1",
54
+ "category_#{@product.category.id}_products[]=0"
80
55
  ].join('&')
81
56
  end
82
57
 
83
58
  context 'products are not passed' do
84
59
  context 'html' do
85
60
  it 'should assign an error and redirect to admin_shop_products_path path' do
86
- put :sort
61
+ put :sort, :category_id => @product.category.id
62
+
87
63
  flash.now[:error].should_not be_nil
88
64
  response.should redirect_to(admin_shop_products_path)
89
65
  end
@@ -91,7 +67,8 @@ describe Admin::Shop::ProductsController do
91
67
 
92
68
  context 'js' do
93
69
  it 'should return an error string and failure status' do
94
- put :sort, :format => 'js'
70
+ put :sort, :category_id => @product.category.id, :format => 'js'
71
+
95
72
  response.should_not be_success
96
73
  response.body.should === 'Could not sort Products.'
97
74
  end
@@ -99,7 +76,8 @@ describe Admin::Shop::ProductsController do
99
76
 
100
77
  context 'json' do
101
78
  it 'should return a json error object and failure status' do
102
- put :sort, :format => 'json'
79
+ put :sort, :category_id => @product.category.id, :format => 'json'
80
+
103
81
  response.should_not be_success
104
82
  JSON.parse(response.body)['error'].should === 'Could not sort Products.'
105
83
  end
@@ -107,17 +85,14 @@ describe Admin::Shop::ProductsController do
107
85
  end
108
86
 
109
87
  context 'products are passed' do
110
- before :each do
111
- mock(ShopCategory).find('1') { @shop_category }
112
- end
113
88
  context 'could not sort' do
114
89
  before :each do
115
- mock(ShopProduct).find('2').stub!.update_attributes!(anything) { raise 'No Sorting' }
90
+ mock(ShopProduct).sort(@product.category.id.to_s, anything) { raise ActiveRecord::RecordNotFound }
116
91
  end
117
92
 
118
93
  context 'html' do
119
94
  it 'should assign an error and redirect to admin_shop_products_path path' do
120
- put :sort, :products => @products, :category_id => 1
95
+ put :sort, :products => @params, :category_id => @product.category.id
121
96
  flash.now[:error].should === 'Could not sort Products.'
122
97
  response.should redirect_to(admin_shop_products_path)
123
98
  end
@@ -125,7 +100,7 @@ describe Admin::Shop::ProductsController do
125
100
 
126
101
  context 'js' do
127
102
  it 'should return an error string and failure status' do
128
- put :sort, :products => @products, :category_id => 1, :format => 'js'
103
+ put :sort, :products => @params, :category_id => @product.category.id, :format => 'js'
129
104
  response.should_not be_success
130
105
  response.body.should === 'Could not sort Products.'
131
106
  end
@@ -133,7 +108,7 @@ describe Admin::Shop::ProductsController do
133
108
 
134
109
  context 'json' do
135
110
  it 'should return a json error object and failure status' do
136
- put :sort, :products => @products, :category_id => 1, :format => 'json'
111
+ put :sort, :products => @params, :category_id => @product.category.id, :format => 'json'
137
112
  response.should_not be_success
138
113
  JSON.parse(response.body)['error'].should === 'Could not sort Products.'
139
114
  end
@@ -142,20 +117,20 @@ describe Admin::Shop::ProductsController do
142
117
 
143
118
  context 'successfully sorted' do
144
119
  before :each do
145
- mock(ShopProduct).find(anything).times(2).stub!.update_attributes!(anything) { true }
120
+ mock(ShopProduct).sort(@product.category.id.to_s, anything) { true }
146
121
  end
147
122
 
148
123
  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.'
124
+ it 'should redirect to admin_shop_products_path path' do
125
+ put :sort, :products => @params, :category_id => @product.category.id
152
126
  response.should redirect_to(admin_shop_products_path)
153
127
  end
154
128
  end
155
129
 
156
130
  context 'js' do
157
131
  it 'should return success string and success status' do
158
- put :sort, :products => @products, :category_id => 1, :format => 'js'
132
+ put :sort, :products => @params, :category_id => @product.category.id, :format => 'js'
133
+
159
134
  response.should be_success
160
135
  response.body.should === 'Products successfully sorted.'
161
136
  end
@@ -163,7 +138,8 @@ describe Admin::Shop::ProductsController do
163
138
 
164
139
  context 'json' do
165
140
  it 'should return a json success object and success status' do
166
- put :sort, :products => @products, :category_id => 1, :format => 'json'
141
+ put :sort, :products => @params, :category_id => @product.category.id, :format => 'json'
142
+
167
143
  response.should be_success
168
144
  JSON.parse(response.body)['notice'].should === 'Products successfully sorted.'
169
145
  end
@@ -173,12 +149,7 @@ describe Admin::Shop::ProductsController do
173
149
  end
174
150
 
175
151
  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
-
152
+ context 'product could not be created' do
182
153
  context 'html' do
183
154
  it 'should assign a flash error and render new' do
184
155
  post :create, :shop_product => {}
@@ -209,59 +180,61 @@ describe Admin::Shop::ProductsController do
209
180
 
210
181
  context 'product successfully created' do
211
182
  before :each do
212
- mock(ShopProduct).new() { @shop_product }
213
- stub(@shop_product).save! { true }
183
+ @params = {
184
+ :page_attributes => {
185
+ :title => 'name',
186
+ :parent_id => @product.category.page.id,
187
+ :parts_attributes => [{
188
+ :name => 'description',
189
+ :content => '*name*'
190
+ }]
191
+ },
192
+ :price => 11.11
193
+ }
214
194
  end
215
-
216
195
  context 'html' do
217
196
  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.'
197
+ it 'should redirect to edit_shop_product path' do
198
+ post :create, :shop_product => @params
199
+
221
200
  response.should redirect_to(admin_shop_products_path)
222
201
  end
223
202
  end
224
203
  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))
204
+ it 'should redirect to edit_shop_product path' do
205
+ post :create, :shop_product => @params, :continue => true
206
+
207
+ response.should redirect_to(edit_admin_shop_product_path(assigns(:shop_product)))
229
208
  end
230
209
  end
231
210
  end
232
211
 
233
212
  context 'js' do
234
213
  it 'should render the collection partial and success status' do
235
- post :create, :shop_product => {}, :format => 'js'
214
+ post :create, :shop_product => @params, :format => 'js'
215
+
236
216
  response.should be_success
237
- assigns(:shop_product).should === @shop_product
238
217
  response.should render_template('/admin/shop/products/index/_product')
239
218
  end
240
219
  end
241
220
 
242
221
  context 'json' do
243
222
  it 'should render the json object and redirect to json show' do
244
- post :create ,:shop_product => {}, :format => 'json'
223
+ post :create ,:shop_product => @params, :format => 'json'
224
+
245
225
  response.should be_success
246
- response.body.should === @shop_product.to_json(ShopProduct.params)
226
+ response.body.should === assigns(:shop_product).to_json
247
227
  end
248
228
  end
249
229
  end
250
230
  end
251
231
 
252
232
  describe '#update' do
253
- before :each do
254
- mock(ShopProduct).find('1') { @shop_product }
255
- end
256
-
257
233
  context 'could not update' do
258
- before :each do
259
- stub(@shop_product).update_attributes!({}) { raise ActiveRecord::RecordNotSaved }
260
- end
261
-
262
234
  context 'html' do
263
235
  it 'should assign a flash error and render edit' do
264
- put :update, :id => @shop_product.id, :shop_product => {}
236
+ put :update, :id => @product.id, :shop_product => { :title => 'failure' }
237
+
265
238
  response.should render_template(:edit)
266
239
  flash.now[:error].should === 'Could not update Product.'
267
240
  end
@@ -269,7 +242,7 @@ describe Admin::Shop::ProductsController do
269
242
 
270
243
  context 'js' do
271
244
  it 'should render the error and failure status' do
272
- put :update, :id => @shop_product.id, :shop_product => {}, :format => 'js'
245
+ put :update, :id => @product.id, :shop_product => { :title => 'failure' }, :format => 'js'
273
246
  response.should_not be_success
274
247
  response.body.should === 'Could not update Product.'
275
248
  end
@@ -277,38 +250,32 @@ describe Admin::Shop::ProductsController do
277
250
 
278
251
  context 'json' do
279
252
  it 'should assign an error json object and failure status' do
280
- put :update, :id => @shop_product.id, :shop_product => {}, :format => 'json'
253
+ put :update, :id => @product.id, :shop_product => { :title => 'failure' }, :format => 'json'
281
254
  response.should_not be_success
282
255
  JSON.parse(response.body)['error'].should === 'Could not update Product.'
283
256
  end
284
257
  end
285
258
  end
286
259
 
287
- context 'successfully updated' do
288
- before :each do
289
- stub(@shop_product).update_attributes!({}) { true }
290
- end
291
-
260
+ context 'successfully updated' do
292
261
  context 'html' do
293
262
  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.'
263
+ it 'should redirect to edit_shop_product path' do
264
+ put :update, :id => @product.id, :shop_product => { :page_attributes => { :title => 'success', :parent_id => @product.category.page.id } }
297
265
  response.should redirect_to(admin_shop_products_path)
298
266
  end
299
267
  end
300
268
  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))
269
+ it 'should redirect to edit_shop_product path' do
270
+ put :update, :id => @product.id, :shop_product => { :page_attributes => { :title => 'success', :parent_id => @product.category.page.id } }, :continue => true
271
+ response.should redirect_to(edit_admin_shop_product_path(assigns(:shop_product)))
305
272
  end
306
273
  end
307
274
  end
308
275
 
309
276
  context 'js' do
310
277
  it 'should render the partial and success status' do
311
- put :update, :id => @shop_product.id, :shop_product => {}, :format => 'js'
278
+ put :update, :id => @product.id, :shop_product => { :page_attributes => { :title => 'success', :parent_id => @product.category.page.id } }, :format => 'js'
312
279
  response.should be_success
313
280
  response.should render_template('/admin/shop/products/index/_product')
314
281
  end
@@ -316,66 +283,30 @@ describe Admin::Shop::ProductsController do
316
283
 
317
284
  context 'json' do
318
285
  it 'should assign the json object and success status' do
319
- put :update, :id => @shop_product.id, :shop_product => {}, :format => 'json'
286
+ put :update, :id => @product.id, :shop_product => { :page_attributes => { :title => 'success', :parent_id => @product.category.page.id } }, :format => 'json'
287
+
320
288
  response.should be_success
321
- response.body.should === @shop_product.to_json(ShopProduct.params)
289
+ response.body.should === assigns(:shop_product).to_json(ShopProduct.params)
322
290
  end
323
291
  end
324
292
  end
325
293
  end
326
294
 
327
295
  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
296
  context 'product successfully destroyed' do
364
- before :each do
365
- stub(@shop_product).destroy { true }
366
- end
367
297
 
368
298
  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.'
299
+ it 'should redirect to shop_products path' do
300
+ delete :destroy, :id => @product.id
301
+
372
302
  response.should redirect_to(admin_shop_products_path)
373
303
  end
374
304
  end
375
305
 
376
306
  context 'js' do
377
307
  it 'should render success message and success status' do
378
- delete :destroy, :id => 1, :format => 'js'
308
+ delete :destroy, :id => @product.id, :format => 'js'
309
+
379
310
  response.body.should === 'Product deleted successfully.'
380
311
  response.should be_success
381
312
  end
@@ -383,7 +314,8 @@ describe Admin::Shop::ProductsController do
383
314
 
384
315
  context 'json' do
385
316
  it 'should return a success json object and success status' do
386
- delete :destroy, :id => 1, :format => 'json'
317
+ delete :destroy, :id => @product.id, :format => 'json'
318
+
387
319
  JSON.parse(response.body)['notice'].should === 'Product deleted successfully.'
388
320
  response.should be_success
389
321
  end