radiant-shop-extension 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +75 -0
- data/HISTORY.md +77 -0
- data/MIT-LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +141 -0
- data/VERSION +1 -0
- data/app/.DS_Store +0 -0
- data/app/controllers/admin/shop/categories_controller.rb +206 -0
- data/app/controllers/admin/shop/customers_controller.rb +137 -0
- data/app/controllers/admin/shop/orders_controller.rb +171 -0
- data/app/controllers/admin/shop/products/images_controller.rb +144 -0
- data/app/controllers/admin/shop/products_controller.rb +217 -0
- data/app/controllers/admin/shops_controller.rb +9 -0
- data/app/controllers/shop/categories_controller.rb +49 -0
- data/app/controllers/shop/line_items_controller.rb +165 -0
- data/app/controllers/shop/orders_controller.rb +16 -0
- data/app/controllers/shop/products_controller.rb +48 -0
- data/app/models/form_checkout.rb +245 -0
- data/app/models/shop_address.rb +13 -0
- data/app/models/shop_addressable.rb +11 -0
- data/app/models/shop_category.rb +85 -0
- data/app/models/shop_category_page.rb +7 -0
- data/app/models/shop_customer.rb +27 -0
- data/app/models/shop_line_item.rb +32 -0
- data/app/models/shop_order.rb +108 -0
- data/app/models/shop_payment.rb +6 -0
- data/app/models/shop_payment_method.rb +5 -0
- data/app/models/shop_product.rb +87 -0
- data/app/models/shop_product_attachment.rb +30 -0
- data/app/models/shop_product_page.rb +7 -0
- data/app/views/.DS_Store +0 -0
- data/app/views/admin/.DS_Store +0 -0
- data/app/views/admin/pages/_shop_category.html.haml +4 -0
- data/app/views/admin/pages/_shop_product.html.haml +4 -0
- data/app/views/admin/shop/categories/edit.html.haml +12 -0
- data/app/views/admin/shop/categories/edit/_fields.html.haml +28 -0
- data/app/views/admin/shop/categories/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/categories/edit/_meta.html.haml +7 -0
- data/app/views/admin/shop/categories/edit/_part.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/_popup.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +5 -0
- data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +10 -0
- data/app/views/admin/shop/categories/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/categories/index/_category.html.haml +16 -0
- data/app/views/admin/shop/categories/new.html.haml +10 -0
- data/app/views/admin/shop/categories/remove.html.haml +12 -0
- data/app/views/admin/shop/customers/index.html.haml +36 -0
- data/app/views/admin/shop/orders/index.html.haml +33 -0
- data/app/views/admin/shop/products/edit.html.haml +14 -0
- data/app/views/admin/shop/products/edit/_fields.html.haml +38 -0
- data/app/views/admin/shop/products/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/products/edit/_image.html.haml +12 -0
- data/app/views/admin/shop/products/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/products/edit/_part.html.haml +3 -0
- data/app/views/admin/shop/products/edit/_popup.html.haml +3 -0
- data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -0
- data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -0
- data/app/views/admin/shop/products/edit/meta/_category.html.haml +5 -0
- data/app/views/admin/shop/products/edit/meta/_sku.html.haml +5 -0
- data/app/views/admin/shop/products/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/products/edit/parts/_images.html.haml +5 -0
- data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +6 -0
- data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +18 -0
- data/app/views/admin/shop/products/index.html.haml +10 -0
- data/app/views/admin/shop/products/index/_bottom.html.haml +5 -0
- data/app/views/admin/shop/products/index/_product.html.haml +13 -0
- data/app/views/admin/shop/products/new.html.haml +10 -0
- data/app/views/admin/shop/products/remove.html.haml +12 -0
- data/app/views/shop/categories/show.html.haml +1 -0
- data/app/views/shop/orders/show.html.haml +1 -0
- data/app/views/shop/products/index.html.haml +1 -0
- data/app/views/shop/products/show.html.haml +1 -0
- data/config/locales/en.yml +50 -0
- data/config/routes.rb +38 -0
- data/config/shop_cart.yml +16 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20100311053701_initial.rb +153 -0
- data/db/migrate/20100520033059_create_layouts.rb +119 -0
- data/db/migrate/20100903122123_create_forms.rb +44 -0
- data/db/migrate/20100908063639_create_snippets.rb +22 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +14 -0
- data/lib/shop/controllers/application_controller.rb +39 -0
- data/lib/shop/controllers/site_controller.rb +12 -0
- data/lib/shop/interface/products.rb +49 -0
- data/lib/shop/models/image.rb +14 -0
- data/lib/shop/models/page.rb +14 -0
- data/lib/shop/tags/address.rb +40 -0
- data/lib/shop/tags/cart.rb +49 -0
- data/lib/shop/tags/category.rb +83 -0
- data/lib/shop/tags/core.rb +12 -0
- data/lib/shop/tags/helpers.rb +142 -0
- data/lib/shop/tags/item.rb +109 -0
- data/lib/shop/tags/product.rb +109 -0
- data/lib/shop/tags/responses.rb +34 -0
- data/lib/tasks/shop_extension_tasks.rake +54 -0
- data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
- data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
- data/public/images/admin/extensions/shop/products/sort.png +0 -0
- data/public/javascripts/admin/extensions/shop/products/edit.js +115 -0
- data/public/javascripts/admin/extensions/shop/products/index.js +65 -0
- data/public/stylesheets/sass/admin/extensions/shop/edit.sass +86 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +158 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +129 -0
- data/radiant-shop-extension.gemspec +245 -0
- data/shop_extension.rb +62 -0
- data/spec/controllers/admin/shop/categories_controller_spec.rb +443 -0
- data/spec/controllers/admin/shop/products/images_controller_spec.rb +477 -0
- data/spec/controllers/admin/shop/products_controller_spec.rb +394 -0
- data/spec/controllers/admin/shops_controller_spec.rb +19 -0
- data/spec/controllers/shop/categories_controller_spec.rb +42 -0
- data/spec/controllers/shop/line_items_controller_spec.rb +256 -0
- data/spec/controllers/shop/orders_controller_specs.rb +37 -0
- data/spec/controllers/shop/products_controller_spec.rb +51 -0
- data/spec/datasets/forms.rb +153 -0
- data/spec/datasets/images.rb +13 -0
- data/spec/datasets/shop_addresses.rb +27 -0
- data/spec/datasets/shop_categories.rb +13 -0
- data/spec/datasets/shop_line_items.rb +9 -0
- data/spec/datasets/shop_orders.rb +21 -0
- data/spec/datasets/shop_products.rb +34 -0
- data/spec/helpers/nested_tag_helper.rb +33 -0
- data/spec/lib/shop/models/image_spec.rb +28 -0
- data/spec/lib/shop/models/page_spec.rb +38 -0
- data/spec/lib/shop/tags/address_spec.rb +196 -0
- data/spec/lib/shop/tags/cart_spec.rb +169 -0
- data/spec/lib/shop/tags/category_spec.rb +201 -0
- data/spec/lib/shop/tags/core_spec.rb +16 -0
- data/spec/lib/shop/tags/helpers_spec.rb +381 -0
- data/spec/lib/shop/tags/item_spec.rb +313 -0
- data/spec/lib/shop/tags/product_spec.rb +334 -0
- data/spec/matchers/comparison.rb +72 -0
- data/spec/matchers/render_matcher.rb +33 -0
- data/spec/models/form_checkout_spec.rb +376 -0
- data/spec/models/shop_category_page_spec.rb +10 -0
- data/spec/models/shop_category_spec.rb +58 -0
- data/spec/models/shop_line_item_spec.rb +42 -0
- data/spec/models/shop_order_spec.rb +228 -0
- data/spec/models/shop_product_attachment_spec.rb +72 -0
- data/spec/models/shop_product_page_spec.rb +10 -0
- data/spec/models/shop_product_spec.rb +135 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +22 -0
- data/vendor/plugins/acts_as_list/README +23 -0
- data/vendor/plugins/acts_as_list/init.rb +3 -0
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/vendor/plugins/json_fields/.gitignore +3 -0
- data/vendor/plugins/json_fields/MIT-LICENSE +20 -0
- data/vendor/plugins/json_fields/README.rdoc +65 -0
- data/vendor/plugins/json_fields/Rakefile +55 -0
- data/vendor/plugins/json_fields/init.rb +2 -0
- data/vendor/plugins/json_fields/lib/json_fields.rb +99 -0
- data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +124 -0
- data/vendor/plugins/json_fields/spec/spec.opts +6 -0
- data/vendor/plugins/json_fields/spec/spec_helper.rb +29 -0
- data/vendor/plugins/json_fields/spec/test_models.rb +12 -0
- metadata +324 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ShopCategory do
|
4
|
+
dataset :shop_categories
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@category = shop_categories(:bread)
|
8
|
+
@categories = [
|
9
|
+
shop_categories(:bread),
|
10
|
+
shop_categories(:milk)
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'attributes' do
|
15
|
+
|
16
|
+
it 'should have a title' do
|
17
|
+
@category.name.should == 'bread'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have a handle' do
|
21
|
+
@category.handle.should == 'bread'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a position' do
|
25
|
+
@category.position.should == 1
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have a products array' do
|
29
|
+
@category.products.class.should == Array
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'validation' do
|
35
|
+
|
36
|
+
it 'should generate a valid handle on validation' do
|
37
|
+
@product = ShopCategory.new({ :name => 'delicious_ _:_;_=_+_._~_bread' })
|
38
|
+
@product.valid? == true
|
39
|
+
@product.handle.should == 'delicious_______________bread'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should find a category by handle' do
|
45
|
+
ShopCategory.find_by_handle(@category.handle).should == @category
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'Class Methods' do
|
49
|
+
|
50
|
+
describe '#attrs' do
|
51
|
+
it 'should have a set of standard parameters' do
|
52
|
+
ShopCategory.attrs.should === [ :id, :handle, :description, :created_at, :updated_at ]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ShopLineItem do
|
4
|
+
|
5
|
+
dataset :shop_line_items
|
6
|
+
|
7
|
+
it 'should calculate a weight' do
|
8
|
+
shop_line_items(:one).weight.should === 31.0
|
9
|
+
shop_line_items(:two).weight.should === 62.0
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should calculate the price' do
|
13
|
+
shop_line_items(:one).price.should === 11.0
|
14
|
+
shop_line_items(:two).price.should === 22.0
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have a set of standard parameters' do
|
18
|
+
ShopLineItem.params.should === [
|
19
|
+
:id,
|
20
|
+
:quantity
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should adjust quantity to 1 if less than' do
|
25
|
+
s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 0 })
|
26
|
+
s.valid?
|
27
|
+
s.quantity.should === 1
|
28
|
+
|
29
|
+
s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 1 })
|
30
|
+
s.valid?
|
31
|
+
s.quantity.should === 1
|
32
|
+
|
33
|
+
s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => -100 })
|
34
|
+
s.valid?
|
35
|
+
s.quantity.should === 1
|
36
|
+
|
37
|
+
s = ShopLineItem.new({ :item => shop_products(:crusty_bread), :quantity => 100 })
|
38
|
+
s.valid?
|
39
|
+
s.quantity.should === 100
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ShopOrder do
|
4
|
+
|
5
|
+
dataset :shop_orders, :shop_line_items, :shop_products
|
6
|
+
|
7
|
+
context 'instance' do
|
8
|
+
describe 'accessors' do
|
9
|
+
it 'should return the total items' do
|
10
|
+
shop_orders(:empty).quantity.should === 0
|
11
|
+
shop_orders(:one_item).quantity.should === 1
|
12
|
+
shop_orders(:several_items).quantity.should === 3
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should calculate a total weight' do
|
16
|
+
shop_orders(:empty).weight.should === 0
|
17
|
+
shop_orders(:one_item).weight.to_f.should === 31.0
|
18
|
+
shop_orders(:several_items).weight.to_f.should === 92.0
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should calculate the total price' do
|
22
|
+
shop_orders(:empty).price.should === 0
|
23
|
+
shop_orders(:one_item).price.to_f.should === 11.0
|
24
|
+
shop_orders(:several_items).price.to_f.should === 32.0
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#new?' do
|
28
|
+
context 'success' do
|
29
|
+
it 'should return true' do
|
30
|
+
shop_orders(:empty).update_attribute(:status, 'new')
|
31
|
+
shop_orders(:empty).new?.should === true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context 'failure' do
|
35
|
+
it 'should return false' do
|
36
|
+
shop_orders(:empty).update_attribute(:status, 'paid')
|
37
|
+
shop_orders(:empty).new?.should === false
|
38
|
+
|
39
|
+
shop_orders(:empty).update_attribute(:status, 'shipped')
|
40
|
+
shop_orders(:empty).new?.should === false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
describe '#paid?' do
|
45
|
+
context 'success' do
|
46
|
+
it 'should return true' do
|
47
|
+
shop_orders(:empty).update_attribute(:status, 'paid')
|
48
|
+
shop_orders(:empty).paid?.should === true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context 'failure' do
|
52
|
+
it 'should return false' do
|
53
|
+
shop_orders(:empty).update_attribute(:status, 'new')
|
54
|
+
shop_orders(:empty).paid?.should === false
|
55
|
+
|
56
|
+
shop_orders(:empty).update_attribute(:status, 'shipped')
|
57
|
+
shop_orders(:empty).paid?.should === false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
describe '#shipped?' do
|
62
|
+
context 'success' do
|
63
|
+
it 'should return true' do
|
64
|
+
shop_orders(:empty).update_attribute(:status, 'shipped')
|
65
|
+
shop_orders(:empty).shipped?.should === true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
context 'failure' do
|
69
|
+
it 'should return false' do
|
70
|
+
shop_orders(:empty).update_attribute(:status, 'new')
|
71
|
+
shop_orders(:empty).shipped?.should === false
|
72
|
+
|
73
|
+
shop_orders(:empty).update_attribute(:status, 'paid')
|
74
|
+
shop_orders(:empty).shipped?.should === false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'mutators' do
|
81
|
+
describe '#add!' do
|
82
|
+
context 'item not in cart' do
|
83
|
+
before :each do
|
84
|
+
@shop_order = shop_orders(:empty)
|
85
|
+
@shop_product = shop_products(:crusty_bread)
|
86
|
+
end
|
87
|
+
context 'no quantity or type passed' do
|
88
|
+
it 'should assign a default type and default quantity' do
|
89
|
+
@shop_order.add!(@shop_product.id)
|
90
|
+
|
91
|
+
@shop_order.line_items.count.should == 1
|
92
|
+
@shop_order.line_items.first.item_type.should === 'ShopProduct'
|
93
|
+
@shop_order.line_items.first.quantity.should === 1
|
94
|
+
@shop_order.line_items.first.item.should === @shop_product
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context 'quantity passed' do
|
98
|
+
it 'should assign the default type and new quantity' do
|
99
|
+
@shop_order.add!(@shop_product.id, 2)
|
100
|
+
|
101
|
+
@shop_order.line_items.count.should === 1
|
102
|
+
@shop_order.line_items.first.item_type.should === 'ShopProduct'
|
103
|
+
@shop_order.line_items.first.quantity.should === 2
|
104
|
+
@shop_order.line_items.first.item.should === @shop_product
|
105
|
+
end
|
106
|
+
end
|
107
|
+
context 'type and quantity passed' do
|
108
|
+
it 'should assign the new type and new quantity' do
|
109
|
+
@shop_order.add!(@shop_product.id, 2, 'ShopPackage')
|
110
|
+
|
111
|
+
@shop_order.line_items.count.should === 1
|
112
|
+
@shop_order.quantity.should === 2
|
113
|
+
@shop_order.line_items.first.item_type.should === 'ShopPackage'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
context 'item in cart' do
|
118
|
+
before :each do
|
119
|
+
@shop_order = shop_orders(:one_item)
|
120
|
+
@shop_line_item = shop_orders(:one_item).line_items.first
|
121
|
+
end
|
122
|
+
context 'no quantity or type passed' do
|
123
|
+
it 'should assign a default type and default quantity' do
|
124
|
+
@shop_order.add!(@shop_line_item.id)
|
125
|
+
|
126
|
+
@shop_order.line_items.count.should === 1
|
127
|
+
@shop_order.quantity.should === 2
|
128
|
+
end
|
129
|
+
end
|
130
|
+
context 'quantity passed' do
|
131
|
+
it 'should assign the default type and new quantity' do
|
132
|
+
@shop_order.add!(@shop_line_item.id, 2)
|
133
|
+
|
134
|
+
@shop_order.line_items.count.should === 1
|
135
|
+
@shop_order.quantity.should === 3
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
describe '#update!' do
|
141
|
+
before :each do
|
142
|
+
@shop_order = shop_orders(:one_item)
|
143
|
+
@shop_line_item = shop_orders(:one_item).line_items.first
|
144
|
+
end
|
145
|
+
context 'quantity not set' do
|
146
|
+
it 'should assign a quantity of 1' do
|
147
|
+
@shop_order.update!(@shop_line_item.id)
|
148
|
+
|
149
|
+
@shop_order.line_items.count.should === 1
|
150
|
+
@shop_order.quantity.should === 1
|
151
|
+
end
|
152
|
+
end
|
153
|
+
context 'quantity set' do
|
154
|
+
context 'quantity > 0' do
|
155
|
+
it 'should assign that quantity' do
|
156
|
+
@shop_order.update!(@shop_line_item.id, 1)
|
157
|
+
@shop_order.quantity.should === 1
|
158
|
+
|
159
|
+
@shop_order.update!(@shop_line_item.id, 2)
|
160
|
+
@shop_order.quantity.should === 2
|
161
|
+
|
162
|
+
@shop_order.update!(@shop_line_item.id, 100)
|
163
|
+
@shop_order.quantity.should === 100
|
164
|
+
end
|
165
|
+
end
|
166
|
+
context 'quantity <= 0' do
|
167
|
+
it 'should remove that item for 0' do
|
168
|
+
@shop_order.update!(@shop_line_item.id, 0)
|
169
|
+
@shop_order.quantity.should === 0
|
170
|
+
@shop_order.line_items.count.should === 0
|
171
|
+
end
|
172
|
+
it 'should remove that item for -1' do
|
173
|
+
@shop_order.update!(@shop_line_item.id, -1)
|
174
|
+
@shop_order.quantity.should === 0
|
175
|
+
@shop_order.line_items.count.should === 0
|
176
|
+
end
|
177
|
+
it 'should remove that item for -100' do
|
178
|
+
@shop_order.update!(@shop_line_item.id, -100)
|
179
|
+
@shop_order.quantity.should === 0
|
180
|
+
@shop_order.line_items.count.should === 0
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
describe '#remove!' do
|
186
|
+
it 'should remove the item' do
|
187
|
+
@shop_order = shop_orders(:several_items)
|
188
|
+
|
189
|
+
@shop_order.remove!(@shop_order.line_items.first.id)
|
190
|
+
@shop_order.quantity.should === 2
|
191
|
+
@shop_order.line_items.count.should === 2
|
192
|
+
end
|
193
|
+
end
|
194
|
+
describe '#clear!' do
|
195
|
+
it 'should remove all items' do
|
196
|
+
@shop_order = shop_orders(:several_items)
|
197
|
+
|
198
|
+
@shop_order.clear!
|
199
|
+
@shop_order.quantity.should === 0
|
200
|
+
@shop_order.line_items.count.should === 0
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'class methods' do
|
207
|
+
describe '#search' do
|
208
|
+
context 'status' do
|
209
|
+
it 'should return valid subsets' do
|
210
|
+
count = ShopOrder.count
|
211
|
+
|
212
|
+
old = ShopOrder.first
|
213
|
+
old.update_attribute(:status, 'paid')
|
214
|
+
|
215
|
+
results = ShopOrder.search('new')
|
216
|
+
results.count.should === count - 1
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe '#params' do
|
222
|
+
it 'should have a set of standard parameters' do
|
223
|
+
ShopOrder.params.should === [ :id, :notes, :status ]
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ShopProductAttachment do
|
4
|
+
dataset :shop_products
|
5
|
+
|
6
|
+
context 'attributes' do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@product_image = shop_products(:soft_bread).attachments.first
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have a product id' do
|
13
|
+
@product_image.shop_product_id.should === shop_products(:soft_bread).id
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have an image id' do
|
17
|
+
@product_image.image_id.should === images(:soft_bread_front).id
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have a position' do
|
21
|
+
@product_image.position.should === 1
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a product' do
|
25
|
+
@product_image.product.class.should == ShopProduct
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have an image' do
|
29
|
+
@product_image.image.class.should == Image
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'alias methods' do
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
@product_image = shop_products(:soft_bread).attachments.first
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#url' do
|
41
|
+
it 'should return its assets url' do
|
42
|
+
@product_image.url.should === @product_image.image.url
|
43
|
+
end
|
44
|
+
end
|
45
|
+
describe '#title' do
|
46
|
+
it 'should return its assets title' do
|
47
|
+
@product_image.title.should === @product_image.image.title
|
48
|
+
end
|
49
|
+
end
|
50
|
+
describe '#caption' do
|
51
|
+
it 'should return its assets caption' do
|
52
|
+
@product_image.caption.should === @product_image.image.caption
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'class methods' do
|
58
|
+
describe '#params' do
|
59
|
+
it 'should have a set of standard parameters' do
|
60
|
+
ShopProductAttachment.params.should === [
|
61
|
+
:id,
|
62
|
+
:title,
|
63
|
+
:caption,
|
64
|
+
:image_file_name,
|
65
|
+
:image_content_type,
|
66
|
+
:image_file_size
|
67
|
+
]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ShopProduct do
|
4
|
+
|
5
|
+
dataset :shop_products
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@product = shop_products(:soft_bread)
|
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
|
17
|
+
|
18
|
+
it 'should have a name' do
|
19
|
+
@product.name.should == 'soft bread'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have an sku' do
|
23
|
+
@product.sku.should == 'soft_bread'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should have a position' do
|
27
|
+
@product.position.should == 1
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should have a price' do
|
31
|
+
@product.price.should === 10.00
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should have a category' do
|
35
|
+
@product.category.class.should == ShopCategory
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'validation' do
|
41
|
+
|
42
|
+
it 'should require a name and category' do
|
43
|
+
@product = ShopProduct.new()
|
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
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should validate but not require the price' do
|
58
|
+
@product = ShopProduct.new({ :name => 'bread', :category => shop_categories(:bread) })
|
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
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should generate a valid sku on validation' do
|
81
|
+
@product = ShopProduct.new({ :name => 'dark_ _:_;_=_+_._~_toasted', :category => shop_categories(:bread) })
|
82
|
+
@product.valid? === true
|
83
|
+
@product.sku.should === 'dark_______________toasted'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should have an array of images' do
|
87
|
+
@product.attachments.class.should == Array
|
88
|
+
@product.images.class.should == Array
|
89
|
+
@product.images.length.should === 3
|
90
|
+
@product.images.length.should === @product.attachments.length
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#slug' do
|
96
|
+
it 'should return a generated slug' do
|
97
|
+
product = ShopProduct.new
|
98
|
+
product.sku = 'product'
|
99
|
+
stub(product).category.stub!.handle { 'category' }
|
100
|
+
|
101
|
+
product.slug.should === %{/#{Radiant::Config['shop.url_prefix']}/category/product}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#layout' do
|
106
|
+
it 'should return the layout defined by its category' do
|
107
|
+
@product.layout.should === @product.category.product_layout
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#available_images' do
|
112
|
+
it 'should return all the Images minus its own' do
|
113
|
+
@images = Image.all - @product.images
|
114
|
+
|
115
|
+
@product.available_images.should === @images
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#slug_prefix' do
|
120
|
+
it 'should return the configured shop.url_prefix' do
|
121
|
+
@product.slug_prefix.should === Radiant::Config['shop.url_prefix']
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'Class Methods' do
|
126
|
+
|
127
|
+
describe '#attrs' do
|
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
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|