google4r-checkout 1.1.5 → 1.1.6

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/CHANGES CHANGED
@@ -1,5 +1,9 @@
1
1
  =google4r-checkout Changelog
2
2
 
3
+ == 1.1.6 (2012-08-01)
4
+
5
+ * Bugfixes when creating recurring subscriptions parsed from XML, contributed by James Martin
6
+
3
7
  == 1.1.5 (2012-08-01)
4
8
 
5
9
  * Raise a more informative exception for non-XML notifications, contributed by James Martin
@@ -330,7 +330,7 @@ module Google4R #:nodoc:
330
330
 
331
331
  subscription_element = element.elements['subscription']
332
332
  if not subscription_element.nil?
333
- result.create_subscription(Subscription.create_from_element(subscription_element))
333
+ result.create_subscription(Subscription.create_from_element(subscription_element, result))
334
334
  end
335
335
 
336
336
  return result
@@ -477,7 +477,7 @@ module Google4R #:nodoc:
477
477
  @recurrent_items = []
478
478
  end
479
479
 
480
- def self.create_from_element(element)
480
+ def self.create_from_element(element, shopping_cart)
481
481
  result = Subscription.new
482
482
  result.no_charge_after = Time.iso8601(element.attributes['no-charge-after']) rescue nil
483
483
  result.period = element.attributes['period'] rescue nil
@@ -489,7 +489,7 @@ module Google4R #:nodoc:
489
489
  end
490
490
 
491
491
  element.elements.each('recurrent-item') do |item_element|
492
- result.recurrent_items << Item.create_from_element(item_element)
492
+ result.recurrent_items << Item.create_from_element(item_element, shopping_cart)
493
493
  end
494
494
 
495
495
  return result
@@ -0,0 +1,159 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
+
3
+ require 'google4r/checkout'
4
+
5
+ require 'test/frontend_configuration'
6
+
7
+ # Test for the Subscription class.
8
+ class Google4R::Checkout::ItemTest < Test::Unit::TestCase
9
+ include Google4R::Checkout
10
+
11
+ def setup
12
+ @frontend = Frontend.new(FRONTEND_CONFIGURATION)
13
+ @frontend.tax_table_factory = TestTaxTableFactory.new
14
+
15
+ @xml_str = %q{<?xml version="1.0" encoding="UTF-8"?>
16
+ <item>
17
+ <subscription type="google" period="MONTHLY">
18
+ <payments>
19
+ <subscription-payment is-exact="true">
20
+ <maximum-charge currency="USD">1.0</maximum-charge>
21
+ </subscription-payment>
22
+ </payments>
23
+ <recurrent-item>
24
+ <item-name>An interesting subscription</item-name>
25
+ <item-description>A flat rate monthly charge</item-description>
26
+ <unit-price currency="USD">1.0</unit-price>
27
+ <quantity>1</quantity>
28
+ </recurrent-item>
29
+ </subscription>
30
+ <item-name>Interesting Subscription</item-name>
31
+ <item-description>Keep up-to-date with that thing you like</item-description>
32
+ <unit-price currency="USD">0.0</unit-price>
33
+ <quantity>1</quantity>
34
+ <merchant-private-item-data>
35
+ <item-note>Text 1</item-note>
36
+ <item-note>Text 2</item-note>
37
+ <nested>
38
+ <tags>value</tags>
39
+ </nested>
40
+ </merchant-private-item-data>
41
+ <tax-table-selector>Some Table</tax-table-selector>
42
+ </item>
43
+ }
44
+
45
+ @optional_tags = [ 'merchant-item-id', 'merchant-private-item-data', 'tax-table-selector' ]
46
+
47
+ @command = @frontend.create_checkout_command
48
+ @shopping_cart = @command.shopping_cart
49
+ @item = @shopping_cart.create_item
50
+ @digital_content = @item.digital_content
51
+ end
52
+
53
+ def test_item_behaves_correctly
54
+ [ :shopping_cart, :name, :name=, :description, :description=, :unit_price, :unit_price=,
55
+ :quantity, :quantity=, :id, :id=, :private_data, :private_data=,
56
+ :tax_table, :tax_table=, :digital_content, :weight, :weight=
57
+ ].each do |symbol|
58
+ assert_respond_to @item, symbol
59
+ end
60
+ end
61
+
62
+ def test_item_gets_initialized_correctly
63
+ assert_equal @shopping_cart, @item.shopping_cart
64
+ assert_nil @item.name
65
+ assert_nil @item.description
66
+ assert_nil @item.unit_price
67
+ assert_nil @item.quantity
68
+ assert_nil @item.private_data
69
+ assert_nil @item.id
70
+ assert_nil @item.tax_table
71
+ assert_nil @item.digital_content
72
+ end
73
+
74
+ def test_item_setters_work
75
+ @item.name = "name"
76
+ assert_equal "name", @item.name
77
+
78
+ @item.description = "description"
79
+ assert_equal "description", @item.description
80
+
81
+ @item.unit_price = Money.new(100, "EUR")
82
+ assert_equal Money.new(100, "EUR"), @item.unit_price
83
+
84
+ @item.quantity = 10
85
+ assert_equal 10, @item.quantity
86
+
87
+ @item.id = "id"
88
+ assert_equal "id", @item.id
89
+
90
+ @item.private_data = Hash.new
91
+ assert_equal Hash.new, @item.private_data
92
+
93
+ @item.weight = Weight.new(2.2)
94
+ assert_equal Weight, @item.weight.class
95
+ end
96
+
97
+ def test_set_tax_table_works
98
+ table = @command.tax_tables.first
99
+ @item.tax_table = table
100
+ assert_equal table, @item.tax_table
101
+ end
102
+
103
+ def test_set_tax_table_raises_if_table_is_unknown_in_command
104
+ assert_raises(RuntimeError) { @item.tax_table = TaxTable.new(false) }
105
+ end
106
+
107
+ def test_set_private_data_only_works_with_hashes
108
+ assert_raises(RuntimeError) { @shopping_cart.private_data = 1 }
109
+ assert_raises(RuntimeError) { @shopping_cart.private_data = nil }
110
+ assert_raises(RuntimeError) { @shopping_cart.private_data = 'Foobar' }
111
+ assert_raises(RuntimeError) { @shopping_cart.private_data = [] }
112
+ end
113
+
114
+ def test_item_price_must_be_money_instance
115
+ assert_raises(RuntimeError) { @item.unit_price = nil }
116
+ assert_raises(RuntimeError) { @item.unit_price = "String" }
117
+ assert_raises(RuntimeError) { @item.unit_price = 10 }
118
+ end
119
+
120
+ def test_create_from_element_works
121
+ @optional_tags.power.each do |optional_tag_names|
122
+ xml_str = @xml_str
123
+
124
+ optional_tag_names.each { |name| xml_str = xml_str.gsub(%r{<#{name}.*?</#{name}>}, '') }
125
+
126
+ command = @frontend.create_checkout_command
127
+ tax_table = TaxTable.new(false)
128
+ tax_table.name = 'Some Table'
129
+ command.tax_tables << tax_table
130
+ item = Item.create_from_element(REXML::Document.new(xml_str).root, command.shopping_cart)
131
+
132
+ assert_equal command.shopping_cart, item.shopping_cart
133
+
134
+ assert_equal 'Interesting Subscription', item.name
135
+ assert_equal 'Keep up-to-date with that thing you like', item.description
136
+ assert_equal Money.new(0, 'USD'), item.unit_price
137
+ assert_equal 1, item.quantity
138
+
139
+ hash =
140
+ {
141
+ 'item-note' => [ 'Text 1', 'Text 2' ],
142
+ 'nested' => { 'tags' => 'value' }
143
+ }
144
+ assert_equal hash, item.private_data unless optional_tag_names.include?('merchant-private-item-data')
145
+ assert_equal 'Some Table', item.tax_table.name unless optional_tag_names.include?('tax-table-selector')
146
+
147
+ subscription = item.subscription
148
+ assert_equal 1, subscription.recurrent_items.count
149
+ assert_equal Google4R::Checkout::Item::Subscription::MONTHLY, subscription.period
150
+ assert_equal Google4R::Checkout::Item::Subscription::GOOGLE, subscription.type
151
+
152
+ recurrent_item = subscription.recurrent_items.first
153
+ assert_equal 'An interesting subscription', recurrent_item.name
154
+ assert_equal 'A flat rate monthly charge', recurrent_item.description
155
+ assert_equal 1, recurrent_item.quantity
156
+ assert_equal Money.new(100, 'USD'), recurrent_item.unit_price
157
+ end
158
+ end
159
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google4r-checkout
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,6 +160,7 @@ files:
160
160
  - test/unit/ship_items_command_test.rb
161
161
  - test/unit/shipping_adjustment_test.rb
162
162
  - test/unit/shopping_cart_test.rb
163
+ - test/unit/subscription_test.rb
163
164
  - test/unit/tax_rule_test.rb
164
165
  - test/unit/tax_table_test.rb
165
166
  - test/unit/tracking_data_test.rb
@@ -253,6 +254,7 @@ test_files:
253
254
  - test/unit/ship_items_command_test.rb
254
255
  - test/unit/shipping_adjustment_test.rb
255
256
  - test/unit/shopping_cart_test.rb
257
+ - test/unit/subscription_test.rb
256
258
  - test/unit/tax_rule_test.rb
257
259
  - test/unit/tax_table_test.rb
258
260
  - test/unit/tracking_data_test.rb