radiant-shop-extension 0.90.4 → 0.91.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ class AddressChanges < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :shop_addresses, :phone, :string
4
+ add_column :shop_addresses, :street_1, :string
5
+ add_column :shop_addresses, :street_2, :string
6
+ add_column :shop_addresses, :of_type, :string
7
+ add_column :shop_addresses, :addressable_id, :id
8
+ add_column :shop_addresses, :addressable_type, :string
9
+
10
+ ShopAddress.find_each do |a|
11
+ a.update_attribute(:street_1, a.street)
12
+ end
13
+
14
+ # remove_column :shop_addresses, :street
15
+ end
16
+
17
+ def self.down
18
+ add_column :shop_addresses, :street, :string
19
+
20
+ ShopAddress.find_each do |a|
21
+ a.update_attribute(:street, a.street_1)
22
+ end
23
+
24
+ # remove_column :shop_addresses, :phone
25
+ # remove_column :shop_addresses, :street_1
26
+ # remove_column :shop_addresses, :street_2
27
+ # remove_column :shop_addresses, :of_type
28
+ # remove_column :shop_addresses, :shop_addressable_id
29
+ # remove_column :shop_addresses, :shop_addressable_type
30
+ end
31
+
32
+ end
@@ -4,6 +4,8 @@ module Shop
4
4
 
5
5
  def self.included(base)
6
6
  base.class_eval do
7
+ filter_parameter_logging :password, :password_confirmation, :credit
8
+
7
9
  def current_shop_order
8
10
  return @current_shop_order if defined?(@current_shop_order)
9
11
  @current_shop_order = find_or_create_shop_order if request.session[:shop_order]
@@ -4,9 +4,9 @@ module Shop
4
4
 
5
5
  def self.included(base)
6
6
  base.class_eval do
7
- has_many :orders, :class_name => 'ShopOrder', :foreign_key => :customer_id
8
- has_many :billings, :through => :orders
9
- has_many :shippings, :through => :orders
7
+ has_one :billing, :class_name => 'ShopBilling', :as => :addressable
8
+ has_one :shipping, :class_name => 'ShopShipping', :as => :addressable
9
+ has_many :orders, :class_name => 'ShopOrder', :foreign_key => :customer_id
10
10
 
11
11
  accepts_nested_attributes_for :orders, :allow_destroy => true
12
12
  end
@@ -9,30 +9,29 @@ module Shop
9
9
 
10
10
  @type@ = (billing)|(shipping)
11
11
  }
12
- tag 'shop:cart:address' do |tag|
13
- Forms::Tags::Helpers.require!(tag,'shop:cart:address','type')
12
+ [:billing,:shipping].each do |of_type|
13
+ tag "shop:cart:#{of_type}" do |tag|
14
+ tag.locals.send(of_type, Shop::Tags::Helpers.current_address(tag,of_type))
15
+
16
+ tag.expand
17
+ end
14
18
 
15
- tag.locals.address = Shop::Tags::Helpers.current_address(tag)
16
- tag.locals.address_type = tag.attr['type']
19
+ # Expand if an address has been assigned to the order
20
+ desc %{ Expand if an address has been assigned to the order }
21
+ tag "shop:cart:#{of_type}:if_#{of_type}" do |tag|
22
+ tag.expand if tag.locals.send(of_type).present?
23
+ end
17
24
 
18
- tag.expand
19
- end
20
-
21
- # Expand if an address has been assigned to the order
22
- desc %{ Expand if an address has been assigned to the order }
23
- tag 'shop:cart:address:if_address' do |tag|
24
- tag.expand if tag.locals.address.name.present? rescue nil
25
- end
26
-
27
- # Expand if an address has not been assigned to the order
28
- desc %{ Expand if an address has not been assigned to the order }
29
- tag 'shop:cart:address:unless_address' do |tag|
30
- tag.expand unless tag.locals.address.name.present? rescue nil
31
- end
25
+ # Expand if an address has not been assigned to the order
26
+ desc %{ Expand if an address has not been assigned to the order }
27
+ tag "shop:cart:#{of_type}:unless_#{of_type}" do |tag|
28
+ tag.expand unless tag.locals.send(of_type).present?
29
+ end
32
30
 
