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
@@ -7,6 +7,7 @@ describe FormCheckout do
7
7
  before :each do
8
8
  mock_page_with_request_and_data
9
9
  end
10
+
10
11
  describe '#create' do
11
12
  context 'gateway' do
12
13
  context 'order has no billing' do
@@ -17,7 +18,7 @@ describe FormCheckout do
17
18
  end
18
19
 
19
20
  it 'should return the standard response' do
20
- @checkout = FormCheckout.new(@form, @page)
21
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
21
22
  result = @checkout.create
22
23
 
23
24
  result[:gateway].should be_nil
@@ -36,7 +37,7 @@ describe FormCheckout do
36
37
  end
37
38
 
38
39
  it 'should assign ActiveMerchant to testing mode' do
39
- @checkout = FormCheckout.new(@form, @page)
40
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
40
41
  @checkout.create
41
42
 
42
43
  ActiveMerchant::Billing::Base.mode.should === :test
@@ -44,7 +45,7 @@ describe FormCheckout do
44
45
 
45
46
  it 'should return true for payment results' do
46
47
  mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
47
- @checkout = FormCheckout.new(@form, @page)
48
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
48
49
  result = @checkout.create
49
50
 
50
51
  result[:gateway].should === true
@@ -54,7 +55,7 @@ describe FormCheckout do
54
55
 
55
56
  it 'should assign a payment object' do
56
57
  mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
57
- @checkout = FormCheckout.new(@form, @page)
58
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
58
59
  result = @checkout.create
59
60
 
60
61
  @order.payment.card_number.should === "XXXX-XXXX-XXXX-1"
@@ -64,10 +65,8 @@ describe FormCheckout do
64
65
 
65
66
  it 'should assign session shop_order to nil' do
66
67
  mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { true }
67
- @checkout = FormCheckout.new(@form, @page)
68
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
68
69
  result = @checkout.create
69
-
70
- result[:session][:shop_order].should be_nil
71
70
  end
72
71
  end
73
72
 
@@ -80,9 +79,9 @@ describe FormCheckout do
80
79
  end
81
80
  context 'no gateway' do
82
81
  it 'should return gateway false' do
83
- @form[:extensions][:checkout][:gateway] = nil
82
+ @form[:extensions][:bogus_checkout][:gateway] = nil
84
83
 
85
- @checkout = FormCheckout.new(@form, @page)
84
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
86
85
  result = @checkout.create
87
86
 
88
87
  result[:gateway].should === false
@@ -97,7 +96,7 @@ describe FormCheckout do
97
96
  it 'should return card and payment false' do
98
97
  @data[:card] = nil
99
98
 
100
- @checkout = FormCheckout.new(@form, @page)
99
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
101
100
  result = @checkout.create
102
101
 
103
102
  result[:gateway].should === true
@@ -112,7 +111,7 @@ describe FormCheckout do
112
111
  it 'should return card and payment false' do
113
112
  mock.instance_of(ActiveMerchant::Billing::CreditCard).valid? { false }
114
113
 
115
- @checkout = FormCheckout.new(@form, @page)
114
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
116
115
  result = @checkout.create
117
116
 
118
117
  result[:gateway].should === true
@@ -138,20 +137,27 @@ describe FormCheckout do
138
137
  mock_valid_form_checkout_request
139
138
  end
140
139
  context 'payment successful' do
141
- it 'should configure mail to be sent' do
142
- @checkout = FormCheckout.new(@form, @page)
143
- @checkout.create
140
+ before :each do
141
+ @checkout = FormCheckout.new(@form,@page,@form[:extensions][:bogus_checkout])
142
+ end
143
+ it 'should configure order and invoice to be sent' do
144
+ @config = @form[:extensions][:bogus_checkout][:extensions]
145
+ @config[:invoice].merge!({
146
+ :to => @order.billing.email
147
+ })
148
+
149
+ @form_mail = Object.new
150
+ mock(@form_mail).create.times(2) { true }
151
+ mock(FormMail).new(@form,@page,@config[:order]) { @form_mail }
152
+ mock(FormMail).new(@form,@page,@config[:invoice]) { @form_mail }
144
153
 
