acfs 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/acfs/model/attributes.rb +4 -1
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/model/attributes_spec.rb +23 -5
- data/spec/acfs_spec.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9983fabc6b3c91e17cf08ac15da6e51aecf584b5
|
4
|
+
data.tar.gz: 53f6525a13c507bd7cac8132d2618a2b92e551ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7869d4338121f188461dd2e2b4383f1175ebec3255e868a36cd53c63df31cbf6bb746135c8aaddebefb3f3ec5185e565606330a23ebcd75f3f4f838a94ec3591
|
7
|
+
data.tar.gz: d9c7a0575f86fd9e2b71fc98336166aef3e770e82fe6c7f5365b7751eeee78a987fa8eb433b326e228ceccc62c2daba610268664594b5992127911676f5aa735
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ level and automatic request queuing and parallel processing. See Usage for more.
|
|
13
13
|
|
14
14
|
Add this line to your application's Gemfile:
|
15
15
|
|
16
|
-
gem 'acfs', '~> 0.
|
16
|
+
gem 'acfs', '~> 0.10.0'
|
17
17
|
|
18
18
|
**Note:** Acfs is under development. I'll try to avoid changes to the public
|
19
19
|
API but internal APIs may change quite often.
|
@@ -33,7 +33,7 @@ module Acfs::Model
|
|
33
33
|
# user.attributes # => { "name" => "John" }
|
34
34
|
#
|
35
35
|
def attributes
|
36
|
-
self.class.attributes.keys.inject({}) { |h, k| h[k.
|
36
|
+
HashWithIndifferentAccess.new self.class.attributes.keys.inject({}) { |h, k| h[k.to_sym] = public_send k; h }
|
37
37
|
end
|
38
38
|
|
39
39
|
# Update all attributes with given hash.
|
@@ -51,6 +51,8 @@ module Acfs::Model
|
|
51
51
|
# Write a hash of attributes and values.
|
52
52
|
#
|
53
53
|
def write_attributes(attributes, opts = {})
|
54
|
+
return false unless attributes.respond_to? :each
|
55
|
+
|
54
56
|
procs = {}
|
55
57
|
|
56
58
|
attributes.each do |key, _|
|
@@ -64,6 +66,7 @@ module Acfs::Model
|
|
64
66
|
procs.each do |key, proc|
|
65
67
|
write_attribute key, instance_exec(&proc), opts
|
66
68
|
end
|
69
|
+
true
|
67
70
|
end
|
68
71
|
|
69
72
|
# Write an attribute.
|
data/lib/acfs/version.rb
CHANGED
@@ -7,7 +7,7 @@ describe Acfs::Model::Attributes do
|
|
7
7
|
before { model.attribute :name, :string, default: 'John' }
|
8
8
|
|
9
9
|
it 'should have attribute list' do
|
10
|
-
expect(model.new.attributes).to include(
|
10
|
+
expect(model.new.attributes).to include(:name)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should set default attributes' do
|
@@ -33,10 +33,28 @@ describe Acfs::Model::Attributes do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should return hash of all attributes' do
|
36
|
-
expect(model.new.attributes).to be == {
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
expect(model.new.attributes).to be == { name: 'John', age: 25 }.stringify_keys
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#write_attributes' do
|
41
|
+
before do
|
42
|
+
model.attribute :name, :string, default: 'John'
|
43
|
+
model.attribute :age, :integer, default: 25
|
44
|
+
end
|
45
|
+
let(:m) { model.new }
|
46
|
+
|
47
|
+
it 'should update attributes' do
|
48
|
+
m.write_attributes name: 'James'
|
49
|
+
|
50
|
+
expect(m.attributes).to be == { name: 'James', age: 25 }.stringify_keys
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should do nothing on non-array types' do
|
54
|
+
ret = m.write_attributes 'James'
|
55
|
+
|
56
|
+
expect(ret).to be_false
|
57
|
+
expect(m.attributes).to be == { name: 'John', age: 25 }.stringify_keys
|
40
58
|
end
|
41
59
|
end
|
42
60
|
|
data/spec/acfs_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe "Acfs" do
|
|
28
28
|
stub = stub_request(:put, "http://users.example.org/users/2")
|
29
29
|
.to_return { |request| { body: request.body, headers: {'Content-Type' => request.headers['Content-Type']}} }
|
30
30
|
|
31
|
-
@user = MyUser.find
|
31
|
+
@user = MyUser.find 2
|
32
32
|
Acfs.run
|
33
33
|
|
34
34
|
expect(@user).to_not be_changed
|
@@ -133,6 +133,7 @@ describe "Acfs" do
|
|
133
133
|
|
134
134
|
it 'should load associated resources from different service' do
|
135
135
|
@user = MyUser.find 2 do |user|
|
136
|
+
expect(user.id).to be == 2
|
136
137
|
@comments = Comment.where user: user.id
|
137
138
|
end
|
138
139
|
|