fortnox-api 0.5.2 → 0.6.0

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.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +9 -1104
  4. data/.travis.yml +22 -2
  5. data/Gemfile +3 -1
  6. data/Guardfile +4 -2
  7. data/README.md +2 -2
  8. data/Rakefile +3 -1
  9. data/bin/console +17 -3
  10. data/fortnox-api.gemspec +32 -27
  11. data/lib/fortnox/api.rb +17 -16
  12. data/lib/fortnox/api/circular_queue.rb +13 -7
  13. data/lib/fortnox/api/mappers.rb +29 -25
  14. data/lib/fortnox/api/mappers/article.rb +7 -6
  15. data/lib/fortnox/api/mappers/base.rb +18 -16
  16. data/lib/fortnox/api/mappers/base/from_json.rb +37 -30
  17. data/lib/fortnox/api/mappers/base/to_json.rb +39 -37
  18. data/lib/fortnox/api/mappers/customer.rb +7 -7
  19. data/lib/fortnox/api/mappers/default_delivery_types.rb +4 -2
  20. data/lib/fortnox/api/mappers/default_templates.rb +5 -4
  21. data/lib/fortnox/api/mappers/edi_information.rb +5 -4
  22. data/lib/fortnox/api/mappers/email_information.rb +5 -4
  23. data/lib/fortnox/api/mappers/invoice.rb +10 -8
  24. data/lib/fortnox/api/mappers/invoice_row.rb +12 -7
  25. data/lib/fortnox/api/mappers/order.rb +10 -7
  26. data/lib/fortnox/api/mappers/order_row.rb +13 -6
  27. data/lib/fortnox/api/mappers/project.rb +6 -4
  28. data/lib/fortnox/api/mappers/terms_of_payments.rb +17 -0
  29. data/lib/fortnox/api/mappers/unit.rb +17 -0
  30. data/lib/fortnox/api/models.rb +9 -5
  31. data/lib/fortnox/api/models/article.rb +68 -67
  32. data/lib/fortnox/api/models/base.rb +52 -36
  33. data/lib/fortnox/api/models/customer.rb +95 -94
  34. data/lib/fortnox/api/models/document.rb +186 -0
  35. data/lib/fortnox/api/models/invoice.rb +44 -44
  36. data/lib/fortnox/api/models/label.rb +5 -3
  37. data/lib/fortnox/api/models/order.rb +8 -8
  38. data/lib/fortnox/api/models/project.rb +10 -8
  39. data/lib/fortnox/api/models/terms_of_payments.rb +28 -0
  40. data/lib/fortnox/api/models/unit.rb +24 -0
  41. data/lib/fortnox/api/repositories.rb +9 -5
  42. data/lib/fortnox/api/repositories/article.rb +6 -4
  43. data/lib/fortnox/api/repositories/base.rb +49 -46
  44. data/lib/fortnox/api/repositories/base/loaders.rb +32 -36
  45. data/lib/fortnox/api/repositories/base/savers.rb +23 -21
  46. data/lib/fortnox/api/repositories/customer.rb +6 -4
  47. data/lib/fortnox/api/repositories/invoice.rb +6 -4
  48. data/lib/fortnox/api/repositories/order.rb +6 -4
  49. data/lib/fortnox/api/repositories/project.rb +6 -4
  50. data/lib/fortnox/api/repositories/terms_of_payments.rb +17 -0
  51. data/lib/fortnox/api/repositories/unit.rb +17 -0
  52. data/lib/fortnox/api/request_handling.rb +12 -12
  53. data/lib/fortnox/api/types.rb +62 -11
  54. data/lib/fortnox/api/types/default_delivery_types.rb +5 -3
  55. data/lib/fortnox/api/types/default_templates.rb +3 -1
  56. data/lib/fortnox/api/types/defaulted.rb +2 -2
  57. data/lib/fortnox/api/types/document_row.rb +41 -42
  58. data/lib/fortnox/api/types/edi_information.rb +10 -8
  59. data/lib/fortnox/api/types/email_information.rb +10 -8
  60. data/lib/fortnox/api/types/enums.rb +60 -47
  61. data/lib/fortnox/api/types/invoice_row.rb +8 -8
  62. data/lib/fortnox/api/types/model.rb +14 -10
  63. data/lib/fortnox/api/types/nullable.rb +7 -7
  64. data/lib/fortnox/api/types/order_row.rb +5 -5
  65. data/lib/fortnox/api/types/required.rb +5 -5
  66. data/lib/fortnox/api/types/sized.rb +14 -6
  67. data/lib/fortnox/api/version.rb +3 -1
  68. data/spec/fortnox/api/mappers/article_spec.rb +3 -1
  69. data/spec/fortnox/api/mappers/base/from_json_spec.rb +15 -13
  70. data/spec/fortnox/api/mappers/base/to_json_spec.rb +4 -3
  71. data/spec/fortnox/api/mappers/base_spec.rb +40 -35
  72. data/spec/fortnox/api/mappers/contexts/json_conversion.rb +12 -11
  73. data/spec/fortnox/api/mappers/customer_spec.rb +3 -1
  74. data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +3 -1
  75. data/spec/fortnox/api/mappers/edi_information_spec.rb +4 -2
  76. data/spec/fortnox/api/mappers/email_information_spec.rb +4 -2
  77. data/spec/fortnox/api/mappers/examples/mapper.rb +17 -9
  78. data/spec/fortnox/api/mappers/invoice_row_spec.rb +8 -3
  79. data/spec/fortnox/api/mappers/invoice_spec.rb +4 -1
  80. data/spec/fortnox/api/mappers/order_row_spec.rb +9 -2
  81. data/spec/fortnox/api/mappers/order_spec.rb +4 -1
  82. data/spec/fortnox/api/mappers/project_spec.rb +3 -1
  83. data/spec/fortnox/api/mappers/terms_of_payments_spec.rb +16 -0
  84. data/spec/fortnox/api/mappers/unit_spec.rb +57 -0
  85. data/spec/fortnox/api/models/article_spec.rb +2 -0
  86. data/spec/fortnox/api/models/base_spec.rb +46 -38
  87. data/spec/fortnox/api/models/customer_spec.rb +2 -0
  88. data/spec/fortnox/api/models/examples/document_base.rb +5 -3
  89. data/spec/fortnox/api/models/examples/model.rb +12 -9
  90. data/spec/fortnox/api/models/invoice_spec.rb +2 -0
  91. data/spec/fortnox/api/models/order_spec.rb +2 -0
  92. data/spec/fortnox/api/models/project_spec.rb +2 -0
  93. data/spec/fortnox/api/models/terms_of_payments_spec.rb +9 -0
  94. data/spec/fortnox/api/models/unit_spec.rb +31 -0
  95. data/spec/fortnox/api/repositories/article_spec.rb +7 -5
  96. data/spec/fortnox/api/repositories/base_spec.rb +121 -100
  97. data/spec/fortnox/api/repositories/customer_spec.rb +7 -5
  98. data/spec/fortnox/api/repositories/examples/all.rb +5 -4
  99. data/spec/fortnox/api/repositories/examples/find.rb +50 -41
  100. data/spec/fortnox/api/repositories/examples/only.rb +14 -13
  101. data/spec/fortnox/api/repositories/examples/save.rb +23 -29
  102. data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +11 -11
  103. data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +11 -10
  104. data/spec/fortnox/api/repositories/examples/search.rb +15 -15
  105. data/spec/fortnox/api/repositories/invoice_spec.rb +8 -6
  106. data/spec/fortnox/api/repositories/order_spec.rb +8 -6
  107. data/spec/fortnox/api/repositories/project_spec.rb +7 -5
  108. data/spec/fortnox/api/repositories/terms_of_payments_spec.rb +30 -0
  109. data/spec/fortnox/api/repositories/unit_spec.rb +34 -0
  110. data/spec/fortnox/api/types/account_number_spec.rb +12 -9
  111. data/spec/fortnox/api/types/default_delivery_types_spec.rb +6 -4
  112. data/spec/fortnox/api/types/edi_information_spec.rb +9 -7
  113. data/spec/fortnox/api/types/email_information_spec.rb +8 -6
  114. data/spec/fortnox/api/types/email_spec.rb +27 -14
  115. data/spec/fortnox/api/types/enums_spec.rb +3 -1
  116. data/spec/fortnox/api/types/examples/document_row.rb +10 -8
  117. data/spec/fortnox/api/types/examples/enum.rb +29 -22
  118. data/spec/fortnox/api/types/examples/types.rb +8 -4
  119. data/spec/fortnox/api/types/housework_types_spec.rb +68 -0
  120. data/spec/fortnox/api/types/invoice_row_spec.rb +3 -1
  121. data/spec/fortnox/api/types/model_spec.rb +12 -9
  122. data/spec/fortnox/api/types/nullable_spec.rb +8 -6
  123. data/spec/fortnox/api/types/order_row_spec.rb +4 -2
  124. data/spec/fortnox/api/types/required_spec.rb +4 -2
  125. data/spec/fortnox/api/types/sized_spec.rb +18 -16
  126. data/spec/fortnox/api_spec.rb +45 -43
  127. data/spec/spec_helper.rb +9 -6
  128. data/spec/support/helpers.rb +3 -1
  129. data/spec/support/helpers/configuration_helper.rb +2 -0
  130. data/spec/support/helpers/dummy_class_helper.rb +7 -8
  131. data/spec/support/helpers/repository_helper.rb +2 -0
  132. data/spec/support/helpers/when_performing_helper.rb +3 -1
  133. data/spec/support/matchers.rb +2 -0
  134. data/spec/support/matchers/type.rb +3 -1
  135. data/spec/support/matchers/type/attribute_matcher.rb +15 -14
  136. data/spec/support/matchers/type/enum_matcher.rb +9 -7
  137. data/spec/support/matchers/type/have_account_number_matcher.rb +11 -9
  138. data/spec/support/matchers/type/have_country_code_matcher.rb +6 -4
  139. data/spec/support/matchers/type/have_currency_matcher.rb +4 -2
  140. data/spec/support/matchers/type/have_customer_type_matcher.rb +6 -4
  141. data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +4 -2
  142. data/spec/support/matchers/type/have_discount_type_matcher.rb +4 -2
  143. data/spec/support/matchers/type/have_email_matcher.rb +11 -9
  144. data/spec/support/matchers/type/have_housework_type_matcher.rb +9 -0
  145. data/spec/support/matchers/type/have_nullable_date_matcher.rb +29 -29
  146. data/spec/support/matchers/type/have_nullable_matcher.rb +23 -21
  147. data/spec/support/matchers/type/have_nullable_string_matcher.rb +30 -32
  148. data/spec/support/matchers/type/have_sized_float_matcher.rb +4 -2
  149. data/spec/support/matchers/type/have_sized_integer_matcher.rb +4 -2
  150. data/spec/support/matchers/type/have_sized_string_matcher.rb +16 -15
  151. data/spec/support/matchers/type/have_vat_type_matcher.rb +4 -2
  152. data/spec/support/matchers/type/numeric_matcher.rb +25 -23
  153. data/spec/support/matchers/type/require_attribute_matcher.rb +36 -37
  154. data/spec/support/matchers/type/type_matcher.rb +18 -16
  155. data/spec/support/vcr_setup.rb +2 -0
  156. data/spec/vcr_cassettes/orders/{house_work_type_babysitting.yml → housework_type_babysitting.yml} +9 -10
  157. data/spec/vcr_cassettes/orders/{house_work_type_cleaning.yml → housework_type_cleaning.yml} +9 -10
  158. data/spec/vcr_cassettes/orders/{house_work_type_construction.yml → housework_type_construction.yml} +9 -10
  159. data/spec/vcr_cassettes/orders/{house_work_type_cooking.yml → housework_type_cooking.yml} +7 -7
  160. data/spec/vcr_cassettes/orders/{house_work_type_electricity.yml → housework_type_electricity.yml} +9 -10
  161. data/spec/vcr_cassettes/orders/{house_work_type_gardening.yml → housework_type_gardening.yml} +9 -10
  162. data/spec/vcr_cassettes/orders/{house_work_type_glassmetalwork.yml → housework_type_glassmetalwork.yml} +9 -10
  163. data/spec/vcr_cassettes/orders/{house_work_type_grounddrainagework.yml → housework_type_grounddrainagework.yml} +9 -10
  164. data/spec/vcr_cassettes/orders/{house_work_type_hvac.yml → housework_type_hvac.yml} +9 -10
  165. data/spec/vcr_cassettes/orders/{house_work_type_masonry.yml → housework_type_masonry.yml} +9 -10
  166. data/spec/vcr_cassettes/orders/{house_work_type_othercare.yml → housework_type_othercare.yml} +9 -10
  167. data/spec/vcr_cassettes/orders/{house_work_type_othercosts.yml → housework_type_othercosts.yml} +9 -10
  168. data/spec/vcr_cassettes/orders/{house_work_type_paintingwallpapering.yml → housework_type_paintingwallpapering.yml} +9 -10
  169. data/spec/vcr_cassettes/orders/{house_work_type_snowplowing.yml → housework_type_snowplowing.yml} +9 -10
  170. data/spec/vcr_cassettes/orders/{house_work_type_textileclothing.yml → housework_type_textileclothing.yml} +9 -10
  171. data/spec/vcr_cassettes/orders/{house_work_type_tutoring.yml → housework_type_tutoring.yml} +7 -7
  172. data/spec/vcr_cassettes/termsofpayments/all.yml +51 -0
  173. data/spec/vcr_cassettes/termsofpayments/find_failure.yml +45 -0
  174. data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +46 -0
  175. data/spec/vcr_cassettes/termsofpayments/find_new.yml +46 -0
  176. data/spec/vcr_cassettes/termsofpayments/save_new.yml +45 -0
  177. data/spec/vcr_cassettes/termsofpayments/save_old.yml +46 -0
  178. data/spec/vcr_cassettes/units/all.yml +48 -0
  179. data/spec/vcr_cassettes/units/find_failure.yml +45 -0
  180. data/spec/vcr_cassettes/units/find_id_1.yml +46 -0
  181. data/spec/vcr_cassettes/units/find_new.yml +48 -0
  182. data/spec/vcr_cassettes/units/save_new.yml +47 -0
  183. data/spec/vcr_cassettes/units/save_old.yml +48 -0
  184. data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +47 -0
  185. metadata +127 -88
  186. data/docs/account.rb +0 -59
  187. data/docs/extraction_script.js +0 -23
  188. data/docs/generation_script.rb +0 -43
  189. data/docs/json/account.json +0 -77
  190. data/lib/fortnox/api/models/document_base.rb +0 -189
  191. data/spec/fortnox/api/types/house_work_types_spec.rb +0 -64
  192. data/spec/support/matchers/type/have_house_work_type_matcher.rb +0 -7
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ENV['RUBY_ENV'] = 'test'
2
4
 
