ledger_sync 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efcf3cc57a3f68ad9612fde0eb59ac3e06acd8d644a579397c2c1a17046d4be1
4
- data.tar.gz: db61863e31a0fc7004e020b1c0672b52a3de117edd7b57a5ff874edf6505e20c
3
+ metadata.gz: f2b28cb8266fdd627c4c7b19166f0fae7c65742556662e5fdb4150aa6d73a297
4
+ data.tar.gz: 5184d055660ead3e05e63dc4e3ad6bff063d79af1e9571311d62ca1ad67acfab
5
5
  SHA512:
6
- metadata.gz: 777f81a8164db6a0e8d82081bcd70d01bdf34542ace2ae494fa475e632201df1e23211308d6df18f97eab5bf49fe1743bcce52bfc44b0e2aebf8d468ce3b8e21
7
- data.tar.gz: 3398a7232feb2f4659061705f7aefe960fcf2459a84f156d6ab86f2be8967f0a28c6a0035b4688780dcca99d6937a23b1f0de38bffc0f2e1031c577056fbcef6
6
+ metadata.gz: f937d553df677636512d4e8345b2c188f0533a9cc7e8f74911b90b258646c206ed9f5c3172f422a4c31a32724d9d58086aa362ada77526f113cb733fe7554ad7
7
+ data.tar.gz: 267bf6cefa55aa03de38086666917e852d865e7045c68bc923648fd2c237e26fdf71a1a700bba239c4afa15430283b6748ed8b61b334b923d56c99c43c5f6c3f
data/Gemfile.lock CHANGED
@@ -1,10 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ledger_sync (1.5.1)
4
+ ledger_sync (1.5.2)
5
5
  activemodel
6
6
  colorize
7
- coveralls (~> 0.8.23)
8
7
  dotenv (~> 2.7.6)
9
8
  dry-schema (~> 1.5.4)
10
9
  dry-validation (~> 1.5.6)
@@ -265,6 +264,7 @@ DEPENDENCIES
265
264
  bump (~> 0.9.0)
266
265
  bundler (~> 2.1)
267
266
  byebug
267
+ coveralls (~> 0.8.23)
268
268
  factory_bot (~> 6.1.0)
269
269
  jekyll (~> 3.8.4)
270
270
  jekyll-menus (~> 0.6.0)
data/ledger_sync.gemspec CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency('bump', '~> 0.9.0')
35
35
  spec.add_development_dependency('bundler', '~> 2.1')
36
36
  spec.add_development_dependency('byebug', '>= 0')
37
+ spec.add_development_dependency('coveralls', '~> 0.8.23')
37
38
  spec.add_development_dependency('factory_bot', '~> 6.1.0')
38
39
  spec.add_development_dependency('jekyll', '~> 3.8.4')
39
40
  spec.add_development_dependency('jekyll-menus', '~> 0.6.0')
@@ -47,7 +48,6 @@ Gem::Specification.new do |spec|
47
48
  spec.add_development_dependency('webmock', '>= 0')
48
49
  spec.add_runtime_dependency('activemodel', '>= 0')
49
50
  spec.add_runtime_dependency('colorize', '>= 0')
50
- spec.add_runtime_dependency('coveralls', '~> 0.8.23')
51
51
  spec.add_runtime_dependency('dotenv', '~> 2.7.6')
52
52
  spec.add_runtime_dependency('dry-schema', '~> 1.5.4')