145
- @form[:extensions][:mail][:to].should === shop_addresses(:billing).email
146
- @form[:extensions][:mail][:recipient].should === shop_addresses(:billing).email
147
- @form[:extensions][:mail][:subject].should === @form[:extensions][:checkout][:mail][:subject]
148
- @form[:extensions][:mail][:bcc].should === @form[:extensions][:checkout][:mail][:bcc]
154
+ @checkout.create
149
155
  end
150
156
  end
151
157
 
152
158
  context 'payment unsuccesful' do
153
159
  it 'should not configure mail to be sent' do
154
- @checkout = FormCheckout.new(@form, @page)
160
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
155
161
  stub(@checkout).success? { false }
156
162
  @checkout.create
157
163
 
@@ -166,13 +172,13 @@ describe FormCheckout do
166
172
  @order = shop_orders(:several_items)
167
173
 
168
174
  mock_valid_form_checkout_request
169
- @form[:extensions][:checkout][:mail] = nil
175
+ @form[:extensions][:bogus_checkout][:extensions] = nil
170
176
  end
171
177
  it 'should not configure mail to be sent' do
172
- @checkout = FormCheckout.new(@form, @page)
178
+ @checkout = FormCheckout.new(@form, @page, @form[:extensions][:bogus_checkout])
173
179
  result = @checkout.create
174
180
 
175
- @form[:extensions][:mail].should be_nil
181
+ do_not_allow(FormMail).new(@form,@page,anything)
176
182
  end
177
183
  end
178
184
  end
@@ -25,14 +25,6 @@ describe ShopCategory do
25
25
  it 'should have a product_layout Layout' do
26
26
  @category.product_layout.is_a?(Layout).should be_true
27
27
  end
28
-
29
- it 'should have many discountables' do
30
- @category.discountables.is_a?(Array).should be_true
31
- end
32
-
33
- it 'should have many discounts' do
34
- @category.discounts.is_a?(Array).should be_true
35
- end
36
28
  end
37
29
 
38
30
  describe 'validations' do
@@ -105,14 +97,14 @@ describe ShopCategory do
105
97
  @category.page.slug = 'delicious_ _:_;_=_+_._~_bread'
106
98
  @category.page.breadcrumb = nil
107
99
  @category.valid?
108
- @category.page.breadcrumb.should === 'delicious_______________bread'
100
+ @category.page.breadcrumb.should === @category.page.title
109
101
  end
110
102
  end
111
103
  context 'has been set' do
112
104
  it 'should generate on validation' do
113
105
  @category.page.breadcrumb = 'delicious_ _:_;_=_+_._~_bread'
114
106
  @category.valid?
115
- @category.page.breadcrumb.should === 'delicious_______________bread'
107
+ @category.page.breadcrumb.should === 'delicious_ _:_;_=_+_._~_bread'
116
108
  end
117
109
  end
118
110
  end
@@ -2,49 +2,86 @@ require 'spec/spec_helper'
2
2
 
3
3
  describe ShopLineItem do
4
4
 
