Top Level Namespace
Defined Under Namespace
Modules: FactoryBot, LedgerSync, TestLedgerHelpers, WebMock
Classes: Resonad
Instance Method Summary
collapse
Instance Method Details
#core_qa_support(*paths) ⇒ Object
21
22
23
24
25
|
# File 'lib/ledger_sync/test/support.rb', line 21
def core_qa_support(*paths)
paths.each do |path|
require File.join('ledger_sync/test/support/qa/', path.to_s)
end
end
|
#core_support(*paths) ⇒ Object
15
16
17
18
19
|
# File 'lib/ledger_sync/test/support.rb', line 15
def core_support(*paths)
paths.each do |path|
require File.join('ledger_sync/test/support/', path.to_s)
end
end
|
#generate_resource_factories ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/ledger_sync/test/support/factory_bot.rb', line 65
def generate_resource_factories
LedgerSync.ledgers.each do |ledger_key, ledger|
ledger.client_class.resources.each do |resource_key, resource_class|
factory_key = "#{ledger_key}_#{resource_key}".to_sym
next if FactoryBot.factories.registered?(factory_key)
register_factory(prefix: ledger_key, resource_class: resource_class)
end
end
end
|
#qa_support(*paths) ⇒ Object
9
10
11
12
13
|
# File 'lib/ledger_sync/test/support.rb', line 9
def qa_support(*paths)
paths.each do |path|
require File.join('qa/support/', path.to_s)
end
end
|
#rand_id(*args) ⇒ String
Used for uniqueness in QuickBooks Online given the unique name requirement
146
147
148
|
# File 'lib/ledger_sync/test/support/factory_bot.rb', line 146
def rand_id(*args)
FactoryBot.rand_id(*args)
end
|
#register_factory(args = {}) ⇒ Object
Override factory registration to work with Resource and its relationships and attribute types.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/ledger_sync/test/support/factory_bot.rb', line 9
def register_factory(args = {}) prefix = args.fetch(:prefix)
resource_class = args.fetch(:resource_class)
key = "#{prefix}_#{resource_class.resource_type}"
FactoryBot.define do
factory key, class: resource_class do
resource_class.resource_attributes.each do |attribute, resource_attribute|
case resource_attribute.type
when LedgerSync::Type::StringFromSet
add_attribute(attribute) { resource_attribute.type.values.first }
when LedgerSync::Type::String, LedgerSync::Type::ID
case attribute.to_sym
when :ledger_id
sequence(attribute) { nil }
else sequence(attribute) { |n| "#{attribute}-#{rand_id(n)}" }
end
when LedgerSync::Type::Float
add_attribute(attribute) { 1.23 }
when LedgerSync::Type::Boolean
add_attribute(attribute) { false }
when LedgerSync::Type::Date
add_attribute(attribute) { Date.today }
when LedgerSync::Type::Hash
add_attribute(attribute) { {} }
when LedgerSync::Type::Integer
add_attribute(attribute) { 123 }
when LedgerSync::Type::ReferenceOne
key_ending = if resource_attribute.type.resource_class.is_a?(Array)
resource_attribute.type.resource_class.first.resource_type
else
resource_attribute.type.resource_class.resource_type
end
resource_attribute_key = "#{prefix}_#{key_ending}"
next if resource_attribute_key == key
references_one attribute, factory: resource_attribute_key
when LedgerSync::Type::ReferenceMany
key_ending = if resource_attribute.type.resource_class.is_a?(Array)
resource_attribute.type.resource_class.first.resource_type
else
resource_attribute.type.resource_class.resource_type
end
resource_attribute_key = "#{prefix}_#{key_ending}"
next if resource_attribute_key == key
references_many attribute, factory: resource_attribute_key
else
raise "Do not know how to default type: #{resource_attribute.type.class.name}"
end
end
end
end
end
|
#setup_client_qa_support(*clients, keyed: false) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/ledger_sync/test/support/qa/ledger_support_setup.rb', line 3
def setup_client_qa_support(*clients, keyed: false) qa_clients = Hash[clients.uniq.map do |client|
key = client.config.root_key
qa_support "#{key}_helpers"
[
client,
{
env_key: "#{key}_qa".upcase,
helpers_module: Object.const_get("QA::#{client.base_module.name.split('::').last}Helpers"),
key: key
}
]
end]
RSpec.configure do |config|
qa_clients.each_value do |data|
if keyed
config.include data[:helpers_module], qa: true, client: data[:key]
else
config.include data[:helpers_module], qa: true
end
end
config.around(:each, qa: true) do |example|
described_class = example.metadata[:described_class]
config = if described_class.respond_to?(:config)
described_class.config
else
described_class.inferred_config
end
client_key = example.metadata.fetch(:client, config.root_key)
env_key = "#{client_key}_QA".upcase
if ENV.fetch(env_key, nil) == '1'
ClimateControl.modify(Dotenv.parse(ENV.fetch('LOCAL_DOTENV_PATH', '.env.local'))) do
example.run
end
else
skip "Set #{env_key}=1 to run #{client_key} QA tests"
end
end
end
end
|
#stubs_and_times ⇒ Object
3
4
5
|
# File 'lib/ledger_sync/test/support/webmock_helpers.rb', line 3
def stubs_and_times
@stubs_and_times ||= []
end
|
#stubs_and_times_reset ⇒ Object
7
8
9
|
# File 'lib/ledger_sync/test/support/webmock_helpers.rb', line 7
def stubs_and_times_reset
@stubs_and_times = []
end
|
#support(*paths) ⇒ Object
3
4
5
6
7
|
# File 'lib/ledger_sync/test/support.rb', line 3
def support(*paths)
paths.each do |path|
require File.join('support/', path.to_s)
end
end
|
#test_run_id(*args) ⇒ String
Used for uniqueness in QuickBooks Online given the unique name requirement
155
156
157
|
# File 'lib/ledger_sync/test/support/factory_bot.rb', line 155
def test_run_id(*args)
@test_run_id ||= FactoryBot.test_run_id(*args)
end
|