fortnox-api 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +9 -1104
- data/.travis.yml +22 -2
- data/Gemfile +3 -1
- data/Guardfile +4 -2
- data/README.md +2 -2
- data/Rakefile +3 -1
- data/bin/console +17 -3
- data/fortnox-api.gemspec +32 -27
- data/lib/fortnox/api.rb +17 -16
- data/lib/fortnox/api/circular_queue.rb +13 -7
- data/lib/fortnox/api/mappers.rb +29 -25
- data/lib/fortnox/api/mappers/article.rb +7 -6
- data/lib/fortnox/api/mappers/base.rb +18 -16
- data/lib/fortnox/api/mappers/base/from_json.rb +37 -30
- data/lib/fortnox/api/mappers/base/to_json.rb +39 -37
- data/lib/fortnox/api/mappers/customer.rb +7 -7
- data/lib/fortnox/api/mappers/default_delivery_types.rb +4 -2
- data/lib/fortnox/api/mappers/default_templates.rb +5 -4
- data/lib/fortnox/api/mappers/edi_information.rb +5 -4
- data/lib/fortnox/api/mappers/email_information.rb +5 -4
- data/lib/fortnox/api/mappers/invoice.rb +10 -8
- data/lib/fortnox/api/mappers/invoice_row.rb +12 -7
- data/lib/fortnox/api/mappers/order.rb +10 -7
- data/lib/fortnox/api/mappers/order_row.rb +13 -6
- data/lib/fortnox/api/mappers/project.rb +6 -4
- data/lib/fortnox/api/mappers/terms_of_payments.rb +17 -0
- data/lib/fortnox/api/mappers/unit.rb +17 -0
- data/lib/fortnox/api/models.rb +9 -5
- data/lib/fortnox/api/models/article.rb +68 -67
- data/lib/fortnox/api/models/base.rb +52 -36
- data/lib/fortnox/api/models/customer.rb +95 -94
- data/lib/fortnox/api/models/document.rb +186 -0
- data/lib/fortnox/api/models/invoice.rb +44 -44
- data/lib/fortnox/api/models/label.rb +5 -3
- data/lib/fortnox/api/models/order.rb +8 -8
- data/lib/fortnox/api/models/project.rb +10 -8
- data/lib/fortnox/api/models/terms_of_payments.rb +28 -0
- data/lib/fortnox/api/models/unit.rb +24 -0
- data/lib/fortnox/api/repositories.rb +9 -5
- data/lib/fortnox/api/repositories/article.rb +6 -4
- data/lib/fortnox/api/repositories/base.rb +49 -46
- data/lib/fortnox/api/repositories/base/loaders.rb +32 -36
- data/lib/fortnox/api/repositories/base/savers.rb +23 -21
- data/lib/fortnox/api/repositories/customer.rb +6 -4
- data/lib/fortnox/api/repositories/invoice.rb +6 -4
- data/lib/fortnox/api/repositories/order.rb +6 -4
- data/lib/fortnox/api/repositories/project.rb +6 -4
- data/lib/fortnox/api/repositories/terms_of_payments.rb +17 -0
- data/lib/fortnox/api/repositories/unit.rb +17 -0
- data/lib/fortnox/api/request_handling.rb +12 -12
- data/lib/fortnox/api/types.rb +62 -11
- data/lib/fortnox/api/types/default_delivery_types.rb +5 -3
- data/lib/fortnox/api/types/default_templates.rb +3 -1
- data/lib/fortnox/api/types/defaulted.rb +2 -2
- data/lib/fortnox/api/types/document_row.rb +41 -42
- data/lib/fortnox/api/types/edi_information.rb +10 -8
- data/lib/fortnox/api/types/email_information.rb +10 -8
- data/lib/fortnox/api/types/enums.rb +60 -47
- data/lib/fortnox/api/types/invoice_row.rb +8 -8
- data/lib/fortnox/api/types/model.rb +14 -10
- data/lib/fortnox/api/types/nullable.rb +7 -7
- data/lib/fortnox/api/types/order_row.rb +5 -5
- data/lib/fortnox/api/types/required.rb +5 -5
- data/lib/fortnox/api/types/sized.rb +14 -6
- data/lib/fortnox/api/version.rb +3 -1
- data/spec/fortnox/api/mappers/article_spec.rb +3 -1
- data/spec/fortnox/api/mappers/base/from_json_spec.rb +15 -13
- data/spec/fortnox/api/mappers/base/to_json_spec.rb +4 -3
- data/spec/fortnox/api/mappers/base_spec.rb +40 -35
- data/spec/fortnox/api/mappers/contexts/json_conversion.rb +12 -11
- data/spec/fortnox/api/mappers/customer_spec.rb +3 -1
- data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +3 -1
- data/spec/fortnox/api/mappers/edi_information_spec.rb +4 -2
- data/spec/fortnox/api/mappers/email_information_spec.rb +4 -2
- data/spec/fortnox/api/mappers/examples/mapper.rb +17 -9
- data/spec/fortnox/api/mappers/invoice_row_spec.rb +8 -3
- data/spec/fortnox/api/mappers/invoice_spec.rb +4 -1
- data/spec/fortnox/api/mappers/order_row_spec.rb +9 -2
- data/spec/fortnox/api/mappers/order_spec.rb +4 -1
- data/spec/fortnox/api/mappers/project_spec.rb +3 -1
- data/spec/fortnox/api/mappers/terms_of_payments_spec.rb +16 -0
- data/spec/fortnox/api/mappers/unit_spec.rb +57 -0
- data/spec/fortnox/api/models/article_spec.rb +2 -0
- data/spec/fortnox/api/models/base_spec.rb +46 -38
- data/spec/fortnox/api/models/customer_spec.rb +2 -0
- data/spec/fortnox/api/models/examples/document_base.rb +5 -3
- data/spec/fortnox/api/models/examples/model.rb +12 -9
- data/spec/fortnox/api/models/invoice_spec.rb +2 -0
- data/spec/fortnox/api/models/order_spec.rb +2 -0
- data/spec/fortnox/api/models/project_spec.rb +2 -0
- data/spec/fortnox/api/models/terms_of_payments_spec.rb +9 -0
- data/spec/fortnox/api/models/unit_spec.rb +31 -0
- data/spec/fortnox/api/repositories/article_spec.rb +7 -5
- data/spec/fortnox/api/repositories/base_spec.rb +121 -100
- data/spec/fortnox/api/repositories/customer_spec.rb +7 -5
- data/spec/fortnox/api/repositories/examples/all.rb +5 -4
- data/spec/fortnox/api/repositories/examples/find.rb +50 -41
- data/spec/fortnox/api/repositories/examples/only.rb +14 -13
- data/spec/fortnox/api/repositories/examples/save.rb +23 -29
- data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +11 -11
- data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +11 -10
- data/spec/fortnox/api/repositories/examples/search.rb +15 -15
- data/spec/fortnox/api/repositories/invoice_spec.rb +8 -6
- data/spec/fortnox/api/repositories/order_spec.rb +8 -6
- data/spec/fortnox/api/repositories/project_spec.rb +7 -5
- data/spec/fortnox/api/repositories/terms_of_payments_spec.rb +30 -0
- data/spec/fortnox/api/repositories/unit_spec.rb +34 -0
- data/spec/fortnox/api/types/account_number_spec.rb +12 -9
- data/spec/fortnox/api/types/default_delivery_types_spec.rb +6 -4
- data/spec/fortnox/api/types/edi_information_spec.rb +9 -7
- data/spec/fortnox/api/types/email_information_spec.rb +8 -6
- data/spec/fortnox/api/types/email_spec.rb +27 -14
- data/spec/fortnox/api/types/enums_spec.rb +3 -1
- data/spec/fortnox/api/types/examples/document_row.rb +10 -8
- data/spec/fortnox/api/types/examples/enum.rb +29 -22
- data/spec/fortnox/api/types/examples/types.rb +8 -4
- data/spec/fortnox/api/types/housework_types_spec.rb +68 -0
- data/spec/fortnox/api/types/invoice_row_spec.rb +3 -1
- data/spec/fortnox/api/types/model_spec.rb +12 -9
- data/spec/fortnox/api/types/nullable_spec.rb +8 -6
- data/spec/fortnox/api/types/order_row_spec.rb +4 -2
- data/spec/fortnox/api/types/required_spec.rb +4 -2
- data/spec/fortnox/api/types/sized_spec.rb +18 -16
- data/spec/fortnox/api_spec.rb +45 -43
- data/spec/spec_helper.rb +9 -6
- data/spec/support/helpers.rb +3 -1
- data/spec/support/helpers/configuration_helper.rb +2 -0
- data/spec/support/helpers/dummy_class_helper.rb +7 -8
- data/spec/support/helpers/repository_helper.rb +2 -0
- data/spec/support/helpers/when_performing_helper.rb +3 -1
- data/spec/support/matchers.rb +2 -0
- data/spec/support/matchers/type.rb +3 -1
- data/spec/support/matchers/type/attribute_matcher.rb +15 -14
- data/spec/support/matchers/type/enum_matcher.rb +9 -7
- data/spec/support/matchers/type/have_account_number_matcher.rb +11 -9
- data/spec/support/matchers/type/have_country_code_matcher.rb +6 -4
- data/spec/support/matchers/type/have_currency_matcher.rb +4 -2
- data/spec/support/matchers/type/have_customer_type_matcher.rb +6 -4
- data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +4 -2
- data/spec/support/matchers/type/have_discount_type_matcher.rb +4 -2
- data/spec/support/matchers/type/have_email_matcher.rb +11 -9
- data/spec/support/matchers/type/have_housework_type_matcher.rb +9 -0
- data/spec/support/matchers/type/have_nullable_date_matcher.rb +29 -29
- data/spec/support/matchers/type/have_nullable_matcher.rb +23 -21
- data/spec/support/matchers/type/have_nullable_string_matcher.rb +30 -32
- data/spec/support/matchers/type/have_sized_float_matcher.rb +4 -2
- data/spec/support/matchers/type/have_sized_integer_matcher.rb +4 -2
- data/spec/support/matchers/type/have_sized_string_matcher.rb +16 -15
- data/spec/support/matchers/type/have_vat_type_matcher.rb +4 -2
- data/spec/support/matchers/type/numeric_matcher.rb +25 -23
- data/spec/support/matchers/type/require_attribute_matcher.rb +36 -37
- data/spec/support/matchers/type/type_matcher.rb +18 -16
- data/spec/support/vcr_setup.rb +2 -0
- data/spec/vcr_cassettes/orders/{house_work_type_babysitting.yml → housework_type_babysitting.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_cleaning.yml → housework_type_cleaning.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_construction.yml → housework_type_construction.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_cooking.yml → housework_type_cooking.yml} +7 -7
- data/spec/vcr_cassettes/orders/{house_work_type_electricity.yml → housework_type_electricity.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_gardening.yml → housework_type_gardening.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_glassmetalwork.yml → housework_type_glassmetalwork.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_grounddrainagework.yml → housework_type_grounddrainagework.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_hvac.yml → housework_type_hvac.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_masonry.yml → housework_type_masonry.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_othercare.yml → housework_type_othercare.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_othercosts.yml → housework_type_othercosts.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_paintingwallpapering.yml → housework_type_paintingwallpapering.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_snowplowing.yml → housework_type_snowplowing.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_textileclothing.yml → housework_type_textileclothing.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_tutoring.yml → housework_type_tutoring.yml} +7 -7
- data/spec/vcr_cassettes/termsofpayments/all.yml +51 -0
- data/spec/vcr_cassettes/termsofpayments/find_failure.yml +45 -0
- data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +46 -0
- data/spec/vcr_cassettes/termsofpayments/find_new.yml +46 -0
- data/spec/vcr_cassettes/termsofpayments/save_new.yml +45 -0
- data/spec/vcr_cassettes/termsofpayments/save_old.yml +46 -0
- data/spec/vcr_cassettes/units/all.yml +48 -0
- data/spec/vcr_cassettes/units/find_failure.yml +45 -0
- data/spec/vcr_cassettes/units/find_id_1.yml +46 -0
- data/spec/vcr_cassettes/units/find_new.yml +48 -0
- data/spec/vcr_cassettes/units/save_new.yml +47 -0
- data/spec/vcr_cassettes/units/save_old.yml +48 -0
- data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +47 -0
- metadata +127 -88
- data/docs/account.rb +0 -59
- data/docs/extraction_script.js +0 -23
- data/docs/generation_script.rb +0 -43
- data/docs/json/account.json +0 -77
- data/lib/fortnox/api/models/document_base.rb +0 -189
- data/spec/fortnox/api/types/house_work_types_spec.rb +0 -64
- data/spec/support/matchers/type/have_house_work_type_matcher.rb +0 -7
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Matchers
|
2
4
|
module Type
|
3
|
-
def have_nullable(
|
4
|
-
HaveNullableMatcher.new(
|
5
|
+
def have_nullable(attribute, valid_value, invalid_value, default_value)
|
6
|
+
HaveNullableMatcher.new(attribute, valid_value, invalid_value, default_value)
|
5
7
|
end
|
6
8
|
|
7
9
|
class HaveNullableMatcher
|
8
|
-
def initialize(
|
10
|
+
def initialize(attribute, valid_value, invalid_value, default_value)
|
9
11
|
@attribute = attribute
|
10
12
|
@valid_value = valid_value
|
11
13
|
@invalid_value = invalid_value
|
@@ -13,40 +15,40 @@ module Matchers
|
|
13
15
|
@failure_description = ''
|
14
16
|
end
|
15
17
|
|
16
|
-
def matches?(
|
18
|
+
def matches?(klass)
|
17
19
|
@klass = klass
|
18
20
|
|
19
21
|
accepts_nil? && accepts_valid_value? && defaults_invalid_value?
|
20
22
|
end
|
21
23
|
|
22
24
|
def description
|
23
|
-
"have nullable attribute #{
|
25
|
+
"have nullable attribute #{@attribute.inspect}"
|
24
26
|
end
|
25
27
|
|
26
28
|
def failure_message
|
27
|
-
"Expected class to have nullable attribute #{
|
29
|
+
"Expected class to have nullable attribute #{@attribute.inspect}" << @failure_description
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
def accepts_nil?
|
35
|
+
@klass.new(@attribute => nil)
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
def accepts_valid_value?
|
39
|
+
model = @klass.new(@attribute => @valid_value)
|
40
|
+
model.send(@attribute) == @valid_value
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def defaults_invalid_value?
|
44
|
+
model = @klass.new(@attribute => @invalid_value)
|
45
|
+
value = model.send(@attribute)
|
46
|
+
return true if value == @default_value
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
@failure_description << " (Expected #{@invalid_value.inspect} to default to "\
|
49
|
+
"#{@default_value.inspect}), but got #{value.inspect}"
|
50
|
+
false
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Matchers
|
2
4
|
module Type
|
3
|
-
def have_nullable_string(
|
4
|
-
HaveNullableStringMatcher.new(
|
5
|
+
def have_nullable_string(attribute, valid_hash = {})
|
6
|
+
HaveNullableStringMatcher.new(attribute, valid_hash)
|
5
7
|
end
|
6
8
|
|
7
9
|
class HaveNullableStringMatcher < AttributeMatcher
|
8
|
-
def initialize(
|
9
|
-
super(
|
10
|
+
def initialize(attribute, valid_hash)
|
11
|
+
super(attribute, valid_hash, 'nullable string')
|
10
12
|
end
|
11
13
|
|
12
|
-
def matches?(
|
14
|
+
def matches?(klass)
|
13
15
|
super
|
14
16
|
|
15
17
|
accepts_nil? && accepts_string? && rejects_non_string?
|
@@ -17,33 +19,29 @@ module Matchers
|
|
17
19
|
|
18
20
|
private
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def accepts_string?
|
26
|
-
valid_string = 'A string'
|
27
|
-
model = @klass.new( @valid_hash.merge( @attribute => valid_string ) )
|
28
|
-
model.send(@attribute) == 'A string'
|
29
|
-
end
|
30
|
-
|
31
|
-
def rejects_non_string?
|
32
|
-
non_string = 10.0
|
33
|
-
@klass.new( @valid_hash.merge( @attribute => non_string ) )
|
34
|
-
rescue Fortnox::API::InvalidAttributeValueError => error
|
35
|
-
expected_message = "#{ non_string.inspect } (#{ non_string.class }) "\
|
36
|
-
"has invalid type for #{ @attribute.inspect }"
|
37
|
-
if error.message.include?(expected_message)
|
38
|
-
return true
|
39
|
-
else
|
40
|
-
fail_message = "Expected error message to include #{ expected_message.inspect }, "\
|
41
|
-
"but was #{ error.message.inspect }"
|
42
|
-
fail(fail_message)
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
22
|
+
def accepts_nil?
|
23
|
+
model = @klass.new(@valid_hash.merge(@attribute => nil))
|
24
|
+
model.send(@attribute).nil?
|
25
|
+
end
|
47
26
|
|
27
|
+
def accepts_string?
|
28
|
+
valid_string = 'A string'
|
29
|
+
model = @klass.new(@valid_hash.merge(@attribute => valid_string))
|
30
|
+
model.send(@attribute) == 'A string'
|
31
|
+
end
|
32
|
+
|
33
|
+
def rejects_non_string?
|
34
|
+
non_string = 10.0
|
35
|
+
@klass.new(@valid_hash.merge(@attribute => non_string))
|
36
|
+
rescue Fortnox::API::InvalidAttributeValueError => error
|
37
|
+
expected_message = "#{non_string.inspect} (#{non_string.class}) "\
|
38
|
+
"has invalid type for #{@attribute.inspect}"
|
39
|
+
return true if error.message.include?(expected_message)
|
40
|
+
|
41
|
+
fail_message = "Expected error message to include #{expected_message.inspect}, "\
|
42
|
+
"but was #{error.message.inspect}"
|
43
|
+
raise(fail_message)
|
44
|
+
end
|
45
|
+
end
|
48
46
|
end
|
49
47
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Matchers
|
2
4
|
module Type
|
3
|
-
def have_sized_float(
|
5
|
+
def have_sized_float(attribute, min_value, max_value, valid_hash = {})
|
4
6
|
options = { min_value: min_value, max_value: max_value, step: 0.1 }
|
5
|
-
NumericMatcher.new(
|
7
|
+
NumericMatcher.new(attribute, valid_hash, 'sized float', options)
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Matchers
|
2
4
|
module Type
|
3
|
-
def have_sized_integer(
|
5
|
+
def have_sized_integer(attribute, min_value, max_value, valid_hash = {})
|
4
6
|
options = { min_value: min_value, max_value: max_value, step: 1 }
|
5
|
-
NumericMatcher.new(
|
7
|
+
NumericMatcher.new(attribute, valid_hash, 'sized integer', options)
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Matchers
|
2
4
|
module Type
|
3
|
-
def have_sized_string(
|
4
|
-
HaveSizedStringMatcher.new(
|
5
|
+
def have_sized_string(attribute, max_size, valid_hash = {})
|
6
|
+
HaveSizedStringMatcher.new(attribute, max_size, valid_hash)
|
5
7
|
end
|
6
8
|
|
7
9
|
class HaveSizedStringMatcher < AttributeMatcher
|
8
|
-
def initialize(
|
9
|
-
super(
|
10
|
+
def initialize(attribute, max_size, valid_hash)
|
11
|
+
super(attribute, valid_hash, 'sized string')
|
10
12
|
@max_size = max_size
|
11
13
|
end
|
12
14
|
|
13
|
-
def matches?(
|
15
|
+
def matches?(klass)
|
14
16
|
@klass = klass
|
15
17
|
|
16
18
|
accepts_max_size? && rejects_too_long_string?
|
@@ -18,18 +20,17 @@ module Matchers
|
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
def accepts_max_size?
|
24
|
+
@klass.new(@valid_hash.merge(@attribute => 'a' * @max_size))
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
27
|
+
def rejects_too_long_string?
|
28
|
+
too_long = @max_size + 1
|
29
|
+
too_long_string = 'a' * too_long
|
30
|
+
expect_error("Exception missing for too long string (#{too_long} characters)") do
|
31
|
+
@klass.new(@valid_hash.merge(@attribute => too_long_string))
|
31
32
|
end
|
33
|
+
end
|
32
34
|
end
|
33
|
-
|
34
35
|
end
|
35
36
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Matchers
|
2
4
|
module Type
|
3
|
-
def have_vat_type(
|
4
|
-
EnumMatcher.new(
|
5
|
+
def have_vat_type(attribute, valid_hash = {})
|
6
|
+
EnumMatcher.new(attribute, valid_hash, 'VATType', 'VATTypes')
|
5
7
|
end
|
6
8
|
end
|
7
9
|
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Matchers
|
2
4
|
module Type
|
3
5
|
class NumericMatcher < AttributeMatcher
|
4
|
-
def initialize(
|
5
|
-
super(
|
6
|
+
def initialize(attribute, valid_hash, attr_type, options)
|
7
|
+
super(attribute, valid_hash, attr_type)
|
6
8
|
|
7
9
|
@min_value = options[:min_value]
|
8
10
|
@max_value = options[:max_value]
|
9
11
|
@step = options[:step]
|
10
12
|
end
|
11
13
|
|
12
|
-
def matches?(
|
14
|
+
def matches?(klass)
|
13
15
|
super
|
14
16
|
|
15
17
|
rejects_too_small_value? &&
|
@@ -20,31 +22,31 @@ module Matchers
|
|
20
22
|
|
21
23
|
private
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def rejects_too_small_value?
|
26
|
+
too_small_value = @min_value - @step
|
27
|
+
expected_error_message = "Exception missing for too small value (#{too_small_value})"
|
28
|
+
rejects_value?(too_small_value, expected_error_message)
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
def accepts_min_value?
|
32
|
+
@klass.new(@valid_hash.merge(@attribute => @min_value))
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
def accepts_max_value?
|
36
|
+
@klass.new(@valid_hash.merge(@attribute => @max_value))
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
def rejects_too_big_value?
|
40
|
+
too_big_value = @max_value + @step
|
41
|
+
expected_error_message = "Exception missing for too big value (#{too_big_value})"
|
42
|
+
rejects_value?(too_big_value, expected_error_message)
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
45
|
+
def rejects_value?(value, expected_error_message)
|
46
|
+
expect_error(expected_error_message) do
|
47
|
+
@klass.new(@valid_hash.merge(@attribute => value))
|
47
48
|
end
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fortnox/api'
|
2
4
|
|
3
5
|
module Matchers
|
@@ -9,12 +11,12 @@ module Matchers
|
|
9
11
|
class RequireAttributeMatcher
|
10
12
|
EXCEPTION = Fortnox::API::MissingAttributeError
|
11
13
|
|
12
|
-
def initialize(
|
14
|
+
def initialize(attribute, valid_hash)
|
13
15
|
@attribute = attribute
|
14
|
-
@invalid_hash = valid_hash.dup.tap{ |hash| hash.delete(
|
16
|
+
@invalid_hash = valid_hash.dup.tap { |hash| hash.delete(attribute) }
|
15
17
|
end
|
16
18
|
|
17
|
-
def matches?(
|
19
|
+
def matches?(klass)
|
18
20
|
@klass = klass
|
19
21
|
|
20
22
|
raise_error && includes_error_message
|
@@ -26,44 +28,41 @@ module Matchers
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def description
|
29
|
-
"require attribute #{
|
31
|
+
"require attribute #{@attribute.inspect}"
|
30
32
|
end
|
31
33
|
|
32
34
|
private
|
33
35
|
|
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
|
-
|
64
|
-
"Expected exception to equal #{ expected_error_message.inspect }. "\
|
65
|
-
"Message was #{ @wrong_error_message.inspect }."
|
66
|
-
end
|
36
|
+
def raise_error
|
37
|
+
@klass.new(@invalid_hash)
|
38
|
+
|
39
|
+
false # Fail test since expected error is not thrown
|
40
|
+
rescue EXCEPTION
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
def includes_error_message
|
45
|
+
@klass.new(@invalid_hash)
|
46
|
+
rescue EXCEPTION => error
|
47
|
+
return true if error.message.include? expected_error_message
|
48
|
+
|
49
|
+
@wrong_error_message = error.message
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def expected_error_message
|
54
|
+
@attribute.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def no_exception_failure_message
|
58
|
+
"Expected class to raise #{EXCEPTION} "\
|
59
|
+
"when attribute #{@attribute.inspect} is missing."
|
60
|
+
end
|
61
|
+
|
62
|
+
def wrong_error_message
|
63
|
+
"Expected exception to equal #{expected_error_message.inspect}. "\
|
64
|
+
"Message was #{@wrong_error_message.inspect}."
|
65
|
+
end
|
67
66
|
end
|
68
67
|
end
|
69
68
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Matchers
|
2
4
|
module Type
|
3
5
|
class TypeMatcher < AttributeMatcher
|
4
|
-
def initialize(
|
5
|
-
super(
|
6
|
+
def initialize(attr, valid_hash, attr_name, valid_value, invalid_value)
|
7
|
+
super(attr, valid_hash, attr_name)
|
6
8
|
|
7
9
|
@valid_value = valid_value
|
8
10
|
@invalid_value = invalid_value
|
9
11
|
end
|
10
12
|
|
11
|
-
def matches?(
|
13
|
+
def matches?(klass)
|
12
14
|
super
|
13
15
|
|
14
16
|
correct_type? && rejects_invalid_value? && accepts_valid_value?
|
@@ -16,23 +18,23 @@ module Matchers
|
|
16
18
|
|
17
19
|
private
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
def correct_type?
|
22
|
+
return true if expected_type?
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
@errors << "Attribute #{@attribute.inspect} was expected to be of type #{@attribute_type}, "\
|
25
|
+
"but was #{@actual_type}"
|
26
|
+
false
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
def accepts_valid_value?
|
30
|
+
@klass.new(@valid_hash.merge(@attribute => @valid_value))
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
33
|
+
def rejects_invalid_value?
|
34
|
+
expect_error(@expected_error) do
|
35
|
+
@klass.new(@valid_hash.merge(@attribute => @invalid_value))
|
34
36
|
end
|
35
|
-
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|