5
+ require 'simplecov'
6
+
7
+ SimpleCov.start
8
+
3
9
  require 'rspec/collection_matchers'
4
10
  require 'webmock/rspec'
5
11
  require 'pry'
6
- require "codeclimate-test-reporter"
7
12
  require 'support/matchers'
8
13
  require 'support/helpers'
9
14
  require 'support/vcr_setup'
10
15
 
11
- CodeClimate::TestReporter.start
12
-
13
16
  RSpec.configure do |config|
14
17
  config.run_all_when_everything_filtered = true
15
18
  config.filter_run :focus
@@ -22,12 +25,12 @@ RSpec.configure do |config|
22
25
 
23
26
  config.order = 'random'
24
27
 
25
- WebMock.disable_net_connect!( allow: 'codeclimate.com' )
28
+ WebMock.disable_net_connect!(allow: 'codeclimate.com')
26
29
 
27
30
  config.before do
28
31
  module Test
29
32
  def self.remove_constants
30
- constants.each{ |const| remove_const(const) }
33
+ constants.each { |const| remove_const(const) }
31
34
  self
32
35
  end
33
36
  end
@@ -40,7 +43,7 @@ RSpec.configure do |config|
40
43
  # Reset configuration after each test run
41
44
  config.after do
42
45
  Fortnox::API::DEFAULT_CONFIGURATION.each do |key, value|