53
53
  spec.add_runtime_dependency('dry-validation', '~> 1.5.6')
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples 'a valid operation' do
4
+ it 'is valid' do
5
+ instance = described_class.new(resource: resource, client: client)
6
+ if ENV.fetch('DEBUG', false) && !instance.valid?
7
+ pd instance.errors
8
+ byebug if ENV['DEBUG'] # rubocop:disable Lint/Debugger
9
+ end
10
+ expect(instance).to be_valid
11
+ end
12
+ end
13
+
14
+ RSpec.shared_examples 'a successful operation' do |stubs: []|
15
+ before do
16
+ stubs = Array(stubs)
17
+ stubs.each do |stub|
18
+ if stub.is_a?(Array)
19
+ send(*stub)
20
+ else
21
+ send(stub)
22
+ end
23
+ end
24
+ end
25
+
26
+ it 'is successful' do
27
+ result = described_class.new(resource: resource, client: client).perform
28
+ byebug if ENV.fetch('DEBUG', false) && result.failure? # rubocop:disable Lint/Debugger
29
+ expect(result).to be_a(LedgerSync::OperationResult::Success)
30
+ end
31
+ end
32
+
33
+ RSpec.shared_examples 'an operation' do
34
+ it_behaves_like 'a valid operation'
35
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Test
5
+ module QA
6
+ module LedgerHelpers
7
+ def create_resource_for(*args)
8
+ create_result_for(*args).raise_if_error.resource
9
+ end
10
+
11
+ def create_result_for(client:, resource:)
12
+ result_for(
13
+ client: client,
14
+ method: :create,
15
+ resource: resource
16
+ )
17
+ end
18
+
19
+ def delete_resource_for(*args)
20
+ delete_result_for(*args).raise_if_error.resource
21
+ end
22
+
23
+ def delete_result_for(client:, resource:)
24
+ result_for(
25
+ client: client,
26
+ method: :delete,
27
+ resource: resource
28
+ )
29
+ end
30
+
31
+ def find_resource_for(*args)
32
+ find_result_for(*args).raise_if_error.resource
33
+ end
34
+
35
+ def find_result_for(client:, resource:)
36
+ result_for(
37
+ client: client,
38
+ method: :find,
39
+ resource: resource
40
+ )
41
+ end
42
+
43
+ def result_for(client:, method:, resource:)
44
+ client.operation_for(
45
+ method: method,
46
+ resource: resource
47
+ ).perform
48
+ end
49
+
50
+ def update_resource_for(*args)
51
+ update_result_for(*args).raise_if_error.resource
52
+ end
53
+
54
+ def update_result_for(client:, resource:)
55
+ result_for(
56
+ client: client,
57
+ method: :update,
58
+ resource: resource
59
+ )
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ def setup_client_qa_support(*clients, keyed: false)
4
+ clients.each do |client|
5
+ key = client.config.root_key
6
+
7
+ qa_support "#{key}_helpers"
8
+ helpers_module = Object.const_get("QA::#{client.base_module.name.split('::').last}Helpers")
9
+ env_key = "#{key}_qa".upcase
10
+
11
+ RSpec.configure do |config|
12
+ if keyed
13
+ config.include helpers_module, qa: true, client: key
14
+ else
15
+ config.include helpers_module, qa: true
16
+ end
17
+
18
+ config.around(:each, qa: true) do |example|
19
+ if ENV.fetch(env_key, nil) == '1'
20
+ example.run
21
+ else
22
+ skip "Set #{env_key}=1 to run #{key} QA tests"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples 'a create' do |delete: true|
4
+ it do
5
+ result = create_result_for(
6
+ client: client,
7
+ resource: resource
8
+ )
9
+
10
+ byebug if result.failure? # rubocop:disable Lint/Debugger
11
+
12
+ expect(result).to be_success
13
+
14
+ if delete
15
+ delete_result_for(
16
+ client: client,
17
+ resource: result.resource
18
+ ).raise_if_error
19
+ end
20
+ end
21
+ end
22
+
23
+ RSpec.shared_examples 'a delete' do
24
+ it do
25
+ result = create_result_for(
26
+ client: client,
27
+ resource: resource
28
+ ).raise_if_error
29
+
30
+ resource = result.resource
31
+
32
+ result = delete_result_for(
33
+ client: client,
34
+ resource: resource
35
+ )
36
+
37
+ expect(result).to be_success
38
+
39
+ result = delete_result_for(
40
+ client: client,
41
+ resource: resource
42
+ )
43
+
44
+ expect(result).to be_failure
45
+ end
46
+ end
47
+
48
+ RSpec.shared_examples 'a find' do |delete: true|
49
+ it do
50
+ result = create_result_for(
51
+ client: client,
52
+ resource: resource
53
+ )
54
+
55
+ byebug if result.failure? # rubocop:disable Lint/Debugger
56
+ result.raise_if_error
57
+ expect(result).to be_success
58
+ resource = result.resource
59
+
60
+ begin
61
+ result = find_result_for(
62
+ client: client,
63
+ resource: resource
64
+ )
65
+
66
+ expect(result).to be_success
67
+ ensure
68
+ if delete
69
+ # Be sure to delete resource or raise an exception if this fails
70
+ delete_result_for(
71
+ client: client,
72
+ resource: resource
73
+ ).raise_if_error
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ RSpec.shared_examples 'a find only' do
80
+ it do
81
+ result = find_result_for(
82
+ client: client,
83
+ resource: resource
84
+ )
85
+
86
+ expect(result).to be_success
87
+ end
88
+ end
89
+
90
+ RSpec.shared_examples 'an update' do |delete: true|
91
+ it do
92
+ result = create_result_for(
93
+ client: client,
94
+ resource: resource
95
+ ).raise_if_error
96
+
97
+ expect(result).to be_success
98
+ resource = result.resource
99
+
100
+ begin
101
+ # Ensure values are currently not the same as the updates
102
+ attribute_updates.each do |k, v|
103
+ expect(resource.send(k)).not_to eq(v)
104
+ end
105
+
106
+ resource.assign_attributes(attribute_updates)
107
+ result = update_result_for(
108
+ client: client,
109
+ resource: resource
110
+ )
111
+
112
+ expect(result).to be_success
113
+ resource = result.resource
114
+
115
+ # Ensure values are updated
116
+ attribute_updates.each do |k, v|
117
+ expect(resource.send(k)).to eq(v)
118
+ end
119
+
120
+ result = find_result_for(
121
+ client: client,
122
+ resource: resource.class.new(
123
+ ledger_id: resource.ledger_id
124
+ )
125
+ ).raise_if_error
126
+
127
+ expect(result).to be_success
128
+ resource = result.resource
129
+
130
+ # Ensure values are updated after raw find
131
+ attribute_updates.each do |k, v|
132
+ expect(resource.send(k)).to eq(v)
133
+ end
134
+ ensure
135
+ if delete
136
+ delete_result_for(
137
+ client: client,
138
+ resource: resource
139
+ ).raise_if_error
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ RSpec.shared_examples 'a searcher' do
146
+ it do
147
+ result = client.searcher_for(resource_type: resource.class.resource_module_str).search
148
+
149
+ byebug if result.failure? # rubocop:disable Lint/Debugger
150
+
151
+ expect(result).to be_success
152
+ end
153
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Test
5
+ class Record
6
+ attr_reader :hash, :path, :record
7
+
8
+ def initialize(args = {})
9
+ @hash = args.fetch(:hash)
10
+ @path = args.fetch(:path)
11
+ @record = args.fetch(:record)
12
+ end
13
+
14
+ def id
15
+ @id ||= hash.fetch('id', nil)
16
+ end
17
+ end
18
+
19
+ class RecordCollection
20
+ attr_reader :dir, :record_class, :records
21
+
22
+ def initialize(args = {})
23
+ @dir = args.fetch(:dir)
24
+ @record_class = args.fetch(:record_class, Record)
25
+
26
+ @records = {}
27
+
28
+ # Process json files
29
+ Gem.find_files(File.join(dir, '*.json')).map do |file_path|
30
+ record = File.basename(file_path, '.json').to_sym
31
+ @records[record] = record_class.new(
32
+ hash: JSON.parse(File.open(file_path).read),
33
+ path: file_path,
34
+ record: record
35
+ )
36
+ self.class.define_method(record) do
37
+ records[record]
38
+ end
39
+ end
40
+
41
+ # Process directories
42
+ Dir.chdir(dir) do
43
+ Dir.glob('*').select { |f| File.directory? f }.each do |sub_dir|
44
+ sub_dir_path = File.join(dir, sub_dir)
45
+ next if Gem.find_files(File.join(sub_dir_path, '**/*.json')).empty?
46
+
47
+ @records[sub_dir.to_sym] = RecordCollection.new(dir: sub_dir_path)
48
+ self.class.define_method(sub_dir) do
49
+ records[sub_dir.to_sym]
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def all
56
+ @all ||= begin
57
+ ret = {}
58
+ records.each do |k, v|
59
+ if v.is_a?(self.class)
60
+ v.all.each do |sub_k, sub_v|
61
+ ret[[k, sub_k].join('/').to_s] = sub_v
62
+ end
63
+ else
64
+ ret[k.to_s] = v
65
+ end
66
+ end
67
+ ret
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TestLedgerHelpers
4
+ # Ledger
5
+ def test_ledger_module
6
+ LedgerSync.ledgers.test_ledger.base_module
7
+ end
8
+
9
+ def test_ledger_client
10
+ LedgerSync.ledgers.test_ledger.new(
11
+ api_key: 'api_key'
12
+ )
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ def stubs_and_times
4
+ @stubs_and_times ||= []
5
+ end
6
+
7
+ def stubs_and_times_reset
8
+ @stubs_and_times = []
9
+ end
10
+
11
+ module WebMock
12
+ module API
13
+ # Overwrite the original stub_request method to enforce we explicitly say
14
+ # how many times we expect a request to be called
15
+ def stub_request(*args, times: 1)
16
+ ret = WebMock::StubRegistry.instance
17
+ .register_request_stub(WebMock::RequestStub.new(*args))
18
+ stubs_and_times << [ret, times] unless times.nil?
19
+ ret
20
+ end
21
+ end
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ config.before { WebMock.reset! }
26
+ config.around(qa: true) do |example|
27
+ WebMock.disable!
28
+ example.run
29
+ ensure
30
+ WebMock.enable!
31
+ end
32
+ config.after do
33
+ stubs_and_times.each do |stub, times|
34
+ expect(stub).to have_been_requested.times(times)
35
+ end
36
+ stubs_and_times_reset
37
+ end
38
+ end
@@ -2,19 +2,25 @@
2
2
 
