acfs 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. metadata +8 -141
  3. data/CHANGELOG.md +0 -325
  4. data/LICENSE +0 -22
  5. data/README.md +0 -334
  6. data/acfs.gemspec +0 -37
  7. data/lib/acfs.rb +0 -49
  8. data/lib/acfs/adapter/base.rb +0 -26
  9. data/lib/acfs/adapter/typhoeus.rb +0 -60
  10. data/lib/acfs/collection.rb +0 -27
  11. data/lib/acfs/collections/paginatable.rb +0 -75
  12. data/lib/acfs/configuration.rb +0 -113
  13. data/lib/acfs/errors.rb +0 -106
  14. data/lib/acfs/global.rb +0 -99
  15. data/lib/acfs/location.rb +0 -78
  16. data/lib/acfs/middleware/base.rb +0 -20
  17. data/lib/acfs/middleware/json.rb +0 -27
  18. data/lib/acfs/middleware/logger.rb +0 -23
  19. data/lib/acfs/middleware/msgpack.rb +0 -30
  20. data/lib/acfs/middleware/print.rb +0 -21
  21. data/lib/acfs/middleware/serializer.rb +0 -39
  22. data/lib/acfs/operation.rb +0 -81
  23. data/lib/acfs/request.rb +0 -36
  24. data/lib/acfs/request/callbacks.rb +0 -50
  25. data/lib/acfs/resource.rb +0 -37
  26. data/lib/acfs/resource/attributes.rb +0 -268
  27. data/lib/acfs/resource/attributes/base.rb +0 -28
  28. data/lib/acfs/resource/attributes/boolean.rb +0 -37
  29. data/lib/acfs/resource/attributes/date_time.rb +0 -31
  30. data/lib/acfs/resource/attributes/dict.rb +0 -37
  31. data/lib/acfs/resource/attributes/float.rb +0 -31
  32. data/lib/acfs/resource/attributes/integer.rb +0 -27
  33. data/lib/acfs/resource/attributes/list.rb +0 -34
  34. data/lib/acfs/resource/attributes/string.rb +0 -24
  35. data/lib/acfs/resource/attributes/uuid.rb +0 -47
  36. data/lib/acfs/resource/dirty.rb +0 -35
  37. data/lib/acfs/resource/initialization.rb +0 -29
  38. data/lib/acfs/resource/loadable.rb +0 -33
  39. data/lib/acfs/resource/locatable.rb +0 -128
  40. data/lib/acfs/resource/operational.rb +0 -22
  41. data/lib/acfs/resource/persistence.rb +0 -257
  42. data/lib/acfs/resource/query_methods.rb +0 -264
  43. data/lib/acfs/resource/service.rb +0 -42
  44. data/lib/acfs/resource/validation.rb +0 -37
  45. data/lib/acfs/response.rb +0 -28
  46. data/lib/acfs/response/formats.rb +0 -25
  47. data/lib/acfs/response/status.rb +0 -31
  48. data/lib/acfs/rspec.rb +0 -11
  49. data/lib/acfs/runner.rb +0 -97
  50. data/lib/acfs/service.rb +0 -91
  51. data/lib/acfs/service/middleware.rb +0 -56
  52. data/lib/acfs/service/middleware/stack.rb +0 -63
  53. data/lib/acfs/singleton_resource.rb +0 -83
  54. data/lib/acfs/stub.rb +0 -172
  55. data/lib/acfs/util.rb +0 -20
  56. data/lib/acfs/version.rb +0 -14
  57. data/lib/acfs/yard.rb +0 -5
  58. data/spec/acfs/adapter/typhoeus_spec.rb +0 -28
  59. data/spec/acfs/collection_spec.rb +0 -155
  60. data/spec/acfs/configuration_spec.rb +0 -51
  61. data/spec/acfs/global_spec.rb +0 -137
  62. data/spec/acfs/location_spec.rb +0 -23
  63. data/spec/acfs/middleware/json_spec.rb +0 -63
  64. data/spec/acfs/middleware/msgpack_spec.rb +0 -60
  65. data/spec/acfs/operation_spec.rb +0 -10
  66. data/spec/acfs/request/callbacks_spec.rb +0 -46
  67. data/spec/acfs/request_spec.rb +0 -77
  68. data/spec/acfs/resource/attributes/boolean_spec.rb +0 -56
  69. data/spec/acfs/resource/attributes/date_time_spec.rb +0 -49
  70. data/spec/acfs/resource/attributes/dict_spec.rb +0 -75
  71. data/spec/acfs/resource/attributes/float_spec.rb +0 -59
  72. data/spec/acfs/resource/attributes/integer_spec.rb +0 -34
  73. data/spec/acfs/resource/attributes/list_spec.rb +0 -58
  74. data/spec/acfs/resource/attributes/uuid_spec.rb +0 -40
  75. data/spec/acfs/resource/attributes_spec.rb +0 -179
  76. data/spec/acfs/resource/dirty_spec.rb +0 -47
  77. data/spec/acfs/resource/initialization_spec.rb +0 -30
  78. data/spec/acfs/resource/loadable_spec.rb +0 -20
  79. data/spec/acfs/resource/locatable_spec.rb +0 -116
  80. data/spec/acfs/resource/persistance_spec.rb +0 -316
  81. data/spec/acfs/resource/query_methods_spec.rb +0 -541
  82. data/spec/acfs/resource/validation_spec.rb +0 -127
  83. data/spec/acfs/response/formats_spec.rb +0 -50
  84. data/spec/acfs/response/status_spec.rb +0 -69
  85. data/spec/acfs/runner_spec.rb +0 -97
  86. data/spec/acfs/service/middleware_spec.rb +0 -33
  87. data/spec/acfs/service_spec.rb +0 -46
  88. data/spec/acfs/singleton_resource_spec.rb +0 -15
  89. data/spec/acfs/stub_spec.rb +0 -343
  90. data/spec/acfs_spec.rb +0 -203
  91. data/spec/fixtures/config.yml +0 -14
  92. data/spec/spec_helper.rb +0 -41
  93. data/spec/support/hash.rb +0 -9
  94. data/spec/support/response.rb +0 -10
  95. data/spec/support/service.rb +0 -91
  96. data/spec/support/shared/find_callbacks.rb +0 -48
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Resource::Attributes::List do
4
- let(:type) { Acfs::Resource::Attributes::List.new }
5
-
6
- describe '#cast' do
7
- subject { -> { type.cast value } }
8
-
9
- context 'with nil' do
10
- let(:value) { nil }
11
- it { expect(subject.call).to eq nil }
12
- end
13
-
14
- context 'with blank string (I)' do
15
- let(:value) { '' }
16
- it { expect(subject.call).to eq Array.new }
17
- end
18
-
19
- context 'with blank string (II)' do
20
- let(:value) { " \t" }
21
- it { expect(subject.call).to eq Array.new }
22
- end
23
-
24
- context 'with array' do
25
- let(:value) { %w(abc cde efg) }
26
- it { expect(subject.call).to eq value }
27
- end
28
-
29
- context 'with convertable object (I)' do
30
- let(:value) do
31
- Class.new do
32
- def to_ary
33
- [1, 2, 3]
34
- end
35
- end.new
36
- end
37
-
38
- it { expect(subject.call).to eq [1, 2, 3] }
39
- end
40
-
41
- context 'with convertable object (II)' do
42
- let(:value) do
43
- Class.new do
44
- def to_a
45
- [1, 2, 3]
46
- end
47
- end.new
48
- end
49
-
50
- it { expect(subject.call).to eq [1, 2, 3] }
51
- end
52
-
53
- context 'with non castable object' do
54
- let(:value) { Object.new }
55
- it { expect(subject.call).to eq [value] }
56
- end
57
- end
58
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Resource::Attributes::UUID do
4
- let(:type) { Acfs::Resource::Attributes::UUID.new }
5
-
6
- describe '#cast' do
7
- subject { -> { type.cast(value) } }
8
-
9
- context 'with nil' do
10
- let(:value) { nil }
11
- it { expect(subject.call).to eq nil }
12
- end
13
-
14
- context 'with empty string' do
15
- let(:value) { '' }
16
- it { expect(subject.call).to eq nil }
17
- end
18
-
19
- context 'with blank string' do
20
- let(:value) { " \t" }
21
- it { expect(subject.call).to eq nil }
22
- end
23
-
24
- context 'with string UUID' do
25
- let(:value) { '450b7a40-94ad-11e3-baa8-0800200c9a66' }
26
- it { expect(subject.call).to be_a String }
27
- it { expect(subject.call).to eq value }
28
- end
29
-
30
- context 'with invalid string' do
31
- let(:value) { 'invalid string' }
32
- it { is_expected.to raise_error TypeError, /invalid UUID/i }
33
- end
34
-
35
- context 'with invalid UUID' do
36
- let(:value) { 'xxxxxxxx-yyyy-11e3-baa8-0800200c9a66' }
37
- it { is_expected.to raise_error TypeError, /invalid UUID/i }
38
- end
39
- end
40
- end
@@ -1,179 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Resource::Attributes do
4
- let(:model) { Class.new Acfs::Resource }
5
- let(:submodel) { Class.new model }
6
-
7
- describe '#initialize' do
8
- before { model.attribute :name, :string, default: 'John' }
9
-
10
- it 'should have attribute list' do
11
- expect(model.new.attributes).to include(:name)
12
- end
13
-
14
- it 'should set default attributes' do
15
- expect(model.new.name).to be == 'John'
16
- end
17
-
18
- context 'with dynamic default value' do
19
- before do
20
- model.attribute :name, :string, default: 'John'
21
- model.attribute :mail, :string, default: -> { "#{name}@srv.tld" }
22
- end
23
-
24
- it 'should set dynamic default attributes' do
25
- expect(model.new.mail).to be == 'John@srv.tld'
26
- end
27
- end
28
- end
29
-
30
- describe '#attributes' do
31
- before do
32
- model.attribute :name, :string, default: 'John'
33
- model.attribute :age, :integer, default: 25
34
- end
35
-
36
- it 'should return hash of all attributes' do
37
- expect(model.new.attributes).to eq(name: 'John', age: 25)
38
- end
39
- end
40
-
41
- describe '#write_attributes' do
42
- before do
43
- model.attribute :name, :string, default: 'John'
44
- model.attribute :age, :integer, default: 25
45
- model.send :define_method, :name= do |name|
46
- write_attribute :name, "The Great #{name}"
47
- end
48
- end
49
- let(:args) { [params] }
50
- let(:params) { {name: 'James'} }
51
- let(:m) { model.new }
52
- let(:action) { -> { m.write_attributes(*args) } }
53
- subject { action }
54
-
55
- it 'should update attributes' do
56
- should change(m, :attributes)
57
- .from(name: 'The Great John', age: 25)
58
- .to(name: 'The Great James', age: 25)
59
- end
60
-
61
- context 'without non-hash params' do
62
- let(:params) { 'James' }
63
-
64
- it { should_not change(m, :attributes) }
65
- its(:call) { should eq false }
66
- end
67
-
68
- context 'with unknown attributes' do
69
- let(:params) { {name: 'James', born_at: 'today'} }
70
-
71
- it { should_not raise_error }
72
-
73
- it 'should update known attributes and store unknown' do
74
- should change(m, :attributes)
75
- .from(name: 'The Great John', age: 25)
76
- .to(name: 'The Great James', age: 25, born_at: 'today')
77
- end
78
-
79
- context 'with unknown: :raise option' do
80
- let(:args) { [params, {unknown: :raise}] }
81
-
82
- it { should raise_error(ArgumentError, /unknown attribute/i) }
83
-
84
- it do
85
- expect do
86
- begin
87
- subject.call
88
- rescue
89
- true
90
- end
91
- end.to_not change(m, :attributes)
92
- end
93
- end
94
- end
95
- end
96
-
97
- describe '#_getter_' do
98
- before { model.attribute :name, :string, default: 'John' }
99
-
100
- it 'should return value' do
101
- mo = model.new
102
- mo.name = 'Paul'
103
-
104
- expect(mo.name).to be == 'Paul'
105
- end
106
-
107
- it 'should return default value' do
108
- expect(model.new.name).to be == 'John'
109
- end
110
- end
111
-
112
- describe '#_setter_' do
113
- before do
114
- model.attribute :name, :string, default: 'John'
115
- model.attribute :age, :integer, default: '25'
116
- end
117
-
118
- it 'should set value' do
119
- o = model.new
120
- o.name = 'Paul'
121
-
122
- expect(o.name).to be == 'Paul'
123
- end
124
-
125
- it 'should update attributes hash' do
126
- o = model.new
127
- o.name = 'Johannes'
128
-
129
- expect(o.attributes['name']).to be == 'Johannes'
130
- end
131
-
132
- it 'should cast values' do
133
- o = model.new
134
- o.age = '28'
135
-
136
- expect(o.age).to be == 28
137
- end
138
- end
139
-
140
- describe 'class' do
141
- describe '#attributes' do
142
- it 'should add an attribute to model attribute list' do
143
- model.send :attribute, :name, :string
144
-
145
- expect(model.attributes.symbolize_keys).to eq name: nil
146
- end
147
-
148
- it 'should accept a default value' do
149
- model.send :attribute, :name, :string, default: 'John'
150
-
151
- expect(model.attributes.symbolize_keys).to eq name: 'John'
152
- end
153
-
154
- it 'should accept a symbolic type' do
155
- model.send :attribute, :age, :integer, default: '12'
156
-
157
- expect(model.attributes.symbolize_keys).to eq age: 12
158
- end
159
-
160
- it 'should accept a class type' do
161
- model.send :attribute, :age, Acfs::Resource::Attributes::Integer,
162
- default: '12'
163
-
164
- expect(model.attributes.symbolize_keys).to eq age: 12
165
- end
166
-
167
- context 'on inherited resources' do
168
- before do
169
- model.attribute :age, :integer, default: 5
170
- submodel.attribute :born_at, :date_time
171
- end
172
-
173
- it 'includes superclass attributes' do
174
- expect(submodel.attributes.keys).to match_array %w(age born_at)
175
- end
176
- end
177
- end
178
- end
179
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Resource::Dirty do
4
- let(:model) { MyUser.new }
5
- before do
6
- stub_request(:get, 'http://users.example.org/users/1')
7
- .to_return response id: 1, name: 'Anon', age: 12
8
- stub_request(:post, 'http://users.example.org/users')
9
- .to_return response id: 5, name: 'dhh', age: 12
10
- end
11
-
12
- it 'includes ActiveModel::Dirty' do
13
- model.is_a? ActiveModel::Dirty
14
- end
15
-
16
- describe '#changed?' do
17
- context 'after attribute change' do
18
- let(:user) { MyUser.new name: 'dhh' }
19
-
20
- it { expect(user).to be_changed }
21
-
22
- context 'and saving' do
23
- before { user.save }
24
- it { expect(user).to_not be_changed }
25
- end
26
- end
27
-
28
- context 'after model load' do
29
- let(:user) { MyUser.find 1 }
30
- before { user && Acfs.run }
31
-
32
- it { expect(user).to_not be_changed }
33
- end
34
-
35
- context 'after model new without attrs' do
36
- let(:user) { MyUser.new }
37
-
38
- it { expect(user).to_not be_changed }
39
- end
40
-
41
- context 'after model new with attrs' do
42
- let(:user) { MyUser.new name: 'Uschi' }
43
-
44
- it { expect(user).to be_changed }
45
- end
46
- end
47
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Acfs::Resource::Initialization' do
4
- let(:model) do
5
- Class.new(Acfs::Resource).tap do |c|
6
- c.class_eval do
7
- attr_accessor :name, :age
8
- private :age=
9
- end
10
- end
11
- end
12
-
13
- describe '#initialize' do
14
- it 'should allow to set attributes with initializer' do
15
- m = model.new name: 'John'
16
- expect(m.name).to eq 'John'
17
- end
18
-
19
- it 'should raise error when attributes with private setters are given' do
20
- expect { model.new age: 25 }.to raise_error(NoMethodError)
21
- end
22
- end
23
-
24
- describe '#persisted?' do
25
- subject { model.new.persisted? }
26
- it 'should be false' do
27
- should be false
28
- end
29
- end
30
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Resource::Loadable do
4
- let(:model) { MyUser.find 1 }
5
- before do
6
- stub_request(:get, 'http://users.example.org/users/1')
7
- .to_return response id: 1, name: 'Anon', age: 12
8
- end
9
-
10
- describe '#loaded?' do
11
- context 'before Acfs#run' do
12
- it { expect(model).to_not be_loaded }
13
- end
14
-
15
- context 'afer Acfs#run' do
16
- before { model && Acfs.run }
17
- it { expect(model).to be_loaded }
18
- end
19
- end
20
- end
@@ -1,116 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Acfs::Resource::Locatable do
4
- let(:model) { MyUser }
5
- before do
6
- stub_request(:get, 'http://users.example.org/users/1')
7
- .to_return response id: 1, name: 'Anon', age: 12
8
- stub_request(:get, 'http://users.example.org/users/1/profile')
9
- .to_return response user_id: 2, twitter_handle: '@anon'
10
- end
11
-
12
- describe '.url' do
13
- it 'should return URL' do
14
- expect(model.url).to be == 'http://users.example.org/users'
15
- end
16
-
17
- it 'should return URL with id path part if specified' do
18
- expect(model.url(5)).to be == 'http://users.example.org/users/5'
19
- end
20
-
21
- context 'with attribute in path' do
22
- let(:model) { Profile }
23
-
24
- it 'should replace placeholder' do
25
- expect(model.url(user_id: 1))
26
- .to eq 'http://users.example.org/users/1/profile'
27
- end
28
-
29
- context 'without attributes' do
30
- it 'should raise an error if attribute is missing' do
31
- expect { model.url }.to raise_error ArgumentError
32
- end
33
- end
34
- end
35
-
36
- describe 'custom paths' do
37
- let(:model) { Session }
38
- let(:location) { Session.location action: action }
39
- subject { location }
40
-
41
- context ':list location' do
42
- let(:action) { :list }
43
-
44
- its(:raw_uri) do
45
- should eq 'http://users.example.org/users/:user_id/sessions'
46
- end
47
- end
48
-
49
- context ':create location' do
50
- let(:action) { :create }
51
- its(:raw_uri) { should eq 'http://users.example.org/sessions' }
52
- end
53
-
54
- context ':read location' do
55
- let(:action) { :read }
56
- its(:raw_uri) { should eq 'http://users.example.org/sessions/:id' }
57
- end
58
-
59
- context ':update location' do
60
- let(:action) { :update }
61
- its(:raw_uri) do
62
- expect { subject }.to raise_error ArgumentError, /update.*disabled/
63
- end
64
- end
65
-
66
- context ':delete location' do
67
- let(:action) { :delete }
68
- its(:raw_uri) do
69
- should eq 'http://users.example.org/users/:user_id/sessions/del/:id'
70
- end
71
- end
72
- end
73
- end
74
-
75
- describe '#url' do
76
- context 'new resource' do
77
- let(:m) { model.new }
78
-
79
- it 'should return nil' do
80
- expect(m.url).to be_nil
81
- end
82
-
83
- context 'new resource with id' do
84
- let(:m) { model.new id: 475 }
85
-
86
- it 'should return resource URL' do
87
- expect(m.url).to eq 'http://users.example.org/users/475'
88
- end
89
- end
90
-
91
- context 'with attribute in path' do
92
- it 'should return nil' do
93
- expect(m.url).to be_nil
94
- end
95
- end
96
- end
97
-
98
- context 'loaded resource' do
99
- let(:m) { model.find 1 }
100
- before { m && Acfs.run }
101
-
102
- it "should return resource's URL" do
103
- expect(m.url).to eq 'http://users.example.org/users/1'
104
- end
105
-
106
- context 'with attribute in path' do
107
- let(:model) { Profile }
108
- let(:m) { model.find user_id: 1 }
109
-
110
- it "should return resource's URL" do
111
- expect(m.url).to eq 'http://users.example.org/users/2/profile'
112
- end
113
- end
114
- end
115
- end
116
- end