43
- Fortnox::API.config.send("#{ key }=", value)
46
+ Fortnox::API.config.send("#{key}=", value)
44
47
  end
45
48
  end
46
49
  end
@@ -1 +1,3 @@
1
- Dir[File.expand_path('spec/support/helpers/*.rb')].each{ |file| require file }
1
+ # frozen_string_literal: true
2
+
3
+ Dir[File.expand_path('spec/support/helpers/*.rb')].each { |file| require file }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Helpers
2
4
  module Configuration
3
5
  def set_api_test_configuration
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry-types'
2
4
 
3
5
  module Helpers
4
6
  def using_test_classes
5
- around( :all ) do |example|
7
+ around(:all) do |example|
6
8
  classes_before_examples = Object.constants
7
9
 
8
10
  save_dry_types_state
@@ -16,15 +18,13 @@ module Helpers
16
18
 
17
19
  clean_up_dry_types
18
20
 
19
- classes_created_by_block.each do |klass|
20
- Object.send(:remove_const, klass)
21
- end
21
+ classes_created_by_block.each { |klass| Object.send(:remove_const, klass) }
22
22
  end
23
23
  end
24
24
 
25
- alias_method :using_test_class, :using_test_classes
25
+ alias using_test_class using_test_classes
26
26
 
27
- private
27
+ private
28
28
 