33
- [:id, :name, :email, :unit, :street, :city, :state, :country, :postcode].each do |method|
34
- tag "shop:cart:address:#{method}" do |tag|
35
- tag.locals.address.send(method) rescue nil
31
+ [:id, :name, :phone, :email, :unit, :street_1, :street_2, :city, :state, :country, :postcode].each do |method|
32
+ tag "shop:cart:#{of_type}:#{method}" do |tag|
33
+ tag.locals.send(of_type).send(method) rescue nil # Rescue is so we can have null inputs if no address exists
34
+ end
36
35
  end
37
36
  end
38
37
 
@@ -18,7 +18,7 @@ module Shop
18
18
  # Outputs a list of credit card types
19
19
  desc %{ Outputs a list of credit card types }
20
20
  tag 'form:card:type' do |tag|
21
- content = %{<select name="card[type]" id="card_type">\n}
21
+ content = %{<select name="credit_card[type]" id="credit_card_type">\n}
22
22
  cards = {}
23
23
  cards.merge! CARD_TYPES
24
24
 
@@ -34,7 +34,7 @@ module Shop
34
34
  # Outputs a list of months for credit cards
35
35
  desc %{ Outputs a list of months for credit cards }
36
36
  tag 'form:card:month' do |tag|
37
- content = %{<select name="card[month]" id="card_month">\n}
37
+ content = %{<select name="credit_card[month]" id="credit_card_month">\n}
38
38
  Date::MONTHNAMES[1,12].each_with_index do |name,index|
39
39
  month = sprintf('%02d', index+1)