3
3
  def support(*paths)
4
4
  paths.each do |path|
5
- require File.join(LedgerSync.root, 'spec/support/', path.to_s)
5
+ require File.join('support/', path.to_s)
6
+ end
7
+ end
8
+
9
+ def qa_support(*paths)
10
+ paths.each do |path|
11
+ require File.join('qa/support/', path.to_s)
6
12
  end
7
13
  end
8
14
 
9
15
  def core_support(*paths)
10
16
  paths.each do |path|
11
- require File.join(LedgerSync.root, 'lib/ledger_sync/test/support/', path.to_s)
17
+ require File.join('ledger_sync/test/support/', path.to_s)
12
18
  end
13
19
  end
14
20
 
15
- def qa_support(*paths)
21
+ def core_qa_support(*paths)
16
22
  paths.each do |path|
17
- require File.join(LedgerSync.root, 'spec/qa/support/', path.to_s)
23
+ require File.join('ledger_sync/test/support/qa/', path.to_s)
18
24
  end
19
25
  end
20
26
 
@@ -25,7 +31,7 @@ module LedgerSync
25
31
  require 'webmock/rspec'
26
32
  require 'simplecov'
27
33
  require 'coveralls'
28
- Coveralls.wear!
34
+ Coveralls.wear!('rails')
29
35
 
