acfs 1.4.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/README.md +22 -39
  4. data/acfs.gemspec +8 -14
  5. data/lib/acfs/adapter/base.rb +2 -0
  6. data/lib/acfs/adapter/typhoeus.rb +16 -11
  7. data/lib/acfs/collections/paginatable.rb +1 -1
  8. data/lib/acfs/configuration.rb +13 -3
  9. data/lib/acfs/errors.rb +41 -21
  10. data/lib/acfs/global.rb +2 -2
  11. data/lib/acfs/location.rb +26 -32
  12. data/lib/acfs/middleware/base.rb +2 -2
  13. data/lib/acfs/middleware/json.rb +4 -2
  14. data/lib/acfs/middleware/logger.rb +4 -6
  15. data/lib/acfs/middleware/serializer.rb +1 -1
  16. data/lib/acfs/operation.rb +21 -8
  17. data/lib/acfs/request/callbacks.rb +4 -4
  18. data/lib/acfs/request.rb +4 -11
  19. data/lib/acfs/resource/attributes/date_time.rb +1 -1
  20. data/lib/acfs/resource/attributes/uuid.rb +1 -1
  21. data/lib/acfs/resource/attributes.rb +16 -15
  22. data/lib/acfs/resource/dirty.rb +2 -2
  23. data/lib/acfs/resource/initialization.rb +5 -5
  24. data/lib/acfs/resource/locatable.rb +11 -8
  25. data/lib/acfs/resource/operational.rb +6 -3
  26. data/lib/acfs/resource/persistence.rb +13 -15
  27. data/lib/acfs/resource/query_methods.rb +10 -10
  28. data/lib/acfs/resource/service.rb +2 -2
  29. data/lib/acfs/resource/validation.rb +17 -7
  30. data/lib/acfs/response.rb +5 -5
  31. data/lib/acfs/runner.rb +15 -15
  32. data/lib/acfs/service.rb +16 -19
  33. data/lib/acfs/singleton_resource.rb +2 -2
  34. data/lib/acfs/stub.rb +41 -31
  35. data/lib/acfs/version.rb +2 -2
  36. data/spec/acfs/adapter/typhoeus_spec.rb +2 -2
  37. data/spec/acfs/collection_spec.rb +66 -41
  38. data/spec/acfs/configuration_spec.rb +22 -12
  39. data/spec/acfs/global_spec.rb +11 -9
  40. data/spec/acfs/location_spec.rb +2 -2
  41. data/spec/acfs/middleware/json_spec.rb +22 -8
  42. data/spec/acfs/middleware/{msgpack_spec.rb → message_pack_spec.rb} +6 -6
  43. data/spec/acfs/operation_spec.rb +3 -2
  44. data/spec/acfs/request/callbacks_spec.rb +19 -10
  45. data/spec/acfs/request_spec.rb +16 -20
  46. data/spec/acfs/resource/attributes/boolean_spec.rb +32 -32
  47. data/spec/acfs/resource/attributes/date_time_spec.rb +16 -8
  48. data/spec/acfs/resource/attributes/dict_spec.rb +15 -9
  49. data/spec/acfs/resource/attributes/float_spec.rb +20 -10
  50. data/spec/acfs/resource/attributes/integer_spec.rb +10 -5
  51. data/spec/acfs/resource/attributes/list_spec.rb +13 -8
  52. data/spec/acfs/resource/attributes/uuid_spec.rb +12 -6
  53. data/spec/acfs/resource/attributes_spec.rb +37 -38
  54. data/spec/acfs/resource/dirty_spec.rb +6 -3
  55. data/spec/acfs/resource/initialization_spec.rb +4 -5
  56. data/spec/acfs/resource/loadable_spec.rb +3 -1
  57. data/spec/acfs/resource/locatable_spec.rb +24 -18
  58. data/spec/acfs/resource/{persistance_spec.rb → persistence_spec.rb} +122 -90
  59. data/spec/acfs/resource/query_methods_spec.rb +143 -110
  60. data/spec/acfs/resource/validation_spec.rb +34 -27
  61. data/spec/acfs/response/formats_spec.rb +8 -8
  62. data/spec/acfs/response/status_spec.rb +16 -9
  63. data/spec/acfs/runner_spec.rb +10 -8
  64. data/spec/acfs/service/middleware_spec.rb +3 -3
  65. data/spec/acfs/service_spec.rb +6 -5
  66. data/spec/acfs/singleton_resource_spec.rb +2 -1
  67. data/spec/acfs/stub_spec.rb +57 -53
  68. data/spec/acfs_spec.rb +111 -93
  69. data/spec/spec_helper.rb +1 -2
  70. data/spec/support/response.rb +2 -2
  71. data/spec/support/service.rb +1 -1
  72. data/spec/support/shared/find_callbacks.rb +14 -10
  73. metadata +30 -29