40
40
  content << %{<option value="#{month}">#{month} - #{name}</option>\n}
@@ -45,7 +45,7 @@ module Shop
45
45
  # Ouputs a list of years for credit cards
46
46
  desc %{ Ouputs a list of years for credit cards }
47
47
  tag 'form:card:year' do |tag|
48
- content = %{<select name="card[year]" id="card_year">\n}
48
+ content = %{<select name="credit_card[year]" id="credit_card_year">\n}
49
49
  (Time.new.year ... Time.new.year + 15).each do |year|
50
50
  content << %{<option value="#{year}">#{year}</option>\n}
51
51
  end
@@ -191,26 +191,32 @@ module Shop
191
191
  end
192
192
 
193
193
  # Return the current address for the current order
194
- # @tag['attr]['type'] = the address type (billing|shippin)
195
- def current_address(tag)
196
- result = nil
197
-
198
- if tag.locals.address.present? and tag.locals.address_type == tag.attr['type']
199
- result = tag.locals.address
194
+ # of_type = the address type (billing|shipping)
195
+ def current_address(tag,of_type = 'billing')
196
+ if tag.locals.send(of_type).present?
197
+ return tag.locals.send(of_type)
198
+ end
200
199
 
201
- elsif tag.locals.shop_order.present?
200
+ if tag.locals.shop_order.present?
202
201
  begin
203
- address = tag.locals.shop_order.send(tag.attr['type']) # Get the address type (order.billing)
204
- if address.present? # If that address exists
205
- result = address # The result is that address
206
- end
202
+ # Get the address type (order.billing)
203
+ address = tag.locals.shop_order.send(of_type)
204
+ return address unless address.nil?
207
205
  rescue
208
- result = nil # Will catch an incorrect address type being send
206
+ nil
209
207
  end
210
-
211
208
  end
212
209
 
213
- result
210
+ if tag.locals.user.present?
211
+ begin
212
+ address = tag.locals.user.send(of_type)
213
+ return address unless address.nil?
214
+ rescue
215
+ nil
216
+ end
217
+ end
218
+
219
+ nil
214
220
  end
215
221
 
216
222
  def currency(number,attr = {})
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{radiant-shop-extension}
8
- s.version = "0.90.4"
8
+ s.version = "0.91.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dirk Kelly", "John Barker", "Darcy Laycock"]
12
- s.date = %q{2010-11-24}
12
+ s.date = %q{2010-12-08}
13
13
  s.description = %q{Radiant Shop is an attempt at a simple but complete store. It includes Products, Categories, Orders and Credit Card Payments}
14
14
  s.email = %q{dk@dirkkelly.com}
15
15
  s.extra_rdoc_files = [
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "app/models/form_checkout.rb",
35
35
  "app/models/form_line_item.rb",
36
36
  "app/models/shop_address.rb",
37
+ "app/models/shop_billing.rb",
37
38
  "app/models/shop_category.rb",
38
39
  "app/models/shop_category_page.rb",
39
40
  "app/models/shop_customer.rb",
@@ -44,6 +45,7 @@ Gem::Specification.new do |s|
44
45
  "app/models/shop_product.rb",
45
46
  "app/models/shop_product_attachment.rb",
46
47
  "app/models/shop_product_page.rb",
48
+ "app/models/shop_shipping.rb",
47
49
  "app/views/.DS_Store",
48
50
  "app/views/admin/.DS_Store",
49
51
  "app/views/admin/shop/categories/edit.html.haml",
@@ -138,6 +140,7 @@ Gem::Specification.new do |s|
138
140
  "config/locales/en.yml",
139
141
  "config/routes.rb",
140
142
  "db/migrate/20101011063133_setup_shop.rb",
143
+ "db/migrate/20101208045754_address_changes.rb",
141
144
  "db/seed.rb",
142
145
  "db/seeds/forms.rb",
143
146
  "db/seeds/layouts.rb",
@@ -210,6 +213,7 @@ Gem::Specification.new do |s|
210
213
  "spec/models/form_address_spec.rb",
211
214
  "spec/models/form_checkout_spec.rb",
212
215
  "spec/models/shop_address_spec.rb",
216
+ "spec/models/shop_billing_spec.rb",
213
217
  "spec/models/shop_category_page_spec.rb",
214
218
  "spec/models/shop_category_spec.rb",
215
219
  "spec/models/shop_customer_spec.rb",
@@ -219,6 +223,7 @@ Gem::Specification.new do |s|
219
223
  "spec/models/shop_product_attachment_spec.rb",
220
224
  "spec/models/shop_product_page_spec.rb",
221
225
  "spec/models/shop_product_spec.rb",
226
+ "spec/models/shop_shipping_spec.rb",
222
227
  "spec/spec.opts",
223
228
  "spec/spec_helper.rb"
224
229
  ]
@@ -261,6 +266,7 @@ Gem::Specification.new do |s|
261
266
  "spec/models/form_address_spec.rb",
262
267
  "spec/models/form_checkout_spec.rb",
263
268
  "spec/models/shop_address_spec.rb",
269
+ "spec/models/shop_billing_spec.rb",
264
270
  "spec/models/shop_category_page_spec.rb",
265
271
  "spec/models/shop_category_spec.rb",
266
272
  "spec/models/shop_customer_spec.rb",
@@ -270,6 +276,7 @@ Gem::Specification.new do |s|
270
276
  "spec/models/shop_product_attachment_spec.rb",
271
277
  "spec/models/shop_product_page_spec.rb",
272
278
  "spec/models/shop_product_spec.rb",
279
+ "spec/models/shop_shipping_spec.rb",
273
280
  "spec/spec_helper.rb"
274
281
  ]
275
282
 
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + "/../../../spec_helper"
2
2
 
3
3
  describe Admin::Shop::OrdersController do
4
4
 
5
- dataset :shop_orders, :users
5
+ dataset :shop_orders, :shop_addresses, :users
6
6
 
