vizjerai-google-checkout 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +14 -0
- data/MIT-LICENSE.txt +23 -0
- data/README.txt +143 -0
- data/Rakefile +34 -0
- data/VERSION.yml +4 -0
- data/examples/google_notifications_controller.rb +159 -0
- data/lib/duck_punches/hpricot.rb +24 -0
- data/lib/google-checkout/cart.rb +304 -0
- data/lib/google-checkout/command.rb +255 -0
- data/lib/google-checkout/geography/area.rb +11 -0
- data/lib/google-checkout/geography/postal.rb +26 -0
- data/lib/google-checkout/geography/us_country.rb +24 -0
- data/lib/google-checkout/geography/us_state.rb +22 -0
- data/lib/google-checkout/geography/us_zip.rb +22 -0
- data/lib/google-checkout/geography/world.rb +12 -0
- data/lib/google-checkout/geography.rb +7 -0
- data/lib/google-checkout/merchant_calculation.rb +30 -0
- data/lib/google-checkout/notification.rb +352 -0
- data/lib/google-checkout/shipping/filters.rb +32 -0
- data/lib/google-checkout/shipping/flat_rate.rb +26 -0
- data/lib/google-checkout/shipping/merchant_calculated.rb +29 -0
- data/lib/google-checkout/shipping/method.rb +11 -0
- data/lib/google-checkout/shipping/pickup.rb +22 -0
- data/lib/google-checkout/shipping/restrictions.rb +32 -0
- data/lib/google-checkout/shipping.rb +8 -0
- data/lib/google-checkout.rb +65 -0
- data/spec/fixtures/google/checkout-shopping-cart.xml +22 -0
- data/spec/fixtures/google/commands/add-merchant-order-number.xml +5 -0
- data/spec/fixtures/google/commands/add-tracking-data.xml +8 -0
- data/spec/fixtures/google/commands/archive-order.xml +3 -0
- data/spec/fixtures/google/commands/authorize-order.xml +2 -0
- data/spec/fixtures/google/commands/cancel-order.xml +5 -0
- data/spec/fixtures/google/commands/charge-order.xml +4 -0
- data/spec/fixtures/google/commands/deliver-order.xml +9 -0
- data/spec/fixtures/google/commands/process-order.xml +2 -0
- data/spec/fixtures/google/commands/refund-order.xml +6 -0
- data/spec/fixtures/google/commands/send-buyer-message.xml +7 -0
- data/spec/fixtures/google/commands/unarchive-order.xml +2 -0
- data/spec/fixtures/google/merchant_calculations/shipping.xml +40 -0
- data/spec/fixtures/google/notifications/authorization-amount-notification.xml +10 -0
- data/spec/fixtures/google/notifications/charge-amount-notification.xml +8 -0
- data/spec/fixtures/google/notifications/chargeback-amount-notification.xml +8 -0
- data/spec/fixtures/google/notifications/new-order-notification.xml +94 -0
- data/spec/fixtures/google/notifications/order-state-change-notification.xml +11 -0
- data/spec/fixtures/google/notifications/refund-amount-notification.xml +8 -0
- data/spec/fixtures/google/notifications/risk-information-notification.xml +23 -0
- data/spec/fixtures/google/responses/checkout-redirect.xml +5 -0
- data/spec/fixtures/google/responses/error-charged.xml +5 -0
- data/spec/fixtures/google/responses/error.xml +5 -0
- data/spec/fixtures/google/responses/request-received.xml +3 -0
- data/spec/google-checkout/cart_spec.rb +110 -0
- data/spec/google-checkout/command_spec.rb +216 -0
- data/spec/google-checkout/geography/postal_spec.rb +26 -0
- data/spec/google-checkout/geography/us_country_spec.rb +26 -0
- data/spec/google-checkout/geography/us_state_spec.rb +11 -0
- data/spec/google-checkout/geography/us_zip_spec.rb +11 -0
- data/spec/google-checkout/geography/world_spec.rb +12 -0
- data/spec/google-checkout/merchant_calculation_spec.rb +17 -0
- data/spec/google-checkout/notification_spec.rb +253 -0
- data/spec/google-checkout/response_spec.rb +49 -0
- data/spec/google-checkout/shipping/flat_rate_spec.rb +46 -0
- data/spec/google-checkout/shipping/merchant_calculated_spec.rb +70 -0
- data/spec/google-checkout/shipping/pickup_spec.rb +22 -0
- data/spec/google-checkout_spec.rb +15 -0
- data/spec/spec_helper.rb +47 -0
- data/support/cacert.pem +7815 -0
- metadata +145 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout::Geography::UsZip do
|
4
|
+
before(:each) do
|
5
|
+
@area = GoogleCheckout::Geography::UsZip.new('53*')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should generate the us zip area tag' do
|
9
|
+
@area.to_xml.should match(%r{<us-zip-area>.*</us-zip-area>})
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout::Geography::World do
|
4
|
+
before(:each) do
|
5
|
+
@area = GoogleCheckout::Geography::World.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should generate a self closing world tag' do
|
9
|
+
@area.to_xml.should eql("<world-area/>")
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout, "Merchant Calculation" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@calculation = GoogleCheckout::MerchantCalculation.parse(read_xml_fixture('merchant_calculations/shipping'))
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should find buyer language" do
|
10
|
+
@calculation.buyer_language.should == 'en_US'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should find the address id" do
|
14
|
+
@calculation.address_id.should == "739030698069958"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe "basic notification", :shared => true do
|
4
|
+
|
5
|
+
it "should get serial number" do
|
6
|
+
@notification.serial_number.should == 'bea6bc1b-e1e2-44fe-80ff-0180e33a2614'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should get google order number" do
|
10
|
+
@notification.google_order_number.should == '841171949013218'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should generate acknowledgment XML" do
|
14
|
+
@notification.acknowledgment_xml.should match(/notification-acknowledgment/)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe GoogleCheckout, "New Order Notification" do
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
@notification = GoogleCheckout::Notification.parse(read_xml_fixture('notifications/new-order-notification'))
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should identify type of notification" do
|
26
|
+
@notification.should be_kind_of(GoogleCheckout::NewOrderNotification)
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like "basic notification"
|
30
|
+
|
31
|
+
it "should find fulfillment order state" do
|
32
|
+
@notification.fulfillment_order_state.should == 'NEW'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should find financial order state" do
|
36
|
+
@notification.financial_order_state.should == 'REVIEWING'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use financial state shortcut" do
|
40
|
+
@notification.state.should == "REVIEWING"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should create Money object from order total" do
|
44
|
+
@notification.order_total.should be_kind_of(Money)
|
45
|
+
@notification.order_total.cents.should == 19098
|
46
|
+
@notification.order_total.currency.should == 'USD'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should throw error when accessing non-existent value" do
|
50
|
+
lambda { @notification.there_is_no_field_with_this_name }.should raise_error(NoMethodError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should find sub-keys of merchant-private-data as if they were at the root" do
|
54
|
+
@notification.peepcode_order_number.should == '1234-5678-9012'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should find total tax" do
|
58
|
+
@notification.total_tax.should be_kind_of(Money)
|
59
|
+
@notification.total_tax.cents.should == 0
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should find email marketing allowed" do
|
63
|
+
@notification.email_allowed.should be_false
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should get buyer-billing-address/contact-name" do
|
67
|
+
@notification.billing_name.should == 'Bill Hu'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should get buyer-billing-address/email" do
|
71
|
+
@notification.billing_email.should == 'billhu@example.com'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should get buyer-billing-address/address1" do
|
75
|
+
@notification.billing_address1.should == '99 Credit Lane'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should get buyer-billing-address/city" do
|
79
|
+
@notification.billing_city.should == 'Mountain View'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should get buyer-billing-address/region" do
|
83
|
+
@notification.billing_region.should == 'CA'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should get buyer-billing-address/postal-code" do
|
87
|
+
@notification.billing_postal_code.should == '94043'
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should get buyer-billing-address/country-code" do
|
91
|
+
@notification.billing_country_code.should == 'US'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should get buyer-billing-address/phone" do
|
95
|
+
@notification.billing_phone.should == '5555557890'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should get buyer-billing-address/structured-name/first-name" do
|
99
|
+
@notification.billing_first_name.should == 'Bill'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should get buyer-billing-address/structured-name/last-name" do
|
103
|
+
@notification.billing_last_name.should == 'Hu'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should get buyer-shipping-address/contact-name" do
|
107
|
+
@notification.shipping_name.should == 'John Smith'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should get buyer-shipping-address/email" do
|
111
|
+
@notification.shipping_email.should == 'johnsmith@example.com'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should get buyer-shipping-address/address1" do
|
115
|
+
@notification.shipping_address1.should == '10 Example Road'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should get buyer-shipping-address/city" do
|
119
|
+
@notification.shipping_city.should == 'Sampleville'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should get buyer-shipping-address/region" do
|
123
|
+
@notification.shipping_region.should == 'CA'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should get buyer-shipping-address/postal-code" do
|
127
|
+
@notification.shipping_postal_code.should == '94141'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should get buyer-shipping-address/country-code" do
|
131
|
+
@notification.shipping_country_code.should == 'US'
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should get buyer-shipping-address/phone" do
|
135
|
+
@notification.shipping_phone.should == '5555551234'
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should get buyer-shipping-address/structured-name/first-name" do
|
139
|
+
@notification.shipping_first_name.should == 'John'
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should get buyer-shipping-address/structured-name/last-name" do
|
143
|
+
@notification.shipping_last_name.should == 'Smith'
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
describe GoogleCheckout, "Order State Change Notification" do
|
150
|
+
|
151
|
+
before(:each) do
|
152
|
+
@notification = GoogleCheckout::Notification.parse(read_xml_fixture('notifications/order-state-change-notification'))
|
153
|
+
end
|
154
|
+
|
155
|
+
it_should_behave_like "basic notification"
|
156
|
+
|
157
|
+
it "should identify type of notification" do
|
158
|
+
@notification.should be_kind_of(GoogleCheckout::OrderStateChangeNotification)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should find new financial state" do
|
162
|
+
@notification.new_financial_order_state.should == 'CHARGING'
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should find new fulfillment state" do
|
166
|
+
@notification.new_fulfillment_order_state.should == 'NEW'
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should use financial state shortcut" do
|
170
|
+
@notification.state.should == 'CHARGING'
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
describe GoogleCheckout, "Risk Information Notification" do
|
176
|
+
|
177
|
+
before(:each) do
|
178
|
+
@notification = GoogleCheckout::Notification.parse(read_xml_fixture('notifications/risk-information-notification'))
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should identify type of notification" do
|
182
|
+
@notification.should be_kind_of(GoogleCheckout::RiskInformationNotification)
|
183
|
+
end
|
184
|
+
|
185
|
+
it_should_behave_like "basic notification"
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
describe GoogleCheckout, "Charge Amount Notification" do
|
190
|
+
|
191
|
+
before(:each) do
|
192
|
+
@notification = GoogleCheckout::Notification.parse(read_xml_fixture('notifications/charge-amount-notification'))
|
193
|
+
end
|
194
|
+
|
195
|
+
it_should_behave_like "basic notification"
|
196
|
+
|
197
|
+
it "should identify type of notification" do
|
198
|
+
@notification.should be_kind_of(GoogleCheckout::ChargeAmountNotification)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should get latest charge amount" do
|
202
|
+
@notification.latest_charge_amount.should be_kind_of(Money)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should get total charge amount" do
|
206
|
+
@notification.total_charge_amount.should be_kind_of(Money)
|
207
|
+
@notification.total_charge_amount.cents.should == 22606
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
describe GoogleCheckout, "Authorization Amount Notification" do
|
213
|
+
|
214
|
+
before(:each) do
|
215
|
+
@notification = GoogleCheckout::Notification.parse(read_xml_fixture('notifications/authorization-amount-notification'))
|
216
|
+
end
|
217
|
+
|
218
|
+
it_should_behave_like "basic notification"
|
219
|
+
|
220
|
+
it "should identify type of notification" do
|
221
|
+
@notification.should be_kind_of(GoogleCheckout::AuthorizationAmountNotification)
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
describe GoogleCheckout, "Chargeback Amount Notification" do
|
227
|
+
|
228
|
+
before(:each) do
|
229
|
+
@notification = GoogleCheckout::Notification.parse(read_xml_fixture('notifications/chargeback-amount-notification'))
|
230
|
+
end
|
231
|
+
|
232
|
+
it_should_behave_like "basic notification"
|
233
|
+
|
234
|
+
it "should identify type of notification" do
|
235
|
+
@notification.should be_kind_of(GoogleCheckout::ChargebackAmountNotification)
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
describe GoogleCheckout, "Refund Amount Notification" do
|
241
|
+
|
242
|
+
before(:each) do
|
243
|
+
@notification = GoogleCheckout::Notification.parse(read_xml_fixture('notifications/refund-amount-notification'))
|
244
|
+
end
|
245
|
+
|
246
|
+
it_should_behave_like "basic notification"
|
247
|
+
|
248
|
+
it "should identify type of notification" do
|
249
|
+
@notification.should be_kind_of(GoogleCheckout::RefundAmountNotification)
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
# Responses
|
4
|
+
|
5
|
+
describe GoogleCheckout, "Checkout Redirect" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@response = GoogleCheckout::Notification.parse(read_xml_fixture('responses/checkout-redirect'))
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should identify type of notification" do
|
12
|
+
@response.should be_kind_of(GoogleCheckout::CheckoutRedirect)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should unescape url" do
|
16
|
+
@response.redirect_url.should == 'https://checkout.google.com/buy?foo=bar&id=8572098456'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe GoogleCheckout, "Request Received" do
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
@response = GoogleCheckout::Notification.parse(read_xml_fixture('responses/request-received'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should identify type of notification" do
|
28
|
+
@response.should be_kind_of(GoogleCheckout::RequestReceived)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
# Errors
|
34
|
+
|
35
|
+
describe GoogleCheckout, "Error" do
|
36
|
+
|
37
|
+
before(:each) do
|
38
|
+
@response = GoogleCheckout::Notification.parse(read_xml_fixture('responses/error'))
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should identify type of notification" do
|
42
|
+
@response.should be_kind_of(GoogleCheckout::Error)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should read error message" do
|
46
|
+
@response.message.should == 'Bad username and/or password for API Access.'
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout::Shipping::FlatRate do
|
4
|
+
before(:each) do
|
5
|
+
@shipping = GoogleCheckout::Shipping::FlatRate.new('UPS Ground', '10.00')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should include the name in the generated xml' do
|
9
|
+
@shipping.to_xml.should match(%r{<flat-rate-shipping name="UPS Ground">})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should include the price in the generated xml' do
|
13
|
+
@shipping.price = '1.00'
|
14
|
+
@shipping.to_xml.should match(%r{<price .*>1.00</price>})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should include the currency in the generated xml' do
|
18
|
+
@shipping.currency = 'CAD'
|
19
|
+
@shipping.to_xml.should match(%r{<price currency="CAD">})
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should generate the shipping-restrictions tag if they are set' do
|
23
|
+
@shipping.shipping_restrictions[:allowed] << GoogleCheckout::Geography::UsState.new('WI')
|
24
|
+
@shipping.to_xml.should match(%r{<shipping-restrictions>.*</shipping-restrictions>})
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should not generate the shipping-restrictions tag if they are not set' do
|
28
|
+
@shipping.to_xml.should_not match(%r{<shipping-restrictions>.*</shipping-restrictions>})
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should include the allowed areas in the generated xml' do
|
32
|
+
@shipping.shipping_restrictions[:allowed] << GoogleCheckout::Geography::UsState.new('WI')
|
33
|
+
@shipping.to_xml.should match(%r{<allowed-areas>.*</allowed-areas>})
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should include the excluded areas in the generated xml' do
|
37
|
+
@shipping.shipping_restrictions[:excluded] << GoogleCheckout::Geography::UsState.new('WI')
|
38
|
+
@shipping.to_xml.should match(%r{<excluded-areas>.*</excluded-areas>})
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should include the all us po box in the generated xml' do
|
42
|
+
@shipping.shipping_restrictions[:allow_us_po_box] = false
|
43
|
+
@shipping.to_xml.should match(%r{<allow-us-po-box>false</allow-us-po-box>})
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout::Shipping::FlatRate do
|
4
|
+
before(:each) do
|
5
|
+
@shipping = GoogleCheckout::Shipping::MerchantCalculated.new('UPS Ground', '10.00')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should include the name in the generated xml' do
|
9
|
+
@shipping.to_xml.should match(%r{<merchant-calculated-shipping name="UPS Ground">})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should include the price in the generated xml' do
|
13
|
+
@shipping.price = '1.00'
|
14
|
+
@shipping.to_xml.should match(%r{<price .*>1.00</price>})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should include the currency in the generated xml' do
|
18
|
+
@shipping.currency = 'CAD'
|
19
|
+
@shipping.to_xml.should match(%r{<price currency="CAD">})
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should generate the shipping-restrictions tag if they are set' do
|
23
|
+
@shipping.shipping_restrictions[:allowed] << GoogleCheckout::Geography::UsState.new('WI')
|
24
|
+
@shipping.to_xml.should match(%r{<shipping-restrictions>.*</shipping-restrictions>})
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should not generate the shipping-restrictions tag if they are not set' do
|
28
|
+
@shipping.to_xml.should_not match(%r{<shipping-restrictions>.*</shipping-restrictions>})
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should include the shipping-restrictions allowed areas in the generated xml' do
|
32
|
+
@shipping.shipping_restrictions[:allowed] << GoogleCheckout::Geography::UsState.new('WI')
|
33
|
+
@shipping.to_xml.should match(%r{<shipping-restrictions>.*<allowed-areas>.*</allowed-areas>.*</shipping-restrictions>})
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should include the shipping-restrictions excluded areas in the generated xml' do
|
37
|
+
@shipping.shipping_restrictions[:excluded] << GoogleCheckout::Geography::UsState.new('WI')
|
38
|
+
@shipping.to_xml.should match(%r{<shipping-restrictions>.*<excluded-areas>.*</excluded-areas>.*</shipping-restrictions>})
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should include the shipping-restrictions allow us po box in the generated xml' do
|
42
|
+
@shipping.shipping_restrictions[:allow_us_po_box] = false
|
43
|
+
@shipping.to_xml.should match(%r{<shipping-restrictions>.*<allow-us-po-box>false</allow-us-po-box>.*</shipping-restrictions>})
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should generate the address filters tag if they are set' do
|
47
|
+
@shipping.address_filters[:allowed] << GoogleCheckout::Geography::UsState.new('WI')
|
48
|
+
@shipping.to_xml.should match(%r{<address-filters>.*</address-filters>})
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not generate the address filters tag if they are not set' do
|
52
|
+
@shipping.to_xml.should_not match(%r{<address-filters>.*</address-filters>})
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should include the address filters allowed areas in the generated xml' do
|
56
|
+
@shipping.address_filters[:allowed] << GoogleCheckout::Geography::UsState.new('WI')
|
57
|
+
@shipping.to_xml.should match(%r{<address-filters>.*<allowed-areas>.*</allowed-areas>.*</address-filters>})
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should include the address filters excluded areas in the generated xml' do
|
61
|
+
@shipping.address_filters[:excluded] << GoogleCheckout::Geography::UsState.new('WI')
|
62
|
+
@shipping.to_xml.should match(%r{<address-filters>.*<excluded-areas>.*</excluded-areas>.*</address-filters>})
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should include the address filters allow us po box in the generated xml' do
|
66
|
+
@shipping.address_filters[:allow_us_po_box] = false
|
67
|
+
@shipping.to_xml.should match(%r{<address-filters>.*<allow-us-po-box>false</allow-us-po-box>.*</address-filters>})
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout::Shipping::Pickup do
|
4
|
+
before(:each) do
|
5
|
+
@shipping = GoogleCheckout::Shipping::Pickup.new('Digital Delivery')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should include the name in the generated xml' do
|
9
|
+
@shipping.to_xml.should match(%r{<pickup name="Digital Delivery">})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should include the price in the generated xml' do
|
13
|
+
@shipping.price = '1.00'
|
14
|
+
@shipping.to_xml.should match(%r{<price .*>1.00</price>})
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should include the currency in the generated xml' do
|
18
|
+
@shipping.currency = 'CAD'
|
19
|
+
@shipping.to_xml.should match(%r{<price currency="CAD">})
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe GoogleCheckout do
|
4
|
+
|
5
|
+
it "should use sandbox if set" do
|
6
|
+
GoogleCheckout.use_sandbox
|
7
|
+
GoogleCheckout.should be_sandbox
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should not use sandbox if set to production" do
|
11
|
+
GoogleCheckout.use_production
|
12
|
+
GoogleCheckout.should_not be_sandbox
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require File.dirname(__FILE__) + "/../lib/google-checkout"
|
4
|
+
|
5
|
+
def read_xml_fixture(filename)
|
6
|
+
File.read(File.dirname(__FILE__) + "/fixtures/google/#{filename}.xml")
|
7
|
+
end
|
8
|
+
|
9
|
+
# A better +be_kind_of+ with more informative error messages.
|
10
|
+
#
|
11
|
+
# The default +be_kind_of+ just says
|
12
|
+
#
|
13
|
+
# "expected to return true but got false"
|
14
|
+
#
|
15
|
+
# This one says
|
16
|
+
#
|
17
|
+
# "expected File but got Tempfile"
|
18
|
+
|
19
|
+
class BeKindOf
|
20
|
+
|
21
|
+
def initialize(expected) # + args
|
22
|
+
@expected = expected
|
23
|
+
end
|
24
|
+
|
25
|
+
def matches?(target)
|
26
|
+
@target = target
|
27
|
+
@target.kind_of?(@expected)
|
28
|
+
end
|
29
|
+
|
30
|
+
def failure_message
|
31
|
+
"expected #{@expected} but got #{@target.class}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def negative_failure_message
|
35
|
+
"expected #{@expected} to not be #{@target.class}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def description
|
39
|
+
"be_kind_of #{@target}"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def be_kind_of(expected) # + args
|
45
|
+
BeKindOf.new(expected)
|
46
|
+
end
|
47
|
+
|