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.
- data/HISTORY.md +21 -3
- data/LICENSE +42 -0
- data/README.md +62 -25
- data/Rakefile +4 -5
- data/VERSION +1 -1
- data/app/controllers/admin/shop/categories_controller.rb +1 -0
- data/app/controllers/admin/shop/orders_controller.rb +1 -1
- data/app/controllers/admin/shop/products_controller.rb +18 -7
- data/app/helpers/shop_helper.rb +8 -0
- data/app/models/form_address.rb +5 -5
- data/app/models/form_checkout.rb +25 -17
- data/app/models/form_line_item.rb +1 -1
- data/app/models/shop_category.rb +22 -7
- data/app/models/shop_customer.rb +1 -1
- data/app/models/shop_line_item.rb +26 -26
- data/app/models/shop_order.rb +0 -2
- data/app/models/shop_product.rb +15 -18
- data/app/views/.DS_Store +0 -0
- data/app/views/admin/shop/categories/edit/meta/_status.html.haml +3 -0
- data/app/views/admin/shop/products/edit/_foot.html.haml +1 -8
- data/app/views/admin/shop/products/edit/meta/_layout.html.haml +6 -0
- data/app/views/admin/shop/products/edit/meta/_status.html.haml +3 -0
- data/app/views/admin/shop/products/index/_product.html.haml +1 -1
- data/config/locales/en.yml +8 -7
- data/config/routes.rb +4 -16
- data/db/migrate/20101011063133_setup_shop.rb +94 -0
- data/db/seeds/forms.rb +113 -154
- data/db/seeds/layouts.rb +67 -103
- data/db/seeds/pages.rb +101 -0
- data/db/seeds/products.rb +29 -0
- data/db/seeds/snippets.rb +36 -21
- data/lib/shop/controllers/application_controller.rb +5 -3
- data/lib/shop/models/form_extension.rb +1 -2
- data/lib/shop/models/page.rb +0 -1
- data/lib/shop/models/user.rb +0 -1
- data/lib/shop/tags/card.rb +8 -2
- data/lib/shop/tags/cart.rb +5 -1
- data/lib/shop/tags/helpers.rb +35 -60
- data/lib/shop/tags/item.rb +2 -16
- data/lib/shop/tags/product.rb +7 -0
- data/lib/tasks/shop_extension_tasks.rake +9 -4
- data/public/javascripts/admin/extensions/shop/products/edit.js +0 -25
- data/radiant-shop-extension.gemspec +25 -201
- data/shop_extension.rb +18 -19
- data/spec/datasets/forms.rb +25 -28
- data/spec/datasets/shop_categories.rb +2 -2
- data/spec/datasets/shop_config.rb +24 -0
- data/spec/datasets/shop_customers.rb +1 -0
- data/spec/datasets/shop_line_items.rb +21 -3
- data/spec/datasets/shop_products.rb +4 -1
- data/spec/datasets/tags.rb +19 -0
- data/spec/lib/shop/models/page_spec.rb +1 -1
- data/spec/lib/shop/tags/card_spec.rb +30 -4
- data/spec/lib/shop/tags/cart_spec.rb +29 -12
- data/spec/lib/shop/tags/helpers_spec.rb +45 -66
- data/spec/lib/shop/tags/item_spec.rb +6 -10
- data/spec/lib/shop/tags/product_spec.rb +27 -2
- data/spec/models/form_address_spec.rb +9 -8
- data/spec/models/form_checkout_spec.rb +28 -22
- data/spec/models/shop_category_spec.rb +2 -10
- data/spec/models/shop_line_item_spec.rb +71 -34
- data/spec/models/shop_order_spec.rb +5 -5
- data/spec/models/shop_product_attachment_spec.rb +1 -0
- data/spec/models/shop_product_spec.rb +4 -47
- data/spec/spec.opts +3 -5
- metadata +60 -248
- data/Gemfile +0 -26
- data/Gemfile.lock +0 -75
- data/MIT-LICENSE +0 -20
- data/app/controllers/admin/shop/discounts/discountables_controller.rb +0 -44
- data/app/controllers/admin/shop/discounts_controller.rb +0 -64
- data/app/controllers/admin/shop/packages/packings_controller.rb +0 -90
- data/app/controllers/admin/shop/packages_controller.rb +0 -63
- data/app/controllers/admin/shop/products/variant_templates_controller.rb +0 -27
- data/app/controllers/admin/shop/products/variants_controller.rb +0 -60
- data/app/controllers/admin/shop/variants_controller.rb +0 -48
- data/app/models/form_discount.rb +0 -39
- data/app/models/shop_discount.rb +0 -37
- data/app/models/shop_discountable.rb +0 -64
- data/app/models/shop_group.rb +0 -15
- data/app/models/shop_grouping.rb +0 -6
- data/app/models/shop_package.rb +0 -74
- data/app/models/shop_packing.rb +0 -22
- data/app/models/shop_product_variant.rb +0 -34
- data/app/models/shop_variant.rb +0 -23
- data/app/views/admin/pages/_shop_category.html.haml +0 -4
- data/app/views/admin/pages/_shop_product.html.haml +0 -4
- data/app/views/admin/shop/discounts/edit/_foot.html.haml +0 -16
- data/app/views/admin/shop/discounts/edit/_form.html.haml +0 -15
- data/app/views/admin/shop/discounts/edit/_head.html.haml +0 -4
- data/app/views/admin/shop/discounts/edit/_inputs.html.haml +0 -2
- data/app/views/admin/shop/discounts/edit/_meta.html.haml +0 -8
- data/app/views/admin/shop/discounts/edit/_parts.html.haml +0 -9
- data/app/views/admin/shop/discounts/edit/_popups.html.haml +0 -4
- data/app/views/admin/shop/discounts/edit/buttons/_browse_categories.html.haml +0 -1
- data/app/views/admin/shop/discounts/edit/buttons/_browse_products.html.haml +0 -1
- data/app/views/admin/shop/discounts/edit/inputs/_amount.html.haml +0 -3
- data/app/views/admin/shop/discounts/edit/inputs/_code.html.haml +0 -3
- data/app/views/admin/shop/discounts/edit/inputs/_name.html.haml +0 -3
- data/app/views/admin/shop/discounts/edit/meta/_finish.html.haml +0 -5
- data/app/views/admin/shop/discounts/edit/meta/_start.html.haml +0 -5
- data/app/views/admin/shop/discounts/edit/parts/_categories.html.haml +0 -3
- data/app/views/admin/shop/discounts/edit/parts/_products.html.haml +0 -3
- data/app/views/admin/shop/discounts/edit/popups/_browse_categories.html.haml +0 -6
- data/app/views/admin/shop/discounts/edit/popups/_browse_products.html.haml +0 -6
- data/app/views/admin/shop/discounts/edit/shared/_category.html.haml +0 -11
- data/app/views/admin/shop/discounts/edit/shared/_product.html.haml +0 -12
- data/app/views/admin/shop/discounts/edit.html.haml +0 -11
- data/app/views/admin/shop/discounts/index/_discount.html.haml +0 -13
- data/app/views/admin/shop/discounts/index/_foot.html.haml +0 -5
- data/app/views/admin/shop/discounts/index/_head.html.haml +0 -2
- data/app/views/admin/shop/discounts/index/buttons/_new_discount.html.haml +0 -1
- data/app/views/admin/shop/discounts/index.html.haml +0 -13
- data/app/views/admin/shop/discounts/new.html.haml +0 -11
- data/app/views/admin/shop/discounts/remove.html.haml +0 -12
- data/app/views/admin/shop/packages/edit/_foot.html.haml +0 -17
- data/app/views/admin/shop/packages/edit/_form.html.haml +0 -15
- data/app/views/admin/shop/packages/edit/_head.html.haml +0 -4
- data/app/views/admin/shop/packages/edit/_inputs.html.haml +0 -2
- data/app/views/admin/shop/packages/edit/_meta.html.haml +0 -8
- data/app/views/admin/shop/packages/edit/_parts.html.haml +0 -9
- data/app/views/admin/shop/packages/edit/_popups.html.haml +0 -4
- data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +0 -1
- data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +0 -3
- data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +0 -3
- data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +0 -5
- data/app/views/admin/shop/packages/edit/parts/_description.html.haml +0 -1
- data/app/views/admin/shop/packages/edit/parts/_products.html.haml +0 -3
- data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +0 -7
- data/app/views/admin/shop/packages/edit/shared/_product.html.haml +0 -8
- data/app/views/admin/shop/packages/edit.html.haml +0 -11
- data/app/views/admin/shop/packages/index/_foot.html.haml +0 -8
- data/app/views/admin/shop/packages/index/_head.html.haml +0 -2
- data/app/views/admin/shop/packages/index/_package.html.haml +0 -9
- data/app/views/admin/shop/packages/index/buttons/_new_package.html.haml +0 -1
- data/app/views/admin/shop/packages/index.html.haml +0 -13
- data/app/views/admin/shop/packages/new.html.haml +0 -11
- data/app/views/admin/shop/packages/remove.html.haml +0 -12
- data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +0 -1
- data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +0 -1
- data/app/views/admin/shop/products/edit/parts/_variants.html.haml +0 -3
- data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +0 -6
- data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +0 -16
- data/app/views/admin/shop/products/edit/shared/_template.html.haml +0 -6
- data/app/views/admin/shop/products/edit/shared/_variant.html.haml +0 -10
- data/app/views/admin/shop/products/index/buttons/_variants.html.haml +0 -1
- data/app/views/admin/shop/variants/edit/_foot.html.haml +0 -9
- data/app/views/admin/shop/variants/edit/_form.html.haml +0 -13
- data/app/views/admin/shop/variants/edit/_head.html.haml +0 -4
- data/app/views/admin/shop/variants/edit/_inputs.html.haml +0 -2
- data/app/views/admin/shop/variants/edit/_meta.html.haml +0 -8
- data/app/views/admin/shop/variants/edit/_parts.html.haml +0 -9
- data/app/views/admin/shop/variants/edit/_popups.html.haml +0 -4
- data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +0 -3
- data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +0 -3
- data/app/views/admin/shop/variants/edit.html.haml +0 -11
- data/app/views/admin/shop/variants/index/_foot.html.haml +0 -5
- data/app/views/admin/shop/variants/index/_head.html.haml +0 -2
- data/app/views/admin/shop/variants/index/_variant.html.haml +0 -9
- data/app/views/admin/shop/variants/index/buttons/_add_variant.html.haml +0 -1
- data/app/views/admin/shop/variants/index/buttons/_categories.html.haml +0 -1
- data/app/views/admin/shop/variants/index.html.haml +0 -13
- data/app/views/admin/shop/variants/new.html.haml +0 -11
- data/app/views/admin/shop/variants/remove.html.haml +0 -12
- data/app/views/shop/categories/show.html.haml +0 -1
- data/app/views/shop/orders/show.html.haml +0 -1
- data/app/views/shop/products/index.html.haml +0 -1
- data/app/views/shop/products/show.html.haml +0 -1
- data/cucumber.yml +0 -1
- data/db/migrate/20100311053701_initial.rb +0 -153
- data/db/migrate/20100927041219_remove_payment_methods.rb +0 -16
- data/db/migrate/20100927041624_change_payments_add_gateway.rb +0 -11
- data/db/migrate/20100927140446_change_payment_add_card_type_card_number.rb +0 -11
- data/db/migrate/20100929011106_fix_relationship_foreign_keys.rb +0 -101
- data/db/migrate/20100929011607_drop_shop_addressables.rb +0 -25
- data/db/migrate/20100929030510_create_shop_groups.rb +0 -19
- data/db/migrate/20100929080301_shop_groups_change_add_description.rb +0 -11
- data/db/migrate/20100929081200_create_variants.rb +0 -20
- data/db/migrate/20100929143531_change_variants_add_updated_by.rb +0 -25
- data/db/migrate/20100929145641_change_created_by_to_id.rb +0 -75
- data/db/migrate/20100929235221_change_category_add_variant_id.rb +0 -9
- data/db/migrate/20100930235221_create_packages.rb +0 -31
- data/db/migrate/20101005231713_create_page_ids.rb +0 -11
- data/db/migrate/20101006051214_create_pages_for_products_and_categories.rb +0 -73
- data/db/migrate/20101007111845_add_default_position_to_attachment.rb +0 -9
- data/db/migrate/20101010071143_create_discounts.rb +0 -29
- data/db/migrate/20101010072225_modify_categories_remove_variant.rb +0 -9
- data/db/migrate/20101010130034_change_discountables_add_observer.rb +0 -15
- data/db/migrate/20101011063133_change_orders_set_limits_to_null.rb +0 -11
- data/features/support/env.rb +0 -16
- data/features/support/paths.rb +0 -14
- data/lib/shop/interface/packages.rb +0 -34
- data/lib/shop/interface/variants.rb +0 -34
- data/lib/shop/tags/package.rb +0 -95
- data/lib/shop/tags/product_variant.rb +0 -52
- data/lib/shop/tags/responses.rb +0 -34
- data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
- data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
- data/mockups/discounts/new-edit.bmml +0 -492
- data/public/javascripts/admin/extensions/shop/discounts/edit.js +0 -76
- data/public/javascripts/admin/extensions/shop/packages/edit.js +0 -109
- data/public/stylesheets/sass/admin/extensions/shop/discounts/edit.sass +0 -125
- data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +0 -162
- data/spec/controllers/admin/shop/discounts/discountables_controller_spec.rb +0 -73
- data/spec/controllers/admin/shop/discounts_controller_spec.rb +0 -81
- data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +0 -188
- data/spec/controllers/admin/shop/packages_controller_spec.rb +0 -32
- data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +0 -53
- data/spec/controllers/admin/shop/products/variants_controller_spec.rb +0 -116
- data/spec/controllers/admin/shop/variants_controller_spec.rb +0 -67
- data/spec/datasets/shop_discountables.rb +0 -22
- data/spec/datasets/shop_discounts.rb +0 -29
- data/spec/datasets/shop_groups.rb +0 -15
- data/spec/datasets/shop_packages.rb +0 -25
- data/spec/datasets/shop_product_variants.rb +0 -22
- data/spec/datasets/shop_variants.rb +0 -17
- data/spec/lib/shop/tags/package_spec.rb +0 -342
- data/spec/lib/shop/tags/product_variant_spec.rb +0 -175
- data/spec/lib/shop/tags/responses_spec.rb +0 -129
- data/spec/models/form_discount_spec.rb +0 -63
- data/spec/models/shop_discount_spec.rb +0 -130
- data/spec/models/shop_discountable_spec.rb +0 -114
- data/spec/models/shop_group_spec.rb +0 -38
- data/spec/models/shop_package_spec.rb +0 -117
- data/spec/models/shop_packing_spec.rb +0 -67
- data/spec/models/shop_product_variant_spec.rb +0 -92
- 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][:
|
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
|
-
|
142
|
-
@checkout = FormCheckout.new(@form
|
143
|
-
|
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
|
-
@
|
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][:
|
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
|
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 ===
|
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 === '
|
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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
18
|
-
it 'should
|
19
|
-
|
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
|
-
|
26
|
-
|
27
|
-
:
|
28
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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, :
|
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!(
|
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 === '
|
140
|
+
@order.line_items.first.item_type.should === 'ShopProductAlternative'
|
141
141
|
end
|
142
142
|
end
|
143
143
|
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
|
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 ===
|
168
|
+
@product.page.breadcrumb.should === @product.page.title
|
193
169
|
end
|
194
170
|
end
|
195
171
|
context 'has been set' do
|
196
|
-
it 'should
|
172
|
+
it 'should be left as is' do
|
197
173
|
@product.page.breadcrumb = 'delicious_ _:_;_=_+_._~_bread'
|
198
174
|
@product.valid?
|
199
|
-
@product.page.breadcrumb.should === '
|
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