acfs 0.20.0.dev.b184 → 0.20.0
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/.travis.yml +10 -17
- data/CHANGELOG.md +0 -6
- data/acfs.gemspec +0 -2
- data/lib/acfs.rb +24 -17
- data/lib/acfs/errors.rb +29 -52
- data/lib/acfs/model.rb +36 -35
- data/lib/acfs/model/attributes.rb +2 -2
- data/lib/acfs/model/persistence.rb +6 -55
- data/lib/acfs/stub.rb +1 -1
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/model/attributes_spec.rb +1 -1
- data/spec/acfs/model/persistance_spec.rb +3 -57
- data/spec/spec_helper.rb +1 -1
- data/spec/support/service.rb +6 -12
- metadata +5 -7
- data/lib/acfs/model/validation.rb +0 -13
- data/spec/acfs/model/validation_spec.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4e5e93e4dee6f02a8b6a830f83a710bd98a7134
|
4
|
+
data.tar.gz: 9833f7ea561dfe761689915f61daf25a33e25ca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20fae6a5edfd9e81f9f893846951d907226f6c77866cb20938c926dbad8f3b21842c051314cfb91268cdee3e98875e836456436a024be9505148562deabe79c1
|
7
|
+
data.tar.gz: 7eb8bf6e3bd84961a550201d77f2f6e2fe85779108045a4fe991b4537d50cdabedf916e35361b80027022f2e43d141e8e116201ebd859d23b780fc004e48cc76
|
data/.travis.yml
CHANGED
@@ -1,22 +1,15 @@
|
|
1
1
|
language: ruby
|
2
2
|
bundler_args: --without development
|
3
3
|
rvm:
|
4
|
-
- 2.0.0
|
5
|
-
- 1.9.3
|
6
|
-
- jruby
|
7
|
-
- rbx-19mode
|
4
|
+
- 2.0.0
|
5
|
+
- 1.9.3
|
6
|
+
- jruby
|
7
|
+
- rbx-19mode
|
8
|
+
|
8
9
|
gemfile:
|
9
|
-
- gemfiles/Gemfile.rails-
|
10
|
-
- gemfiles/Gemfile.rails-3-2
|
11
|
-
- gemfiles/Gemfile.rails-
|
10
|
+
- gemfiles/Gemfile.rails-3-1
|
11
|
+
- gemfiles/Gemfile.rails-3-2
|
12
|
+
- gemfiles/Gemfile.rails-4-0
|
13
|
+
|
12
14
|
services:
|
13
|
-
- rabbitmq
|
14
|
-
deploy:
|
15
|
-
provider: rubygems
|
16
|
-
api_key:
|
17
|
-
secure: gNudZK0JaRRweudmkpdkJjUMydItTSW5cXjpYdYCfahqd/cD0xPjxotr2TCHrJibfVauoT/PytbQWcP3jnOYytp6oS0up5Y+uKpGmbqVYx/rZvShWALszcBs71lUh/IZpDXNHc+yo/01HCn10/uQUFRtrjWgMwHtHxXb09xE4wQ=
|
18
|
-
gem: acfs
|
19
|
-
on:
|
20
|
-
branch: master
|
21
|
-
repo: jgraichen/acfs
|
22
|
-
rvm: 2.0.0
|
15
|
+
- rabbitmq
|
data/CHANGELOG.md
CHANGED
data/acfs.gemspec
CHANGED
data/lib/acfs.rb
CHANGED
@@ -4,30 +4,35 @@ require 'active_support/core_ext/class'
|
|
4
4
|
require 'active_support/core_ext/string'
|
5
5
|
require 'active_support/core_ext/module'
|
6
6
|
|
7
|
+
require 'acfs/version'
|
8
|
+
require 'acfs/errors'
|
9
|
+
require 'acfs/global'
|
10
|
+
|
7
11
|
module Acfs
|
8
12
|
extend ActiveSupport::Autoload
|
9
|
-
require 'acfs/version'
|
10
|
-
require 'acfs/errors'
|
11
|
-
require 'acfs/global'
|
12
|
-
|
13
|
-
require 'acfs/collection'
|
14
|
-
require 'acfs/configuration'
|
15
|
-
require 'acfs/model'
|
16
|
-
require 'acfs/operation'
|
17
|
-
require 'acfs/request'
|
18
|
-
require 'acfs/resource'
|
19
|
-
require 'acfs/response'
|
20
|
-
require 'acfs/runner'
|
21
|
-
require 'acfs/service'
|
22
|
-
|
23
13
|
extend Global
|
24
14
|
|
15
|
+
autoload :Collection
|
16
|
+
autoload :Model
|
17
|
+
autoload :Request
|
18
|
+
autoload :Response
|
19
|
+
autoload :Service
|
25
20
|
autoload :Stub
|
21
|
+
autoload :Operation
|
22
|
+
autoload :Runner
|
23
|
+
autoload :Configuration
|
24
|
+
|
25
|
+
module Messaging
|
26
|
+
extend ActiveSupport::Autoload
|
27
|
+
|
28
|
+
autoload :Client
|
29
|
+
autoload :Receiver
|
30
|
+
end
|
26
31
|
|
27
32
|
module Middleware
|
28
33
|
extend ActiveSupport::Autoload
|
29
|
-
require 'acfs/middleware/base'
|
30
34
|
|
35
|
+
autoload :Base
|
31
36
|
autoload :Print
|
32
37
|
autoload :Logger
|
33
38
|
autoload :JsonDecoder
|
@@ -37,8 +42,10 @@ module Acfs
|
|
37
42
|
end
|
38
43
|
|
39
44
|
module Adapter
|
40
|
-
|
41
|
-
|
45
|
+
extend ActiveSupport::Autoload
|
46
|
+
|
47
|
+
autoload :Base
|
48
|
+
autoload :Typhoeus
|
42
49
|
end
|
43
50
|
end
|
44
51
|
|
data/lib/acfs/errors.rb
CHANGED
@@ -3,52 +3,46 @@ module Acfs
|
|
3
3
|
# Acfs base error.
|
4
4
|
#
|
5
5
|
class Error < StandardError
|
6
|
-
def initialize(opts = {}, message = nil)
|
7
|
-
opts.merge! message: message if message
|
8
|
-
super opts[:message]
|
9
|
-
end
|
10
6
|
end
|
11
7
|
|
12
8
|
# Response error containing the responsible response object.
|
13
9
|
#
|
14
10
|
class ErroneousResponse < Error
|
15
|
-
|
11
|
+
attr_accessor :response
|
16
12
|
|
17
|
-
def initialize(
|
18
|
-
|
19
|
-
message = '
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
message << response.request.data.map{|k,v| "#{k.inspect}: #{v.inspect}"}.join("\n ")
|
34
|
-
end
|
35
|
-
if response.request.headers.any?
|
36
|
-
message << "\n with headers:\n "
|
37
|
-
message << response.request.headers.map{|k,v| "#{k}: #{v}"}.join("\n ")
|
38
|
-
end
|
13
|
+
def initialize(data = {})
|
14
|
+
self.response = data[:response]
|
15
|
+
message = ''
|
16
|
+
message << "Received erroneous response: #{response.code}"
|
17
|
+
if response.data
|
18
|
+
message << "\n with content:\n "
|
19
|
+
message << response.data.map{|k,v| "#{k.inspect}: #{v.inspect}"}.join("\n ")
|
20
|
+
end
|
21
|
+
if response.headers.any?
|
22
|
+
message << "\n with headers:\n "
|
23
|
+
message << response.headers.map{|k,v| "#{k}: #{v}"}.join("\n ")
|
24
|
+
end
|
25
|
+
message << "\nbased on request: #{response.request.method.upcase} #{response.request.url} #{response.request.format}"
|
26
|
+
if response.request.data
|
27
|
+
message << "\n with content:\n "
|
28
|
+
message << response.request.data.map{|k,v| "#{k.inspect}: #{v.inspect}"}.join("\n ")
|
39
29
|
end
|
40
|
-
|
30
|
+
if response.request.headers.any?
|
31
|
+
message << "\n with headers:\n "
|
32
|
+
message << response.request.headers.map{|k,v| "#{k}: #{v}"}.join("\n ")
|
33
|
+
end
|
34
|
+
super message
|
41
35
|
end
|
42
36
|
end
|
43
37
|
|
44
38
|
class AmbiguousStubError < Error
|
45
39
|
attr_reader :stubs, :operation
|
46
40
|
|
47
|
-
def initialize(
|
48
|
-
@stubs =
|
49
|
-
@operation =
|
41
|
+
def initialize(stubs, operation)
|
42
|
+
@stubs = stubs
|
43
|
+
@operation = operation
|
50
44
|
|
51
|
-
super
|
45
|
+
super 'Ambiguous stubs.'
|
52
46
|
end
|
53
47
|
|
54
48
|
end
|
@@ -59,27 +53,10 @@ module Acfs
|
|
59
53
|
end
|
60
54
|
|
61
55
|
class InvalidResource < ErroneousResponse
|
62
|
-
|
63
|
-
|
64
|
-
def initialize(opts = {})
|
65
|
-
@errors = opts.delete :errors
|
66
|
-
@resource = opts.delete :resource
|
67
|
-
super
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# A ResourceNotLoaded error will be thrown when calling some
|
72
|
-
# modifing methods on not loaded resources as it is usally
|
73
|
-
# unwanted to call e.g. `update_attributes` on a not loaded
|
74
|
-
# resource.
|
75
|
-
# Correct solution is to first run `Acfs.run` to fetch the
|
76
|
-
# resource and then update the resource.
|
77
|
-
#
|
78
|
-
class ResourceNotLoaded < Error
|
79
|
-
attr_reader :resource
|
56
|
+
attr_accessor :errors
|
80
57
|
|
81
|
-
def initialize(
|
82
|
-
|
58
|
+
def initialize(data)
|
59
|
+
self.errors = data[:errors]
|
83
60
|
super
|
84
61
|
end
|
85
62
|
end
|
data/lib/acfs/model.rb
CHANGED
@@ -1,43 +1,44 @@
|
|
1
1
|
require 'active_model'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
require 'acfs/model/query_methods'
|
13
|
-
require 'acfs/model/relations'
|
14
|
-
require 'acfs/model/service'
|
15
|
-
require 'acfs/model/validation'
|
3
|
+
require 'acfs/model/attributes'
|
4
|
+
require 'acfs/model/dirty'
|
5
|
+
require 'acfs/model/loadable'
|
6
|
+
require 'acfs/model/locatable'
|
7
|
+
require 'acfs/model/persistence'
|
8
|
+
require 'acfs/model/operational'
|
9
|
+
require 'acfs/model/query_methods'
|
10
|
+
require 'acfs/model/relations'
|
11
|
+
require 'acfs/model/service'
|
16
12
|
|
17
|
-
|
13
|
+
module Acfs
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
extend ActiveModel::Naming
|
24
|
-
extend ActiveModel::Translation
|
25
|
-
include ActiveModel::Conversion
|
26
|
-
include ActiveModel::Validations
|
15
|
+
# @api public
|
16
|
+
#
|
17
|
+
module Model
|
18
|
+
extend ActiveSupport::Concern
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
included do
|
21
|
+
if ActiveModel::VERSION::MAJOR >= 4
|
22
|
+
include ActiveModel::Model
|
23
|
+
else
|
24
|
+
extend ActiveModel::Naming
|
25
|
+
extend ActiveModel::Translation
|
26
|
+
include ActiveModel::Conversion
|
27
|
+
include ActiveModel::Validations
|
28
|
+
|
29
|
+
require 'acfs/model/initialization'
|
30
|
+
include Model::Initialization
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
include Model::Attributes
|
34
|
+
include Model::Loadable
|
35
|
+
include Model::Persistence
|
36
|
+
include Model::Locatable
|
37
|
+
include Model::Operational
|
38
|
+
include Model::QueryMethods
|
39
|
+
include Model::Relations
|
40
|
+
include Model::Service
|
41
|
+
include Model::Dirty
|
42
|
+
end
|
42
43
|
end
|
43
44
|
end
|
@@ -187,7 +187,7 @@ module Acfs::Model
|
|
187
187
|
# @return [ Hash{ String => Object, Proc } ] Attributes with default values.
|
188
188
|
#
|
189
189
|
def attributes
|
190
|
-
@attributes ||= {}
|
190
|
+
@attributes ||= {}
|
191
191
|
end
|
192
192
|
|
193
193
|
# @api public
|
@@ -205,7 +205,7 @@ module Acfs::Model
|
|
205
205
|
# @return [ Hash{ Symbol => Class } ] Attributes and their types.
|
206
206
|
#
|
207
207
|
def attribute_types
|
208
|
-
@attribute_types ||= {}
|
208
|
+
@attribute_types ||= {}
|
209
209
|
end
|
210
210
|
|
211
211
|
private
|
@@ -26,7 +26,7 @@ module Acfs
|
|
26
26
|
# user2.save
|
27
27
|
# user2.persisted? # => true
|
28
28
|
#
|
29
|
-
# @return [
|
29
|
+
# @return [TrueClass, FalseClass] True if resource has no changes and is not newly created, false otherwise.
|
30
30
|
#
|
31
31
|
def persisted?
|
32
32
|
!new? && !changed?
|
@@ -36,7 +36,7 @@ module Acfs
|
|
36
36
|
#
|
37
37
|
# Return true if model is a new record and was not saved yet.
|
38
38
|
#
|
39
|
-
# @return [
|
39
|
+
# @return [TrueClass, FalseClass] True if resource is newly created, false otherwise.
|
40
40
|
#
|
41
41
|
def new?
|
42
42
|
read_attribute(:id).nil?
|
@@ -52,7 +52,7 @@ module Acfs
|
|
52
52
|
#
|
53
53
|
# Saving a resource is a synchronous operation.
|
54
54
|
#
|
55
|
-
# @return [
|
55
|
+
# @return [TrueClass, FalseClass] True if save operation was successful, false otherwise.
|
56
56
|
# @see #save! See #save! for available options.
|
57
57
|
#
|
58
58
|
def save(*args)
|
@@ -79,6 +79,8 @@ module Acfs
|
|
79
79
|
# @see #save
|
80
80
|
#
|
81
81
|
def save!(opts = {})
|
82
|
+
#raise ::Acfs::InvalidResource errors: errors.to_a unless valid?
|
83
|
+
|
82
84
|
opts[:data] = attributes unless opts[:data]
|
83
85
|
|
84
86
|
operation (new? ? :create : :update), opts do |data|
|
@@ -86,60 +88,13 @@ module Acfs
|
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
89
|
-
# @api public
|
90
|
-
#
|
91
|
-
# Update attributes with given data and save resource.
|
92
|
-
#
|
93
|
-
# Saving a resource is a synchronous operation.
|
94
|
-
#
|
95
|
-
# @param [Hash] attrs Hash with attributes to write.
|
96
|
-
# @param [Hash] opts Options passed to `save`.
|
97
|
-
#
|
98
|
-
# @return [Boolean] True if save operation was successful, false otherwise.
|
99
|
-
#
|
100
|
-
# @see #save
|
101
|
-
# @see #attributes=
|
102
|
-
# @see #update_attributes!
|
103
|
-
#
|
104
|
-
def update_attributes(attrs, opts = {})
|
105
|
-
check_loaded! opts
|
106
|
-
|
107
|
-
self.attributes = attrs
|
108
|
-
save opts
|
109
|
-
end
|
110
|
-
|
111
|
-
# @api public
|
112
|
-
#
|
113
|
-
# Update attributes with given data and save resource.
|
114
|
-
#
|
115
|
-
# Saving a resource is a synchronous operation.
|
116
|
-
#
|
117
|
-
# @param [Hash] attrs Hash with attributes to write.
|
118
|
-
# @param [Hash] opts Options passed to `save!`.
|
119
|
-
#
|
120
|
-
# @raise [Acfs::InvalidResource]
|
121
|
-
# If remote services respond with 422 response. Will fill errors with data from response
|
122
|
-
# @raise [Acfs::ErroneousResponse]
|
123
|
-
# If remote service respond with not successful response.
|
124
|
-
#
|
125
|
-
# @see #save!
|
126
|
-
# @see #attributes=
|
127
|
-
# @see #update_attributes
|
128
|
-
#
|
129
|
-
def update_attributes!(attrs, opts = {})
|
130
|
-
check_loaded! opts
|
131
|
-
|
132
|
-
self.attributes = attrs
|
133
|
-
save! opts
|
134
|
-
end
|
135
|
-
|
136
91
|
# @api public
|
137
92
|
#
|
138
93
|
# Destroy resource by sending a DELETE request.
|
139
94
|
#
|
140
95
|
# Deleting a resource is a synchronous operation.
|
141
96
|
#
|
142
|
-
# @return [
|
97
|
+
# @return [TrueClass, FalseClass]
|
143
98
|
# @see #delete!
|
144
99
|
#
|
145
100
|
def delete(opts = {})
|
@@ -231,10 +186,6 @@ module Acfs
|
|
231
186
|
self.attributes = data
|
232
187
|
loaded!
|
233
188
|
end
|
234
|
-
|
235
|
-
def check_loaded!(opts = {})
|
236
|
-
raise ResourceNotLoaded, resource: self unless loaded? or opts[:force]
|
237
|
-
end
|
238
189
|
end
|
239
190
|
end
|
240
191
|
end
|
data/lib/acfs/stub.rb
CHANGED
@@ -98,7 +98,7 @@ module Acfs
|
|
98
98
|
|
99
99
|
accepted_stubs = stubs.select { |stub| stub.accept? op }
|
100
100
|
|
101
|
-
raise AmbiguousStubError.new
|
101
|
+
raise AmbiguousStubError.new accepted_stubs, op if accepted_stubs.size > 1
|
102
102
|
|
103
103
|
accepted_stubs.first
|
104
104
|
end
|
data/lib/acfs/version.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Model::Persistence do
|
4
4
|
let(:model_class) { MyUser }
|
5
5
|
before do
|
6
|
-
@get_stub = stub_request(:get, 'http://users.example.org/users/1').to_return response({ id: 1, name:
|
6
|
+
@get_stub = stub_request(:get, 'http://users.example.org/users/1').to_return response({ id: 1, name: "Anon", age: 12 })
|
7
7
|
|
8
8
|
@patch_stub = stub_request(:put, 'http://users.example.org/users/1')
|
9
9
|
.with(body: '{"id":1,"name":"Idefix","age":12}')
|
@@ -71,20 +71,6 @@ describe Acfs::Model::Persistence do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
context 'unloaded model' do
|
75
|
-
let!(:model) { model_class.find 1 }
|
76
|
-
|
77
|
-
describe '#update_attributes' do
|
78
|
-
subject { -> { model.update_attributes name: 'John' } }
|
79
|
-
it { expect{ subject.call }.to raise_error Acfs::ResourceNotLoaded }
|
80
|
-
end
|
81
|
-
|
82
|
-
describe '#update_attributes!' do
|
83
|
-
subject { -> { model.update_attributes! name: 'John' } }
|
84
|
-
it { expect{ subject.call }.to raise_error Acfs::ResourceNotLoaded }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
74
|
context 'loaded model' do
|
89
75
|
context 'without changes' do
|
90
76
|
let(:model) { model_class.find 1 }
|
@@ -116,46 +102,6 @@ describe Acfs::Model::Persistence do
|
|
116
102
|
expect(model).to be_frozen
|
117
103
|
end
|
118
104
|
end
|
119
|
-
|
120
|
-
describe '#update_atributes!' do
|
121
|
-
let(:model) { model_class.find 1 }
|
122
|
-
before { model; Acfs.run }
|
123
|
-
|
124
|
-
it 'should set attributes' do
|
125
|
-
model.update_attributes name: 'Idefix'
|
126
|
-
expect(model.attributes.symbolize_keys).to eq id: 1, name: 'Idefix', age: 12
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should save resource' do
|
130
|
-
expect(model).to receive(:save).with({})
|
131
|
-
model.update_attributes name: 'Idefix'
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should pass second hash to save' do
|
135
|
-
expect(model).to receive(:save).with({ bla: 'blub' })
|
136
|
-
model.update_attributes({ name: 'Idefix' }, { bla: 'blub' })
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe '#update_atributes' do
|
141
|
-
let(:model) { model_class.find 1 }
|
142
|
-
before { model; Acfs.run }
|
143
|
-
|
144
|
-
it 'should set attributes' do
|
145
|
-
model.update_attributes! name: 'Idefix'
|
146
|
-
expect(model.attributes.symbolize_keys).to eq id: 1, name: 'Idefix', age: 12
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'should save resource' do
|
150
|
-
expect(model).to receive(:save!).with({})
|
151
|
-
model.update_attributes! name: 'Idefix'
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'should pass second hash to save' do
|
155
|
-
expect(model).to receive(:save!).with({ bla: 'blub' })
|
156
|
-
model.update_attributes!({ name: 'Idefix' }, { bla: 'blub' })
|
157
|
-
end
|
158
|
-
end
|
159
105
|
end
|
160
106
|
|
161
107
|
describe '.create!' do
|
@@ -179,7 +125,7 @@ describe Acfs::Model::Persistence do
|
|
179
125
|
|
180
126
|
it 'should raise an error' do
|
181
127
|
expect { model_class.create! data }.to raise_error ::Acfs::InvalidResource do |error|
|
182
|
-
expect(error.errors).to be == { name:
|
128
|
+
expect(error.errors).to be == { name: ['required'] }.stringify_keys
|
183
129
|
end
|
184
130
|
end
|
185
131
|
end
|
@@ -211,7 +157,7 @@ describe Acfs::Model::Persistence do
|
|
211
157
|
|
212
158
|
it 'should contain error hash' do
|
213
159
|
model = model_class.create data
|
214
|
-
expect(model.errors.to_hash).to be == { name:
|
160
|
+
expect(model.errors.to_hash).to be == { name: [ "required" ]}.stringify_keys
|
215
161
|
end
|
216
162
|
end
|
217
163
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,7 +21,7 @@ RSpec.configure do |config|
|
|
21
21
|
# order dependency and want to debug it, you can fix the order by providing
|
22
22
|
# the seed, which is printed after each run.
|
23
23
|
# --seed 1234
|
24
|
-
config.order =
|
24
|
+
config.order = "random"
|
25
25
|
|
26
26
|
config.expect_with :rspec do |c|
|
27
27
|
# Only allow expect syntax
|
data/spec/support/service.rb
CHANGED
@@ -16,7 +16,8 @@ class CommentService < Acfs::Service
|
|
16
16
|
use Acfs::Middleware::JsonDecoder
|
17
17
|
end
|
18
18
|
|
19
|
-
class MyUser
|
19
|
+
class MyUser
|
20
|
+
include Acfs::Model
|
20
21
|
service UserService, path: 'users'
|
21
22
|
|
22
23
|
attribute :id, :integer
|
@@ -24,23 +25,16 @@ class MyUser < Acfs::Resource
|
|
24
25
|
attribute :age, :integer
|
25
26
|
end
|
26
27
|
|
27
|
-
class
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
class MyUserWithValidations < MyUser
|
32
|
-
validates_presence_of :name, :age
|
33
|
-
validates_format_of :name, with: /\A\w+\s+\w+.?\z/
|
34
|
-
end
|
35
|
-
|
36
|
-
class Session < Acfs::Resource
|
28
|
+
class Session
|
29
|
+
include Acfs::Model
|
37
30
|
service UserService
|
38
31
|
|
39
32
|
attribute :id, :string
|
40
33
|
attribute :user, :integer
|
41
34
|
end
|
42
35
|
|
43
|
-
class Comment
|
36
|
+
class Comment
|
37
|
+
include Acfs::Model
|
44
38
|
service CommentService
|
45
39
|
|
46
40
|
attribute :id, :integer
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.20.0
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -160,7 +160,6 @@ files:
|
|
160
160
|
- lib/acfs/model/query_methods.rb
|
161
161
|
- lib/acfs/model/relations.rb
|
162
162
|
- lib/acfs/model/service.rb
|
163
|
-
- lib/acfs/model/validation.rb
|
164
163
|
- lib/acfs/operation.rb
|
165
164
|
- lib/acfs/request.rb
|
166
165
|
- lib/acfs/request/callbacks.rb
|
@@ -188,7 +187,6 @@ files:
|
|
188
187
|
- spec/acfs/model/locatable_spec.rb
|
189
188
|
- spec/acfs/model/persistance_spec.rb
|
190
189
|
- spec/acfs/model/query_methods_spec.rb
|
191
|
-
- spec/acfs/model/validation_spec.rb
|
192
190
|
- spec/acfs/request/callbacks_spec.rb
|
193
191
|
- spec/acfs/request_spec.rb
|
194
192
|
- spec/acfs/response/formats_spec.rb
|
@@ -216,9 +214,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
216
214
|
version: '0'
|
217
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
216
|
requirements:
|
219
|
-
- - '
|
217
|
+
- - '>='
|
220
218
|
- !ruby/object:Gem::Version
|
221
|
-
version:
|
219
|
+
version: '0'
|
222
220
|
requirements: []
|
223
221
|
rubyforge_project:
|
224
222
|
rubygems_version: 2.0.3
|
@@ -239,7 +237,6 @@ test_files:
|
|
239
237
|
- spec/acfs/model/locatable_spec.rb
|
240
238
|
- spec/acfs/model/persistance_spec.rb
|
241
239
|
- spec/acfs/model/query_methods_spec.rb
|
242
|
-
- spec/acfs/model/validation_spec.rb
|
243
240
|
- spec/acfs/request/callbacks_spec.rb
|
244
241
|
- spec/acfs/request_spec.rb
|
245
242
|
- spec/acfs/response/formats_spec.rb
|
@@ -252,3 +249,4 @@ test_files:
|
|
252
249
|
- spec/spec_helper.rb
|
253
250
|
- spec/support/response.rb
|
254
251
|
- spec/support/service.rb
|
252
|
+
has_rdoc:
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Acfs::Model::Validation do
|
4
|
-
let(:params) { {} }
|
5
|
-
let(:model) { MyUserWithValidations.new params }
|
6
|
-
|
7
|
-
describe '#valid?' do
|
8
|
-
context 'with valid attributes' do
|
9
|
-
let(:params) { {name: 'john smith', age: 24} }
|
10
|
-
subject { model }
|
11
|
-
|
12
|
-
it { should be_valid }
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with invalid attributes' do
|
16
|
-
let(:params) { {name: 'invname'} }
|
17
|
-
subject { model }
|
18
|
-
|
19
|
-
it { should_not be_valid }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '#errors' do
|
24
|
-
context 'with valid attributes' do
|
25
|
-
let(:params) { {name: 'john smith', age: 24} }
|
26
|
-
before { model.valid? }
|
27
|
-
subject { model.errors }
|
28
|
-
|
29
|
-
it { should be_empty }
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with invalid attributes' do
|
33
|
-
let(:params) { {name: 'john'} }
|
34
|
-
before { model.valid? }
|
35
|
-
subject { model.errors }
|
36
|
-
|
37
|
-
it { should_not be_empty }
|
38
|
-
it { should have(2).items }
|
39
|
-
|
40
|
-
it 'should contain a list of error messages' do
|
41
|
-
expect(subject.to_hash).to eq age: ["can't be blank"], name: ['is invalid']
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#save!' do
|
47
|
-
context 'with invalid attributes' do
|
48
|
-
let(:params) { {name: 'john'} }
|
49
|
-
subject { -> { model.save! } }
|
50
|
-
|
51
|
-
it { expect { subject.call }.to raise_error Acfs::InvalidResource }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|