@@ -10,61 +10,70 @@ describe Acfs::Resource::Validation do
10
10
  context 'with valid attributes' do
11
11
  subject { model }
12
12
 
13
- it { should be_valid }
13
+ it { is_expected.to be_valid }
14
14
  end
15
15
 
16
16
  context 'with invalid attributes' do
17
- let(:params) { {name: 'invname'} }
18
17
  subject { model }
19
18
 
20
- it { should_not be_valid }
19
+ let(:params) { {name: 'invname'} }
20
+
21
+ it { is_expected.not_to be_valid }
21
22
  end
22
23
 
23
24
  context 'on resource with service side errors' do
25
+ subject(:resource) { MyUser.create(params) }
26
+
24
27
  before { Acfs::Stub.enable }
28
+
25
29
  after { Acfs::Stub.disable }
26
30
 
27
31
  before do
28
32
  Acfs::Stub.resource MyUser, :create, return: {errors: {name: ['can\'t be blank']}}, raise: 422
29
33
  end
30
34
 
31
- let(:params) { {} }
32
- let(:resource) { MyUser.create params }
33
- subject { resource }
35
+ let(:params) { {} }
34
36
 
35
- it { should_not be_valid }
37
+ it { is_expected.not_to be_valid }
36
38
 
37
- it 'should not override errors' do
38
- subject.valid?
39
- expect(subject.errors.to_hash).to eq(name: ['can\'t be blank'])
39
+ it 'does not override errors' do
40
+ resource.valid?
41
+ expect(resource.errors.to_hash).to eq(name: ['can\'t be blank'])
40
42
  end
41
43
  end
42
44
  end
43
45
 
44
46
  describe '#errors' do
45
47
  context 'with valid attributes' do
48
+ subject { model.errors }
49
+
46
50
  let(:params) { {name: 'john smith', age: 24} }
51
+
47
52
  before { model.valid? }
48
- subject { model.errors }
49
53
 
50
- it { should be_empty }
54
+ it { is_expected.to be_empty }
51
55
  end
52
56
 
53
57
  context 'with invalid attributes' do
58
+ subject(:errors) { model.errors }
59
+
54
60
  let(:params) { {name: 'john'} }
61
+
55
62
  before { model.valid? }
56
- subject { model.errors }
57
63
 
58
- it { should_not be_empty }
59
- it { should have(2).items }
64
+ it { is_expected.not_to be_empty }
65
+ it { is_expected.to have(2).items }
60
66
 
61
- it 'should contain a list of error messages' do
62
- expect(subject.to_hash).to eq age: ["can't be blank"], name: ['is invalid']
67
+ it 'contains a list of error messages' do
68
+ expect(errors.to_hash).to eq age: ["can't be blank"], name: ['is invalid']
63
69
  end
64
70
  end
65
71
 
66
72
  context 'server side errors' do
73
+ subject { resource.errors.to_hash }
74
+
67
75
  before { Acfs::Stub.enable }
76
+
68
77
  after { Acfs::Stub.disable }
69
78
 
70
79
  before do
@@ -74,7 +83,6 @@ describe Acfs::Resource::Validation do
74
83
 
75
84
  let(:params) { {} }
76
85
  let(:resource) { MyUser.create params }
77
- subject { resource.errors.to_hash }
78
86
 
79
87
  context 'with `field => [messages]` payload' do
80
88
  let(:errors) { {name: ['cannot be blank']} }
@@ -97,33 +105,32 @@ describe Acfs::Resource::Validation do
97
105
  end
98
106
 
99
107
  describe '#save!' do
100
- subject { -> { model.save! } }
108
+ subject(:save) { -> { model.save! } }
109
+
101
110
  before { allow(model).to receive(:operation) }
102
111
 
103
112
  context 'with invalid attributes' do
104
113
  let(:params) { {name: 'john'} }
105
114
 
106
- it { expect { subject.call }.to raise_error Acfs::InvalidResource }
115
+ it { expect { save.call }.to raise_error Acfs::InvalidResource }
107
116
  end
108
117
 
109
118
  context 'on new resource' do
110
- it 'should validate with `create` context' do
119
+ it 'validates with `create` context' do
111
120
  expect(model).to receive(:valid?).with(:create).and_call_original
112
- subject.call
121
+ save.call
113
122
  end
114
123
  end
115
124
 
116
125
  context 'on changed resource' do
117
126
  before { model.loaded! }
127
+
118
128
  let(:model) { super().tap {|m| m.id = 1 } }
119
129
 
120
- it 'should validate with `save` context' do
130
+ it 'validates with `save` context' do
121
131
  expect(model).to receive(:valid?).with(:save).and_call_original
122
- subject.call
132
+ save.call
123
133
  end
124
134
  end
125
135
  end
126
-
127
- describe 'validates with context' do
128
- end
129
136
  end
@@ -13,8 +13,8 @@ describe Acfs::Response::Formats do
13
13
  context 'without Content-Type header' do
14
14
  let(:headers) { {} }
15
15
 
16
- it "should fallback on 'text/plain'" do
17
- expect(response.content_type).to be == Mime[:text]
16
+ it "fallbacks on 'text/plain'" do
17
+ expect(response.content_type).to eq Mime[:text]
18
18
  end
19
19
  end
20
20
 
@@ -22,13 +22,13 @@ describe Acfs::Response::Formats do
22
22
  let(:mime_type) { 'application/json' }
23
23
 
24
24
  describe '#content_type' do
25
- it 'should return Mime::JSON' do
26
- expect(response.content_type).to be == Mime[:json]
25
+ it 'returns Mime::JSON' do
26
+ expect(response.content_type).to eq Mime[:json]
27
27
  end
28
28
  end
29
29
 
30
30
  describe '#json?' do
31
- it 'should return true' do
31
+ it 'returns true' do
32
32
  expect(response).to be_json
33
33
  end
34
34
  end
@@ -37,13 +37,13 @@ describe Acfs::Response::Formats do
37
37
  let(:mime_type) { 'application/json; charset=utf8' }
38
38
 
39
39
  describe '#content_type' do
40
- it 'should return Mime::JSON' do
41
- expect(response.content_type).to be == Mime[:json]
40
+ it 'returns Mime::JSON' do
41
+ expect(response.content_type).to eq Mime[:json]
42
42
  end
43
43
  end
44
44
 
45
45
  describe '#json?' do
46
- it 'should return true' do
46
+ it 'returns true' do
47
47
  expect(response).to be_json
48
48
  end
49
49
  end
@@ -14,18 +14,18 @@ describe Acfs::Response::Status do
14
14
  context 'when given' do
15
15
  let(:status) { 200 }
16
16
 
17
- it 'should return status code' do
18
- expect(response.code).to be == 200
19
- expect(response.status_code).to be == 200
17
+ it 'returns status code' do
18
+ expect(response.code).to eq 200
19
+ expect(response.status_code).to eq 200
20
20
  end
21
21
  end
22
22
 
23
23
  context 'when nil' do
24
24
  let(:status) { nil }
25
25
 
26
- it 'should return zero' do
27
- expect(response.code).to be == 0
28
- expect(response.status_code).to be == 0
26
+ it 'returns zero' do
27
+ expect(response.code).to eq 0
28
+ expect(response.status_code).to eq 0
29
29
  end
30
30
  end
31
31
  end
@@ -33,38 +33,45 @@ describe Acfs::Response::Status do
33
33
  describe '#success?' do
34
34
  context 'with success status code' do
35
35
  let(:status) { 200 }
36
+
36
37
  it { expect(response).to be_success }
37
38
  end
38
39
 
39
40
  context 'with error status code' do
40
41
  let(:status) { 500 }
41
- it { expect(response).to_not be_success }
42
+
43
+ it { expect(response).not_to be_success }
42
44
  end
43
45
 
44
46
  context 'with zero status code' do
45
47
  let(:status) { nil }
46
- it { expect(response).to_not be_success }
48
+
49
+ it { expect(response).not_to be_success }
47
50
  end
48
51
  end
49
52
 
50
53
  describe '#modified?' do
51
54
  context 'with success status code' do
52
55
  let(:status) { 200 }
56
+
53
57
  it { expect(response).to be_modified }
54
58
  end
55
59
 
56
60
  context 'with not modified status code' do
57
61
  let(:status) { 304 }
58
- it { expect(response).to_not be_modified }
62
+
63
+ it { expect(response).not_to be_modified }
59
64
  end
60
65
 
61
66
  context 'with error status code' do
62
67
  let(:status) { 500 }
68
+
63
69
  it { expect(response).to be_modified }
64
70
  end
65
71
 
66
72
  context 'with zero status code' do
67
73
  let(:status) { nil }
74
+
68
75
  it { expect(response).to be_modified }
69
76
  end
70
77
  end
@@ -48,7 +48,7 @@ describe ::Acfs::Runner do
48
48
  end
49
49
 
50
50
  describe '#process' do
51
- it 'should trigger event' do
51
+ it 'triggers event' do
52
52
  runner.process ::Acfs::Operation.new MyUser, :read, params: {id: 0}
53
53
  expect(collector.events).to have(1).items
54
54
  expect(collector2.events).to have(1).items
@@ -56,7 +56,7 @@ describe ::Acfs::Runner do
56
56
  end
57
57
 
58
58
  describe '#run' do
59
- it 'should trigger event' do
59
+ it 'triggers event' do
60
60
  runner.run ::Acfs::Operation.new MyUser, :read, params: {id: 0}