29
29
  def save_dry_types_state
30
30
  @types = Dry::Types.container._container.keys
@@ -32,8 +32,7 @@ private
32
32
 
33
33
  def clean_up_dry_types
34
34
  container = Dry::Types.container._container
35
- (container.keys - @types).each{ |key| container.delete(key) }
35
+ (container.keys - @types).each { |key| container.delete(key) }
36
36
  Dry::Types.instance_variable_set('@type_map', Concurrent::Map.new)
37
37
  end
38
-
39
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Helpers
2
4
  module Repositories
3
5
  # Returns directory for VCR.
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Helpers
2
- def when_performing &block
4
+ def when_performing(&block)
3
5
  block.to_proc
4
6
  end
5
7
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'support/matchers/type'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'support/matchers/type/attribute_matcher'
2
4
  require 'support/matchers/type/type_matcher'
3
5
  require 'support/matchers/type/have_nullable_matcher'
@@ -11,7 +13,7 @@ require 'support/matchers/type/have_sized_string_matcher'
11
13
  require 'support/matchers/type/have_default_delivery_type_matcher'
12
14
  require 'support/matchers/type/have_nullable_string_matcher'
13
15
  require 'support/matchers/type/have_sized_float_matcher'
14
- require 'support/matchers/type/have_house_work_type_matcher'
16
+ require 'support/matchers/type/have_housework_type_matcher'
15
17
  require 'support/matchers/type/have_account_number_matcher'