30
36
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
31
37
  [
@@ -49,8 +55,10 @@ module LedgerSync
49
55
 
50
56
  paths_to_require.each { |e| require e.to_s }
51
57
 
52
- # Include test adaptor
53
- core_support 'test_ledger/config'
58
+ core_support 'webmock_helpers'
59
+ core_support 'record_collection'
60
+
61
+ core_support 'qa/ledger_support_setup'
54
62
 
55
63
  core_support :factory_bot
56
64
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LedgerSync
4
- VERSION = '1.5.1'
4
+ VERSION = '1.5.2'
5
5
 
6
6
  def self.version
7
7
  if !ENV['TRAVIS'] || ENV.fetch('TRAVIS_TAG', '') != ''
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ledger_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Jackson
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.23
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.23
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: factory_bot
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -248,20 +262,6 @@ dependencies:
248
262
  - - ">="
249
263
  - !ruby/object:Gem::Version
250
264
  version: '0'
251
- - !ruby/object:Gem::Dependency
252
- name: coveralls
253
- requirement: !ruby/object:Gem::Requirement
254
- requirements:
255
- - - "~>"
256
- - !ruby/object:Gem::Version
257
- version: 0.8.23
258
- type: :runtime
259
- prerelease: false
260
- version_requirements: !ruby/object:Gem::Requirement
261
- requirements:
262
- - - "~>"
263
- - !ruby/object:Gem::Version
264
- version: 0.8.23
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: dotenv
267
267
  requirement: !ruby/object:Gem::Requirement
@@ -1065,6 +1065,11 @@ files:
1065
1065
  - lib/ledger_sync/serializer.rb
1066
1066
  - lib/ledger_sync/test/support.rb
1067
1067
  - lib/ledger_sync/test/support/factory_bot.rb
1068
+ - lib/ledger_sync/test/support/operation_shared_examples.rb
1069
+ - lib/ledger_sync/test/support/qa/ledger_helpers.rb
1070
+ - lib/ledger_sync/test/support/qa/ledger_support_setup.rb
1071
+ - lib/ledger_sync/test/support/qa/shared_examples.rb
1072
+ - lib/ledger_sync/test/support/record_collection.rb
1068
1073
  - lib/ledger_sync/test/support/test_ledger/client.rb
1069
1074
  - lib/ledger_sync/test/support/test_ledger/config.rb
1070
1075
  - lib/ledger_sync/test/support/test_ledger/customer/deserializer.rb
@@ -1094,6 +1099,8 @@ files:
1094
1099
  - lib/ledger_sync/test/support/test_ledger/webhook.rb
1095
1100
  - lib/ledger_sync/test/support/test_ledger/webhook_event.rb
1096
1101
  - lib/ledger_sync/test/support/test_ledger/webhook_notification.rb
1102
+ - lib/ledger_sync/test/support/test_ledger_helpers.rb
1103
+ - lib/ledger_sync/test/support/webmock_helpers.rb
1097
1104
  - lib/ledger_sync/type/boolean.rb
1098
1105
  - lib/ledger_sync/type/date.rb
1099
1106
  - lib/ledger_sync/type/float.rb