radiant-shop-extension 0.11.5 → 0.11.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/app/controllers/admin/shop/discounts/discountables_controller.rb +44 -0
- data/app/controllers/admin/shop/discounts_controller.rb +64 -0
- data/app/controllers/admin/shop/orders_controller.rb +19 -3
- data/app/controllers/admin/shop/packages_controller.rb +1 -3
- data/app/controllers/admin/shop/products_controller.rb +1 -2
- data/app/controllers/admin/shop/variants_controller.rb +3 -4
- data/app/models/form_address.rb +4 -2
- data/app/models/form_discount.rb +39 -0
- data/app/models/form_line_item.rb +1 -11
- data/app/models/shop_category.rb +3 -0
- data/app/models/shop_customer.rb +0 -9
- data/app/models/shop_discount.rb +37 -0
- data/app/models/shop_discountable.rb +64 -0
- data/app/models/shop_line_item.rb +24 -1
- data/app/models/shop_order.rb +41 -28
- data/app/models/shop_product.rb +11 -0
- data/app/models/shop_product_variant.rb +3 -0
- data/app/models/shop_variant.rb +1 -3
- data/app/views/admin/shop/discounts/edit.html.haml +11 -0
- data/app/views/admin/shop/discounts/edit/_foot.html.haml +16 -0
- data/app/views/admin/shop/discounts/edit/_form.html.haml +15 -0
- data/app/views/admin/shop/discounts/edit/_head.html.haml +4 -0
- data/app/views/admin/shop/discounts/edit/_inputs.html.haml +2 -0
- data/app/views/admin/shop/discounts/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/discounts/edit/_parts.html.haml +9 -0
- data/app/views/admin/shop/discounts/edit/_popups.html.haml +4 -0
- data/app/views/admin/shop/discounts/edit/buttons/_browse_categories.html.haml +1 -0
- data/app/views/admin/shop/discounts/edit/buttons/_browse_products.html.haml +1 -0
- data/app/views/admin/shop/discounts/edit/inputs/_amount.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/inputs/_code.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/inputs/_name.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/meta/_finish.html.haml +5 -0
- data/app/views/admin/shop/discounts/edit/meta/_start.html.haml +5 -0
- data/app/views/admin/shop/discounts/edit/parts/_categories.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/parts/_products.html.haml +3 -0
- data/app/views/admin/shop/discounts/edit/popups/_browse_categories.html.haml +6 -0
- data/app/views/admin/shop/discounts/edit/popups/_browse_products.html.haml +6 -0
- data/app/views/admin/shop/discounts/edit/shared/_category.html.haml +11 -0
- data/app/views/admin/shop/discounts/edit/shared/_product.html.haml +12 -0
- data/app/views/admin/shop/discounts/index.html.haml +13 -0
- data/app/views/admin/shop/discounts/index/_discount.html.haml +13 -0
- data/app/views/admin/shop/discounts/index/_foot.html.haml +5 -0
- data/app/views/admin/shop/discounts/index/_head.html.haml +2 -0
- data/app/views/admin/shop/discounts/index/buttons/_new_discount.html.haml +1 -0
- data/app/views/admin/shop/discounts/new.html.haml +11 -0
- data/app/views/admin/shop/discounts/remove.html.haml +12 -0
- data/app/views/admin/shop/orders/index.html.haml +1 -1
- data/app/views/admin/shop/orders/index/_foot.html.haml +3 -1
- data/app/views/admin/shop/orders/index/_head.html.haml +1 -3
- data/app/views/admin/shop/packages/index.html.haml +1 -1
- data/app/views/admin/shop/packages/index/_foot.html.haml +3 -2
- data/app/views/admin/shop/packages/index/_head.html.haml +1 -3
- data/app/views/admin/shop/packages/index/buttons/_new_package.html.haml +1 -0
- data/app/views/admin/shop/products/index.html.haml +1 -1
- data/app/views/admin/shop/products/index/_foot.html.haml +3 -2
- data/app/views/admin/shop/products/index/_head.html.haml +1 -3
- data/app/views/admin/shop/products/index/buttons/_add_category.html.haml +1 -0
- data/app/views/admin/shop/products/index/buttons/_variants.html.haml +1 -1
- data/app/views/admin/shop/variants/index.html.haml +1 -1
- data/app/views/admin/shop/variants/index/_foot.html.haml +3 -2
- data/app/views/admin/shop/variants/index/_head.html.haml +1 -3
- data/app/views/admin/shop/variants/index/buttons/_add_variant.html.haml +1 -0
- data/app/views/admin/shop/variants/index/buttons/_categories.html.haml +1 -0
- data/config/routes.rb +11 -5
- data/db/migrate/20101010071143_create_discounts.rb +29 -0
- data/db/migrate/20101010072225_modify_categories_remove_variant.rb +9 -0
- data/db/migrate/20101010130034_change_discountables_add_observer.rb +15 -0
- data/db/migrate/20101011063133_change_orders_set_limits_to_null.rb +11 -0
- data/lib/shop/interface/discounts.rb +34 -0
- data/lib/shop/interface/orders.rb +2 -2
- data/lib/shop/interface/packages.rb +2 -2
- data/lib/shop/interface/products.rb +2 -2
- data/lib/shop/interface/variants.rb +2 -2
- data/lib/shop/models/form_extension.rb +12 -1
- data/lib/shop/models/user.rb +18 -0
- data/lib/shop/tags/cart.rb +24 -0
- data/lib/shop/tags/helpers.rb +1 -1
- data/lib/shop/tags/item.rb +26 -11
- data/lib/shop/tags/tax.rb +73 -0
- data/lib/tasks/shop_extension_tasks.rake +1 -1
- data/mockups/discounts/new-edit.bmml +49 -49
- data/public/javascripts/admin/extensions/shop/discounts/edit.js +76 -0
- data/public/stylesheets/sass/admin/extensions/shop/discounts/edit.sass +125 -0
- data/public/stylesheets/sass/admin/extensions/shop/index.sass +14 -40
- data/radiant-shop-extension.gemspec +70 -7
- data/shop_extension.rb +23 -12
- data/spec/controllers/admin/shop/discounts/discountables_controller_spec.rb +73 -0
- data/spec/controllers/admin/shop/discounts_controller_spec.rb +81 -0
- data/spec/controllers/admin/shop/orders_controller_spec.rb +35 -0
- data/spec/datasets/forms.rb +23 -12
- data/spec/datasets/shop_discountables.rb +22 -0
- data/spec/datasets/shop_discounts.rb +29 -0
- data/spec/lib/shop/tags/cart_spec.rb +75 -1
- data/spec/lib/shop/tags/item_spec.rb +4 -7
- data/spec/lib/shop/tags/tax_spec.rb +201 -0
- data/spec/models/form_discount_spec.rb +63 -0
- data/spec/models/shop_category_spec.rb +8 -0
- data/spec/models/shop_discount_spec.rb +130 -0
- data/spec/models/shop_discountable_spec.rb +114 -0
- data/spec/models/shop_line_item_spec.rb +9 -1
- data/spec/models/shop_order_spec.rb +253 -199
- data/spec/models/shop_product_spec.rb +31 -2
- data/spec/models/shop_variant_spec.rb +0 -15
- metadata +97 -21
- data/app/views/admin/shop/products/index/buttons/_discounts.html.haml +0 -1
- data/app/views/admin/shop/products/index/buttons/_packages.html.haml +0 -1
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe Admin::Shop::DiscountsController do
|
4
|
+
|
5
|
+
dataset :users, :shop_discounts
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
login_as :admin
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'index' do
|
12
|
+
context 'instance variables' do
|
13
|
+
it 'should be assigned' do
|
14
|
+
get :index
|
15
|
+
|
16
|
+
assigns(:inputs).should === []
|
17
|
+
assigns(:meta).should === []
|
18
|
+
assigns(:buttons).should === ['new_discount']
|
19
|
+
assigns(:parts).should === []
|
20
|
+
assigns(:popups).should === []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#new' do
|
26
|
+
context 'instance variables' do
|
27
|
+
it 'should be assigned' do
|
28
|
+
get :new
|
29
|
+
|
30
|
+
assigns(:inputs).should === ['name','amount','code']
|
31
|
+
assigns(:meta).should === ['start','finish']
|
32
|
+
assigns(:buttons).should === []
|
33
|
+
assigns(:parts).should === []
|
34
|
+
assigns(:popups).should === []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#edit' do
|
40
|
+
context 'instance variables' do
|
41
|
+
it 'should be assigned' do
|
42
|
+
get :edit, :id => shop_discounts(:ten_percent).id
|
43
|
+
|
44
|
+
assigns(:inputs).should === ['name','amount','code']
|
45
|
+
assigns(:meta).should === ['start','finish']
|
46
|
+
assigns(:buttons).should === ['browse_categories', 'browse_products']
|
47
|
+
assigns(:parts).should === ['categories', 'products']
|
48
|
+
assigns(:popups).should === ['browse_categories', 'browse_products']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#create' do
|
54
|
+
context 'instance variables' do
|
55
|
+
it 'should be assigned' do
|
56
|
+
post :create, :shop_variant => {}
|
57
|
+
|
58
|
+
assigns(:inputs).should === ['name','amount','code']
|
59
|
+
assigns(:meta).should === ['start','finish']
|
60
|
+
assigns(:buttons).should === []
|
61
|
+
assigns(:parts).should === []
|
62
|
+
assigns(:popups).should === []
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#update' do
|
68
|
+
context 'instance variables' do
|
69
|
+
it 'should be assigned' do
|
70
|
+
put :update, :id => shop_discounts(:ten_percent).id, :shop_variant => {}
|
71
|
+
|
72
|
+
assigns(:inputs).should === ['name','amount','code']
|
73
|
+
assigns(:meta).should === ['start','finish']
|
74
|
+
assigns(:buttons).should === ['browse_categories', 'browse_products']
|
75
|
+
assigns(:parts).should === ['categories', 'products']
|
76
|
+
assigns(:popups).should === ['browse_categories', 'browse_products']
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -8,6 +8,37 @@ describe Admin::Shop::OrdersController do
|
|
8
8
|
login_as :admin
|
9
9
|
end
|
10
10
|
|
11
|
+
describe '#index' do
|
12
|
+
context 'scoping' do
|
13
|
+
it 'should accept shipped parameter' do
|
14
|
+
get :index, :status => 'new'
|
15
|
+
|
16
|
+
assigns(:shop_orders).should === ShopOrder.all(:conditions => { :status => 'new'})
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should accept paid parameter' do
|
20
|
+
get :index, :status => 'paid'
|
21
|
+
|
22
|
+
assigns(:shop_orders).should === ShopOrder.all(:conditions => { :status => 'paid'})
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should accept shipped parameter' do
|
26
|
+
get :index, :status => 'shipped'
|
27
|
+
|
28
|
+
assigns(:shop_orders).should === ShopOrder.all(:conditions => { :status => 'shipped'})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#export' do
|
34
|
+
it 'should be scoped by status parameter' do
|
35
|
+
pending
|
36
|
+
get :export, :status => 'shipped'
|
37
|
+
|
38
|
+
assigns(:shop_orders).should === ShopOrder.all(:conditions => { :status => 'shipped'})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
11
42
|
describe '#edit' do
|
12
43
|
context 'instance variables' do
|
13
44
|
context 'order with no address or customer' do
|
@@ -82,4 +113,8 @@ describe Admin::Shop::OrdersController do
|
|
82
113
|
end
|
83
114
|
end
|
84
115
|
|
116
|
+
describe '#export' do
|
117
|
+
|
118
|
+
end
|
119
|
+
|
85
120
|
end
|
data/spec/datasets/forms.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
class FormsDataset < Dataset::Base
|
2
2
|
|
3
|
-
uses :pages, :shop_orders
|
3
|
+
uses :pages, :shop_orders, :shop_discounts
|
4
4
|
|
5
5
|
def load
|
6
6
|
create_record :form, :checkout,
|
7
7
|
:title => 'Checkout',
|
8
|
-
:body =>
|
9
|
-
:
|
10
|
-
:
|
8
|
+
:body => checkout_body,
|
9
|
+
:config => checkout_config,
|
10
|
+
:content => ''
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def checkout_body
|
14
14
|
<<-BODY
|
15
15
|
<r:shop:cart>
|
16
16
|
<div class="addresses">
|
@@ -49,13 +49,7 @@ class FormsDataset < Dataset::Base
|
|
49
49
|
BODY
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
<<-CONTENT
|
54
|
-
|
55
|
-
CONTENT
|
56
|
-
end
|
57
|
-
|
58
|
-
def config
|
52
|
+
def checkout_config
|
59
53
|
<<-CONFIG
|
60
54
|
checkout:
|
61
55
|
test: true
|
@@ -157,6 +151,23 @@ CONFIG
|
|
157
151
|
|
158
152
|
@request.session = { :shop_order => @order.id }
|
159
153
|
end
|
154
|
+
|
155
|
+
def mock_valid_form_discount_request
|
156
|
+
@form = forms(:checkout)
|
157
|
+
@form[:extensions] = {
|
158
|
+
:discount => {
|
159
|
+
:process => 'add'
|
160
|
+
}
|
161
|
+
}
|
162
|
+
@data = {
|
163
|
+
:discount => {
|
164
|
+
:code => shop_discounts(:ten_percent).code
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
@request.session = { :shop_order => @order.id }
|
169
|
+
end
|
170
|
+
|
160
171
|
end
|
161
172
|
|
162
173
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class ShopDiscountablesDataset < Dataset::Base
|
2
|
+
|
3
|
+
uses :shop_discounts, :shop_categories, :shop_products
|
4
|
+
|
5
|
+
def load
|
6
|
+
create_record :shop_discountables, :ten_percent_bread,
|
7
|
+
:discount_id => shop_discounts(:ten_percent).id,
|
8
|
+
:discounted_id => shop_categories(:bread).id,
|
9
|
+
:discounted_type => 'ShopCategory'
|
10
|
+
|
11
|
+
create_record :shop_discountables, :five_percent_bread,
|
12
|
+
:discount_id => shop_discounts(:five_percent).id,
|
13
|
+
:discounted_id => shop_categories(:bread).id,
|
14
|
+
:discounted_type => 'ShopCategory'
|
15
|
+
|
16
|
+
create_record :shop_discountables, :five_percent_crusty_bread,
|
17
|
+
:discount_id => shop_discounts(:five_percent).id,
|
18
|
+
:discounted_id => shop_products(:crusty_bread).id,
|
19
|
+
:discounted_type => 'ShopProduct'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class ShopDiscountsDataset < Dataset::Base
|
2
|
+
|
3
|
+
def load
|
4
|
+
create_record :shop_discounts, :ten_percent,
|
5
|
+
:name => 'ten percent',
|
6
|
+
:code => '10pcoff',
|
7
|
+
:amount => 10.00
|
8
|
+
|
9
|
+
create_record :shop_discounts, :five_percent,
|
10
|
+
:name => 'five percent',
|
11
|
+
:code => '5pcoff',
|
12
|
+
:amount => 10.00
|
13
|
+
|
14
|
+
create_record :shop_discounts, :one_percent,
|
15
|
+
:name => 'one percent',
|
16
|
+
:code => '1pcoff',
|
17
|
+
:amount => 1.00,
|
18
|
+
:starts_at => nil,
|
19
|
+
:finishes_at => nil
|
20
|
+
|
21
|
+
create_record :shop_discounts, :invalid,
|
22
|
+
:name => 'invalid',
|
23
|
+
:code => 'invalid',
|
24
|
+
:amount => 100,
|
25
|
+
:starts_at => Time.now - 5.days,
|
26
|
+
:finishes_at => Time.now - 2.days
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -6,12 +6,16 @@ require 'spec/helpers/nested_tag_helper'
|
|
6
6
|
#
|
7
7
|
describe Shop::Tags::Cart do
|
8
8
|
|
9
|
-
dataset :pages, :shop_orders
|
9
|
+
dataset :pages, :shop_orders, :shop_payments
|
10
10
|
|
11
11
|
it 'should describe these tags' do
|
12
12
|
Shop::Tags::Cart.tags.sort.should == [
|
13
13
|
'shop:cart:if_cart',
|
14
14
|
'shop:cart:unless_cart',
|
15
|
+
'shop:cart:payment',
|
16
|
+
'shop:cart:payment:if_paid',
|
17
|
+
'shop:cart:payment:unless_paid',
|
18
|
+
'shop:cart:payment:date',
|
15
19
|
'shop:cart',
|
16
20
|
'shop:cart:id',
|
17
21
|
'shop:cart:status',
|
@@ -93,6 +97,76 @@ describe Shop::Tags::Cart do
|
|
93
97
|
end
|
94
98
|
end
|
95
99
|
|
100
|
+
context 'payment' do
|
101
|
+
before :each do
|
102
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @order }
|
103
|
+
@order.status = 'paid'
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '<r:shop:cart:payment />' do
|
107
|
+
context 'payment exists' do
|
108
|
+
it 'should expand' do
|
109
|
+
tag = %{<r:shop:cart:payment>success</r:shop:cart:payment>}
|
110
|
+
expected = %{success}
|
111
|
+
@page.should render(tag).as(expected)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
context 'payment doesnt exist' do
|
115
|
+
it 'should expand' do
|
116
|
+
stub(@order).paid? { false }
|
117
|
+
tag = %{<r:shop:cart:payment>success</r:shop:cart:payment>}
|
118
|
+
expected = %{success}
|
119
|
+
@page.should render(tag).as(expected)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '<r:shop:cart:payment:if_paid />' do
|
125
|
+
context 'payment exists' do
|
126
|
+
it 'should expand' do
|
127
|
+
tag = %{<r:shop:cart:payment:if_paid>success</r:shop:cart:payment:if_paid>}
|
128
|
+
expected = %{success}
|
129
|
+
@page.should render(tag).as(expected)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
context 'payment doesnt exist' do
|
133
|
+
it 'should expand' do
|
134
|
+
stub(@order).paid? { false }
|
135
|
+
tag = %{<r:shop:cart:payment:if_paid>failure</r:shop:cart:payment:if_paid>}
|
136
|
+
expected = %{}
|
137
|
+
@page.should render(tag).as(expected)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '<r:shop:cart:payment:unless_paid />' do
|
143
|
+
context 'payment exists' do
|
144
|
+
it 'should expand' do
|
145
|
+
stub(@order).paid? { false }
|
146
|
+
tag = %{<r:shop:cart:payment:unless_paid>success</r:shop:cart:payment:unless_paid>}
|
147
|
+
expected = %{success}
|
148
|
+
@page.should render(tag).as(expected)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
context 'payment doesnt exist' do
|
152
|
+
it 'should expand' do
|
153
|
+
tag = %{<r:shop:cart:payment:unless_paid>failure</r:shop:cart:payment:unless_paid>}
|
154
|
+
expected = %{}
|
155
|
+
@page.should render(tag).as(expected)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '<r:shop:cart:payment:date />' do
|
161
|
+
it 'should return the created_at date of the payment' do
|
162
|
+
tag = %{<r:shop:cart:payment:date />}
|
163
|
+
expected = @order.payment.created_at.to_s(:long)
|
164
|
+
@page.should render(tag).as(expected)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
96
170
|
describe 'simple attributes' do
|
97
171
|
before :each do
|
98
172
|
mock(Shop::Tags::Helpers).current_order(anything) { @order }
|
@@ -21,7 +21,10 @@ describe Shop::Tags::Item do
|
|
21
21
|
'shop:cart:item:sku',
|
22
22
|
'shop:cart:item:link',
|
23
23
|
'shop:cart:item:price',
|
24
|
-
'shop:cart:item:
|
24
|
+
'shop:cart:item:value',
|
25
|
+
'shop:cart:item:discounted',
|
26
|
+
'shop:cart:item:if_discounted',
|
27
|
+
'shop:cart:item:unless_discounted'].sort
|
25
28
|
end
|
26
29
|
|
27
30
|
context 'within a cart' do
|
@@ -208,12 +211,6 @@ describe Shop::Tags::Item do
|
|
208
211
|
tag = %{<r:shop:cart:item:sku />}
|
209
212
|
exp = @line_item.item.sku
|
210
213
|
|
211
|
-
@page.should render(tag).as(exp)
|
212
|
-
end
|
213
|
-
it 'should render <r:weight />' do
|
214
|
-
tag = %{<r:shop:cart:item:weight />}
|
215
|
-
exp = @line_item.item.weight.to_s
|
216
|
-
|
217
214
|
@page.should render(tag).as(exp)
|
218
215
|
end
|
219
216
|
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Tests for shop address tags
|
5
|
+
#
|
6
|
+
describe Shop::Tags::Tax do
|
7
|
+
|
8
|
+
dataset :pages, :shop_line_items
|
9
|
+
|
10
|
+
it 'should describe these tags' do
|
11
|
+
Shop::Tags::Tax.tags.sort.should == [
|
12
|
+
'shop:cart:tax',
|
13
|
+
'shop:cart:tax:if_tax',
|
14
|
+
'shop:cart:tax:unless_tax',
|
15
|
+
'shop:cart:tax:name',
|
16
|
+
'shop:cart:tax:percentage',
|
17
|
+
'shop:cart:tax:strategy',
|
18
|
+
'shop:cart:tax:cost',
|
19
|
+
'shop:cart:tax:if_inclusive',
|
20
|
+
'shop:cart:tax:if_exclusive'
|
21
|
+
].sort
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'inside cart' do
|
25
|
+
before :all do
|
26
|
+
Radiant::Config['shop.tax_strategy'] = 'inclusive'
|
27
|
+
Radiant::Config['shop.tax_name'] = 'gst'
|
28
|
+
Radiant::Config['shop.tax_percentage'] = '10'
|
29
|
+
@page = pages(:home)
|
30
|
+
end
|
31
|
+
|
32
|
+
before :each do
|
33
|
+
@order = shop_orders(:several_items)
|
34
|
+
mock(Shop::Tags::Helpers).current_order(anything) { @order }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '<r:shop:cart:tax/>' do
|
38
|
+
it 'should expand' do
|
39
|
+
tag = %{<r:shop:cart:tax>success</r:shop:cart:tax>}
|
40
|
+
exp = %{success}
|
41
|
+
|
42
|
+
@page.should render(tag).as(exp)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '<r:shop:cart:tax:if_tax />' do
|
47
|
+
context 'tax configured correctly' do
|
48
|
+
context 'inclusive' do
|
49
|
+
before :each do
|
50
|
+
Radiant::Config['shop.tax_strategy'] = 'inclusive'
|
51
|
+
end
|
52
|
+
it 'should expand' do
|
53
|
+
tag = %{<r:shop:cart:tax:if_tax>success</r:shop:cart:tax:if_tax>}
|
54
|
+
exp = %{success}
|
55
|
+
|
56
|
+
@page.should render(tag).as(exp)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
context 'exclusive' do
|
60
|
+
before :each do
|
61
|
+
Radiant::Config['shop.tax_strategy'] = 'exclusive'
|
62
|
+
end
|
63
|
+
it 'should expand' do
|
64
|
+
tag = %{<r:shop:cart:tax:if_tax>success</r:shop:cart:tax:if_tax>}
|
65
|
+
exp = %{success}
|
66
|
+
|
67
|
+
@page.should render(tag).as(exp)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context 'tax not configured correctly' do
|
72
|
+
before :each do
|
73
|
+
Radiant::Config['shop.tax_strategy'] = 'failure'
|
74
|
+
end
|
75
|
+
it 'should not expand' do
|
76
|
+
tag = %{<r:shop:cart:tax:if_tax>failure</r:shop:cart:tax:if_tax>}
|
77
|
+
exp = %{}
|
78
|
+
|
79
|
+
@page.should render(tag).as(exp)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '<r:shop:cart:tax:unless_tax />' do
|
85
|
+
context 'tax configured correctly' do
|
86
|
+
context 'inclusive' do
|
87
|
+
before :each do
|
88
|
+
Radiant::Config['shop.tax_strategy'] = 'inclusive'
|
89
|
+
end
|
90
|
+
it 'should not expand' do
|
91
|
+
tag = %{<r:shop:cart:tax:unless_tax>failure</r:shop:cart:tax:unless_tax>}
|
92
|
+
exp = %{}
|
93
|
+
|
94
|
+
@page.should render(tag).as(exp)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
context 'exclusive' do
|
98
|
+
before :each do
|
99
|
+
Radiant::Config['shop.tax_strategy'] = 'exclusive'
|
100
|
+
end
|
101
|
+
it 'should not expand' do
|
102
|
+
tag = %{<r:shop:cart:tax:unless_tax>failure</r:shop:cart:tax:unless_tax>}
|
103
|
+
exp = %{}
|
104
|
+
|
105
|
+
@page.should render(tag).as(exp)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
context 'tax not configured correctly' do
|
110
|
+
before :each do
|
111
|
+
Radiant::Config['shop.tax_strategy'] = 'failure'
|
112
|
+
end
|
113
|
+
it 'should expand' do
|
114
|
+
tag = %{<r:shop:cart:tax:unless_tax>success</r:shop:cart:tax:unless_tax>}
|
115
|
+
exp = %{success}
|
116
|
+
|
117
|
+
@page.should render(tag).as(exp)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '<r:shop:cart:tax:strategy/>' do
|
123
|
+
it 'should return the tax strategy' do
|
124
|
+
tag = %{<r:shop:cart:tax:strategy/>}
|
125
|
+
exp = Radiant::Config['shop.tax_strategy']
|
126
|
+
|
127
|
+
@page.should render(tag).as(exp)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '<r:shop:cart:tax:name/>' do
|
132
|
+
it 'should return the tax name' do
|
133
|
+
tag = %{<r:shop:cart:tax:name/>}
|
134
|
+
exp = Radiant::Config['shop.tax_name']
|
135
|
+
|
136
|
+
@page.should render(tag).as(exp)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '<r:shop:cart:tax:percentage/>' do
|
141
|
+
it 'should return the tax percentage' do
|
142
|
+
tag = %{<r:shop:cart:tax:percentage/>}
|
143
|
+
exp = Radiant::Config['shop.tax_percentage']
|
144
|
+
|
145
|
+
@page.should render(tag).as(exp)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '<r:shop:cart:tax:cost/>' do
|
150
|
+
it 'should return the cost of tax on the cart' do
|
151
|
+
tag = %{<r:shop:cart:tax:cost/>}
|
152
|
+
exp = ::Shop::Tags::Helpers.currency(@order.tax)
|
153
|
+
|
154
|
+
@page.should render(tag).as(exp)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '<r:shop:cart:tax:if_inclusive/>' do
|
159
|
+
context 'is inclusive' do
|
160
|
+
it 'should expand' do
|
161
|
+
Radiant::Config['shop.tax_strategy'] = 'inclusive'
|
162
|
+
tag = %{<r:shop:cart:tax:if_inclusive>success</r:shop:cart:tax:if_inclusive>}
|
163
|
+
exp = %{success}
|
164
|
+
|
165
|
+
@page.should render(tag).as(exp)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
context 'not inclusive' do
|
169
|
+
it 'should not expand' do
|
170
|
+
Radiant::Config['shop.tax_strategy'] = 'exclusive'
|
171
|
+
tag = %{<r:shop:cart:tax:if_inclusive>failure</r:shop:cart:tax:if_inclusive>}
|
172
|
+
exp = %{}
|
173
|
+
|
174
|
+
@page.should render(tag).as(exp)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '<r:shop:cart:tax:if_exclusive/>' do
|
180
|
+
context 'is exclusive' do
|
181
|
+
it 'should expand' do
|
182
|
+
Radiant::Config['shop.tax_strategy'] = 'exclusive'
|
183
|
+
tag = %{<r:shop:cart:tax:if_exclusive>success</r:shop:cart:tax:if_exclusive>}
|
184
|
+
exp = %{success}
|
185
|
+
|
186
|
+
@page.should render(tag).as(exp)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
context 'not exclusive' do
|
190
|
+
it 'should not expand' do
|
191
|
+
Radiant::Config['shop.tax_strategy'] = 'inclusive'
|
192
|
+
tag = %{<r:shop:cart:tax:if_exclusive>failure</r:shop:cart:tax:if_exclusive>}
|
193
|
+
exp = %{}
|
194
|
+
|
195
|
+
@page.should render(tag).as(exp)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|