7
7
  before(:each) do
8
8
  login_as :admin
@@ -21,7 +21,7 @@ class FormsDataset < Dataset::Base
21
21
  </li>
22
22
  <li>
23
23
  <r:label for='billing[unit]'>Address</r:label>
24
- <r:text name='billing[unit]' /> <r:text name='billing[street]' /> <r:text name='billing[suburb]' />
24
+ <r:text name='billing[unit]' /> <r:text name='billing[street_1]' /> <r:text name='billing[suburb]' />
25
25
  </li>
26
26
  <li>
27
27
  <r:label for='billing[state]'>State and Country</r:label>
@@ -33,14 +33,14 @@ class FormsDataset < Dataset::Base
33
33
  </li>
34
34
  </ol>
35
35
  </div>
36
- <ol class="card">
36
+ <ol class="credit_card">
37
37
  <li>
38
- <r:label for='card[name]'>Name on Card</r:label>
39
- <r:text name='card[name]' />
38
+ <r:label for='credit_card[name]'>Name on Card</r:label>
39
+ <r:text name='credit_card[name]' />
40
40
  </li>
41
41
  <li>
42
- <r:label for='card[number]'>Card</r:label>
43
- <r:card:type /> <r:text name='card[number]' /> <r:text name='card[verification]' length='4' />
42
+ <r:label for='credit_card[number]'>Card</r:label>
43
+ <r:card:type /> <r:text name='credit_card[number]' /> <r:text name='credit_card[verification]' length='4' />
44
44
  <r:card:month /> <r:card:year />
45
45
  </li>
46
46
  </ol>
@@ -109,7 +109,7 @@ CONFIG
109
109
  }
110
110
 