16
18
  require 'support/matchers/type/have_discount_type_matcher'
17
19
  require 'support/matchers/type/have_sized_integer_matcher'
@@ -1,39 +1,40 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
5
  class AttributeMatcher
4
- def initialize( attribute, valid_hash, attribute_type )
6
+ def initialize(attribute, valid_hash, attribute_type)
5
7
  @attribute = attribute
6
8
  @valid_hash = valid_hash.dup
7
9
  @attribute_type = attribute_type
8
10
  @errors = ''
9
11
  end
10
12
 
11
- def matches? ( klass )
13
+ def matches?(klass)
12
14
  @klass = klass
13
15
  end
14
16
 
15
17
  def description
16
- "have #{ @attribute_type } attribute #{ @attribute.inspect }"
18
+ "have #{@attribute_type} attribute #{@attribute.inspect}"
17
19
  end
18
20
 
19
21
  def failure_message
20
- "Expected class to have attribute #{ @attribute.inspect } defined as #{ @attribute_type }, "\
22
+ "Expected class to have attribute #{@attribute.inspect} defined as #{@attribute_type}, "\
21
23
  "but got following errors:
22
- #{ @errors }"
24
+ #{@errors}"
23
25
  end
24
26
 
25
27
  protected
26
28
 
27
- def expect_error(msg)
28
- yield
29
-
30
- @errors << msg
31
- false # Fail test since expected error not thrown
32
- rescue Dry::Struct::Error
33
- # TODO: check if error message is correct
34
- true
35
- end
29
+ def expect_error(msg)
30
+ yield
36
31
 
32
+ @errors << msg
33
+ false # Fail test since expected error not thrown
34
+ rescue Dry::Struct::Error
35
+ # TODO: check if error message is correct
36
+ true
37
+ end
37
38
  end
38
39
  end
39
40
  end
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
5
  class EnumMatcher < TypeMatcher
4
- def initialize( attribute, valid_hash, enum_type, enum_types, nonsense_value: 'NONSENSE'.freeze )
6
+ def initialize(attribute, valid_hash, enum_type, enum_types, nonsense_value: 'NONSENSE')
5
7
  valid_value = Fortnox::API::Types.const_get(enum_types).values.first
6
8
 
7
- super( attribute, valid_hash, enum_type, valid_value, nonsense_value )
9
+ super(attribute, valid_hash, enum_type, valid_value, nonsense_value)
8
10
 
9
11
  @enum_type = Fortnox::API::Types.const_get(enum_type)
10
- @expected_error = "Exception missing for nonsense value #{ @invalid_value.inspect }"
12
+ @expected_error = "Exception missing for nonsense value #{@invalid_value.inspect}"
11
13
  end
