acfs 0.21.0.b185 → 0.21.0.rc1
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/CHANGELOG.md +4 -0
- data/lib/acfs/errors.rb +3 -1
- data/lib/acfs/model/service.rb +2 -2
- data/lib/acfs/model/validation.rb +1 -1
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/model/validation_spec.rb +24 -3
- data/spec/support/service.rb +7 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da189dd54ceae27622ddb4e7d3e153fa565bdcba
|
4
|
+
data.tar.gz: c4edca0b269946131682fda7683b2c52776d91b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc1c986f071bbda315229aafe2eaededa834a16bc2bbae62e9a2224340f9afad943fe36ba6784a372533eeea6748d3ffc1a706406bc95b86fb82ea8de1c6cee3
|
7
|
+
data.tar.gz: a562624d60d854eba64f406c8488de84287935a3bc80c20d1aa03416070cd01dec6fe744922e8da0418d48c882b96e407bccafdc195c30f0fca8fc48daf96c0f
|
data/CHANGELOG.md
CHANGED
data/lib/acfs/errors.rb
CHANGED
@@ -16,7 +16,7 @@ module Acfs
|
|
16
16
|
|
17
17
|
def initialize(opts = {})
|
18
18
|
@response = opts[:response]
|
19
|
-
message = 'Received erroneous response'
|
19
|
+
message = opts[:message] || 'Received erroneous response'
|
20
20
|
if response
|
21
21
|
message << ": #{response.code}"
|
22
22
|
if response.data
|
@@ -64,6 +64,8 @@ module Acfs
|
|
64
64
|
def initialize(opts = {})
|
65
65
|
@errors = opts.delete :errors
|
66
66
|
@resource = opts.delete :resource
|
67
|
+
opts[:message] ||= @errors.map{ |k,v| "#{k}: #{v.join ', '}" }.join ', ' if @errors.is_a? Hash
|
68
|
+
opts[:message] ||= @errors.join ', ' if @errors.is_a? Array
|
67
69
|
super
|
68
70
|
end
|
69
71
|
end
|
data/lib/acfs/model/service.rb
CHANGED
@@ -33,8 +33,8 @@ module Acfs::Model
|
|
33
33
|
# @param [ Object ] options Option delegated to service class initializer.
|
34
34
|
#
|
35
35
|
def service(klass = nil, options = {})
|
36
|
-
return @service
|
37
|
-
@service
|
36
|
+
return (@service = klass.new options) if klass
|
37
|
+
@service || superclass.service
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -5,7 +5,7 @@ module Acfs::Model
|
|
5
5
|
module Validation
|
6
6
|
|
7
7
|
def save!(*_)
|
8
|
-
raise ::Acfs::InvalidResource.new resource: self, errors: errors.to_a unless valid? :save
|
8
|
+
raise ::Acfs::InvalidResource.new resource: self, errors: errors.to_a unless valid? (new? ? :create : :save)
|
9
9
|
|
10
10
|
super
|
11
11
|
end
|
data/lib/acfs/version.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Acfs::Model::Validation do
|
4
|
-
let(:params) { {} }
|
4
|
+
let(:params) { {name: 'john smith', age: 24} }
|
5
5
|
let(:model) { MyUserWithValidations.new params }
|
6
6
|
|
7
7
|
describe '#valid?' do
|
8
8
|
context 'with valid attributes' do
|
9
|
-
let(:params) { {name: 'john smith', age: 24} }
|
10
9
|
subject { model }
|
11
10
|
|
12
11
|
it { should be_valid }
|
@@ -44,11 +43,33 @@ describe Acfs::Model::Validation do
|
|
44
43
|
end
|
45
44
|
|
46
45
|
describe '#save!' do
|
46
|
+
subject { -> { model.save! } }
|
47
|
+
before { model.stub(:operation) }
|
48
|
+
|
47
49
|
context 'with invalid attributes' do
|
48
50
|
let(:params) { {name: 'john'} }
|
49
|
-
subject { -> { model.save! } }
|
50
51
|
|
51
52
|
it { expect { subject.call }.to raise_error Acfs::InvalidResource }
|
52
53
|
end
|
54
|
+
|
55
|
+
context 'on new resource' do
|
56
|
+
it 'should validate with `create` context' do
|
57
|
+
expect(model).to receive(:valid?).with(:create).and_call_original
|
58
|
+
subject.call
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'on changed resource' do
|
63
|
+
let(:model) { super().tap { |m| m.id = 1 } }
|
64
|
+
|
65
|
+
it 'should validate with `save` context' do
|
66
|
+
expect(model).to receive(:valid?).with(:save).and_call_original
|
67
|
+
subject.call
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'validates with context' do
|
73
|
+
|
53
74
|
end
|
54
75
|
end
|
data/spec/support/service.rb
CHANGED
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.21.0.
|
4
|
+
version: 0.21.0.rc1
|
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-
|
11
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -252,3 +252,4 @@ test_files:
|
|
252
252
|
- spec/spec_helper.rb
|
253
253
|
- spec/support/response.rb
|
254
254
|
- spec/support/service.rb
|
255
|
+
has_rdoc:
|