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,13 @@
|
|
1
|
+
class ImagesDataset < Dataset::Base
|
2
|
+
def load
|
3
|
+
images = [ :soft_bread_front, :soft_bread_back, :soft_bread_top, :crusty_bread_front, :warm_bread_front ]
|
4
|
+
|
5
|
+
images.each_with_index do |image, i|
|
6
|
+
create_record :image, image,
|
7
|
+
:title => image.to_s,
|
8
|
+
:asset_file_name => "#{image.to_s}_file_name.png",
|
9
|
+
:asset_content_type => "image/png",
|
10
|
+
:asset_file_size => i+1*1000
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class ShopAddressesDataset < Dataset::Base
|
2
|
+
def load
|
3
|
+
|
4
|
+
# TODO Investigate why inflectors are breaking here
|
5
|
+
|
6
|
+
create_record :shop_addresss, :billing,
|
7
|
+
:name => 'Billing Address',
|
8
|
+
:email => 'billing@address.com',
|
9
|
+
:unit => 'a',
|
10
|
+
:street => '1 Bill Street',
|
11
|
+
:city => 'Billvilles',
|
12
|
+
:state => 'BI',
|
13
|
+
:country=> 'Billington',
|
14
|
+
:postcode=> '1234'
|
15
|
+
|
16
|
+
create_record :shop_addresss, :shipping,
|
17
|
+
:name => 'Shipping Address',
|
18
|
+
:email => 'shipping@address.com',
|
19
|
+
:unit => 'b',
|
20
|
+
:street => '2 Ship Street',
|
21
|
+
:city => 'Shipvilles',
|
22
|
+
:state => 'SH',
|
23
|
+
:country=> 'Shippington',
|
24
|
+
:postcode=> '5678'
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ShopCategoriesDataset < Dataset::Base
|
2
|
+
def load
|
3
|
+
categories = [:bread, :milk, :salad]
|
4
|
+
|
5
|
+
categories.each_with_index do |category, i|
|
6
|
+
create_record :shop_category, category,
|
7
|
+
:name => category.to_s,
|
8
|
+
:handle => category.to_s,
|
9
|
+
:position => i + 1
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class ShopLineItemsDataset < Dataset::Base
|
2
|
+
|
3
|
+
uses :shop_products
|
4
|
+
|
5
|
+
def load
|
6
|
+
create_record :shop_line_item, :one, :item_id => shop_products(:crusty_bread).id, :item_type => 'ShopProduct'
|
7
|
+
create_record :shop_line_item, :two, :item_id => shop_products(:crusty_bread).id, :item_type => 'ShopProduct', :quantity => 2
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ShopOrdersDataset < Dataset::Base
|
2
|
+
|
3
|
+
uses :shop_products
|
4
|
+
|
5
|
+
def load
|
6
|
+
create_record :shop_order, :empty
|
7
|
+
create_record :shop_order, :one_item
|
8
|
+
create_record :shop_order, :several_items
|
9
|
+
|
10
|
+
create_record :shop_line_item, :crusty_bread, :item_id => shop_products(:crusty_bread).id, :item_type => 'ShopProduct'
|
11
|
+
create_record :shop_line_item, :soft_bread, :item_id => shop_products(:soft_bread).id, :item_type => 'ShopProduct'
|
12
|
+
create_record :shop_line_item, :choc_milk, :item_id => shop_products(:choc_milk).id, :item_type => 'ShopProduct'
|
13
|
+
create_record :shop_line_item, :full_milk, :item_id => shop_products(:full_milk).id, :item_type => 'ShopProduct'
|
14
|
+
|
15
|
+
shop_orders(:one_item).line_items << shop_line_items(:crusty_bread)
|
16
|
+
|
17
|
+
shop_orders(:several_items).line_items << shop_line_items(:soft_bread)
|
18
|
+
shop_orders(:several_items).line_items << shop_line_items(:choc_milk)
|
19
|
+
shop_orders(:several_items).line_items << shop_line_items(:full_milk)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class ShopProductsDataset < Dataset::Base
|
2
|
+
|
3
|
+
uses :shop_categories, :images
|
4
|
+
|
5
|
+
def load
|
6
|
+
categories = {
|
7
|
+
:bread => [ :soft, :crusty, :warm ],
|
8
|
+
:milk => [ :full, :hilo, :choc ]
|
9
|
+
}
|
10
|
+
|
11
|
+
categories.each do |category, products|
|
12
|
+
products.each_with_index do |product, i|
|
13
|
+
create_record :shop_product, "#{product.to_s}_#{category.to_s}".to_sym,
|
14
|
+
:name => "#{product.to_s} #{category.to_s}",
|
15
|
+
:sku => "#{product.to_s}_#{category.to_s}",
|
16
|
+
:price => i + 1 * 10,
|
17
|
+
:position => i + 1,
|
18
|
+
:weight => i + 10 * 3,
|
19
|
+
:category => shop_categories(category)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
shop_products(:soft_bread).images = [
|
24
|
+
images(:soft_bread_front),
|
25
|
+
images(:soft_bread_back),
|
26
|
+
images(:soft_bread_top)
|
27
|
+
]
|
28
|
+
|
29
|
+
shop_products(:crusty_bread).images << images(:crusty_bread_front)
|
30
|
+
|
31
|
+
shop_products(:warm_bread).images << images(:warm_bread_front)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# Nested tag helper is used to test tags that can be declared inside other tags.
|
3
|
+
#
|
4
|
+
# @example
|
5
|
+
# tag = NestedTagHelper.new
|
6
|
+
# tag.push '<div>', '</div>'
|
7
|
+
# tag.push '<h1>', '</h1>'
|
8
|
+
# tag.push 'Title'
|
9
|
+
# tag.to_s => '<div><h1>Title</h1></div>'
|
10
|
+
#
|
11
|
+
class NestedTagHelper
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@tag_stack = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def push(opening, closing = nil)
|
18
|
+
@tag_stack.push Tag.new(opening, closing)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
closing_tags = []
|
23
|
+
@tag_stack.collect do |tag|
|
24
|
+
closing_tags.unshift tag.closing
|
25
|
+
tag.opening
|
26
|
+
end.join('') + closing_tags.join('')
|
27
|
+
end
|
28
|
+
|
29
|
+
private #######################################################################
|
30
|
+
|
31
|
+
Tag = Struct.new(:opening, :closing)
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Tests for shop order page model extensions
|
5
|
+
#
|
6
|
+
describe Shop::Models::Image do
|
7
|
+
|
8
|
+
dataset :images, :shop_products
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
@image = images(:soft_bread_front)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'relationships' do
|
15
|
+
|
16
|
+
describe 'belongs_to :shop_category' do
|
17
|
+
it 'should accept and return a shop_category object' do
|
18
|
+
@shop_product = shop_products(:soft_bread)
|
19
|
+
|
20
|
+
@image.shop_products << @shop_product
|
21
|
+
|
22
|
+
@image.shop_products.include?(@shop_product).should === true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Tests for shop order page model extensions
|
5
|
+
#
|
6
|
+
describe Shop::Models::Page do
|
7
|
+
|
8
|
+
dataset :pages, :shop_categories, :shop_products
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
@page = pages(:home)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'relationships' do
|
15
|
+
|
16
|
+
describe 'belongs_to :shop_category' do
|
17
|
+
it 'should accept and return a shop_category object' do
|
18
|
+
@shop_category = shop_categories(:bread)
|
19
|
+
|
20
|
+
@page.shop_category = @shop_category
|
21
|
+
|
22
|
+
@page.shop_category.should === @shop_category
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'belongs_to :shop_product' do
|
27
|
+
it 'should accept and return a shop_product object' do
|
28
|
+
@shop_product = shop_products(:warm_bread)
|
29
|
+
|
30
|
+
@page.shop_product = @shop_product
|
31
|
+
|
32
|
+
@page.shop_product.should === @shop_product
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Tests for shop address tags
|
5
|
+
#
|
6
|
+
describe Shop::Tags::Address do
|
7
|
+
|
8
|
+
dataset :pages, :shop_addresses, :shop_orders
|
9
|
+
|
10
|
+
it 'should describe these tags' do
|
11
|
+
Shop::Tags::Address.tags.sort.should == [
|
12
|
+
'shop:cart:address',
|
13
|
+
'shop:cart:address:if_address',
|
14
|
+
'shop:cart:address:unless_address',
|
15
|
+
'shop:cart:address:id',
|
16
|
+
'shop:cart:address:name',
|
17
|
+
'shop:cart:address:email',
|
18
|
+
'shop:cart:address:unit',
|
19
|
+
'shop:cart:address:street',
|
20
|
+
'shop:cart:address:city',
|
21
|
+
'shop:cart:address:state',
|
22
|
+
'shop:cart:address:country',
|
23
|
+
'shop:cart:address:postcode',
|
24
|
+
].sort
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'inside cart' do
|
28
|
+
before :all do
|
29
|
+
@page = pages(:home)
|
30
|
+
end
|
31
|
+
|
32
|
+
before :each do
|
33
|
+
@order = shop_orders(:one_item)
|
34
|
+
@billing = shop_addresses(:billing)
|
35
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @order }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'shop:cart:address:if_address' do
|
39
|
+
context 'success' do
|
40
|
+
before :each do
|
41
|
+
mock(Shop::Tags::Helpers).current_address(anything) { @billing }
|
42
|
+
end
|
43
|
+
it 'should expand' do
|
44
|
+
tag = %{<r:shop:cart:address type='billing'><r:if_address>success</r:if_address></r:shop:cart:address>}
|
45
|
+
exp = %{success}
|
46
|
+
|
47
|
+
@page.should render(tag).as(exp)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context 'failure' do
|
51
|
+
before :each do
|
52
|
+
mock(Shop::Tags::Helpers).current_address(anything) { nil }
|
53
|
+
end
|
54
|
+
it 'should not expand' do
|
55
|
+
tag = %{<r:shop:cart:address type='billing'><r:if_address>failure</r:if_address></r:shop:cart:address>}
|
56
|
+
exp = %{}
|
57
|
+
|
58
|
+
@page.should render(tag).as(exp)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'shop:cart:address:unless_address' do
|
64
|
+
context 'success' do
|
65
|
+
before :each do
|
66
|
+
mock(Shop::Tags::Helpers).current_address(anything) { @billing }
|
67
|
+
end
|
68
|
+
it 'should expand' do
|
69
|
+
stub(@order).billing { @billing }
|
70
|
+
|
71
|
+
tag = %{<r:shop:cart:address type='billing'><r:unless_address>failure</r:unless_address></r:shop:cart:address>}
|
72
|
+
exp = %{}
|
73
|
+
|
74
|
+
@page.should render(tag).as(exp)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
context 'failure' do
|
78
|
+
before :each do
|
79
|
+
mock(Shop::Tags::Helpers).current_address(anything) { nil }
|
80
|
+
end
|
81
|
+
it 'should not expand' do
|
82
|
+
stub(@order).billing { nil }
|
83
|
+
|
84
|
+
tag = %{<r:shop:cart:address type='billing'><r:unless_address>success</r:unless_address></r:shop:cart:address>}
|
85
|
+
exp = %{success}
|
86
|
+
|
87
|
+
@page.should render(tag).as(exp)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'shop:address' do
|
93
|
+
context 'no address' do
|
94
|
+
before :each do
|
95
|
+
mock(Shop::Tags::Helpers).current_address(anything) { @billing }
|
96
|
+
end
|
97
|
+
it 'should expand' do
|
98
|
+
tag = %{<r:shop:cart:address type='billing'>success</r:shop:cart:address>}
|
99
|
+
exp = %{success}
|
100
|
+
|
101
|
+
@page.should render(tag).as(exp)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
context 'address' do
|
105
|
+
before :each do
|
106
|
+
mock(Shop::Tags::Helpers).current_address(anything) { nil }
|
107
|
+
end
|
108
|
+
it 'should expand' do
|
109
|
+
tag = %{<r:shop:cart:address type='billing'>success</r:shop:cart:address>}
|
110
|
+
exp = %{success}
|
111
|
+
|
112
|
+
@page.should render(tag).as(exp)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'attributes' do
|
118
|
+
before :each do
|
119
|
+
mock(Shop::Tags::Helpers).current_address(anything) { @billing }
|
120
|
+
end
|
121
|
+
context 'shop:cart:address:id' do
|
122
|
+
it 'should return the id' do
|
123
|
+
tag = %{<r:shop:cart:address type='billing'><r:id /></r:shop:cart:address>}
|
124
|
+
exp = @billing.id.to_s
|
125
|
+
|
126
|
+
@page.should render(tag).as(exp)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
context 'shop:cart:address:name' do
|
130
|
+
it 'should return the name' do
|
131
|
+
tag = %{<r:shop:cart:address type='billing'><r:name /></r:shop:cart:address>}
|
132
|
+
exp = @billing.name
|
133
|
+
|
134
|
+
@page.should render(tag).as(exp)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
context 'shop:cart:address:email' do
|
138
|
+
it 'should return the email' do
|
139
|
+
tag = %{<r:shop:cart:address type='billing'><r:email /></r:shop:cart:address>}
|
140
|
+
exp = @billing.email
|
141
|
+
|
142
|
+
@page.should render(tag).as(exp)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
context 'shop:cart:address:unit' do
|
146
|
+
it 'should return the unit' do
|
147
|
+
tag = %{<r:shop:cart:address type='billing'><r:unit /></r:shop:cart:address>}
|
148
|
+
exp = @billing.unit
|
149
|
+
|
150
|
+
@page.should render(tag).as(exp)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
context 'shop:cart:address:street' do
|
154
|
+
it 'should return the street' do
|
155
|
+
tag = %{<r:shop:cart:address type='billing'><r:street /></r:shop:cart:address>}
|
156
|
+
exp = @billing.street
|
157
|
+
|
158
|
+
@page.should render(tag).as(exp)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
context 'shop:cart:address:city' do
|
162
|
+
it 'should return the city' do
|
163
|
+
tag = %{<r:shop:cart:address type='billing'><r:city /></r:shop:cart:address>}
|
164
|
+
exp = @billing.city
|
165
|
+
|
166
|
+
@page.should render(tag).as(exp)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
context 'shop:cart:address:state' do
|
170
|
+
it 'should return the city' do
|
171
|
+
tag = %{<r:shop:cart:address type='billing'><r:state /></r:shop:cart:address>}
|
172
|
+
exp = @billing.state
|
173
|
+
|
174
|
+
@page.should render(tag).as(exp)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
context 'shop:cart:address:country' do
|
178
|
+
it 'should return the country' do
|
179
|
+
tag = %{<r:shop:cart:address type='billing'><r:country /></r:shop:cart:address>}
|
180
|
+
exp = @billing.country
|
181
|
+
|
182
|
+
@page.should render(tag).as(exp)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
context 'shop:cart:address:postcode' do
|
186
|
+
it 'should return the postcode' do
|
187
|
+
tag = %{<r:shop:cart:address type='billing'><r:postcode /></r:shop:cart:address>}
|
188
|
+
exp = @billing.postcode
|
189
|
+
|
190
|
+
@page.should render(tag).as(exp)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'spec/helpers/nested_tag_helper'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Tests for shop order tags module
|
6
|
+
#
|
7
|
+
describe Shop::Tags::Cart do
|
8
|
+
|
9
|
+
dataset :pages
|
10
|
+
|
11
|
+
it 'should describe these tags' do
|
12
|
+
Shop::Tags::Cart.tags.sort.should == [
|
13
|
+
'shop:if_cart',
|
14
|
+
'shop:unless_cart',
|
15
|
+
'shop:cart',
|
16
|
+
'shop:cart:id',
|
17
|
+
'shop:cart:status',
|
18
|
+
'shop:cart:quantity',
|
19
|
+
'shop:cart:weight',
|
20
|
+
'shop:cart:price'].sort
|
21
|
+
end
|
22
|
+
|
23
|
+
before :all do
|
24
|
+
@page = pages(:home)
|
25
|
+
end
|
26
|
+
|
27
|
+
before :each do
|
28
|
+
order = Object.new
|
29
|
+
|
30
|
+
@shop_order = order
|
31
|
+
@shop_orders = [ order, order, order ]
|
32
|
+
|
33
|
+
item = Object.new
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'outside cart context' do
|
37
|
+
describe '<r:shop:if_cart>' do
|
38
|
+
context 'success' do
|
39
|
+
it 'should render' do
|
40
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @shop_order }
|
41
|
+
|
42
|
+
tag = %{<r:shop:if_cart>success</r:shop:if_cart>}
|
43
|
+
expected = %{success}
|
44
|
+
@page.should render(tag).as(expected)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
context 'failure' do
|
48
|
+
it 'should render' do
|
49
|
+
mock(Shop::Tags::Helpers).current_order(anything) { nil }
|
50
|
+
|
51
|
+
tag = %{<r:shop:if_cart>failure</r:shop:if_cart>}
|
52
|
+
expected = %{}
|
53
|
+
@page.should render(tag).as(expected)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '<r:shop:unless_cart>' do
|
59
|
+
context 'success' do
|
60
|
+
it 'should render' do
|
61
|
+
mock(Shop::Tags::Helpers).current_order(anything) { nil }
|
62
|
+
|
63
|
+
tag = %{<r:shop:unless_cart>success</r:shop:unless_cart>}
|
64
|
+
expected = %{success}
|
65
|
+
@page.should render(tag).as(expected)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
context 'failure' do
|
69
|
+
it 'should render' do
|
70
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @shop_order }
|
71
|
+
|
72
|
+
tag = %{<r:shop:unless_cart>failure</r:shop:unless_cart>}
|
73
|
+
expected = %{}
|
74
|
+
@page.should render(tag).as(expected)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '<r:shop:cart>' do
|
80
|
+
context 'success' do
|
81
|
+
it 'should render' do
|
82
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @shop_order }
|
83
|
+
|
84
|
+
tag = %{<r:shop:cart>success</r:shop:cart>}
|
85
|
+
expected = %{success}
|
86
|
+
|
87
|
+
@page.should render(tag).as(expected)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'failure' do
|
92
|
+
it 'should not render' do
|
93
|
+
tag = %{<r:shop:cart>Failure</r:shop:cart>}
|
94
|
+
expected = %{}
|
95
|
+
|
96
|
+
@page.should render(tag).as(expected)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'simple attributes' do
|
102
|
+
before :each do
|
103
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @shop_order }
|
104
|
+
end
|
105
|
+
it 'should render <r:id />' do
|
106
|
+
stub(@shop_order).id { 1 }
|
107
|
+
|
108
|
+
tag = %{<r:shop:cart:id />}
|
109
|
+
expected = %{1}
|
110
|
+
|
111
|
+
@page.should render(tag).as(expected)
|
112
|
+
end
|
113
|
+
it 'should render <r:status />' do
|
114
|
+
stub(@shop_order).status { 'new' }
|
115
|
+
|
116
|
+
tag = %{<r:shop:cart:status />}
|
117
|
+
expected = %{new}
|
118
|
+
|
119
|
+
@page.should render(tag).as(expected)
|
120
|
+
end
|
121
|
+
it 'should render <r:quantity />' do
|
122
|
+
stub(@shop_order).quantity { 1 }
|
123
|
+
|
124
|
+
tag = %{<r:shop:cart:quantity />}
|
125
|
+
expected = %{1}
|
126
|
+
|
127
|
+
@page.should render(tag).as(expected)
|
128
|
+
end
|
129
|
+
it 'should render <r:weight />' do
|
130
|
+
stub(@shop_order).weight { 100 }
|
131
|
+
|
132
|
+
tag = %{<r:shop:cart:weight />}
|
133
|
+
expected = %{100}
|
134
|
+
|
135
|
+
@page.should render(tag).as(expected)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '<r:price />' do
|
140
|
+
before :each do
|
141
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @shop_order }
|
142
|
+
stub(@shop_order).price { 1234.34567890 }
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should render a standard price' do
|
146
|
+
tag = %{<r:shop:cart:price />}
|
147
|
+
expected = %{$1,234.35}
|
148
|
+
|
149
|
+
@page.should render(tag).as(expected)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should render a high precision price' do
|
153
|
+
tag = %{<r:shop:cart:price precision="8"/>}
|
154
|
+
expected = %{$1,234.34567890}
|
155
|
+
|
156
|
+
@page.should render(tag).as(expected)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should render a custom format' do
|
160
|
+
tag = %{<r:shop:cart:price unit="%" separator="-" delimiter="+" />}
|
161
|
+
expected = %{%1+234-35}
|
162
|
+
|
163
|
+
@page.should render(tag).as(expected)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|