radiant-shop-extension 0.11.6 → 0.90.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. data/HISTORY.md +21 -3
  2. data/LICENSE +42 -0
  3. data/README.md +62 -25
  4. data/Rakefile +4 -5
  5. data/VERSION +1 -1
  6. data/app/controllers/admin/shop/categories_controller.rb +1 -0
  7. data/app/controllers/admin/shop/orders_controller.rb +1 -1
  8. data/app/controllers/admin/shop/products_controller.rb +18 -7
  9. data/app/helpers/shop_helper.rb +8 -0
  10. data/app/models/form_address.rb +5 -5
  11. data/app/models/form_checkout.rb +25 -17
  12. data/app/models/form_line_item.rb +1 -1
  13. data/app/models/shop_category.rb +22 -7
  14. data/app/models/shop_customer.rb +1 -1
  15. data/app/models/shop_line_item.rb +26 -26
  16. data/app/models/shop_order.rb +0 -2
  17. data/app/models/shop_product.rb +15 -18
  18. data/app/views/.DS_Store +0 -0
  19. data/app/views/admin/shop/categories/edit/meta/_status.html.haml +3 -0
  20. data/app/views/admin/shop/products/edit/_foot.html.haml +1 -8
  21. data/app/views/admin/shop/products/edit/meta/_layout.html.haml +6 -0
  22. data/app/views/admin/shop/products/edit/meta/_status.html.haml +3 -0
  23. data/app/views/admin/shop/products/index/_product.html.haml +1 -1
  24. data/config/locales/en.yml +8 -7
  25. data/config/routes.rb +4 -16
  26. data/db/migrate/20101011063133_setup_shop.rb +94 -0
  27. data/db/seeds/forms.rb +113 -154
  28. data/db/seeds/layouts.rb +67 -103
  29. data/db/seeds/pages.rb +101 -0
  30. data/db/seeds/products.rb +29 -0
  31. data/db/seeds/snippets.rb +36 -21
  32. data/lib/shop/controllers/application_controller.rb +5 -3
  33. data/lib/shop/models/form_extension.rb +1 -2
  34. data/lib/shop/models/page.rb +0 -1
  35. data/lib/shop/models/user.rb +0 -1
  36. data/lib/shop/tags/card.rb +8 -2
  37. data/lib/shop/tags/cart.rb +5 -1
  38. data/lib/shop/tags/helpers.rb +35 -60
  39. data/lib/shop/tags/item.rb +2 -16
  40. data/lib/shop/tags/product.rb +7 -0
  41. data/lib/tasks/shop_extension_tasks.rake +9 -4
  42. data/public/javascripts/admin/extensions/shop/products/edit.js +0 -25
  43. data/radiant-shop-extension.gemspec +25 -201
  44. data/shop_extension.rb +18 -19
  45. data/spec/datasets/forms.rb +25 -28
  46. data/spec/datasets/shop_categories.rb +2 -2
  47. data/spec/datasets/shop_config.rb +24 -0
  48. data/spec/datasets/shop_customers.rb +1 -0
  49. data/spec/datasets/shop_line_items.rb +21 -3
  50. data/spec/datasets/shop_products.rb +4 -1
  51. data/spec/datasets/tags.rb +19 -0
  52. data/spec/lib/shop/models/page_spec.rb +1 -1
  53. data/spec/lib/shop/tags/card_spec.rb +30 -4
  54. data/spec/lib/shop/tags/cart_spec.rb +29 -12
  55. data/spec/lib/shop/tags/helpers_spec.rb +45 -66
  56. data/spec/lib/shop/tags/item_spec.rb +6 -10
  57. data/spec/lib/shop/tags/product_spec.rb +27 -2
  58. data/spec/models/form_address_spec.rb +9 -8
  59. data/spec/models/form_checkout_spec.rb +28 -22
  60. data/spec/models/shop_category_spec.rb +2 -10
  61. data/spec/models/shop_line_item_spec.rb +71 -34
  62. data/spec/models/shop_order_spec.rb +5 -5
  63. data/spec/models/shop_product_attachment_spec.rb +1 -0
  64. data/spec/models/shop_product_spec.rb +4 -47
  65. data/spec/spec.opts +3 -5
  66. metadata +60 -248
  67. data/Gemfile +0 -26
  68. data/Gemfile.lock +0 -75
  69. data/MIT-LICENSE +0 -20
  70. data/app/controllers/admin/shop/discounts/discountables_controller.rb +0 -44
  71. data/app/controllers/admin/shop/discounts_controller.rb +0 -64
  72. data/app/controllers/admin/shop/packages/packings_controller.rb +0 -90
  73. data/app/controllers/admin/shop/packages_controller.rb +0 -63
  74. data/app/controllers/admin/shop/products/variant_templates_controller.rb +0 -27
  75. data/app/controllers/admin/shop/products/variants_controller.rb +0 -60
  76. data/app/controllers/admin/shop/variants_controller.rb +0 -48
  77. data/app/models/form_discount.rb +0 -39
  78. data/app/models/shop_discount.rb +0 -37
  79. data/app/models/shop_discountable.rb +0 -64
  80. data/app/models/shop_group.rb +0 -15
  81. data/app/models/shop_grouping.rb +0 -6
  82. data/app/models/shop_package.rb +0 -74
  83. data/app/models/shop_packing.rb +0 -22
  84. data/app/models/shop_product_variant.rb +0 -34
  85. data/app/models/shop_variant.rb +0 -23
  86. data/app/views/admin/pages/_shop_category.html.haml +0 -4
  87. data/app/views/admin/pages/_shop_product.html.haml +0 -4
  88. data/app/views/admin/shop/discounts/edit/_foot.html.haml +0 -16
  89. data/app/views/admin/shop/discounts/edit/_form.html.haml +0 -15
  90. data/app/views/admin/shop/discounts/edit/_head.html.haml +0 -4
  91. data/app/views/admin/shop/discounts/edit/_inputs.html.haml +0 -2
  92. data/app/views/admin/shop/discounts/edit/_meta.html.haml +0 -8
  93. data/app/views/admin/shop/discounts/edit/_parts.html.haml +0 -9
  94. data/app/views/admin/shop/discounts/edit/_popups.html.haml +0 -4
  95. data/app/views/admin/shop/discounts/edit/buttons/_browse_categories.html.haml +0 -1
  96. data/app/views/admin/shop/discounts/edit/buttons/_browse_products.html.haml +0 -1
  97. data/app/views/admin/shop/discounts/edit/inputs/_amount.html.haml +0 -3
  98. data/app/views/admin/shop/discounts/edit/inputs/_code.html.haml +0 -3
  99. data/app/views/admin/shop/discounts/edit/inputs/_name.html.haml +0 -3
  100. data/app/views/admin/shop/discounts/edit/meta/_finish.html.haml +0 -5
  101. data/app/views/admin/shop/discounts/edit/meta/_start.html.haml +0 -5
  102. data/app/views/admin/shop/discounts/edit/parts/_categories.html.haml +0 -3
  103. data/app/views/admin/shop/discounts/edit/parts/_products.html.haml +0 -3
  104. data/app/views/admin/shop/discounts/edit/popups/_browse_categories.html.haml +0 -6
  105. data/app/views/admin/shop/discounts/edit/popups/_browse_products.html.haml +0 -6
  106. data/app/views/admin/shop/discounts/edit/shared/_category.html.haml +0 -11
  107. data/app/views/admin/shop/discounts/edit/shared/_product.html.haml +0 -12
  108. data/app/views/admin/shop/discounts/edit.html.haml +0 -11
  109. data/app/views/admin/shop/discounts/index/_discount.html.haml +0 -13
  110. data/app/views/admin/shop/discounts/index/_foot.html.haml +0 -5
  111. data/app/views/admin/shop/discounts/index/_head.html.haml +0 -2
  112. data/app/views/admin/shop/discounts/index/buttons/_new_discount.html.haml +0 -1
  113. data/app/views/admin/shop/discounts/index.html.haml +0 -13
  114. data/app/views/admin/shop/discounts/new.html.haml +0 -11
  115. data/app/views/admin/shop/discounts/remove.html.haml +0 -12
  116. data/app/views/admin/shop/packages/edit/_foot.html.haml +0 -17
  117. data/app/views/admin/shop/packages/edit/_form.html.haml +0 -15
  118. data/app/views/admin/shop/packages/edit/_head.html.haml +0 -4
  119. data/app/views/admin/shop/packages/edit/_inputs.html.haml +0 -2
  120. data/app/views/admin/shop/packages/edit/_meta.html.haml +0 -8
  121. data/app/views/admin/shop/packages/edit/_parts.html.haml +0 -9
  122. data/app/views/admin/shop/packages/edit/_popups.html.haml +0 -4
  123. data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +0 -1
  124. data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +0 -3
  125. data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +0 -3
  126. data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +0 -5
  127. data/app/views/admin/shop/packages/edit/parts/_description.html.haml +0 -1
  128. data/app/views/admin/shop/packages/edit/parts/_products.html.haml +0 -3
  129. data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +0 -7
  130. data/app/views/admin/shop/packages/edit/shared/_product.html.haml +0 -8
  131. data/app/views/admin/shop/packages/edit.html.haml +0 -11
  132. data/app/views/admin/shop/packages/index/_foot.html.haml +0 -8
  133. data/app/views/admin/shop/packages/index/_head.html.haml +0 -2
  134. data/app/views/admin/shop/packages/index/_package.html.haml +0 -9
  135. data/app/views/admin/shop/packages/index/buttons/_new_package.html.haml +0 -1
  136. data/app/views/admin/shop/packages/index.html.haml +0 -13
  137. data/app/views/admin/shop/packages/new.html.haml +0 -11
  138. data/app/views/admin/shop/packages/remove.html.haml +0 -12
  139. data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +0 -1
  140. data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +0 -1
  141. data/app/views/admin/shop/products/edit/parts/_variants.html.haml +0 -3
  142. data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +0 -6
  143. data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +0 -16
  144. data/app/views/admin/shop/products/edit/shared/_template.html.haml +0 -6
  145. data/app/views/admin/shop/products/edit/shared/_variant.html.haml +0 -10
  146. data/app/views/admin/shop/products/index/buttons/_variants.html.haml +0 -1
  147. data/app/views/admin/shop/variants/edit/_foot.html.haml +0 -9
  148. data/app/views/admin/shop/variants/edit/_form.html.haml +0 -13
  149. data/app/views/admin/shop/variants/edit/_head.html.haml +0 -4
  150. data/app/views/admin/shop/variants/edit/_inputs.html.haml +0 -2
  151. data/app/views/admin/shop/variants/edit/_meta.html.haml +0 -8
  152. data/app/views/admin/shop/variants/edit/_parts.html.haml +0 -9
  153. data/app/views/admin/shop/variants/edit/_popups.html.haml +0 -4
  154. data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +0 -3
  155. data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +0 -3
  156. data/app/views/admin/shop/variants/edit.html.haml +0 -11
  157. data/app/views/admin/shop/variants/index/_foot.html.haml +0 -5
  158. data/app/views/admin/shop/variants/index/_head.html.haml +0 -2
  159. data/app/views/admin/shop/variants/index/_variant.html.haml +0 -9
  160. data/app/views/admin/shop/variants/index/buttons/_add_variant.html.haml +0 -1
  161. data/app/views/admin/shop/variants/index/buttons/_categories.html.haml +0 -1
  162. data/app/views/admin/shop/variants/index.html.haml +0 -13
  163. data/app/views/admin/shop/variants/new.html.haml +0 -11
  164. data/app/views/admin/shop/variants/remove.html.haml +0 -12
  165. data/app/views/shop/categories/show.html.haml +0 -1
  166. data/app/views/shop/orders/show.html.haml +0 -1
  167. data/app/views/shop/products/index.html.haml +0 -1
  168. data/app/views/shop/products/show.html.haml +0 -1
  169. data/cucumber.yml +0 -1
  170. data/db/migrate/20100311053701_initial.rb +0 -153
  171. data/db/migrate/20100927041219_remove_payment_methods.rb +0 -16
  172. data/db/migrate/20100927041624_change_payments_add_gateway.rb +0 -11
  173. data/db/migrate/20100927140446_change_payment_add_card_type_card_number.rb +0 -11
  174. data/db/migrate/20100929011106_fix_relationship_foreign_keys.rb +0 -101
  175. data/db/migrate/20100929011607_drop_shop_addressables.rb +0 -25
  176. data/db/migrate/20100929030510_create_shop_groups.rb +0 -19
  177. data/db/migrate/20100929080301_shop_groups_change_add_description.rb +0 -11
  178. data/db/migrate/20100929081200_create_variants.rb +0 -20
  179. data/db/migrate/20100929143531_change_variants_add_updated_by.rb +0 -25
  180. data/db/migrate/20100929145641_change_created_by_to_id.rb +0 -75
  181. data/db/migrate/20100929235221_change_category_add_variant_id.rb +0 -9
  182. data/db/migrate/20100930235221_create_packages.rb +0 -31
  183. data/db/migrate/20101005231713_create_page_ids.rb +0 -11
  184. data/db/migrate/20101006051214_create_pages_for_products_and_categories.rb +0 -73
  185. data/db/migrate/20101007111845_add_default_position_to_attachment.rb +0 -9
  186. data/db/migrate/20101010071143_create_discounts.rb +0 -29
  187. data/db/migrate/20101010072225_modify_categories_remove_variant.rb +0 -9
  188. data/db/migrate/20101010130034_change_discountables_add_observer.rb +0 -15
  189. data/db/migrate/20101011063133_change_orders_set_limits_to_null.rb +0 -11
  190. data/features/support/env.rb +0 -16
  191. data/features/support/paths.rb +0 -14
  192. data/lib/shop/interface/packages.rb +0 -34
  193. data/lib/shop/interface/variants.rb +0 -34
  194. data/lib/shop/tags/package.rb +0 -95
  195. data/lib/shop/tags/product_variant.rb +0 -52
  196. data/lib/shop/tags/responses.rb +0 -34
  197. data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
  198. data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
  199. data/mockups/discounts/new-edit.bmml +0 -492
  200. data/public/javascripts/admin/extensions/shop/discounts/edit.js +0 -76
  201. data/public/javascripts/admin/extensions/shop/packages/edit.js +0 -109
  202. data/public/stylesheets/sass/admin/extensions/shop/discounts/edit.sass +0 -125
  203. data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +0 -162
  204. data/spec/controllers/admin/shop/discounts/discountables_controller_spec.rb +0 -73
  205. data/spec/controllers/admin/shop/discounts_controller_spec.rb +0 -81
  206. data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +0 -188
  207. data/spec/controllers/admin/shop/packages_controller_spec.rb +0 -32
  208. data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +0 -53
  209. data/spec/controllers/admin/shop/products/variants_controller_spec.rb +0 -116
  210. data/spec/controllers/admin/shop/variants_controller_spec.rb +0 -67
  211. data/spec/datasets/shop_discountables.rb +0 -22
  212. data/spec/datasets/shop_discounts.rb +0 -29
  213. data/spec/datasets/shop_groups.rb +0 -15
  214. data/spec/datasets/shop_packages.rb +0 -25
  215. data/spec/datasets/shop_product_variants.rb +0 -22
  216. data/spec/datasets/shop_variants.rb +0 -17
  217. data/spec/lib/shop/tags/package_spec.rb +0 -342
  218. data/spec/lib/shop/tags/product_variant_spec.rb +0 -175
  219. data/spec/lib/shop/tags/responses_spec.rb +0 -129
  220. data/spec/models/form_discount_spec.rb +0 -63
  221. data/spec/models/shop_discount_spec.rb +0 -130
  222. data/spec/models/shop_discountable_spec.rb +0 -114
  223. data/spec/models/shop_group_spec.rb +0 -38
  224. data/spec/models/shop_package_spec.rb +0 -117
  225. data/spec/models/shop_packing_spec.rb +0 -67
  226. data/spec/models/shop_product_variant_spec.rb +0 -92
  227. data/spec/models/shop_variant_spec.rb +0 -32
@@ -1,130 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ShopDiscount do
4
-
5
- dataset :shop_discounts, :shop_products, :shop_orders
6
-
7
- describe 'scope' do
8
- before :each do
9
- @valid = ShopDiscount.all_including_invalid(:conditions => { :code => '10pcoff'}).first
10
- @invalid = ShopDiscount.all_including_invalid(:conditions => { :code => 'invalid'}).first
11
- end
12
- context 'all' do
13
- it 'should not return invalid by default' do
14
- ShopDiscount.all.include?(@valid).should be_true
15
- ShopDiscount.all.include?(@invalid).should be_false
16
- end
17
- end
18
- context 'all_including_invalid' do
19
- it 'should return all including invalid' do
20
- ShopDiscount.all_including_invalid.include?(@valid).should be_true
21
- ShopDiscount.all_including_invalid.include?(@invalid).should be_true
22
- end
23
- end
24
- end
25
-
26
- describe 'validations' do
27
- before :each do
28
- @discount = shop_discounts(:ten_percent)
29
- end
30
-
31
- context 'name' do
32
- it 'should require' do
33
- @discount.name = nil
34
- @discount.valid?.should === false
35
- end
36
- it 'should be unique' do
37
- @other = shop_discounts(:five_percent)
38
- @other.name = @discount.name
39
- @other.valid?.should === false
40
- end
41
- end
42
-
43
- context 'code' do
44
- it 'should require' do
45
- @discount.code = nil
46
- @discount.valid?.should === false
47
- end
48
- it 'should be unique' do
49
- @other = shop_discounts(:five_percent)
50
- @other.code = @discount.code
51
- @other.valid?.should === false
52
- end
53
- end
54
-
55
- context 'amount' do
56
- it 'should require' do
57
- @discount.amount = nil
58
- @discount.valid?.should === false
59
- end
60
- it 'should be numerical' do
61
- @discount.amount = 'failure'
62
- @discount.valid?.should === false
63
- end
64
- end
65
- end
66
-
67
- describe 'relationships' do
68
- before :each do
69
- @discount = shop_discounts(:five_percent)
70
- end
71
- context 'categories' do
72
- before :each do
73
- @bread = shop_categories(:bread)
74
- end
75
- it 'should have many' do
76
- @discount.discountables.create(:discounted => @bread)
77
- @discount.categories.include?(@bread).should === true
78
- end
79
- context '#for' do
80
- before :each do
81
- @discount.discountables.create(:discounted => shop_categories(:bread))
82
- @discount.discountables.create(:discounted => shop_categories(:milk))
83
- @discount.discountables.create(:discounted => shop_products(:crusty_bread))
84
- @discount.discountables.create(:discounted => shop_products(:full_milk))
85
- end
86
- it 'should return result of only that type' do
87
- discountables = @discount.discountables.for('ShopCategory')
88
- discountables.each do |d|
89
- d.discounted.is_a?(ShopCategory).should === true
90
- end
91
- end
92
- it 'should return result of only that type regardless of string format' do
93
- discountables = @discount.discountables.for('Shop_category')
94
- discountables.each do |d|
95
- d.discounted.is_a?(ShopCategory).should === true
96
- end
97
-
98
- discountables = @discount.discountables.for('shop_category')
99
- discountables.each do |d|
100
- d.discounted.is_a?(ShopCategory).should === true
101
- end
102
-
103
- discountables = @discount.discountables.for('ShopProduct')
104
- discountables.each do |d|
105
- d.discounted.is_a?(ShopProduct).should === true
106
- end
107
- end
108
- end
109
- end
110
- end
111
-
112
- describe '#available_categories' do
113
- before :each do
114
- @discount = shop_discounts(:ten_percent)
115
- end
116
- it 'should return all categories minus its own' do
117
- @discount.available_categories.should === ShopCategory.all - @discount.categories
118
- end
119
- end
120
-
121
- describe '#available_products' do
122
- before :each do
123
- @discount = shop_discounts(:ten_percent)
124
- end
125
- it 'should return all products minus its own' do
126
- @discount.available_products.should === ShopProduct.all - @discount.products
127
- end
128
- end
129
-
130
- end
@@ -1,114 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ShopDiscountable do
4
-
5
- dataset :shop_discountables, :shop_line_items
6
-
7
- before(:each) do
8
- @discount = shop_discounts(:ten_percent)
9
- end
10
-
11
- describe 'validations' do
12
- before :each do
13
- @discountable = shop_discountables(:ten_percent_bread)
14
- end
15
-
16
- context 'discount' do
17
- it 'should require' do
18
- @discountable.discount = nil
19
- @discountable.valid?.should === false
20
- end
21
- end
22
-
23
- context 'discounted' do
24
- it 'should require' do
25
- @discountable.discounted = nil
26
- @discountable.valid?.should === false
27
- end
28
- it 'should be unique to the class' do
29
- @other = ShopDiscountable.new(:discount => @discount, :discounted => @discountable.discounted)
30
- @other.valid?.should === false
31
-
32
- @other.discounted = shop_categories(:milk)
33
- @other.valid?.should === true
34
- end
35
- end
36
- end
37
-
38
- describe 'category and product hooks' do
39
- describe '#create' do
40
- before :each do
41
- @discount = shop_discounts(:one_percent)
42
- @category = shop_categories(:milk)
43
-
44
- discountable = @discount.discountables.create(:discounted => @category)
45
- end
46
- it 'should assign the category to the discount' do
47
- @discount.categories.include?(@category).should be_true
48
- end
49
- it 'should assign the products to that category' do
50
- @discount.products.should_not be_empty
51
- @discount.products.should === @category.products
52
- end
53
- end
54
-
55
- describe '#destroy' do
56
- before :each do
57
- @discount = shop_discounts(:one_percent)
58
- @category = shop_categories(:milk)
59
-
60
- discountable = @discount.discountables.create(:discounted => @category)
61
- discountable.destroy
62
- end
63
- it 'should remove the category to the discount' do
64
- @discount.categories.include?(@category).should be_false
65
- end
66
- it 'should remove the products of that category' do
67
- @category.products.each do |p|
68
- @discount.products.include?(p).should be_false
69
- end
70
- end
71
- end
72
- end
73
-
74
- describe 'order and line_item hooks' do
75
- before :each do
76
- @discount = shop_discounts(:one_percent)
77
- @order = shop_orders(:several_items)
78
- @line_item_one = shop_orders(:several_items).line_items.first
79
- @line_item_two = shop_orders(:several_items).line_items.last
80
-
81
- # Creates a discount for the items product
82
- @discount.discountables.create(:discounted_id => @line_item_one.item.id, :discounted_type => @line_item_one.item.class.name)
83
- end
84
- describe '#create' do
85
- before :each do
86
- discountable = @discount.discountables.create(:discounted => @order)
87
- end
88
- it 'should assign the category to the discount' do
89
- @discount.orders.include?(@order).should be_true
90
- end
91
- it 'should assign only the items with discounted products to that category' do
92
- @discount.line_items.should_not be_empty
93
- @discount.line_items.include?(@line_item_one).should be_true
94
- @discount.line_items.include?(@line_item_two).should be_false
95
- end
96
- end
97
-
98
- describe '#destroy' do
99
- before :each do
100
- discountable = @discount.discountables.create(:discounted => @order)
101
- discountable.destroy
102
- end
103
- it 'should remove the category to the discount' do
104
- @discount.orders.include?(@order).should be_false
105
- end
106
- it 'should remove the products of that category' do
107
- @order.line_items.each do |p|
108
- @discount.line_items.include?(p).should be_false
109
- end
110
- end
111
- end
112
- end
113
-
114
- end
@@ -1,38 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ShopGroup do
4
-
5
- dataset :shop_groups
6
-
7
- context 'associations' do
8
- before :each do
9
- @group = shop_groups(:breakfast)
10
- end
11
-
12
- describe 'products' do
13
- before :each do
14
- @product = shop_products(:crusty_bread)
15
- end
16
-
17
- it 'should contain an array of products' do
18
- @group.products.include?(@product).should === true
19
- end
20
-
21
- it 'should accept new products' do
22
- @product = shop_products(:choc_milk)
23
- @group.products << @product
24
- @group.products.include?(@product).should === true
25
- end
26
- end
27
- end
28
-
29
- describe '#available_products' do
30
- before :each do
31
- @group = shop_groups(:breakfast)
32
- end
33
- it 'should return available_products' do
34
- @group.available_products.should === (ShopProduct.all - @group.products)
35
- end
36
- end
37
-
38
- end
@@ -1,117 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ShopPackage do
4
-
5
- dataset :shop_packages
6
-
7
- before(:each) do
8
- @package = shop_packages(:all_bread)
9
- end
10
-
11
- describe 'attributes' do
12
-
13
- it 'should have a name' do
14
- @package.name.should == 'all bread'
15
- end
16
-
17
- it 'should have a price' do
18
- @package.price.should === 10.00
19
- end
20
-
21
- end
22
-
23
- describe 'validation' do
24
-
25
- it 'should require a name' do
26
- @package = ShopPackage.new
27
-
28
- @package.valid? === false
29
-
30
- @package.name = "name"
31
- @package.valid? === true
32
- end
33
-
34
- it 'should validate but not require the price' do
35
- @package = ShopPackage.new({ :name => 'name' })
36
- @package.valid? === true
37
-
38
- @package.price = "asdas"
39
- @package.valid? === false
40
-
41
- @package.price = "-999.99"
42
- @package.valid? === false
43
-
44
- @package.price = "9.99.99"
45
- @package.valid? === false
46
-
47
- @package.price = "0.00"
48
- @package.valid? === false
49
-
50
- @package.price = "0.01"
51
- @package.valid? === true
52
-
53
- @package.price = "999999.99"
54
- @package.valid? === true
55
- end
56
-
57
- it 'should generate a valid sku on validation' do
58
- @package = ShopPackage.new({ :name => "dark_ _:_;_=_+_._~_toasted" })
59
-
60
- @package.valid? === true
61
- @package.sku.should === 'dark_______________toasted'
62
- end
63
-
64
- it 'should have an array of products' do
65
- @package.products.class.should == Array
66
- end
67
-
68
- it 'should have an array of line_items' do
69
- @package.line_items.class.should == Array
70
- end
71
-
72
- it 'should have an array of orders' do
73
- @package.orders.class.should == Array
74
- end
75
-
76
- end
77
-
78
- context 'instance methods' do
79
-
80
- describe '#value' do
81
- it 'should return the total value of its products' do
82
- value = 0
83
- @package.packings.map { |pkg| value += (pkg.product.price.to_f * pkg.quantity) }
84
-
85
- @package.value.should === value
86
- end
87
- end
88
-
89
- describe '#weight' do
90
- it 'should return the total value of its products' do
91
- weight = 0
92
- @package.packings.map { |pkg| weight += (pkg.product.weight.to_f * pkg.quantity) }
93
-
94
- @package.weight.should === weight
95
- end
96
- end
97
-
98
- describe '#available_products' do
99
- it 'should return the subset of products not in that package' do
100
- @package.available_products.should === (ShopProduct.all - @package.products)
101
- end
102
- end
103
-
104
- end
105
-
106
-
107
- context 'Class Methods' do
108
-
109
- describe '#params' do
110
- it 'should have a set of standard parameters' do
111
- ShopPackage.attrs.should === [ :id, :name,:price, :sku, :description, :created_at, :updated_at ]
112
- end
113
- end
114
-
115
- end
116
-
117
- end
@@ -1,67 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ShopPacking do
4
-
5
- dataset :shop_packages
6
-
7
- before(:each) do
8
- @packing = shop_packings(:warm_bread)
9
- end
10
-
11
- describe 'attributes' do
12
-
13
- it 'should have a quantity' do
14
- @packing.quantity.should == 1
15
- end
16
-
17
- it 'should have a position' do
18
- @packing.position.should == 1
19
- end
20
-
21
- it 'should have a package' do
22
- @packing.package.class.should == ShopPackage
23
- end
24
-
25
- it 'should have a product' do
26
- @packing.product.class.should == ShopProduct
27
- end
28
-
29
- end
30
-
31
- context 'instance methods' do
32
-
33
- describe '#value' do
34
-
35
- it 'should return the quantity multiplied by the product price' do
36
- @packing.value.should === @packing.quantity * @packing.product.price.to_f
37
- end
38
-
39
- end
40
-
41
- end
42
-
43
- context 'Class Methods' do
44
-
45
- describe '#set_quantity' do
46
- it 'should return the highest of 1 or the quantity' do
47
- @packing.quantity = 0
48
- @packing.save
49
- @packing.quantity.should === 1
50
-
51
- @packing.quantity = 1
52
- @packing.save
53
- @packing.quantity.should === 1
54
-
55
- @packing.quantity = -1
56
- @packing.save
57
- @packing.quantity.should === 1
58
-
59
- @packing.quantity = 2
60
- @packing.save
61
- @packing.quantity.should === 2
62
- end
63
- end
64
-
65
- end
66
-
67
- end
@@ -1,92 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ShopProductVariant do
4
-
5
- dataset :shop_products, :shop_product_variants
6
-
7
- describe 'relationships' do
8
- before :each do
9
- @product = shop_products(:crusty_bread)
10
- end
11
-
12
- context 'product' do
13
- it 'should belong to one' do
14
- @product_variant = shop_product_variants(:mouldy_crusty_bread)
15
- @product_variant.product.should === @product
16
- end
17
- end
18
- end
19
-
20
- describe 'validations' do
21
- before :each do
22
- @product_variant = shop_product_variants(:mouldy_crusty_bread)
23
- end
24
- context 'product' do
25
- it 'should require' do
26
- @product_variant.product = nil
27
- @product_variant.valid?.should be_false
28
- end
29
- end
30
- context 'name' do
31
- it 'should require' do
32
- @product_variant.name = nil
33
- @product_variant.valid?.should be_false
34
- end
35
- it 'should be unique within product' do
36
- @product_variant.name = shop_product_variants(:fresh_crusty_bread).name
37
- @product_variant.valid?.should be_false
38
-
39
- @product_variant.name = shop_product_variants(:royal_soft_bread).name
40
- @product_variant.valid?.should be_true
41
- end
42
- end
43
- context 'price' do
44
- it 'should not require' do
45
- @product_variant.price = nil
46
- @product_variant.valid?.should be_true
47
- end
48
- end
49
- end
50
-
51
- describe '#price' do
52
- before :each do
53
- @product_variant = shop_product_variants(:mouldy_crusty_bread)
54
- end
55
- context 'positive price' do
56
- before :each do
57
- @product_variant.price = 100.00
58
- end
59
- it 'should return the product price plus the variant price' do
60
- @product_variant.price.to_f.should === (@product_variant.product.price.to_f + 100.00)
61
- end
62
- end
63
- context 'negative price' do
64
- before :each do
65
- @product_variant.price = -100.00
66
- end
67
- it 'should return the product price plus the variant price' do
68
- @product_variant.price.to_f.should === (@product_variant.product.price.to_f - 100.00)
69
- end
70
- end
71
- end
72
-
73
- describe '#sku' do
74
- before :each do
75
- @product_variant = shop_product_variants(:mouldy_crusty_bread)
76
- stub(@product_variant).name { 'mouldy and yucky'}
77
- end
78
- it 'should return a concatenation of its name and products sku' do
79
- @product_variant.sku.should === "#{@product_variant.product.sku}-mouldy_and_yucky"
80
- end
81
- end
82
-
83
- describe '#sku' do
84
- before :each do
85
- @product_variant = shop_product_variants(:mouldy_crusty_bread)
86
- end
87
- it 'should return its products slug' do
88
- @product_variant.slug.should === @product_variant.product.slug
89
- end
90
- end
91
-
92
- end
@@ -1,32 +0,0 @@
1
- require 'spec/spec_helper'
2
-
3
- describe ShopVariant do
4
-
5
- dataset :shop_variants, :shop_categories
6
-
7
- describe 'validations' do
8
- before :each do
9
- @variant = shop_variants(:bread_states)
10
- end
11
-
12
- context 'name' do
13
- it 'should require' do
14
- @variant.name = nil
15
- @variant.valid?.should === false
16
- end
17
- it 'should be unique' do
18
- @other = shop_variants(:milk_states)
19
- @other.name = @variant.name
20
- @other.valid?.should === false
21
- end
22
- end
23
-
24
- context 'options' do
25
- it 'should require' do
26
- @variant.options_json = nil
27
- @variant.valid?.should === false
28
- end
29
- end
30
- end
31
-
32
- end