12
14
 
13
15
  private
14
16
 
15
- def expected_type?
16
- @actual_type = @klass.schema[@attribute]
17
- @actual_type == @enum_type
18
- end
17
+ def expected_type?
18
+ @actual_type = @klass.schema[@attribute]
19
+ @actual_type == @enum_type
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
- def have_account_number( attribute, valid_hash = {} )
4
- HaveAccountNumberMatcher.new( attribute, valid_hash )
5
+ def have_account_number(attribute, valid_hash = {})
6
+ HaveAccountNumberMatcher.new(attribute, valid_hash)
5
7
  end
6
8
 
7
9
  class HaveAccountNumberMatcher < TypeMatcher
8
- def initialize( attribute, valid_hash )
9
- super( attribute, valid_hash, 'account number', 1000, -1 )
10
- @expected_error = "Exception missing for invalid value #{ @invalid_value.inspect }".freeze
10
+ def initialize(attribute, valid_hash)
11
+ super(attribute, valid_hash, 'account number', 1000, -1)
12
+ @expected_error = "Exception missing for invalid value #{@invalid_value.inspect}"
11
13
  end
12
14
 
13
15
  private
14
16
 
15
- def expected_type?
16
- @actual_type = @klass.schema[@attribute]
17
- @actual_type == Fortnox::API::Types::AccountNumber
18
- end
17
+ def expected_type?
18
+ @actual_type = @klass.schema[@attribute]
19
+ @actual_type == Fortnox::API::Types::AccountNumber
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
- def have_country_code( attribute, valid_hash = {} )
4
- HaveCountryCodeMatcher.new( attribute, valid_hash )
5
+ def have_country_code(attribute, valid_hash = {})
6
+ HaveCountryCodeMatcher.new(attribute, valid_hash)
5
7
  end
6
8
 
7
9
  class HaveCountryCodeMatcher < EnumMatcher
8
- def initialize( attribute, valid_hash )
9
- super( attribute, valid_hash, 'CountryCode', 'CountryCodes', nonsense_value: 'XX'.freeze )
10
+ def initialize(attribute, valid_hash)
11
+ super(attribute, valid_hash, 'CountryCode', 'CountryCodes', nonsense_value: 'XX')
10
12
  end
11
13
  end
12
14
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
- def have_currency( attribute, valid_hash = {} )
4
- EnumMatcher.new( attribute, valid_hash, 'Currency', 'Currencies' )
5
+ def have_currency(attribute, valid_hash = {})
6
+ EnumMatcher.new(attribute, valid_hash, 'Currency', 'Currencies')
5
7
  end
6
8
  end
7
9
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
- def have_customer_type( attribute, valid_hash = {} )
4
- HaveCustomerTypeMatcher.new( attribute, valid_hash )
5
+ def have_customer_type(attribute, valid_hash = {})
6
+ HaveCustomerTypeMatcher.new(attribute, valid_hash)
5
7
  end
6
8
 
7
9
  class HaveCustomerTypeMatcher < EnumMatcher
8
- def initialize( attribute, valid_hash )
9
- super( attribute, valid_hash, 'CustomerType', 'CustomerTypes' )
10
+ def initialize(attribute, valid_hash)
11
+ super(attribute, valid_hash, 'CustomerType', 'CustomerTypes')
10
12
  end
11
13
  end
12
14
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
- def have_default_delivery_type( attribute, valid_hash = {} )
4
- EnumMatcher.new( attribute, valid_hash, 'DefaultDeliveryType', 'DefaultDeliveryTypeValues' )
5
+ def have_default_delivery_type(attribute, valid_hash = {})
6
+ EnumMatcher.new(attribute, valid_hash, 'DefaultDeliveryType', 'DefaultDeliveryTypeValues')
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
- def have_discount_type( attribute, valid_hash = {} )
4
- EnumMatcher.new( attribute, valid_hash, 'DiscountType', 'DiscountTypes' )
5
+ def have_discount_type(attribute, valid_hash = {})
6
+ EnumMatcher.new(attribute, valid_hash, 'DiscountType', 'DiscountTypes')
5
7
  end
6
8
  end
7
9
  end
@@ -1,22 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
- def have_email( attribute, valid_hash = {} )
4
- HaveEmailMatcher.new( attribute, valid_hash )
5
+ def have_email(attribute, valid_hash = {})
6
+ HaveEmailMatcher.new(attribute, valid_hash)
5
7
  end
