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,67 @@
|
|
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
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ShopPayment do
|
4
|
+
|
5
|
+
dataset :shop_orders, :shop_payments
|
6
|
+
|
7
|
+
describe 'relationships' do
|
8
|
+
context 'order' do
|
9
|
+
before :each do
|
10
|
+
@order = shop_orders(:several_items)
|
11
|
+
end
|
12
|
+
it 'should belong to one' do
|
13
|
+
@payment = shop_payments(:visa)
|
14
|
+
@payment.order.should === @order
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
3
|
describe ShopProductAttachment do
|
4
|
-
|
4
|
+
|
5
|
+
dataset :shop_products, :shop_product_attachments
|
5
6
|
|
6
7
|
context 'attributes' do
|
7
8
|
|
@@ -10,11 +11,11 @@ describe ShopProductAttachment do
|
|
10
11
|
end
|
11
12
|
|
12
13
|
it 'should have a product id' do
|
13
|
-
@product_image.
|
14
|
+
@product_image.product.should === shop_products(:soft_bread)
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'should have an image id' do
|
17
|
-
@product_image.
|
18
|
+
@product_image.image.should === images(:soft_bread_front)
|
18
19
|
end
|
19
20
|
|
20
21
|
it 'should have a position' do
|
@@ -1,135 +1,214 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
3
|
describe ShopProduct do
|
4
|
+
dataset :shop_products, :shop_line_items
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@products = [
|
10
|
-
shop_products(:soft_bread),
|
11
|
-
shop_products(:crusty_bread),
|
12
|
-
shop_products(:warm_bread)
|
13
|
-
]
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'attributes' do
|
6
|
+
describe 'relationships' do
|
7
|
+
before :each do
|
8
|
+
@product = shop_products(:crusty_bread)
|
9
|
+
end
|
17
10
|
|
18
|
-
it 'should have a
|
19
|
-
@product.
|
11
|
+
it 'should have a page Page' do
|
12
|
+
@product.page.is_a?(Page).should be_true
|
20
13
|
end
|
21
14
|
|
22
|
-
it 'should have
|
23
|
-
@product.
|
15
|
+
it 'should have a created_by User' do
|
16
|
+
@product.created_by = users(:customer)
|
17
|
+
@product.created_by.is_a?(User).should be_true
|
24
18
|
end
|
25
19
|
|
26
|
-
it 'should have a
|
27
|
-
@product.
|
20
|
+
it 'should have a updated_by User' do
|
21
|
+
@product.updated_by = users(:customer)
|
22
|
+
@product.updated_by.is_a?(User).should be_true
|
28
23
|
end
|
29
24
|
|
30
|
-
it 'should have
|
31
|
-
@product.
|
25
|
+
it 'should have many line_items' do
|
26
|
+
@product.line_items.is_a?(Array).should be_true
|
32
27
|
end
|
33
28
|
|
34
|
-
it 'should have
|
35
|
-
@product.
|
29
|
+
it 'should have many orders' do
|
30
|
+
@product.orders.is_a?(Array).should be_true
|
36
31
|
end
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
it 'should have many attachments' do
|
34
|
+
@product.attachments.is_a?(Array).should be_true
|
35
|
+
end
|
41
36
|
|
42
|
-
it 'should
|
43
|
-
@product
|
44
|
-
@product.valid? == false
|
45
|
-
|
46
|
-
@product.name = "name"
|
47
|
-
@product.valid? == false
|
48
|
-
@product.name = nil
|
49
|
-
|
50
|
-
@product.category = shop_categories(:bread)
|
51
|
-
@product.valid? == false
|
52
|
-
|
53
|
-
@product.name = "name"
|
54
|
-
@product.valid? == true
|
37
|
+
it 'should have many images' do
|
38
|
+
@product.images.is_a?(Array).should be_true
|
55
39
|
end
|
56
40
|
|
57
|
-
it 'should
|
58
|
-
@product
|
59
|
-
@product.valid? == true
|
60
|
-
|
61
|
-
@product.price = "asdas"
|
62
|
-
@product.valid? == false
|
63
|
-
|
64
|
-
@product.price = "-999.99"
|
65
|
-
@product.valid? == false
|
66
|
-
|
67
|
-
@product.price = "9.99.99"
|
68
|
-
@product.valid? == false
|
69
|
-
|
70
|
-
@product.price = "0.00"
|
71
|
-
@product.valid? == false
|
72
|
-
|
73
|
-
@product.price = "0.01"
|
74
|
-
@product.valid? == true
|
75
|
-
|
76
|
-
@product.price = "999999.99"
|
77
|
-
@product.valid? == true
|
41
|
+
it 'should have many packings' do
|
42
|
+
@product.packings.is_a?(Array).should be_true
|
78
43
|
end
|
79
44
|
|
80
|
-
it 'should
|
81
|
-
@product
|
82
|
-
@product.valid? === true
|
83
|
-
@product.sku.should === 'dark_______________toasted'
|
45
|
+
it 'should have many packages' do
|
46
|
+
@product.packages.is_a?(Array).should be_true
|
84
47
|
end
|
85
48
|
|
86
|
-
it 'should have
|
87
|
-
@product.
|
88
|
-
@product.images.class.should == Array
|
89
|
-
@product.images.length.should === 3
|
90
|
-
@product.images.length.should === @product.attachments.length
|
49
|
+
it 'should have many related' do
|
50
|
+
@product.related.is_a?(Array).should be_true
|
91
51
|
end
|
92
52
|
|
53
|
+
it 'should have many variants' do
|
54
|
+
@product.variants.is_a?(Array).should be_true
|
55
|
+
end
|
93
56
|
end
|
94
57
|
|
95
|
-
describe '
|
96
|
-
|
97
|
-
product
|
98
|
-
|
99
|
-
|
58
|
+
describe 'validations' do
|
59
|
+
before :each do
|
60
|
+
@product = shop_products(:crusty_bread)
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'page' do
|
64
|
+
it 'should require a page' do
|
65
|
+
@product.page = nil
|
66
|
+
@product.valid?.should be_false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'price' do
|
71
|
+
it 'should require a numerical price' do
|
72
|
+
@product.price = 'failure'
|
73
|
+
@product.valid?.should be_false
|
74
|
+
end
|
100
75
|
|
101
|
-
|
76
|
+
it 'should require a positive price' do
|
77
|
+
@product.price = -99.99
|
78
|
+
@product.valid?.should be_false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'methods' do
|
84
|
+
before :each do
|
85
|
+
@product = shop_products(:crusty_bread)
|
86
|
+
end
|
87
|
+
|
88
|
+
context '#name' do
|
89
|
+
it 'should return page title' do
|
90
|
+
@product.name.should === @product.page.title
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context '#sku' do
|
95
|
+
it 'should return a handle formatted url' do
|
96
|
+
@product.sku.should === ShopProduct.to_sku(@product.page.url)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context '#category' do
|
101
|
+
it 'should return page title' do
|
102
|
+
@product.category.should === @product.page.parent.shop_category
|
103
|
+
end
|
102
104
|
end
|
105
|
+
|
106
|
+
context '#category_id' do
|
107
|
+
it 'should return page title' do
|
108
|
+
@product.category_id.should === @product.page.parent.shop_category.id
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context '#description' do
|
113
|
+
it 'should return page title' do
|
114
|
+
@product.description.should === "*#{@product.name}*"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'url' do
|
119
|
+
it 'should return a standard url path' do
|
120
|
+
@product.url.should === @product.page.url
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'customers' do
|
125
|
+
it 'should return a collection of customers' do
|
126
|
+
@product.customers.first.should === @product.line_items.first.customer
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'customer_ids' do
|
131
|
+
it 'should return a collection of customer_ids' do
|
132
|
+
@product.customer_ids.first.should === @product.line_items.first.customer.id
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'image_ids' do
|
137
|
+
it 'should return a collection of customer_ids' do
|
138
|
+
@product.image_ids.first.should === @product.images.first.id
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'available_images' do
|
143
|
+
it 'should return a collection of customer_ids' do
|
144
|
+
@product.available_images.should === (Image.all - @product.images)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'slug' do
|
149
|
+
it 'should return the page slug' do
|
150
|
+
@product.slug.should === @product.page.slug
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'to_json' do
|
155
|
+
it 'should overload standard to_json' do
|
156
|
+
pending 'not sure how to write this'
|
157
|
+
# @category.to_json.should === ShopCategory.params
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
103
161
|
end
|
104
162
|
|
105
|
-
describe '
|
106
|
-
|
107
|
-
@product
|
163
|
+
describe 'filters' do
|
164
|
+
before :each do
|
165
|
+
@product = shop_products(:crusty_bread)
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'handle' do
|
169
|
+
context 'slug' do
|
170
|
+
it 'should generate on validation' do
|
171
|
+
@product.page.slug = 'delicious_ _:_;_=_+_._~_bread'
|
172
|
+
@product.valid?
|
173
|
+
@product.page.slug.should === 'delicious_______________bread'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
context 'breadcrumb' do
|
177
|
+
context 'has not been set' do
|
178
|
+
it 'should generate from the slug on validation' do
|
179
|
+
@product.page.slug = 'delicious_ _:_;_=_+_._~_bread'
|
180
|
+
@product.page.breadcrumb = nil
|
181
|
+
@product.valid?
|
182
|
+
@product.page.breadcrumb.should === 'delicious_______________bread'
|
183
|
+
end
|
184
|
+
end
|
185
|
+
context 'has been set' do
|
186
|
+
it 'should generate on validation' do
|
187
|
+
@product.page.breadcrumb = 'delicious_ _:_;_=_+_._~_bread'
|
188
|
+
@product.valid?
|
189
|
+
@product.page.breadcrumb.should === 'delicious_______________bread'
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
108
193
|
end
|
109
194
|
end
|
110
195
|
|
111
|
-
describe '#
|
112
|
-
it 'should return
|
113
|
-
|
114
|
-
|
115
|
-
@product.available_images.should === @images
|
196
|
+
describe '#attrs' do
|
197
|
+
it 'should return attribute set' do
|
198
|
+
ShopProduct.attrs.should === [ :id, :price, :page_id, :created_at, :updated_at ]
|
116
199
|
end
|
117
200
|
end
|
118
201
|
|
119
|
-
describe '#
|
120
|
-
it 'should return
|
121
|
-
|
202
|
+
describe '#methds' do
|
203
|
+
it 'should return method set' do
|
204
|
+
ShopProduct.methds.should === [ :category_id, :name, :description, :handle, :url, :customer_ids, :image_ids, :created_at, :updated_at ]
|
122
205
|
end
|
123
206
|
end
|
124
207
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
it 'should have a set of standard parameters' do
|
129
|
-
ShopProduct.attrs.should === [ :id, :name, :price, :sku, :description, :created_at, :updated_at ]
|
130
|
-
end
|
208
|
+
describe '#params' do
|
209
|
+
it 'should return parameter set' do
|
210
|
+
ShopProduct.params.should === { :only => ShopProduct.attrs, :methods => ShopProduct.methds }
|
131
211
|
end
|
132
|
-
|
133
212
|
end
|
134
213
|
|
135
214
|
end
|
@@ -0,0 +1,92 @@
|
|
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
|