fakturan_nu 1.1.1 → 1.1.2
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 +4 -4
- data/fakturan_nu.gemspec +1 -1
- data/lib/fakturan_nu/base.rb +4 -2
- data/test/exceptions_test.rb +16 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ed6955e3027b00dace28b8064a0ba10a0432442
|
4
|
+
data.tar.gz: 979f391de0873200d18198ba11b4a4190d689a21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ee731a75e0e05e1bfe543aec9cccaeed9364f7cac99360a249ce47c634b86b82105d3a6d9baed73f39304a4a24b13c658ffdee767380bea1ab10b7867fe4017
|
7
|
+
data.tar.gz: b584bfaee349fd14d4bdc37202fef9a0f2c762622f08a1d49de293b29aba91f242dbde5d8fc10d628b91533856c0e92e606efc372da95e2af0dcc775b584e0b4
|
data/fakturan_nu.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'fakturan_nu'
|
4
|
-
s.version = '1.1.
|
4
|
+
s.version = '1.1.2'
|
5
5
|
s.date = '2015-04-14'
|
6
6
|
s.summary = 'A ruby client for the Fakturan.nu - API'
|
7
7
|
s.description = 'A ruby client for the Fakturan.nu - API. Fakturan.nu is a webbapp for billing.'
|
data/lib/fakturan_nu/base.rb
CHANGED
@@ -44,8 +44,10 @@ module Fakturan
|
|
44
44
|
self.add_to_errors(field_name.to_sym, [{error: :invalid}])
|
45
45
|
field_errors.each do |new_error_hash_with_index| # new_error_hash_OR_error_type ("blank") on presence of has_many
|
46
46
|
new_error_hash_with_index.each do |index, inner_errors_hash|
|
47
|
-
|
48
|
-
|
47
|
+
inner_errors_hash.each do |inner_field_name, inner_field_errors|
|
48
|
+
error_attribute = inner_field_name.split('.').last.to_sym
|
49
|
+
self.send(ass_name)[index.to_i].add_to_errors(error_attribute, inner_field_errors)
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
else # It's a belongs_to or has_one
|
data/test/exceptions_test.rb
CHANGED
@@ -70,29 +70,33 @@ module Fakturan
|
|
70
70
|
assert_equal 400, error.status
|
71
71
|
end
|
72
72
|
|
73
|
+
def test_multiple_validation_errors_on_has_many
|
74
|
+
stub_api_request(:post, '/trees').to_return(body: {errors: {apples: [{"0" => {"apples.colour" => [{error: :too_short, count:4}], "apples.shape" => [{error: :taken, value: "square"}]}}]}}.to_json, status: 422)
|
75
|
+
tree = Fakturan::Tree.new({"apples"=>[{"colour"=>"", "shape"=>"square"}]})
|
76
|
+
assert_equal false, tree.save
|
77
|
+
assert_equal ({:colour=>[{:error=>:too_short, :count=>4}], :shape=>[{:error=>:taken, :value=>"square"}]}), tree.apples.first.errors.details
|
78
|
+
end
|
79
|
+
|
73
80
|
def test_validation_errors_on_associations_when_created_through_params
|
74
81
|
stub_api_request(:post, '/trees').to_return(body: {errors: {apples: [{"0" => {"apples.colour" => [{error: :blank}]}}], "crown.fluffyness" => [{error: :invalid}]}}.to_json, status: 422)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
assert_equal
|
79
|
-
assert_equal (["
|
80
|
-
assert_equal (["Fluffyness is invalid"]), a.crown.errors.to_a
|
82
|
+
tree = Fakturan::Tree.new({"apples"=>[{"something"=>""}], "crown"=>{"fluffyness"=>""}})
|
83
|
+
assert_equal false, tree.save
|
84
|
+
assert_equal ({:colour=>[{:error=>:blank}]}), tree.apples.first.errors.details
|
85
|
+
assert_equal (["Apples is invalid", "Crown fluffyness is invalid"]), tree.errors.to_a
|
86
|
+
assert_equal (["Fluffyness is invalid"]), tree.crown.errors.to_a
|
81
87
|
end
|
82
88
|
|
83
89
|
def test_validation_errors_on_blank_associated_objects
|
84
90
|
stub_api_request(:post, '/trees').to_return(body: {errors: {apples: [{error: :blank}], crown: [{error: :blank}]}}.to_json, status: 422)
|
85
|
-
|
86
|
-
assert_equal false,
|
87
|
-
assert_equal (["Apples can't be blank", "Crown can't be blank"]),
|
88
|
-
assert_equal ({:apples=>[{:error=>:blank}], :crown=>[{:error=>:blank}]}),
|
91
|
+
tree = Fakturan::Tree.new()
|
92
|
+
assert_equal false, tree.save
|
93
|
+
assert_equal (["Apples can't be blank", "Crown can't be blank"]), tree.errors.to_a
|
94
|
+
assert_equal ({:apples=>[{:error=>:blank}], :crown=>[{:error=>:blank}]}), tree.errors.details
|
89
95
|
end
|
90
96
|
|
91
97
|
def test_save_fails_when_has_many_validation_fails
|
92
98
|
stub_api_request(:post, '/invoices').to_return(body: {errors: {rows: [{"0" => {"rows.product_code" => [{error: :too_long, count:30}]}}] }}.to_json, status: 422)
|
93
|
-
|
94
99
|
invoice = Fakturan::Invoice.new(client: { company: "Acme inc" }, rows: [{product_code: '1234567890123456789012345678901'}])
|
95
|
-
|
96
100
|
assert_equal false, invoice.save
|
97
101
|
assert_equal ({:product_code=>[{:error=>:too_long, :count=>30}]}), invoice.rows[0].errors.details
|
98
102
|
assert_equal "Rows is invalid", invoice.errors.to_a.first
|
@@ -100,10 +104,8 @@ module Fakturan
|
|
100
104
|
|
101
105
|
def test_validation_errors_on_associations
|
102
106
|
stub_api_request(:post, '/invoices').to_return(body: {errors: {date: [{error: :blank},{error: :invalid}], rows: [{"0" => {"rows.product_code" => [{error: :too_long, count:30}]}}, {"2" => {"rows.product_code" => [{error: :too_long, count:30}]}}], "client.company" => [{ error: :blank}]}}.to_json, status: 422)
|
103
|
-
|
104
107
|
invoice = Fakturan::Invoice.new(client: {}, rows: [{product_code: '1234567890123456789012345678901'}, {product_code: '1'}, {product_code: '1234567890123456789012345678901'}])
|
105
108
|
invoice.save
|
106
|
-
|
107
109
|
assert_equal "Client company can't be blank", invoice.errors.to_a.last
|
108
110
|
assert_equal ({date: [{error: :blank}, {error: :invalid}], :rows=>[{:error=>:invalid}]}), invoice.errors.details
|
109
111
|
assert_equal ({:product_code=>[{:error=>:too_long, :count=>30}]}), invoice.rows[0].errors.details
|