acfs 0.32.1.1.b274 → 0.32.1.1.b275

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDhjM2JmMTcxNDM2ODcwNzE3NTExM2FjM2UyZGZmNjA4ZWM2MjZlOA==
4
+ NGZmNGMyYTFkNTc3MDVlNzE2OTYxN2FkZjI5YmFiYzFlZTIyMWIwNQ==
5
5
  data.tar.gz: !binary |-
6
- MDkwYzcyZjJjYzA0ODU0ODMyZGI0MDIzZjQzMWUyYjcxOGNkNTRkMw==
6
+ MGFhMTlhN2U0MmY5NDZlZDhiYzk2ZmI1MTliY2I3MjM0OGNkY2IxMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWEzYzdmOGZmNzU0MTMzODgwMGQ2MWM4YjJlMjU1NTM5ZjE4NTg3MzBjOWI3
10
- YjVjMjQ2ZTQ4YmFjOGMyNDNmMjczYWFhOTJkODM3ODVjMjE2NDY1ZTc3OTFi
11
- ZGYyMmEzODVkNTdhMTMzZTQ4MjhiYjlkNWJhM2JlMjFmZDZmMTE=
9
+ NzMyNDkzYTI4YTE5MzRkYTY0NWEzMjUwNThhYzliZjc1ZWMzNDYwNWE3N2E2
10
+ Njg3YWY4NWU2OTNlNzk4MDNmNWQ1ZjdjNGM5MTE3ZmRhYjIwYTM3NDJlNWRi
11
+ NzRkZjA0ZjU4OTRmMjdiMWYxOGNkNmYyOTMxMWU3YmNjNWUyOGM=
12
12
  data.tar.gz: !binary |-
13
- ZDQzNjM4MDVmMDYyYzEzNjc5ZWY2ODMzNTMyYmZmODAyYTQ4NjFjZWU3YzY5
14
- NDY2YzViODc3MDE5YWQ0ZjBhYWY0MzFiYzE1ZDFhOGExZmQ3MDFjMmUzYmYw
15
- NWQyNTdiNmQwMDg0ODU2MDA1OTg0ZjdkMWFkZTUyYmMyOTQ3YjA=
13
+ NDllMTVmMjU2ZmE5NjQwOGQxNWU4MGIyMTI5Yjg0ZDg4NWZmZDUxYmM1NWY3
14
+ YTM5Mjc1ZTFhMDVlNTU1ZTRmOGQ4OWVlMDFkZDg3ZWJiZDFjMmI2NzBlODhj
15
+ MDIwZjM5MGI5ZWQzOGU3MmFiOWFkMjBmZmFkYTM1YzkwNzZjMzc=
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## Next
4
+
5
+ * Do not raise errors on unknown attributes by default, add :unknown option.
6
+
3
7
  ## 0.32.1
4
8
 
5
9
  * Fix multiple callbacks on `QueryMethods#all`
@@ -98,6 +98,16 @@ module Acfs::Model
98
98
  def write_attributes(attributes, opts = {})
99
99
  return false unless attributes.respond_to? :each
100
100
 
101
+ if opts.fetch(:unknown,:ignore) == :raise
102
+ if (attributes.keys.map(&:to_s) - self.class.attributes.keys).any?
103
+ raise ArgumentError.new "Unknown attributes: #{(attributes.keys - self.class.attributes.keys).map(&:inspect).join(', ')}"
104
+ end
105
+ end
106
+
107
+ attributes = attributes.select do |k, v|
108
+ self.class.attributes.keys.include? k.to_s
109
+ end
110
+
101
111
  procs = {}
102
112
 
103
113
  attributes.each do |key, _|
@@ -170,7 +170,7 @@ module Acfs::Model
170
170
  type = data.delete 'type'
171
171
  klass = resource_class_lookup(type)
172
172
  (opts[:origin].is_a?(klass) ? opts[:origin] : klass.new).tap do |m|
173
- m.attributes = data
173
+ m.write_attributes data, opts
174
174
  m.loaded!
175
175
  end
176
176
  end
@@ -42,19 +42,42 @@ describe Acfs::Model::Attributes do
42
42
  model.attribute :name, :string, default: 'John'
43
43
  model.attribute :age, :integer, default: 25
44
44
  end
45
+ let(:args) { [params] }
46
+ let(:params){ {name: 'James'} }
45
47
  let(:m) { model.new }
48
+ let(:action) { lambda{ m.write_attributes *args } }
49
+ subject { action }
46
50
 
47
- it 'should update attributes' do
48
- m.write_attributes name: 'James'
51
+ it 'should update attributes' do
52
+ should change(m, :attributes)
53
+ .from({'name' => 'John', 'age' => 25})
54
+ .to({'name' => 'James', 'age' => 25})
55
+ end
56
+
57
+ context 'without non-hash params' do
58
+ let(:params) { 'James' }
49
59
 
50
- expect(m.attributes).to be == { name: 'James', age: 25 }.stringify_keys
60
+ it { should_not change(m, :attributes) }
61
+ its(:call) { should eq false }
51
62
  end
52
63
 
53
- it 'should do nothing on non-array types' do
54
- ret = m.write_attributes 'James'
64
+ context 'with unknown attributes' do
65
+ let(:params) { {name: 'James', born_at: Time.now} }
55
66
 
56
- expect(ret).to be false
57
- expect(m.attributes).to be == { name: 'John', age: 25 }.stringify_keys
67
+ it { should_not raise_error }
68
+
69
+ it 'should update known attributes' do
70
+ should change(m, :attributes)
71
+ .from({'name' => 'John', 'age' => 25})
72
+ .to({'name' => 'James', 'age' => 25})
73
+ end
74
+
75
+ context 'with unknown: :raise option' do
76
+ let(:args) { [params, {unknown: :raise}] }
77
+
78
+ it { should raise_error(ArgumentError, /unknown attribute/i) }
79
+ it { expect{ subject.call rescue true }.to_not change(m, :attributes) }
80
+ end
58
81
  end
59
82
  end
60
83
 
@@ -32,9 +32,6 @@ RSpec.configure do |config|
32
32
  # --seed 1234
33
33
  config.order = 'random'
34
34
 
35
- # Raise error when using old :should expectation syntax.
36
- config.raise_errors_for_deprecations!
37
-
38
35
  config.before :each do
39
36
  Acfs.runner.clear
40
37
  Acfs::Stub.clear
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.32.1.1.b274
4
+ version: 0.32.1.1.b275
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport