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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24c2d64318701de68d4bebf2c0454ae17222f41e
4
- data.tar.gz: 7b058dbf9ce187553aa1a41420b3792b96f4b8f3
3
+ metadata.gz: da189dd54ceae27622ddb4e7d3e153fa565bdcba
4
+ data.tar.gz: c4edca0b269946131682fda7683b2c52776d91b3
5
5
  SHA512:
6
- metadata.gz: d2b103a60ada7149b1f58c79ffaad1f2419116040742217933819840b940b7f17ffa7a03294835b87ad346a33509c996b33872efd845b59fece94ce72bf265e8
7
- data.tar.gz: 425866d67a2dd571cfd1e5dcb9519616720bf7059ec58004dd4ab61f06f94cf508385448dd9f1674937701e95ffb40ec05f4763803eae403ae5170f1611c39d8
6
+ metadata.gz: dc1c986f071bbda315229aafe2eaededa834a16bc2bbae62e9a2224340f9afad943fe36ba6784a372533eeea6748d3ffc1a706406bc95b86fb82ea8de1c6cee3
7
+ data.tar.gz: a562624d60d854eba64f406c8488de84287935a3bc80c20d1aa03416070cd01dec6fe744922e8da0418d48c882b96e407bccafdc195c30f0fca8fc48daf96c0f
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.21.1
4
+
5
+ * Fix wrong validation context
6
+
3
7
  ## 0.21.0
4
8
 
5
9
  * Add update_attributes
@@ -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
@@ -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 unless klass
37
- @service = klass.new options
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
@@ -3,7 +3,7 @@ module Acfs
3
3
  MAJOR = 0
4
4
  MINOR = 21
5
5
  PATCH = 0
6
- STAGE = nil
6
+ STAGE = 'rc1'
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
9
9
 
@@ -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
@@ -46,3 +46,10 @@ class Comment < Acfs::Resource
46
46
  attribute :id, :integer
47
47
  attribute :text, :string
48
48
  end
49
+
50
+ # DRAFT: Singular resource
51
+ #class Singular < Acfs::Resource
52
+ # service UserService, singular: true
53
+ #
54
+ # attribute :name, :string
55
+ #end
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.b185
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-08-28 00:00:00.000000000 Z
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: