acfs 0.23.2.b208 → 0.23.2.b209

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDZjNTU4YTQ1Yzc2YTUyMDIwNjQ4NWEyNmQxNWFkOWU2MzdhZThlNw==
4
+ NmE2YWExMjM1ZmVjNmQ5OGQ4MGI1ODE2NDdlMThhOThhYTkyZTY0Nw==
5
5
  data.tar.gz: !binary |-
6
- OWZiZDgzMjZiYThjN2EzODBmOWNkOGE1NGU1M2MyNzJhY2RhZmE1MA==
6
+ ZDRhNjFjZGE1N2EwNDkwZDMwOTE0NTYzZjI4Yjk3NTI1OWFhOWFhZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTNjZGRmNTY0NzM4MTI0NjgxODc5YjkzNmU0MGM1ZDg1MGZjZDg2ODhkZTM1
10
- MDRlZjdhMjFhMWIxNGRkZDcyZWNiMWNlYWY1YWUwYTU0ZDg1YWY1ZmI0MTAz
11
- ZDQxM2VjMDQxYzkzMmIyYTViNTBlODQ5MmFmOGMxYmQxODc0MWM=
9
+ NjI0MTIzYThiNmY1ZGNhZjEzYmU1YmQ1ZTAxYjY3MDI2YjRkZTIwOTBlZDI1
10
+ ZGVlMDljNWU4NTE1ODc4YTYxNDczYjQ5MzMwMGE4ZTA3M2Q3MGZlZWM0YzRi
11
+ MDE5MTQ4MmY0OWI2ZjE1ODU4YjI4MGRlODcwN2NkNmNmZTRjMTE=
12
12
  data.tar.gz: !binary |-
13
- OTJkYjRkNzZjM2IwNTQxNGIwNzg2NGFlOWNhYzQ4ZGZmZjAxYzBhZDMwM2Q1
14
- N2YyNjBlNTY5ZmFmMThhZTkyNTY3ZjJjMTIxZGM3MDJjMjcwYmQ3OTY3YWNj
15
- MDU2ODNlZGNjNDdiZjMwZWZhOTgwNDkzNmIzZTczMDYxYmYyYWY=
13
+ YTE5MTg3M2ZjZmFmNjI3MTA4NzY3MGJkZmZjZTFmZmIxNThjZTYxMWU1MTJh
14
+ MWU2MjM0ODgyZTNhOTcxMjZiNjM5NTlmODZjYjhlODRkODQ2MDM0MTA0MWEz
15
+ N2Q5NzZkNWZjODFhY2Q5NjRhMmY4NzgzMjAwMGU4OWM1ODBhZmE=
@@ -8,6 +8,7 @@ module Acfs
8
8
  class Operation
9
9
  attr_reader :action, :params, :resource, :data, :callback
10
10
  delegate :service, to: :resource
11
+ delegate :call, to: :callback
11
12
 
12
13
  def initialize(resource, action, opts = {}, &block)
13
14
  @resource = resource
@@ -11,7 +11,10 @@ module Acfs
11
11
 
12
12
  def initialize(opts)
13
13
  @opts = opts
14
- @opts[:with].stringify_keys! if @opts[:with].respond_to? :stringify_keys
14
+
15
+ @opts[:with].stringify_keys! if @opts[:with].is_a? Hash
16
+ @opts[:return].stringify_keys! if @opts[:return].is_a? Hash
17
+ @opts[:return].map! { |h| h.stringify_keys! if h.is_a? Hash } if @opts[:return].is_a? Array
15
18
  end
16
19
 
17
20
  def accept?(op)
@@ -20,7 +23,7 @@ module Acfs
20
23
  params = op.full_params.stringify_keys
21
24
  data = op.data.stringify_keys
22
25
 
23
- opts[:with] == params || data == opts[:with]
26
+ opts[:with] == params || data == opts[:with] || (opts[:with].nil? && params.empty? && data.empty?)
24
27
  end
25
28
 
26
29
  def calls
@@ -38,7 +41,7 @@ module Acfs
38
41
  if (err = opts[:raise])
39
42
  raise_error op, err, opts[:return]
40
43
  elsif (data = opts[:return])
41
- op.callback.call data
44
+ op.call data
42
45
  else
43
46
  raise ArgumentError, 'Unsupported stub.'
44
47
  end
@@ -10,10 +10,6 @@ describe Acfs::Stub do
10
10
 
11
11
  before do
12
12
  Acfs::Stub.allow_requests = false
13
-
14
- #Acfs::Stub.read(MyUser).with(id: 5).and_return({ id: 5, name: 'John', age: 32 })
15
- #Acfs::Stub.read(MyUser).with(id: 6).and_raise(:not_found)
16
- #Acfs::Stub.create(MyUser).with(name: '', age: 12).and_return(:invalid, errors: { name: [ 'must be present ']})
17
13
  end
18
14
 
19
15
  describe '#called?' do
@@ -82,6 +78,23 @@ describe Acfs::Stub do
82
78
  expect { Acfs.run }.to raise_error(Acfs::ResourceNotFound)
83
79
  end
84
80
  end
81
+
82
+ context 'with type parameter' do
83
+ before do
84
+ Acfs::Stub.resource Computer, :read, with: { id: 1 }, return: { id: 1, type: 'PC' }
85
+ Acfs::Stub.resource Computer, :read, with: { id: 2 }, return: { id: 2, type: 'Mac' }
86
+ end
87
+
88
+ it 'should create inherited type' do
89
+ pc = Computer.find 1
90
+ mac = Computer.find 2
91
+
92
+ Acfs.run
93
+
94
+ expect(pc).to be_a PC
95
+ expect(mac).to be_a Mac
96
+ end
97
+ end
85
98
  end
86
99
 
87
100
  context 'with create action' do
@@ -104,6 +117,45 @@ describe Acfs::Stub do
104
117
  end
105
118
  end
106
119
 
120
+ context 'with list action' do
121
+ before do
122
+ Acfs::Stub.resource MyUser, :list,
123
+ return: [{ id: 1, name: 'John Smith', age: 32 }, { id: 2, name: 'Anon', age: 12 }]
124
+ end
125
+
126
+ it 'should return collection' do
127
+ users = MyUser.all
128
+ Acfs.run
129
+
130
+ expect(users).to have(2).items
131
+ end
132
+
133
+ it 'should return defined resources' do
134
+ users = MyUser.all
135
+ Acfs.run
136
+
137
+ expect(users[0].id).to eq 1
138
+ expect(users[1].id).to eq 2
139
+ expect(users[0].name).to eq 'John Smith'
140
+ expect(users[1].name).to eq 'Anon'
141
+ end
142
+
143
+ context 'with type parameter' do
144
+ before do
145
+ Acfs::Stub.resource Computer, :list,
146
+ return: [{id: 1, type: 'PC'}, {id: 2, type: 'Mac'}]
147
+ end
148
+
149
+ it 'should create inherited type' do
150
+ computers = Computer.all
151
+ Acfs.run
152
+
153
+ expect(computers.first).to be_a PC
154
+ expect(computers.last).to be_a Mac
155
+ end
156
+ end
157
+ end
158
+
107
159
  context 'with update action' do
108
160
  before do
109
161
  Acfs::Stub.resource MyUser, :read, with: { id: 1 }, return: { id: 1, name: 'John Smith', age: 32 }
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.23.2.b208
4
+ version: 0.23.2.b209
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-28 00:00:00.000000000 Z
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport