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.
- data/README.md +5 -1
- data/VERSION +1 -1
- data/app/controllers/admin/shop/categories_controller.rb +32 -65
- data/app/controllers/admin/shop/customers_controller.rb +8 -7
- data/app/controllers/admin/shop/orders_controller.rb +37 -159
- data/app/controllers/admin/shop/packages/packings_controller.rb +90 -0
- data/app/controllers/admin/shop/packages_controller.rb +65 -0
- data/app/controllers/admin/shop/products/images_controller.rb +5 -8
- data/app/controllers/admin/shop/products/variant_templates_controller.rb +27 -0
- data/app/controllers/admin/shop/products/variants_controller.rb +60 -0
- data/app/controllers/admin/shop/products_controller.rb +67 -64
- data/app/controllers/admin/shop/variants_controller.rb +49 -0
- data/app/helpers/shop_helper.rb +5 -0
- data/app/models/form_address.rb +144 -0
- data/app/models/form_checkout.rb +200 -307
- data/app/models/form_line_item.rb +60 -0
- data/app/models/shop_address.rb +2 -2
- data/app/models/shop_category.rb +48 -51
- data/app/models/shop_customer.rb +25 -5
- data/app/models/shop_group.rb +15 -0
- data/app/models/shop_grouping.rb +6 -0
- data/app/models/shop_line_item.rb +7 -6
- data/app/models/shop_order.rb +44 -16
- data/app/models/shop_package.rb +74 -0
- data/app/models/shop_packing.rb +22 -0
- data/app/models/shop_page.rb +7 -0
- data/app/models/shop_payment.rb +5 -1
- data/app/models/shop_product.rb +86 -48
- data/app/models/shop_product_attachment.rb +5 -2
- data/app/models/shop_product_variant.rb +31 -0
- data/app/models/shop_variant.rb +25 -0
- data/app/views/admin/shop/categories/edit.html.haml +9 -10
- data/app/views/admin/shop/categories/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/categories/edit/_form.html.haml +14 -0
- data/app/views/admin/shop/categories/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/categories/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/categories/edit/_meta.html.haml +8 -7
- data/app/views/admin/shop/categories/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/categories/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/categories/edit/inputs/_name.html.haml +4 -0
- data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +6 -5
- data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +6 -5
- data/app/views/admin/shop/categories/edit/meta/_page.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/parts/_description.html.haml +4 -1
- data/app/views/admin/shop/categories/index/_category.html.haml +11 -10
- data/app/views/admin/shop/categories/new.html.haml +10 -9
- data/app/views/admin/shop/customers/edit.html.haml +8 -10
- data/app/views/admin/shop/customers/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/customers/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/customers/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/customers/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/customers/edit/_parts.html.haml +9 -4
- data/app/views/admin/shop/customers/edit/inputs/_email.html.haml +3 -0
- data/app/views/admin/shop/customers/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/customers/edit/parts/_orders.html.haml +10 -6
- data/app/views/admin/shop/customers/index.html.haml +4 -1
- data/app/views/admin/shop/customers/index/_customer.html.haml +3 -3
- data/app/views/admin/shop/customers/index/_foot.html.haml +4 -0
- data/app/views/admin/shop/customers/index/_head.html.haml +4 -0
- data/app/views/admin/shop/customers/new.html.haml +9 -9
- data/app/views/admin/shop/orders/edit.html.haml +11 -0
- data/app/views/admin/shop/orders/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/orders/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/orders/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/orders/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/orders/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/orders/edit/parts/_address.html.haml +7 -0
- data/app/views/admin/shop/orders/edit/parts/_addresses.html.haml +9 -0
- data/app/views/admin/shop/orders/edit/parts/_customer.html.haml +3 -0
- data/app/views/admin/shop/orders/edit/parts/_items.html.haml +8 -0
- data/app/views/admin/shop/orders/index.html.haml +10 -30
- data/app/views/admin/shop/orders/index/_foot.html.haml +3 -0
- data/app/views/admin/shop/orders/index/_head.html.haml +4 -0
- data/app/views/admin/shop/orders/index/_order.html.haml +13 -0
- data/app/views/admin/shop/orders/index/buttons/_all.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_new.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_paid.html.haml +1 -0
- data/app/views/admin/shop/orders/index/buttons/_shipped.html.haml +1 -0
- data/app/views/admin/shop/packages/edit.html.haml +11 -0
- data/app/views/admin/shop/packages/edit/_foot.html.haml +17 -0
- data/app/views/admin/shop/packages/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/packages/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/packages/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/packages/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/packages/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/packages/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/packages/edit/buttons/_browse_products.html.haml +1 -0
- data/app/views/admin/shop/packages/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/inputs/_price.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/meta/_sku.html.haml +5 -0
- data/app/views/admin/shop/packages/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/packages/edit/parts/_products.html.haml +3 -0
- data/app/views/admin/shop/packages/edit/popups/_browse_products.html.haml +7 -0
- data/app/views/admin/shop/packages/edit/shared/_product.html.haml +8 -0
- data/app/views/admin/shop/packages/index.html.haml +13 -0
- data/app/views/admin/shop/packages/index/_foot.html.haml +7 -0
- data/app/views/admin/shop/packages/index/_head.html.haml +4 -0
- data/app/views/admin/shop/packages/index/_package.html.haml +9 -0
- data/app/views/admin/shop/packages/new.html.haml +11 -0
- data/app/views/admin/shop/packages/remove.html.haml +12 -0
- data/app/views/admin/shop/products/edit.html.haml +9 -12
- data/app/views/admin/shop/products/edit/_foot.html.haml +19 -0
- data/app/views/admin/shop/products/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/products/edit/_head.html.haml +4 -2
- data/app/views/admin/shop/products/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/products/edit/_meta.html.haml +8 -8
- data/app/views/admin/shop/products/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/products/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/buttons/_browse_templates.html.haml +1 -0
- data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -1
- data/app/views/admin/shop/products/edit/buttons/_new_variant.html.haml +1 -0
- data/app/views/admin/shop/products/edit/inputs/_name.html.haml +4 -0
- data/app/views/admin/shop/products/edit/inputs/_price.html.haml +3 -0
- data/app/views/admin/shop/products/edit/meta/_category.html.haml +6 -5
- data/app/views/admin/shop/products/edit/meta/_page.html.haml +2 -0
- data/app/views/admin/shop/products/edit/meta/_sku.html.haml +6 -5
- data/app/views/admin/shop/products/edit/parts/_customers.html.haml +5 -0
- data/app/views/admin/shop/products/edit/parts/_description.html.haml +4 -1
- data/app/views/admin/shop/products/edit/parts/_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/parts/_variants.html.haml +3 -0
- data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +1 -1
- data/app/views/admin/shop/products/edit/popups/_browse_templates.html.haml +6 -0
- data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +4 -4
- data/app/views/admin/shop/products/edit/popups/_new_variant.html.haml +16 -0
- data/app/views/admin/shop/products/edit/{_image.html.haml → shared/_image.html.haml} +0 -0
- data/app/views/admin/shop/products/edit/shared/_template.html.haml +6 -0
- data/app/views/admin/shop/products/edit/shared/_variant.html.haml +10 -0
- data/app/views/admin/shop/products/index.html.haml +6 -3
- data/app/views/admin/shop/products/index/_foot.html.haml +10 -0
- data/app/views/admin/shop/products/index/_head.html.haml +4 -0
- data/app/views/admin/shop/products/index/_product.html.haml +18 -10
- data/app/views/admin/shop/products/index/buttons/_discounts.html.haml +1 -0
- data/app/views/admin/shop/products/index/buttons/_packages.html.haml +1 -0
- data/app/views/admin/shop/products/index/buttons/_variants.html.haml +1 -0
- data/app/views/admin/shop/products/new.html.haml +10 -9
- data/app/views/admin/shop/variants/edit.html.haml +11 -0
- data/app/views/admin/shop/variants/edit/_foot.html.haml +9 -0
- data/app/views/admin/shop/variants/edit/_form.html.haml +13 -0
- data/app/views/admin/shop/variants/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/variants/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/variants/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/variants/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/variants/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/variants/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/variants/edit/inputs/_options.html.haml +3 -0
- data/app/views/admin/shop/variants/index.html.haml +13 -0
- data/app/views/admin/shop/variants/index/_foot.html.haml +4 -0
- data/app/views/admin/shop/variants/index/_head.html.haml +4 -0
- data/app/views/admin/shop/variants/index/_variant.html.haml +9 -0
- data/app/views/admin/shop/variants/new.html.haml +11 -0
- data/app/views/admin/shop/variants/remove.html.haml +12 -0
- data/config/locales/en.yml +8 -1
- data/config/routes.rb +11 -22
- data/db/migrate/20100929011106_fix_relationship_foreign_keys.rb +101 -0
- data/db/migrate/20100929011607_drop_shop_addressables.rb +25 -0
- data/db/migrate/20100929030510_create_shop_groups.rb +19 -0
- data/db/migrate/20100929080301_shop_groups_change_add_description.rb +11 -0
- data/db/migrate/20100929081200_create_variants.rb +20 -0
- data/db/migrate/20100929143531_change_variants_add_updated_by.rb +25 -0
- data/db/migrate/20100929145641_change_created_by_to_id.rb +75 -0
- data/db/migrate/20100929235221_change_category_add_variant_id.rb +9 -0
- data/db/migrate/20100930235221_create_packages.rb +31 -0
- data/db/migrate/20101005231713_create_page_ids.rb +11 -0
- data/db/migrate/20101006051214_create_pages_for_products_and_categories.rb +73 -0
- data/db/migrate/20101007111845_add_default_position_to_attachment.rb +9 -0
- data/lib/shop/controllers/application_controller.rb +1 -1
- data/lib/shop/interface/categories.rb +29 -0
- data/lib/shop/interface/customers.rb +15 -15
- data/lib/shop/interface/orders.rb +34 -0
- data/lib/shop/interface/packages.rb +34 -0
- data/lib/shop/interface/products.rb +18 -31
- data/lib/shop/interface/variants.rb +34 -0
- data/lib/shop/models/form_extension.rb +23 -0
- data/lib/shop/models/page.rb +3 -2
- data/lib/shop/tags/address.rb +3 -3
- data/lib/shop/tags/cart.rb +12 -16
- data/lib/shop/tags/category.rb +4 -6
- data/lib/shop/tags/helpers.rb +131 -30
- data/lib/shop/tags/item.rb +16 -33
- data/lib/shop/tags/package.rb +95 -0
- data/lib/shop/tags/product.rb +11 -16
- data/lib/shop/tags/product_variant.rb +52 -0
- data/mockups/discounts/new-edit.bmml +492 -0
- data/public/javascripts/admin/extensions/shop/edit.js +20 -0
- data/public/javascripts/admin/extensions/shop/packages/edit.js +109 -0
- data/public/javascripts/admin/extensions/shop/products/edit.js +64 -65
- data/public/javascripts/admin/extensions/shop/products/index.js +31 -36
- data/public/stylesheets/sass/admin/extensions/shop/edit.sass +58 -11
- data/public/stylesheets/sass/admin/extensions/shop/index.sass +104 -53
- data/public/stylesheets/sass/admin/extensions/shop/packages/edit.sass +162 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +115 -36
- data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +12 -20
- data/radiant-shop-extension.gemspec +182 -38
- data/shop_extension.rb +29 -25
- data/spec/controllers/admin/shop/categories_controller_spec.rb +76 -191
- data/spec/controllers/admin/shop/customers_controller_spec.rb +67 -0
- data/spec/controllers/admin/shop/orders_controller_spec.rb +85 -0
- data/spec/controllers/admin/shop/packages/packings_controller_spec.rb +188 -0
- data/spec/controllers/admin/shop/packages_controller_spec.rb +32 -0
- data/spec/controllers/admin/shop/products/images_controller_spec.rb +10 -15
- data/spec/controllers/admin/shop/products/variant_templates_controller_spec.rb +53 -0
- data/spec/controllers/admin/shop/products/variants_controller_spec.rb +116 -0
- data/spec/controllers/admin/shop/products_controller_spec.rb +80 -148
- data/spec/controllers/admin/shop/variants_controller_spec.rb +67 -0
- data/spec/datasets/forms.rb +23 -8
- data/spec/datasets/shop_addresses.rb +1 -4
- data/spec/datasets/shop_categories.rb +25 -4
- data/spec/datasets/shop_groups.rb +15 -0
- data/spec/datasets/shop_line_items.rb +4 -3
- data/spec/datasets/shop_orders.rb +6 -15
- data/spec/datasets/shop_packages.rb +25 -0
- data/spec/datasets/shop_payments.rb +12 -0
- data/spec/datasets/{images.rb → shop_product_attachments.rb} +9 -1
- data/spec/datasets/shop_product_variants.rb +22 -0
- data/spec/datasets/shop_products.rb +28 -18
- data/spec/datasets/shop_variants.rb +17 -0
- data/spec/lib/shop/models/image_spec.rb +4 -4
- data/spec/lib/shop/tags/address_spec.rb +3 -3
- data/spec/lib/shop/tags/cart_spec.rb +32 -43
- data/spec/lib/shop/tags/category_spec.rb +58 -93
- data/spec/lib/shop/tags/helpers_spec.rb +162 -69
- data/spec/lib/shop/tags/item_spec.rb +116 -158
- data/spec/lib/shop/tags/package_spec.rb +342 -0
- data/spec/lib/shop/tags/product_spec.rb +29 -26
- data/spec/lib/shop/tags/product_variant_spec.rb +175 -0
- data/spec/models/form_address_spec.rb +166 -0
- data/spec/models/form_checkout_spec.rb +27 -157
- data/spec/models/shop_address_spec.rb +81 -0
- data/spec/models/shop_category_spec.rb +114 -31
- data/spec/models/shop_customer_spec.rb +105 -0
- data/spec/models/shop_group_spec.rb +38 -0
- data/spec/models/shop_line_item_spec.rb +5 -5
- data/spec/models/shop_order_spec.rb +89 -83
- data/spec/models/shop_package_spec.rb +117 -0
- data/spec/models/shop_packing_spec.rb +67 -0
- data/spec/models/shop_payment_spec.rb +19 -0
- data/spec/models/shop_product_attachment_spec.rb +4 -3
- data/spec/models/shop_product_spec.rb +171 -92
- data/spec/models/shop_product_variant_spec.rb +92 -0
- data/spec/models/shop_variant_spec.rb +47 -0
- metadata +183 -39
- data/app/controllers/shop/categories_controller.rb +0 -45
- data/app/controllers/shop/line_items_controller.rb +0 -165
- data/app/controllers/shop/orders_controller.rb +0 -16
- data/app/controllers/shop/products_controller.rb +0 -48
- data/app/models/shop_addressable.rb +0 -11
- data/app/views/admin/shop/categories/edit/_fields.html.haml +0 -28
- data/app/views/admin/shop/categories/edit/_part.html.haml +0 -3
- data/app/views/admin/shop/categories/edit/_popup.html.haml +0 -3
- data/app/views/admin/shop/customers/edit/_fields.html.haml +0 -33
- data/app/views/admin/shop/customers/index/_bottom.html.haml +0 -4
- data/app/views/admin/shop/products/edit/_fields.html.haml +0 -38
- data/app/views/admin/shop/products/edit/_part.html.haml +0 -3
- data/app/views/admin/shop/products/edit/_popup.html.haml +0 -3
- data/app/views/admin/shop/products/index/_bottom.html.haml +0 -5
- data/spec/controllers/shop/categories_controller_spec.rb +0 -42
- data/spec/controllers/shop/line_items_controller_spec.rb +0 -256
- data/spec/controllers/shop/orders_controller_specs.rb +0 -37
- data/spec/controllers/shop/products_controller_spec.rb +0 -51
- data/vendor/plugins/json_fields/.gitignore +0 -3
- data/vendor/plugins/json_fields/MIT-LICENSE +0 -20
- data/vendor/plugins/json_fields/README.rdoc +0 -65
- data/vendor/plugins/json_fields/Rakefile +0 -55
- data/vendor/plugins/json_fields/init.rb +0 -2
- data/vendor/plugins/json_fields/lib/json_fields.rb +0 -99
- data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +0 -124
- data/vendor/plugins/json_fields/spec/spec.opts +0 -6
- data/vendor/plugins/json_fields/spec/spec_helper.rb +0 -29
- data/vendor/plugins/json_fields/spec/test_models.rb +0 -12
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ShopCustomer do
|
4
|
+
|
5
|
+
dataset :shop_customers, :shop_orders
|
6
|
+
|
7
|
+
describe 'relationships' do
|
8
|
+
before :each do
|
9
|
+
@customer = shop_customers(:customer)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'orders' do
|
13
|
+
before :each do
|
14
|
+
@order = shop_orders(:empty)
|
15
|
+
end
|
16
|
+
it 'should have many' do
|
17
|
+
@customer.orders << @order
|
18
|
+
@customer.orders.include?(@order).should === true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'billing addresses' do
|
23
|
+
before :each do
|
24
|
+
@order = shop_orders(:several_items)
|
25
|
+
end
|
26
|
+
it 'should have many through orders' do
|
27
|
+
@customer.orders << @order
|
28
|
+
@customer.billings.include?(@order.billing).should === true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'shipping addresses' do
|
33
|
+
before :each do
|
34
|
+
@order = shop_orders(:several_items)
|
35
|
+
end
|
36
|
+
it 'should have many through orders' do
|
37
|
+
@customer.orders << @order
|
38
|
+
@customer.shippings.include?(@order.shipping).should === true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'attributes' do
|
44
|
+
before :each do
|
45
|
+
@customer = shop_customers(:customer)
|
46
|
+
end
|
47
|
+
context 'nested order' do
|
48
|
+
it 'should allowing nesting an order' do
|
49
|
+
@customer.update_attributes({
|
50
|
+
:orders => [ ShopOrder.create({ :status => 'nested' }) ]
|
51
|
+
})
|
52
|
+
@customer.orders.last.status.should === 'nested'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#first_name' do
|
58
|
+
before :each do
|
59
|
+
@customer = ShopCustomer.new
|
60
|
+
end
|
61
|
+
context '1 word' do
|
62
|
+
it 'should return the name' do
|
63
|
+
@customer.name = 'Dirk'
|
64
|
+
@customer.first_name.should === 'Dirk'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
context '2 words' do
|
68
|
+
it 'should return the first name' do
|
69
|
+
@customer.name = 'Dirk Kelly'
|
70
|
+
@customer.first_name.should === 'Dirk'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context '3 words' do
|
74
|
+
it 'should return all but last name' do
|
75
|
+
@customer.name = 'Mr. Dirk Kelly'
|
76
|
+
@customer.first_name.should === 'Mr. Dirk'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#last_name' do
|
82
|
+
before :each do
|
83
|
+
@customer = ShopCustomer.new
|
84
|
+
end
|
85
|
+
context '1 word' do
|
86
|
+
it 'should return nothing' do
|
87
|
+
@customer.name = 'Dirk'
|
88
|
+
@customer.last_name.should === ''
|
89
|
+
end
|
90
|
+
end
|
91
|
+
context '2 words' do
|
92
|
+
it 'should return the last name' do
|
93
|
+
@customer.name = 'Dirk Kelly'
|
94
|
+
@customer.last_name.should === 'Kelly'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context '3 words' do
|
98
|
+
it 'should return the last name' do
|
99
|
+
@customer.name = 'Mr. Dirk Kelly'
|
100
|
+
@customer.last_name.should === 'Kelly'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
@@ -2,16 +2,16 @@ require 'spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe ShopLineItem do
|
4
4
|
|
5
|
-
dataset :shop_line_items
|
5
|
+
dataset :shop_line_items, :shop_products
|
6
6
|
|
7
7
|
it 'should calculate a weight' do
|
8
|
-
shop_line_items(:one).weight.should ===
|
9
|
-
shop_line_items(:two).weight.should ===
|
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
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should calculate the price' do
|
13
|
-
shop_line_items(:one).price.should ===
|
14
|
-
shop_line_items(:two).price.should ===
|
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
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should have a set of standard parameters' do
|
@@ -2,26 +2,26 @@ require 'spec/spec_helper'
|
|
2
2
|
|
3
3
|
describe ShopOrder do
|
4
4
|
|
5
|
-
dataset :shop_orders, :shop_line_items, :shop_products
|
5
|
+
dataset :shop_orders, :shop_line_items, :shop_products, :shop_packages, :shop_payments
|
6
6
|
|
7
7
|
context 'instance' do
|
8
8
|
describe 'accessors' do
|
9
9
|
it 'should return the total items' do
|
10
|
-
shop_orders(:empty).quantity.should
|
11
|
-
shop_orders(:one_item).quantity.should
|
12
|
-
shop_orders(:several_items).quantity.should ===
|
10
|
+
shop_orders(:empty).quantity.should === shop_orders(:empty).line_items.sum(:quantity)
|
11
|
+
shop_orders(:one_item).quantity.should === shop_orders(:one_item).line_items.sum(:quantity)
|
12
|
+
shop_orders(:several_items).quantity.should === shop_orders(:several_items).line_items.sum(:quantity)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should calculate a total weight' do
|
16
|
-
shop_orders(:empty).weight.should
|
17
|
-
shop_orders(:one_item).weight.
|
18
|
-
shop_orders(:several_items).weight.
|
16
|
+
shop_orders(:empty).weight.should === lambda{ weight = 0; shop_orders(:empty).line_items.map { |l| weight += l.weight }; weight }.call
|
17
|
+
shop_orders(:one_item).weight.should === lambda{ weight = 0; shop_orders(:one_item).line_items.map { |l| weight += l.weight }; weight }.call
|
18
|
+
shop_orders(:several_items).weight.should === lambda{ weight = 0; shop_orders(:several_items).line_items.map { |l| weight += l.weight }; weight }.call
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should calculate the total price' do
|
22
|
-
shop_orders(:empty).price.should
|
23
|
-
shop_orders(:one_item).price.
|
24
|
-
shop_orders(:several_items).price.
|
22
|
+
shop_orders(:empty).price.should === lambda{ price = 0; shop_orders(:empty).line_items.map { |l| price += l.price }; price }.call
|
23
|
+
shop_orders(:one_item).price.should === lambda{ price = 0; shop_orders(:one_item).line_items.map { |l| price += l.price }; price }.call
|
24
|
+
shop_orders(:several_items).price.should === lambda{ price = 0; shop_orders(:several_items).line_items.map { |l| price += l.price }; price }.call
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '#new?' do
|
@@ -61,24 +61,32 @@ describe ShopOrder do
|
|
61
61
|
describe '#paid?' do
|
62
62
|
context 'success' do
|
63
63
|
it 'should return true' do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
:gateway => 'Eway',
|
69
|
-
:order => shop_orders(:one_item)
|
70
|
-
})
|
71
|
-
shop_orders(:one_item).update_attribute(:status, 'paid')
|
72
|
-
shop_orders(:one_item).paid?.should === true
|
64
|
+
shop_orders(:several_items).update_attribute(:status, 'paid')
|
65
|
+
|
66
|
+
shop_orders(:several_items).payment.should === shop_payments(:visa)
|
67
|
+
shop_orders(:several_items).paid?.should === true
|
73
68
|
end
|
74
69
|
end
|
75
70
|
context 'failure' do
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
71
|
+
describe 'status is not paid' do
|
72
|
+
it 'should return false' do
|
73
|
+
shop_orders(:several_items).update_attribute(:status, 'new')
|
74
|
+
shop_orders(:several_items).paid?.should === false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
describe 'payment is nil' do
|
78
|
+
it 'should return false' do
|
79
|
+
shop_orders(:several_items).update_attribute(:status, 'paid')
|
80
|
+
shop_orders(:several_items).payment = nil
|
81
|
+
shop_orders(:several_items).paid?.should === false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
describe 'payment amount doesnt match' do
|
85
|
+
it 'should return false' do
|
86
|
+
shop_orders(:several_items).update_attribute(:status, 'paid')
|
87
|
+
shop_orders(:several_items).payment.update_attribute(:amount, 11.00)
|
88
|
+
shop_orders(:several_items).paid?.should === false
|
89
|
+
end
|
82
90
|
end
|
83
91
|
end
|
84
92
|
end
|
@@ -88,123 +96,121 @@ describe ShopOrder do
|
|
88
96
|
describe '#add!' do
|
89
97
|
context 'item not in cart' do
|
90
98
|
before :each do
|
91
|
-
@
|
92
|
-
@
|
99
|
+
@order = shop_orders(:empty)
|
100
|
+
@product = shop_products(:crusty_bread)
|
93
101
|
end
|
94
102
|
context 'no quantity or type passed' do
|
95
103
|
it 'should assign a default type and default quantity' do
|
96
|
-
@
|
104
|
+
@order.add!(@product.id)
|
97
105
|
|
98
|
-
@
|
99
|
-
@
|
100
|
-
@
|
101
|
-
@
|
106
|
+
@order.line_items.count.should === 1
|
107
|
+
@order.line_items.first.item_type.should === 'ShopProduct'
|
108
|
+
@order.line_items.first.quantity.should === 1
|
109
|
+
@order.line_items.first.item.should === @product
|
102
110
|
end
|
103
111
|
end
|
104
112
|
context 'quantity passed' do
|
105
113
|
it 'should assign the default type and new quantity' do
|
106
|
-
@
|
114
|
+
@order.add!(@product.id, 2)
|
107
115
|
|
108
|
-
@
|
109
|
-
@
|
110
|
-
@
|
111
|
-
@
|
116
|
+
@order.line_items.count.should === 1
|
117
|
+
@order.line_items.first.item_type.should === 'ShopProduct'
|
118
|
+
@order.line_items.first.quantity.should === 2
|
119
|
+
@order.line_items.first.item.should === @product
|
112
120
|
end
|
113
121
|
end
|
114
122
|
context 'type and quantity passed' do
|
115
123
|
it 'should assign the new type and new quantity' do
|
116
|
-
@
|
124
|
+
@order.add!(shop_packages(:all_bread).id, 2, 'ShopPackage')
|
117
125
|
|
118
|
-
@
|
119
|
-
@
|
120
|
-
@
|
126
|
+
@order.line_items.count.should === 1
|
127
|
+
@order.quantity.should === 2
|
128
|
+
@order.line_items.first.item_type.should === 'ShopPackage'
|
121
129
|
end
|
122
130
|
end
|
123
131
|
end
|
124
132
|
context 'item in cart' do
|
125
133
|
before :each do
|
126
|
-
@
|
127
|
-
@
|
134
|
+
@order = shop_orders(:one_item)
|
135
|
+
@line_item = @order.line_items.first
|
128
136
|
end
|
129
137
|
context 'no quantity or type passed' do
|
130
138
|
it 'should assign a default type and default quantity' do
|
131
|
-
@
|
139
|
+
@order.add!(@line_item.id)
|
132
140
|
|
133
|
-
@
|
134
|
-
@
|
141
|
+
@order.line_items.count.should === 1
|
142
|
+
@order.quantity.should === 1
|
135
143
|
end
|
136
144
|
end
|
137
145
|
context 'quantity passed' do
|
138
146
|
it 'should assign the default type and new quantity' do
|
139
|
-
@
|
147
|
+
@order.add!(@line_item.id, 2)
|
140
148
|
|
141
|
-
@
|
142
|
-
@
|
149
|
+
@order.line_items.count.should === 1
|
150
|
+
@order.quantity.should === 3
|
143
151
|
end
|
144
152
|
end
|
145
153
|
end
|
146
154
|
end
|
147
|
-
describe '#
|
148
|
-
before :each do
|
149
|
-
@shop_order = shop_orders(:one_item)
|
150
|
-
@shop_line_item = shop_orders(:one_item).line_items.first
|
151
|
-
end
|
155
|
+
describe '#modify!' do
|
152
156
|
context 'quantity not set' do
|
153
|
-
|
154
|
-
@
|
157
|
+
before :each do
|
158
|
+
@order = shop_orders(:one_item)
|
159
|
+
@line_item = @order.line_items.first
|
160
|
+
end
|
161
|
+
it 'should not update the item' do
|
162
|
+
@order.modify!(@line_item.id)
|
155
163
|
|
156
|
-
@
|
157
|
-
@shop_order.quantity.should === 1
|
164
|
+
@order.quantity.should === 1
|
158
165
|
end
|
159
166
|
end
|
160
167
|
context 'quantity set' do
|
168
|
+
before :each do
|
169
|
+
@order = shop_orders(:one_item)
|
170
|
+
@line_item = @order.line_items.first
|
171
|
+
end
|
161
172
|
context 'quantity > 0' do
|
162
173
|
it 'should assign that quantity' do
|
163
|
-
@
|
164
|
-
@
|
174
|
+
@order.modify!(@line_item.id, 1)
|
175
|
+
@order.quantity.should === 1
|
165
176
|
|
166
|
-
@
|
167
|
-
@
|
177
|
+
@order.modify!(@line_item.id, 2)
|
178
|
+
@order.quantity.should === 2
|
168
179
|
|
169
|
-
@
|
170
|
-
@
|
180
|
+
@order.modify!(@line_item.id, 100)
|
181
|
+
@order.quantity.should === 100
|
171
182
|
end
|
172
183
|
end
|
173
184
|
context 'quantity <= 0' do
|
174
185
|
it 'should remove that item for 0' do
|
175
|
-
@
|
176
|
-
@
|
177
|
-
@shop_order.line_items.count.should === 0
|
186
|
+
@order.modify!(@line_item.id, 0)
|
187
|
+
@order.quantity.should === 0
|
178
188
|
end
|
179
189
|
it 'should remove that item for -1' do
|
180
|
-
@
|
181
|
-
@
|
182
|
-
@shop_order.line_items.count.should === 0
|
190
|
+
@order.modify!(@line_item.id, -1)
|
191
|
+
@order.quantity.should === 0
|
183
192
|
end
|
184
193
|
it 'should remove that item for -100' do
|
185
|
-
@
|
186
|
-
@
|
187
|
-
@shop_order.line_items.count.should === 0
|
194
|
+
@order.modify!(@line_item.id, -100)
|
195
|
+
@order.quantity.should === 0
|
188
196
|
end
|
189
197
|
end
|
190
198
|
end
|
191
199
|
end
|
192
200
|
describe '#remove!' do
|
193
201
|
it 'should remove the item' do
|
194
|
-
@
|
202
|
+
@order = shop_orders(:several_items)
|
203
|
+
items = @order.line_items.count
|
195
204
|
|
196
|
-
@
|
197
|
-
@
|
198
|
-
@shop_order.line_items.count.should === 2
|
205
|
+
@order.remove!(@order.line_items.first.id)
|
206
|
+
@order.line_items.count.should === items - 1
|
199
207
|
end
|
200
208
|
end
|
201
209
|
describe '#clear!' do
|
202
210
|
it 'should remove all items' do
|
203
|
-
@
|
204
|
-
|
205
|
-
@
|
206
|
-
@shop_order.quantity.should === 0
|
207
|
-
@shop_order.line_items.count.should === 0
|
211
|
+
@order = shop_orders(:several_items)
|
212
|
+
@order.clear!
|
213
|
+
@order.quantity.should === 0
|
208
214
|
end
|
209
215
|
end
|
210
216
|
end
|
@@ -218,7 +224,7 @@ describe ShopOrder do
|
|
218
224
|
|
219
225
|
old = ShopOrder.first
|
220
226
|
old.update_attribute(:status, 'paid')
|
221
|
-
|
227
|
+
|
222
228
|
results = ShopOrder.search('new')
|
223
229
|
results.count.should === count - 1
|
224
230
|
end
|
@@ -0,0 +1,117 @@
|
|
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
|