5
- dataset :shop_line_items, :shop_products, :shop_discountables
6
-
7
- it 'should calculate a weight' do
8
- shop_line_items(:one).weight.should === (shop_line_items(:one).item.weight * shop_line_items(:one).quantity).to_f
9
- shop_line_items(:two).weight.should === (shop_line_items(:two).item.weight * shop_line_items(:two).quantity).to_f
5
+ dataset :shop_line_items, :shop_products
6
+
7
+ context 'methods' do
8
+
9
+ describe '#weight' do
10
+ it 'should multiple weight by quanttiy' do
11
+ shop_line_items(:one).weight.should === (shop_line_items(:one).item.weight * shop_line_items(:one).quantity).to_f
12
+ shop_line_items(:two).weight.should === (shop_line_items(:two).item.weight * shop_line_items(:two).quantity).to_f
13
+ end
14
+ end
15
+
16
+ describe '#price' do
17
+ it 'should multiple price by quantity' do
18
+ shop_line_items(:one).price.should === (shop_line_items(:one).item_price * shop_line_items(:one).quantity).to_f
19
+ shop_line_items(:two).price.should === (shop_line_items(:two).item_price * shop_line_items(:two).quantity).to_f
20
+ end
21
+ it 'should not inherit the changes of a items base price' do
22
+ shop_line_items(:one).price.to_f.should === shop_line_items(:one).item.price.to_f
23
+ shop_line_items(:one).item.update_attribute(:price, 100.00)
24
+ shop_line_items(:one).price.to_f.should_not === shop_line_items(:one).item.price.to_f
25
+ end
26
+ end
27
+
28
+ describe '#to_json' do
29
+ it 'should overload standard to_json' do
30
+ pending 'not sure how to write this'
31
+ end
32
+ end
33
+
10
34
  end
35
+
36
+ context 'filters' do
37
+
38
+ describe '#adjust_quantity' do
39
+ it 'should adjust quantity to 1 if less than' do
40
+ s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 0 })
41
+ s.valid?
42
+ s.quantity.should === 1
11
43
 
12
- it 'should calculate the price' do
13
- shop_line_items(:one).price.should === (shop_line_items(:one).item.price * shop_line_items(:one).quantity).to_f
14
- shop_line_items(:two).price.should === (shop_line_items(:two).item.price * shop_line_items(:two).quantity).to_f
44
+ s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 1 })
45
+ s.valid?
46
+ s.quantity.should === 1
47
+
48
+ s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => -100 })
49
+ s.valid?
50
+ s.quantity.should === 1
51
+
52
+ s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 100 })
53
+ s.valid?
54
+ s.quantity.should === 100
55
+ end
56
+ end
57
+
58
+ describe '#set_price' do
59
+ it 'should assign the items price to item_price before validations' do
60
+ s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 1 })
61
+ s.item_price.should be_nil
62
+ s.valid?
63
+ s.item_price.should === shop_products(:crusty_bread).price
64
+ end
65
+ end
66
+
15
67
  end
16
68
 
17
- context 'with discount' do
18
- it 'should calculate a reduced price' do
19
- price = shop_line_items(:one).price
20
- ShopDiscountable.create(:discount => shop_discounts(:ten_percent), :discounted => shop_line_items(:one))
21
- shop_line_items(:one).price.should === (price-price*0.1)
69
+ describe '#attrs' do
70
+ it 'should return attribute set' do
71
+ ShopLineItem.attrs.should === [ :id, :quantity ]
22
72
  end
23
73
  end
24
74
 
25
- it 'should have a set of standard parameters' do
26
- ShopLineItem.params.should === [
27
- :id,
28
- :quantity
29
- ]
75
+ describe '#methds' do
76
+ it 'should return method set' do
77
+ ShopLineItem.methds.should === [ :price, :weight ]
78
+ end
30
79
  end
31
80
 
32
- it 'should adjust quantity to 1 if less than' do
33
- s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 0 })
34
- s.valid?
35
- s.quantity.should === 1
36
-
37
- s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 1 })
38
- s.valid?
39
- s.quantity.should === 1
40
-
41
- s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => -100 })
42
- s.valid?
43
- s.quantity.should === 1
44
-
45
- s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 100 })
46
- s.valid?
47
- s.quantity.should === 100
81
+ describe '#params' do
82
+ it 'should return parameter set' do
83
+ ShopLineItem.params.should === { :only => ShopLineItem.attrs, :methods => ShopLineItem.methds }
84
+ end
48
85
  end
49
86
 
50
87
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec/spec_helper'
2
-
2
+
3
3
  describe ShopOrder do
4
-
5
- dataset :shop_orders, :shop_line_items, :shop_products, :shop_packages, :shop_payments
4
+
5
+ dataset :shop_orders, :shop_line_items, :shop_products, :shop_payments
6
6
 
7
7
  describe '#quantity' do
8
8
  it 'should return the total items' do
@@ -133,11 +133,11 @@ describe ShopOrder do
133
133
  end
134
134
  context 'type and quantity passed' do
135
135
  it 'should assign the new type and new quantity' do
136
- @order.add!(shop_packages(:all_bread).id, 2, 'ShopPackage')
136
+ @order.add!(@product.id, 2, 'ShopProductAlternative')
137
137
 
138
138
  @order.line_items.count.should === 1
139
139
  @order.quantity.should === 2
140
- @order.line_items.first.item_type.should === 'ShopPackage'
140
+ @order.line_items.first.item_type.should === 'ShopProductAlternative'
141
141
  end
142
142
  end
143
143
  end
@@ -41,6 +41,7 @@ describe ShopProductAttachment do
41
41
 
42
42
  describe '#url' do
43
43
  it 'should return its assets url' do
44
+ stub(@product_image).image.stub!.url { 'url' }
44
45
  @product_image.url.should === @product_image.image.url
45
46
  end
46
47
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
3
  describe ShopProduct do
4
- dataset :shop_products, :shop_line_items, :shop_discountables
4
+ dataset :shop_products, :shop_line_items
5
5
 
6
6
  describe 'relationships' do
7
7
  before :each do
@@ -38,30 +38,6 @@ describe ShopProduct do
38
38
  @product.images.is_a?(Array).should be_true
39
39
  end
40
40
 
41
- it 'should have many packings' do
42
- @product.packings.is_a?(Array).should be_true
43
- end
44
-
45
- it 'should have many packages' do
46
- @product.packages.is_a?(Array).should be_true
47
- end
48
-
49
- it 'should have many related' do
50
- @product.related.is_a?(Array).should be_true
51
- end
52
-
53
- it 'should have many variants' do
54
- @product.variants.is_a?(Array).should be_true
55
- end
56
-
57
- it 'should have many discountables' do
58
- @product.discountables.is_a?(Array).should be_true
59
- end
60
-
61
- it 'should have many discounts' do
62
- @product.discounts.is_a?(Array).should be_true
63
- end
64
-
65
41
  end
66
42
 
67
43
  describe 'validations' do
@@ -189,37 +165,18 @@ describe ShopProduct do
189
165
  @product.page.slug = 'delicious_ _:_;_=_+_._~_bread'
190
166
  @product.page.breadcrumb = nil
191
167
  @product.valid?
192
- @product.page.breadcrumb.should === 'delicious_______________bread'
168
+ @product.page.breadcrumb.should === @product.page.title
193
169
  end
194
170
  end
195
171
  context 'has been set' do
196
- it 'should generate on validation' do
172
+ it 'should be left as is' do
197
173
  @product.page.breadcrumb = 'delicious_ _:_;_=_+_._~_bread'
198
174
  @product.valid?
199
- @product.page.breadcrumb.should === 'delicious_______________bread'
175
+ @product.page.breadcrumb.should === 'delicious_ _:_;_=_+_._~_bread'
200
176
  end
201
177
  end
202
178
  end
203
179
  end
204
-
205
- context 'discounts' do
206
- context 'after_create' do
207
- it 'should assign its categories discounts to itself' do
208
- @product = ShopProduct.new(
209
- :price => 11.11,
210
- :page_attributes => {
211
- :title => 'New Page With Discounts',
212
- :slug => 'new_page_with_discounts',
213
- :parent_id => shop_categories(:bread).id
214
- }
215
- )
216
- @product.discounts.empty?.should === true
217
- @product.save
218
-
219
- ShopProduct.find(@product).discounts.should === shop_categories(:bread).discounts
220
- end
221
- end
222
- end
223
180
  end
224
181
 
225
182
  describe '#attrs' do
data/spec/spec.opts CHANGED
@@ -1,6 +1,4 @@
1
1
  --colour
2
- --format
3
- progress
4
- --loadby
5
- mtime
6
- --reverse
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse