active_zuora 2.2.0 → 2.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a193209e8dc321e159f45d360a0b1b5a0f4458f
4
- data.tar.gz: 5994cf1d464ebde4d2e674763eee752c8f6c6f13
3
+ metadata.gz: 1715d2a357d7e6e3e86de70a3895226ecec72db3
4
+ data.tar.gz: 9f2695af063c29dce60dd31ef7ffcfdbccf2e522
5
5
  SHA512:
6
- metadata.gz: bcc832f90122ccc3e4d12bba198d83d28cee4c8fba77fcdbb6b42c86d1761fe69c032d175a1e520800ca71f0db4db528136cbfcd3b47026cf162d845d4469431
7
- data.tar.gz: be5417128f8bce2c3d484c9a2403482472854b424a90e2b92ed3f7aef3db312158e25b828ca8eed941181b166f2b46b15c545bf68a55336df138c182a8f04aa5
6
+ metadata.gz: 853f119981d3ba11d661c7d8d79c9e0d53c63d34922c64520efdb9993c1238523b3c6a1c9a5cd06c123de767874f858f2ed55a9f16e76b7dd1ad41d0d3cc70df
7
+ data.tar.gz: eaa53ba199a1aac5e0520778b21034a54267211077cf691e2e78125a0b5ada2c151d52d076eb4b4874b7a59dc1b4b26feffabe6fc7f1706f4b18ad058010d2ac
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,4 @@
1
+ #### v2.2.1
1
2
  #### v2.2.0
2
3
  #### v2.1.4
3
4
  #### v2.1.3
data/lib/active_zuora.rb CHANGED
@@ -18,6 +18,7 @@ require 'active_zuora/amend'
18
18
  require 'active_zuora/generate'
19
19
  require 'active_zuora/batch_subscribe'
20
20
  require 'active_zuora/collection_proxy'
21
+ require 'active_zuora/lazy_attr'
21
22
 
22
23
  module ActiveZuora
23
24
 
@@ -144,7 +144,12 @@ module ActiveZuora
144
144
 
145
145
  customize 'Invoice' do
146
146
  include Generate
147
- exclude_from_queries :regenerate_invoice_pdf
147
+ include LazyAttr
148
+ # The body field can only be accessed for a single invoice at a time, so
149
+ # exclude it here to not break collections of invoices. The contents of
150
+ # the body field will be lazy loaded in when needed.
151
+ exclude_from_queries :regenerate_invoice_pdf, :body
152
+ lazy_load :body
148
153
  end
149
154
 
150
155
  customize 'InvoiceItemAdjustment' do
@@ -0,0 +1,41 @@
1
+ module ActiveZuora
2
+ module LazyAttr
3
+
4
+ # This is meant to be included onto an Invoice class.
5
+ # Returns true/false on success.
6
+ # Result hash is stored in #result.
7
+ # If success, the id will be set in the object.
8
+ # If failure, errors will be present on object.
9
+
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ include Base
14
+ end
15
+
16
+
17
+ def fetch_field(field_name)
18
+ return nil unless self.id
19
+ query_string = "select #{self.class.get_field!(field_name).zuora_name} from #{zuora_object_name} where Id = '#{self.id}'"
20
+ response = self.class.connection.request(:query){ |soap| soap.body = { :query_string => query_string } }
21
+ response[:query_response][:result][:records][field_name.to_sym]
22
+ end
23
+ private :fetch_field
24
+
25
+ module ClassMethods
26
+ def lazy_load(*field_names)
27
+ Array(field_names).map(&:to_sym).each do |field_name|
28
+ define_lazy_field field_name
29
+ end
30
+ end
31
+
32
+ def define_lazy_field(field)
33
+ instance_eval do
34
+ define_method field do
35
+ instance_variable_get("@#{field}") || instance_variable_set("@#{field}", fetch_field(field))
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -57,7 +57,7 @@ module ActiveZuora
57
57
  if relation.is_a?(Hash)
58
58
  where(relation)
59
59
  else
60
- dup.tap do |dup|
60
+ dup.tap do |dup|
61
61
  dup.filters.concat relation.filters
62
62
  dup.filters.uniq!
63
63
  dup.order_attribute = relation.order_attribute
@@ -155,7 +155,7 @@ module ActiveZuora
155
155
  protected
156
156
 
157
157
  def method_missing(method, *args, &block)
158
- # This is how the chaing can happen on class methods or named scopes on the
158
+ # This is how the chaing can happen on class methods or named scopes on the
159
159
  # ZObject class.
160
160
  if Array.method_defined?(method)
161
161
  to_a.send(method, *args, &block)
@@ -219,11 +219,11 @@ module ActiveZuora
219
219
  # Sometimes Zuora will return only a single record, not in an array.
220
220
  results = [results] unless results.is_a?(Array)
221
221
  results.map do |attributes|
222
- # Strip any noisy attributes from the results that have to do with
222
+ # Strip any noisy attributes from the results that have to do with
223
223
  # SOAP namespaces.
224
224
  attributes.delete_if { |key, value| key.to_s.start_with? "@" }
225
225
  # Instantiate the zobject class, but don't track the changes.
226
- zobject_class.new(attributes).tap { |record| record.clear_changed_attributes }
226
+ zobject_class.new(attributes).tap { |record| record.changed_attributes.clear }
227
227
  end
228
228
  end
229
229
 
@@ -248,6 +248,6 @@ end
248
248
 
249
249
 
250
250
 
251
-
251
+
252
252
 
253
253
 
@@ -1,3 +1,3 @@
1
1
  module ActiveZuora
2
- VERSION = "2.2.0"
2
+ VERSION = "2.2.1"
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'LazyAttr' do
4
+ class TestInovice
5
+ include ActiveZuora::LazyAttr
6
+ lazy_load :test_body
7
+ end
8
+
9
+ subject { TestInovice.new }
10
+
11
+ it "should fetch a lazy loaded attribute from the api" do
12
+ expect(subject).to receive(:fetch_field).with(:test_body){ 'Jesse "The Body"' }
13
+ subject.test_body
14
+ end
15
+
16
+ it "should should not refetch an attribute after it's been loaded once" do
17
+ expect(subject).to receive(:fetch_field).with(:test_body).once { 'Jesse "The Body"' }
18
+ subject.test_body
19
+ subject.test_body
20
+ end
21
+
22
+ end
@@ -213,6 +213,7 @@ describe "Subscribe" do
213
213
  invoice.generate!
214
214
  expect(invoice.id).to be_present
215
215
  expect(invoice.account_id).to eq(subscribe_request.account.id)
216
+ expect(invoice.body).to be_present
216
217
  end
217
218
 
218
219
  it "Can successfully batch subscribe from a collection proxy of subscribe requests and generate an invoice for the first subscription" do
@@ -259,7 +260,7 @@ describe "Subscribe" do
259
260
  }
260
261
  }
261
262
  )
262
-
263
+
263
264
  subscribe_request_2 = Z::SubscribeRequest.new(
264
265
  :account => {
265
266
  :name => "Joe Customer",
@@ -303,24 +304,20 @@ describe "Subscribe" do
303
304
  }
304
305
  }
305
306
  )
306
-
307
+
307
308
  collection = Z::CollectionProxy.new([subscribe_request_1,subscribe_request_2])
308
309
  collection.batch_subscribe!
309
-
310
+
310
311
  #subscribe reqeust 1
311
312
  @account = subscribe_request_1.account
312
- expect(subscribe_request_1.new_record?).to be_falsey
313
- expect(subscribe_request_1changed?).to be_falsey
314
313
  expect(subscribe_request_1.subscription_data.subscription.new_record?).to be_falsey
315
314
  expect(subscribe_request_1.subscription_data.subscription.rate_plans.first.
316
315
  rate_plan_charges.first.
317
316
  product_rate_plan_charge).to eq(@product_rate_plan_charge)
318
317
  expect(subscribe_request_1.result).to be_present
319
-
318
+
320
319
  #subscribe reqeust 2
321
320
  @account_2 = subscribe_request_2.account
322
- expect(subscribe_request_2.new_record?).to be_falsey
323
- expect(subscribe_request_2changed?).to be_falsey
324
321
  expect(subscribe_request_2.subscription_data.subscription.new_record?).to be_falsey
325
322
  expect(subscribe_request_2.subscription_data.subscription.rate_plans.first.
326
323
  rate_plan_charges.first.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_zuora
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Lebert
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-06 00:00:00.000000000 Z
12
+ date: 2015-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
@@ -134,6 +134,7 @@ files:
134
134
  - lib/active_zuora/generator.rb
135
135
  - lib/active_zuora/has_many_associations.rb
136
136
  - lib/active_zuora/has_many_proxy.rb
137
+ - lib/active_zuora/lazy_attr.rb
137
138
  - lib/active_zuora/persistence.rb
138
139
  - lib/active_zuora/relation.rb
139
140
  - lib/active_zuora/scoping.rb
@@ -146,6 +147,7 @@ files:
146
147
  - spec/collection_proxy_spec.rb
147
148
  - spec/connection_spec.rb
148
149
  - spec/has_many_integration_spec.rb
150
+ - spec/lazy_attr_spec.rb
149
151
  - spec/spec_helper.rb
150
152
  - spec/subscribe_integration_spec.rb
151
153
  - spec/zobject_integration_spec.rb
@@ -181,6 +183,7 @@ test_files:
181
183
  - spec/collection_proxy_spec.rb
182
184
  - spec/connection_spec.rb
183
185
  - spec/has_many_integration_spec.rb
186
+ - spec/lazy_attr_spec.rb
184
187
  - spec/spec_helper.rb
185
188
  - spec/subscribe_integration_spec.rb
186
189
  - spec/zobject_integration_spec.rb