61
61
  expect(collector.events).to have(1).items
62
62
  expect(collector2.events).to have(0).items
@@ -64,7 +64,7 @@ describe ::Acfs::Runner do
64
64
  end
65
65
 
66
66
  describe '#enqueue' do
67
- it 'should trigger event' do
67
+ it 'triggers event' do
68
68
  runner.enqueue ::Acfs::Operation.new MyUser, :read, params: {id: 0}
69
69
  expect(collector.events).to have(1).items
70
70
  expect(collector2.events).to have(0).items
@@ -76,18 +76,20 @@ describe ::Acfs::Runner do
76
76
  before do
77
77
  expect_any_instance_of(UserService).to receive(:prepare).and_return nil
78
78
  end
79
- it 'it should not do requests when a middleware aborted' do
80
- expect(adapter).to_not receive :run
79
+
80
+ it 'does not do requests when a middleware aborted' do
81
+ expect(adapter).not_to receive :run
81
82
  runner.run ::Acfs::Operation.new MyUser, :read, params: {id: 0}
82
83
  end
83
84
  end
84
85
 
85
86
  describe '#enqueue' do
86
87
  before do
87
- expect_any_instance_of(UserService).to receive(:prepare).and_return nil
88
+ expect_any_instance_of(UserService).to receive(:prepare).and_return(nil)
88
89
  end
89
- it 'it should not do requests when a middleware aborted' do
90
- expect(adapter).to_not receive :queue
90
+
91
+ it 'does not do requests when a middleware aborted' do
92
+ expect(adapter).not_to receive(:queue)
91
93
  runner.enqueue ::Acfs::Operation.new MyUser, :read, params: {id: 0}
92
94
  runner.start
93
95
  end
@@ -13,19 +13,19 @@ describe Acfs::Service::Middleware do
13
13
  describe '.use' do
14
14
  let(:options) { {abc: 'cde'} }
15
15
 
16
- it 'should add middleware to list' do
16
+ it 'adds middleware to list' do
17
17
  srv_class.use middleware
18
18
 
19
19
  expect(srv_class.middleware).to include(middleware)
20
20
  end
21
21
 
22
- it 'should add middleware to stack' do
22
+ it 'adds middleware to stack' do
23
23
  srv_class.use middleware
24
24
 
25
25
  expect(srv_class.middleware.build(1)).to be_a(middleware)
26
26
  end
27
27
 
28
- it 'should instantiate middleware object' do
28
+ it 'instantiates middleware object' do
29
29
  expect(middleware).to receive(:new).with(anything, options)
30
30
 
31
31
  srv_class.use middleware, options
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe Acfs::Service do
6
6
  let(:srv_class) { Class.new(Acfs::Service) { identity :test } }
7
7
  let(:options) { {} }
8
- let(:service) { srv_class.new options }
8
+ let(:service) { srv_class.new(**options) }
9
9
 
10
10
  before do
11
11
  Acfs::Configuration.current.locate :test, ''
@@ -14,23 +14,24 @@ describe Acfs::Service do
14
14
  describe '#initialize' do
15
15
  let(:options) { {path: 'abc', key: 'value'} }
16
16
 
17
- it 'should set options' do
17
+ it 'sets options' do
18
18
  expect(service.options).to eq(options)
19
19
  end
20
20
  end
21
21
 
22
22
  describe '#location' do
23
23
  let(:resource) { Class.new }
24
+
24
25
  before { allow(resource).to receive(:location_default_path, &proc {|_a, p| p }) }
25
26
 
26
- it 'should extract resource path name from given class' do
27
+ it 'extracts resource path name from given class' do
27
28
  expect(service.location(resource).to_s).to eq('/classes')
28
29
  end
29
30
 
30
31
  context 'with path options' do
31
32
  let(:options) { {path: 'abc'} }
32
33
 
33
- it 'should have custom resource path' do
34
+ it 'has custom resource path' do
34
35
  expect(service.location(resource).to_s).to eq('/abc')
35
36
  end
36
37
  end
@@ -41,7 +42,7 @@ describe Acfs::Service do
41
42
  Acfs::Configuration.current.locate :test, 'http://abc.de/api/v1'
42
43
  end
43
44
 
44
- it 'should return configured URI for service' do
45
+ it 'returns configured URI for service' do
45
46
  expect(srv_class.base_url).to eq('http://abc.de/api/v1')
46
47
  end
47
48
  end
@@ -12,6 +12,7 @@ describe Acfs::SingletonResource do
12
12
  end
13
13
 
14
14
  let(:action) { ->(cb) { model.find(&cb) } }
15
- it_should_behave_like 'a query method with multi-callback support'
15
+
16
+ it_behaves_like 'a query method with multi-callback support'
16
17
  end
17
18
  end