fson 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/lib/fson/version.rb +1 -1
- data/spec/fson/builder/add_error_spec.rb +31 -0
- data/spec/fson/builder/data_array_spec.rb +57 -0
- data/spec/fson/builder/data_hash_spec.rb +57 -0
- data/spec/fson/builder/error_spec.rb +15 -0
- data/spec/fson/builder/fail_spec.rb +15 -0
- data/spec/fson/builder/status_spec.rb +15 -0
- data/spec/fson/builder/success_spec.rb +15 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d2d19678ac598f39689752c42b982868685c14f
|
4
|
+
data.tar.gz: 54fa40b6f3b2a0035110db8edf8445acacd88cc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2caaa093fda9daca708bc686f93dd235372045d207f33b9a2e98cb09bbf65f5123f2a1d351abcc82e56f7601582d745c3f7d552160be4e78401c26f5604dea6
|
7
|
+
data.tar.gz: d6215729469c56bc44ade62961d786c25a7fc91d6f4fbcefa874198e935f9c56bd0fcf81a79dc3049a37cf53829bd9faceeab646318d66486e149b0322c1d612
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fson (1.0.
|
4
|
+
fson (1.0.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
diff-lcs (1.2.5)
|
12
12
|
docile (1.1.5)
|
13
13
|
json (1.8.3)
|
14
|
-
oj (2.12.
|
14
|
+
oj (2.12.12)
|
15
15
|
rake (10.4.2)
|
16
16
|
rspec (3.3.0)
|
17
17
|
rspec-core (~> 3.3.0)
|
@@ -38,6 +38,6 @@ PLATFORMS
|
|
38
38
|
DEPENDENCIES
|
39
39
|
codeclimate-test-reporter
|
40
40
|
fson!
|
41
|
-
oj (~> 2.12
|
41
|
+
oj (~> 2.12)
|
42
42
|
rake (~> 10.4)
|
43
43
|
rspec (~> 3.3)
|
data/lib/fson/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Fson::Response do
|
4
|
+
|
5
|
+
context 'when adding response errors' do
|
6
|
+
|
7
|
+
it 'should add error messages' do
|
8
|
+
# given
|
9
|
+
error_1 = 'error message 1'
|
10
|
+
error_2 = 'error message 2'
|
11
|
+
|
12
|
+
# when
|
13
|
+
response = Fson::Response.error.add_error(error_1).add_error(error_2)
|
14
|
+
|
15
|
+
# then
|
16
|
+
expect(response.instance_eval { _errors }).to contain_exactly({:message => error_1}, {:message => error_2})
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should add error message and add error attributes' do
|
20
|
+
# given
|
21
|
+
error = 'error message'
|
22
|
+
code = 401
|
23
|
+
|
24
|
+
# when
|
25
|
+
response = Fson::Response.error.add_error(error) {|e| e[:code] = code}
|
26
|
+
|
27
|
+
# then
|
28
|
+
expect(response.instance_eval { _errors }).to contain_exactly({:message => error, :code => code})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Fson::Response do
|
4
|
+
|
5
|
+
context 'when adding array data' do
|
6
|
+
|
7
|
+
it 'should add given array data' do
|
8
|
+
# given
|
9
|
+
data = [{:id => 1}]
|
10
|
+
|
11
|
+
# when
|
12
|
+
response = Fson::Response.success.data_array(data)
|
13
|
+
|
14
|
+
# then
|
15
|
+
expect(response.instance_eval {_data}).to eq(data)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should add given array data and modify data in block' do
|
19
|
+
# given
|
20
|
+
entry_1 = {:id => 1}
|
21
|
+
entry_2 = {:id => 2}
|
22
|
+
|
23
|
+
# when
|
24
|
+
response = Fson::Response.success.data_array([entry_1]) { |data|
|
25
|
+
data << entry_2
|
26
|
+
}
|
27
|
+
|
28
|
+
# then
|
29
|
+
expect(response.instance_eval {_data}).to eq([entry_1, entry_2])
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should raise an error if given data is not array' do
|
33
|
+
# given
|
34
|
+
data = {:id => 1}
|
35
|
+
|
36
|
+
# expect
|
37
|
+
expect {
|
38
|
+
|
39
|
+
# when
|
40
|
+
Fson::Response.success.data_array(data)
|
41
|
+
|
42
|
+
# then
|
43
|
+
}.to raise_error(RuntimeError, 'Invalid Argument Error')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should raise an error if adding array data to response with hash data' do
|
47
|
+
# expect
|
48
|
+
expect {
|
49
|
+
|
50
|
+
# when
|
51
|
+
Fson::Response.success.data_hash({}).data_array([])
|
52
|
+
|
53
|
+
# then
|
54
|
+
}.to raise_error(RuntimeError, 'Invalid State Error: response data already initialized as a Hash')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Fson::Response do
|
4
|
+
|
5
|
+
context 'when adding hash data' do
|
6
|
+
|
7
|
+
it 'should add given hash data' do
|
8
|
+
# given
|
9
|
+
data = {:id => 1}
|
10
|
+
|
11
|
+
# when
|
12
|
+
response = Fson::Response.success.data_hash(data)
|
13
|
+
|
14
|
+
# then
|
15
|
+
expect(response.instance_eval {_data}).to eq(data)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should add given hash data and modify data in block' do
|
19
|
+
# given
|
20
|
+
data = {:id => 1}
|
21
|
+
code = 200
|
22
|
+
|
23
|
+
# when
|
24
|
+
response = Fson::Response.success.data_hash(data) { |data|
|
25
|
+
data[:code] = code
|
26
|
+
}
|
27
|
+
|
28
|
+
# then
|
29
|
+
expect(response.instance_eval {_data}).to eq({:id => 1, :code => code})
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should raise an error if given data is not hash' do
|
33
|
+
# given
|
34
|
+
data = [1]
|
35
|
+
|
36
|
+
# expect
|
37
|
+
expect {
|
38
|
+
|
39
|
+
# when
|
40
|
+
Fson::Response.success.data_hash(data)
|
41
|
+
|
42
|
+
# then
|
43
|
+
}.to raise_error(RuntimeError, 'Invalid Argument Error')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should raise an error if adding hash data to response with array data' do
|
47
|
+
# expect
|
48
|
+
expect {
|
49
|
+
|
50
|
+
# when
|
51
|
+
Fson::Response.success.data_array([]).data_hash({})
|
52
|
+
|
53
|
+
# then
|
54
|
+
}.to raise_error(RuntimeError, 'Invalid State Error: response data already initialized as an Array')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Fson::Response do
|
4
|
+
|
5
|
+
context 'when setting response status' do
|
6
|
+
|
7
|
+
it 'should set error status' do
|
8
|
+
# when
|
9
|
+
response = Fson::Response.new.error
|
10
|
+
|
11
|
+
# then
|
12
|
+
expect(response.instance_eval {@_response[:status]}).to eq(:error)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Fson::Response do
|
4
|
+
|
5
|
+
context 'when setting response status' do
|
6
|
+
|
7
|
+
it 'should set fail status' do
|
8
|
+
# when
|
9
|
+
response = Fson::Response.new.fail
|
10
|
+
|
11
|
+
# then
|
12
|
+
expect(response.instance_eval {@_response[:status]}).to eq(:fail)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Fson::Response do
|
4
|
+
|
5
|
+
context 'when setting response status' do
|
6
|
+
|
7
|
+
it 'should set status' do
|
8
|
+
# when
|
9
|
+
response = Fson::Response.new.status(:custom)
|
10
|
+
|
11
|
+
# then
|
12
|
+
expect(response.instance_eval {@_response[:status]}).to eq(:custom)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Fson::Response do
|
4
|
+
|
5
|
+
context 'when setting response status' do
|
6
|
+
|
7
|
+
it 'should set success status' do
|
8
|
+
# when
|
9
|
+
response = Fson::Response.error.success
|
10
|
+
|
11
|
+
# then
|
12
|
+
expect(response.instance_eval {@_response[:status]}).to eq(:success)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Kluczny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -61,6 +61,13 @@ files:
|
|
61
61
|
- lib/fson/version.rb
|
62
62
|
- lib/generators/fson/install_generator.rb
|
63
63
|
- lib/generators/fson/templates/initializer.rb
|
64
|
+
- spec/fson/builder/add_error_spec.rb
|
65
|
+
- spec/fson/builder/data_array_spec.rb
|
66
|
+
- spec/fson/builder/data_hash_spec.rb
|
67
|
+
- spec/fson/builder/error_spec.rb
|
68
|
+
- spec/fson/builder/fail_spec.rb
|
69
|
+
- spec/fson/builder/status_spec.rb
|
70
|
+
- spec/fson/builder/success_spec.rb
|
64
71
|
- spec/fson/response/as_json_spec.rb
|
65
72
|
- spec/fson/response/error_spec.rb
|
66
73
|
- spec/fson/response/fail_spec.rb
|
@@ -92,6 +99,13 @@ signing_key:
|
|
92
99
|
specification_version: 4
|
93
100
|
summary: Fluent builder for API JSON responses
|
94
101
|
test_files:
|
102
|
+
- spec/fson/builder/add_error_spec.rb
|
103
|
+
- spec/fson/builder/data_array_spec.rb
|
104
|
+
- spec/fson/builder/data_hash_spec.rb
|
105
|
+
- spec/fson/builder/error_spec.rb
|
106
|
+
- spec/fson/builder/fail_spec.rb
|
107
|
+
- spec/fson/builder/status_spec.rb
|
108
|
+
- spec/fson/builder/success_spec.rb
|
95
109
|
- spec/fson/response/as_json_spec.rb
|
96
110
|
- spec/fson/response/error_spec.rb
|
97
111
|
- spec/fson/response/fail_spec.rb
|