111
111
  @data = {
112
- :card => {
112
+ :credit_card => {
113
113
  :number => '1',
114
114
  :name => 'Mr. Joe Bloggs',
115
115
  :verification => '123',
@@ -141,24 +141,26 @@ CONFIG
141
141
 
142
142
  @data = {
143
143
  :billing => {
144
- :id => shop_addresses(:billing).id,
145
- :name => shop_addresses(:billing).name,
146
- :email => shop_addresses(:billing).email,
147
- :street => shop_addresses(:billing).street,
148
- :city => shop_addresses(:billing).city,
149
- :state => shop_addresses(:billing).state,
150
- :country => shop_addresses(:billing).country,
151
- :postcode => shop_addresses(:billing).postcode
144
+ :id => shop_billings(:order_billing).id,
145
+ :name => shop_billings(:order_billing).name,
146
+ :phone => shop_billings(:order_billing).phone,
147
+ :email => shop_billings(:order_billing).email,
148
+ :street_1 => shop_billings(:order_billing).street_1,
149
+ :city => shop_billings(:order_billing).city,
150
+ :state => shop_billings(:order_billing).state,
151
+ :country => shop_billings(:order_billing).country,
152
+ :postcode => shop_billings(:order_billing).postcode
152
153
  },
153
154
  :shipping => {
154
- :id => shop_addresses(:shipping).id,
155
- :name => shop_addresses(:shipping).name,
156
- :email => shop_addresses(:shipping).email,
157
- :street => shop_addresses(:shipping).street,
158
- :city => shop_addresses(:shipping).city,
159
- :state => shop_addresses(:shipping).state,
160
- :country => shop_addresses(:shipping).country,
161
- :postcode => shop_addresses(:shipping).postcode
155
+ :id => shop_shippings(:order_shipping).id,
156
+ :name => shop_shippings(:order_shipping).name,
157
+ :phone => shop_shippings(:order_shipping).phone,
158
+ :email => shop_shippings(:order_shipping).email,
159
+ :street_1 => shop_shippings(:order_shipping).street_1,
160
+ :city => shop_shippings(:order_shipping).city,
161
+ :state => shop_shippings(:order_shipping).state,
162
+ :country => shop_shippings(:order_shipping).country,
163
+ :postcode => shop_shippings(:order_shipping).postcode
162
164
  }
163
165
  }
164
166
 
@@ -1,24 +1,36 @@
1
1
  class ShopAddressesDataset < Dataset::Base
2
+
3
+ uses :shop_orders
4
+
2
5
  def load
3
- # TODO Investigate why inflectors are breaking here
4
- create_record :shop_addresss, :billing,
5
- :name => 'Billing Address',
6
- :email => 'billing@address.com',
7
- :unit => 'a',
8
- :street => '1 Bill Street',
9
- :city => 'Billvilles',
10
- :state => 'BI',
11
- :country=> 'Billington',
12
- :postcode=> '1234'
6
+ create_record :shop_billing, :order_billing,
7
+ :name => 'Billing Address',
8
+ :phone => '1800 000 000',
9
+ :email => 'billing@billing.com',
10
+ :unit => 'a',
11
+ :street_1 => '1 Bill Street',
12
+ :street_2 => 'Street Bill 1',
13
+ :city => 'Billvilles',
14
+ :state => 'BI',
15
+ :country => 'Billington',
16
+ :of_type => 'billing',
17
+ :postcode => '1234',
18
+ :addressable_id => shop_orders(:several_items).id,
19
+ :addressable_type => 'ShopOrder'
13
20
 
14
- create_record :shop_addresss, :shipping,
15
- :name => 'Shipping Address',
16
- :email => 'shipping@address.com',
17
- :unit => 'b',
18
- :street => '2 Ship Street',
19
- :city => 'Shipvilles',
20
- :state => 'SH',
21
- :country=> 'Shippington',
22
- :postcode=> '1234'
21
+ create_record :shop_shipping, :order_shipping,
22
+ :name => 'Shipping Address',
23
+ :phone => '1800 000 000',
24
+ :email => 'shipping@shipping.com',
25
+ :unit => 'b',
26
+ :street_1 => '2 Ship Street',
27
+ :street_2 => 'Street Ship 2',
28
+ :city => 'Shipvilles',
29
+ :state => 'SH',
30
+ :country => 'Shippington',
31
+ :of_type => 'shipping',
32
+ :postcode => '1234',
33
+ :addressable_id => shop_orders(:several_items).id,
34
+ :addressable_type => 'ShopOrder'
23
35
  end
24
36
  end
@@ -1,16 +1,14 @@
1
1
  class ShopOrdersDataset < Dataset::Base
2
2
 
3
- uses :shop_products, :shop_customers, :shop_addresses
3
+ uses :shop_products, :shop_customers
4
4
 
5
5
  def load
6
6
  create_record :shop_order, :empty
7
7
 
8
8
  create_record :shop_order, :one_item,
9
- :customer => shop_customers(:customer)
9
+ :customer => shop_customers(:customer)
10
10
 
11
11
  create_record :shop_order, :several_items,
12
- :customer => shop_customers(:customer),
13
- :billing => shop_addresses(:billing),
14
- :shipping => shop_addresses(:shipping)
12
+ :customer => shop_customers(:customer)
15
13
  end
16
14
  end
@@ -9,18 +9,34 @@ describe Shop::Tags::Address do
9
9
 
10
10
  it 'should describe these tags' do
11
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',
12
+ 'shop:cart:billing',
13
+ 'shop:cart:billing:if_billing',
14
+ 'shop:cart:billing:unless_billing',
15
+ 'shop:cart:billing:id',
16
+ 'shop:cart:billing:name',
17
+ 'shop:cart:billing:phone',
18
+ 'shop:cart:billing:email',
19
+ 'shop:cart:billing:unit',
20
+ 'shop:cart:billing:street_1',
21
+ 'shop:cart:billing:street_2',
22
+ 'shop:cart:billing:city',
23
+ 'shop:cart:billing:state',
24
+ 'shop:cart:billing:country',
25
+ 'shop:cart:billing:postcode',
26
+ 'shop:cart:shipping',
27
+ 'shop:cart:shipping:if_shipping',
28
+ 'shop:cart:shipping:unless_shipping',
29
+ 'shop:cart:shipping:id',
30
+ 'shop:cart:shipping:name',
31
+ 'shop:cart:shipping:phone',
32
+ 'shop:cart:shipping:email',
33
+ 'shop:cart:shipping:unit',
34
+ 'shop:cart:shipping:street_1',
35
+ 'shop:cart:shipping:street_2',
36
+ 'shop:cart:shipping:city',
37
+ 'shop:cart:shipping:state',
38
+ 'shop:cart:shipping:country',
39
+ 'shop:cart:shipping:postcode',
24
40
  ].sort
25
41
  end
26
42
 
@@ -31,28 +47,47 @@ describe Shop::Tags::Address do
31
47
 
32
48
  before :each do
33
49
  @order = shop_orders(:several_items)
34
- @billing = shop_addresses(:billing)
50
+ @billing = shop_billings(:order_billing)
35
51
  mock(Shop::Tags::Helpers).current_order(anything) { @order }
36
52
  end
37
53
 
38
- describe 'shop:cart:address:if_address' do
54
+ describe 'shop:cart:billing:if_billing' do
39
55
  context 'success' do
56
+ it 'should expand' do
57
+ tag = %{<r:shop:cart:billing:if_billing>success</r:shop:cart:billing:if_billing>}
58
+ exp = %{success}
59
+
60
+ @page.should render(tag).as(exp)
61
+ end
62
+ end
63
+ context 'failure' do
40
64
  before :each do
41
- mock(Shop::Tags::Helpers).current_address(anything) { @billing }
65
+ mock(@order).billing { nil }
42
66
  end
67
+ it 'should not expand' do
68
+ tag = %{<r:shop:cart:billing:if_billing>failure</r:shop:cart:billing:if_billing>}
69
+ exp = %{}
70
+
71
+ @page.should render(tag).as(exp)
72
+ end
73
+ end
74
+ end
75
+
76
+ describe 'shop:cart:shipping:if_shipping' do
77
+ context 'success' do
43
78
  it 'should expand' do
44
- tag = %{<r:shop:cart:address type='billing'><r:if_address>success</r:if_address></r:shop:cart:address>}
79
+ tag = %{<r:shop:cart:shipping:if_shipping>success</r:shop:cart:shipping:if_shipping>}
45
80
  exp = %{success}
46
81
 
47
82
  @page.should render(tag).as(exp)
48
83
  end
49
84
  end
50
- context 'failure' do
85
+ context 'failure' do
51
86
  before :each do
52
- mock(Shop::Tags::Helpers).current_address(anything) { nil }
87
+ mock(@order).shipping { nil }
53
88
  end
54
89
  it 'should not expand' do
55
- tag = %{<r:shop:cart:address type='billing'><r:if_address>failure</r:if_address></r:shop:cart:address>}
90
+ tag = %{<r:shop:cart:shipping:if_shipping>failure</r:shop:cart:shipping:if_shipping>}
56
91
  exp = %{}
57
92
 
58
93
  @page.should render(tag).as(exp)
@@ -60,28 +95,43 @@ describe Shop::Tags::Address do
60
95
  end
61
96
  end
62
97
 
63
- describe 'shop:cart:address:unless_address' do
98
+ describe 'shop:cart:billing:unless_billing' do
64
99
  context 'success' do
65
100
  before :each do
66
- mock(Shop::Tags::Helpers).current_address(anything) { @billing }
101
+ mock(@order).shipping { nil }
67
102
  end
68
103
  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 = %{}
104
+ tag = %{<r:shop:cart:shipping:unless_shipping>success</r:shop:cart:shipping:unless_shipping>}
105
+ exp = %{success}
73
106
 
74
107
  @page.should render(tag).as(exp)
75
108
  end
76
109
  end
77
110
  context 'failure' do
111
+ it 'should not expand' do
112
+ tag = %{<r:shop:cart:shipping:unless_shipping>failure</r:shop:cart:shipping:unless_shipping>}
113
+ exp = %{}
114
+
115
+ @page.should render(tag).as(exp)
116
+ end
117
+ end
118
+ end
119
+
120
+ describe 'shop:cart:shipping:unless_shipping' do
121
+ context 'success' do
78
122
  before :each do
79
- mock(Shop::Tags::Helpers).current_address(anything) { nil }
123
+ mock(@order).shipping { nil }
80
124
  end
81
- it 'should not expand' do
82
- stub(@order).billing { nil }
125
+ it 'should expand' do
126
+ tag = %{<r:shop:cart:shipping:unless_shipping>success</r:shop:cart:shipping:unless_shipping>}
127
+ exp = %{success}
83
128
 
84
- tag = %{<r:shop:cart:address type='billing'><r:unless_address>failure</r:unless_address></r:shop:cart:address>}
129
+ @page.should render(tag).as(exp)
130
+ end
131
+ end
132
+ context 'failure' do
133
+ it 'should not expand' do
134
+ tag = %{<r:shop:cart:shipping:unless_shipping>failure</r:shop:cart:shipping:unless_shipping>}
85
135
  exp = %{}
86
136
 
87
137
  @page.should render(tag).as(exp)
@@ -89,24 +139,21 @@ describe Shop::Tags::Address do
89
139
  end
90
140
  end
91
141
 
92
- describe 'shop:address' do
93
- context 'no address' do
142
+ describe 'shop:billing' do
143
+ context 'billing doesnt exist' do
94
144
  before :each do
95
- mock(Shop::Tags::Helpers).current_address(anything) { @billing }
145
+ mock(@order).billing { nil }
96
146
  end
97
147
  it 'should expand' do
98
- tag = %{<r:shop:cart:address type='billing'>success</r:shop:cart:address>}
148
+ tag = %{<r:shop:cart:billing>success</r:shop:cart:billing>}
99
149
  exp = %{success}
100
150
 
101
151
  @page.should render(tag).as(exp)
102
152
  end
103
153
  end
104
- context 'address' do
105
- before :each do
106
- mock(Shop::Tags::Helpers).current_address(anything) { nil }
107
- end
154
+ context 'billing exists' do
108
155
  it 'should expand' do
109
- tag = %{<r:shop:cart:address type='billing'>success</r:shop:cart:address>}
156
+ tag = %{<r:shop:cart:billing>success</r:shop:cart:billing>}
110
157
  exp = %{success}
111
158
 
112
159
  @page.should render(tag).as(exp)
@@ -115,76 +162,89 @@ describe Shop::Tags::Address do
115
162
  end
116
163
 
117
164
  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
165
+ context 'shop:cart:billing:id' do
122
166
  it 'should return the id' do
123
- tag = %{<r:shop:cart:address type='billing'><r:id /></r:shop:cart:address>}
167
+ tag = %{<r:shop:cart:billing><r:id /></r:shop:cart:billing>}
124
168
  exp = @billing.id.to_s
125
169
 
126
170
  @page.should render(tag).as(exp)
127
171
  end
128
172
  end
129
- context 'shop:cart:address:name' do
173
+ context 'shop:cart:billing:name' do
130
174
  it 'should return the name' do
131
- tag = %{<r:shop:cart:address type='billing'><r:name /></r:shop:cart:address>}
175
+ tag = %{<r:shop:cart:billing><r:name /></r:shop:cart:billing>}
132
176
  exp = @billing.name
133
177
 
134
178
  @page.should render(tag).as(exp)
135
179
  end
136
180
  end
137
- context 'shop:cart:address:email' do
181
+ context 'shop:cart:billing:phone' do
182
+ it 'should return the phone' do
183
+ tag = %{<r:shop:cart:billing><r:phone /></r:shop:cart:billing>}
184
+ exp = @billing.phone
185
+
186
+ @page.should render(tag).as(exp)
187
+ end
188
+ end
189
+ context 'shop:cart:billing:email' do
138
190
  it 'should return the email' do
139
- tag = %{<r:shop:cart:address type='billing'><r:email /></r:shop:cart:address>}
191
+ tag = %{<r:shop:cart:billing><r:email /></r:shop:cart:billing>}
140
192
  exp = @billing.email
141
193
 
142
194
  @page.should render(tag).as(exp)
143
195
  end
144
196
  end
145
- context 'shop:cart:address:unit' do
197
+ context 'shop:cart:billing:unit' do
146
198
  it 'should return the unit' do
147
- tag = %{<r:shop:cart:address type='billing'><r:unit /></r:shop:cart:address>}
199
+ tag = %{<r:shop:cart:billing><r:unit /></r:shop:cart:billing>}
148
200
  exp = @billing.unit
149
201
 
150
202
  @page.should render(tag).as(exp)
151
203
  end
152
204
  end
153
- context 'shop:cart:address:street' do
205
+ context 'shop:cart:billing:street_1' do
206
+ it 'should return the street' do
207
+ tag = %{<r:shop:cart:billing><r:street_1 /></r:shop:cart:billing>}
208
+ exp = @billing.street_1
209
+
210
+ @page.should render(tag).as(exp)
211
+ end
212
+ end
213
+ context 'shop:cart:billing:street_2' do
154
214
  it 'should return the street' do
155
- tag = %{<r:shop:cart:address type='billing'><r:street /></r:shop:cart:address>}
156
- exp = @billing.street
215
+ tag = %{<r:shop:cart:billing><r:street_2 /></r:shop:cart:billing>}
216
+ exp = @billing.street_2
157
217
 
158
218
  @page.should render(tag).as(exp)
159
219
  end
160
220
  end
161
- context 'shop:cart:address:city' do
221
+ context 'shop:cart:billing:city' do
162
222
  it 'should return the city' do
163
- tag = %{<r:shop:cart:address type='billing'><r:city /></r:shop:cart:address>}
223
+ tag = %{<r:shop:cart:billing><r:city /></r:shop:cart:billing>}
164
224
  exp = @billing.city
165
225
 
166
226
  @page.should render(tag).as(exp)
167
227
  end
168
228
  end
169
- context 'shop:cart:address:state' do
229
+ context 'shop:cart:billing:state' do
170
230
  it 'should return the city' do
171
- tag = %{<r:shop:cart:address type='billing'><r:state /></r:shop:cart:address>}
231
+ tag = %{<r:shop:cart:billing><r:state /></r:shop:cart:billing>}
172
232
  exp = @billing.state
173
233
 
174
234
  @page.should render(tag).as(exp)
175
235
  end
176
236
  end
177
- context 'shop:cart:address:country' do
237
+ context 'shop:cart:billing:country' do
178
238
  it 'should return the country' do
179
- tag = %{<r:shop:cart:address type='billing'><r:country /></r:shop:cart:address>}
239
+ tag = %{<r:shop:cart:billing><r:country /></r:shop:cart:billing>}
180
240
  exp = @billing.country
181
241
 
182
242
  @page.should render(tag).as(exp)
183
243
  end
184
244
  end
185
- context 'shop:cart:address:postcode' do
245
+ context 'shop:cart:billing:postcode' do
186
246
  it 'should return the postcode' do
187
- tag = %{<r:shop:cart:address type='billing'><r:postcode /></r:shop:cart:address>}
247
+ tag = %{<r:shop:cart:billing><r:postcode /></r:shop:cart:billing>}
188
248
  exp = @billing.postcode
189
249
 
190
250
  @page.should render(tag).as(exp)