6
8
 
7
9
  class HaveEmailMatcher < TypeMatcher
8
- def initialize( attribute, valid_hash )
9
- super( attribute, valid_hash, 'email', 'valid@email.com', 'invalid@email_without_top_domain' )
10
- @expected_error = "Exception missing for invalid value #{ @invalid_value.inspect }"
10
+ def initialize(attribute, valid_hash)
11
+ super(attribute, valid_hash, 'email', 'valid@email.com', 'invalid@email_without_top_domain')
12
+ @expected_error = "Exception missing for invalid value #{@invalid_value.inspect}"
11
13
  @expected_type = Fortnox::API::Types::Email
12
14
  end
13
15
 
14
16
  private
15
17
 
16
- def expected_type?
17
- @actual_type = @klass.schema[@attribute]
18
- @actual_type == Fortnox::API::Types::Email
19
- end
18
+ def expected_type?
19
+ @actual_type = @klass.schema[@attribute]
20
+ @actual_type == Fortnox::API::Types::Email
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Matchers
4
+ module Type
5
+ def have_housework_type(attribute, valid_hash = {})
6
+ EnumMatcher.new(attribute, valid_hash, 'HouseworkType', 'HouseworkTypes')
7
+ end
8
+ end
9
+ end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Matchers
2
4
  module Type
3
- def have_nullable_date( attribute, valid_value, invalid_value )
4
- HaveNullableDateMatcher.new( attribute, valid_value, invalid_value )
5
+ def have_nullable_date(attribute, valid_value, invalid_value)
6
+ HaveNullableDateMatcher.new(attribute, valid_value, invalid_value)
5
7
  end
6
8
 
7
9
  class HaveNullableDateMatcher < HaveNullableMatcher
8
- def initialize( attribute, valid_value, invalid_value )
10
+ def initialize(attribute, valid_value, invalid_value)
9
11
  @attribute = attribute
10
12
  @valid_value = valid_value
11
13
  @invalid_value = invalid_value
@@ -14,45 +16,43 @@ module Matchers
14
16
  @failure_description = ''
15
17
  end
16
18
 
17
- def matches?( klass )
19
+ def matches?(klass)
18
20
  @klass = klass
19
21
 
20
22
  accepts_nil? && accepts_valid_value? && rejects_invalid_value?
21
23
  end
22
24
 
23
25
  def description
24
- "have nullable attribute #{ @attribute.inspect }"
26
+ "have nullable attribute #{@attribute.inspect}"
25
27
  end
26
28
 
27
29
  def failure_message
28
- "Expected class to have nullable attribute #{ @attribute.inspect }" << @failure_description
30
+ "Expected class to have nullable attribute #{@attribute.inspect}" << @failure_description
29
31
  end
30
32
 
31
33
  private
32
34
 
33
- def accepts_nil?
34
- @klass.new(@attribute => nil)
35
- end
36
-
37
- def accepts_valid_value?
38
- model = @klass.new(@attribute => @valid_value)
39
- model.send(@attribute) == @valid_value
40
- end
41
-
42
- def rejects_invalid_value?
43
- @klass.new(@attribute => @invalid_value)
44
-
45
- @failure_description << " (Expected #{ @expected_error }, but got none)"
46
- return false
47
- rescue @expected_error => error
48
- if error.message == @expected_error_message
49
- return true
50
- else
51
- fail_message = "Expected error message to include #{ expected_message.inspect }, "\
52
- "but was #{ error.message.inspect }"
53
- fail(fail_message)
54
- end
55
- end
35
+ def accepts_nil?
36
+ @klass.new(@attribute => nil)
37
+ end
38
+
39
+ def accepts_valid_value?
40
+ model = @klass.new(@attribute => @valid_value)
41
+ model.send(@attribute) == @valid_value
42
+ end
43
+
44
+ def rejects_invalid_value?
45
+ @klass.new(@attribute => @invalid_value)
46
+
47
+ @failure_description << " (Expected #{@expected_error}, but got none)"
48
+ false
49
+ rescue @expected_error => error
50
+ return true if error.message == @expected_error_message
51
+
52
+ fail_message = "Expected error message to include #{expected_message.inspect}, "\
53
+ "but was #{error.message.inspect}"
54
+ raise(fail_message)
55
+ end
56
56
  end
57
57
  end
58
58
  end