acfs 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +16 -1
- data/README.md +1 -1
- data/acfs.gemspec +0 -6
- data/gemfiles/Gemfile.rails-3-2 +2 -2
- data/gemfiles/Gemfile.rails-4-0 +5 -5
- data/lib/acfs/errors.rb +10 -2
- data/lib/acfs/middleware/msgpack_decoder.rb +1 -1
- data/lib/acfs/model/persistence.rb +32 -14
- data/lib/acfs/model/query_methods.rb +12 -10
- data/lib/acfs/version.rb +1 -1
- data/spec/acfs/middleware/msgpack_decoder_spec.rb +1 -10
- data/spec/acfs/model/dirty_spec.rb +2 -7
- data/spec/acfs/model/loadable_spec.rb +1 -3
- data/spec/acfs/model/locatable_spec.rb +1 -3
- data/spec/acfs/model/persistance_spec.rb +75 -9
- data/spec/acfs/model/query_methods_spec.rb +6 -20
- data/spec/acfs_spec.rb +7 -20
- data/spec/support/response.rb +9 -0
- metadata +4 -87
- data/gemfiles/Gemfile.rails-head +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c960a6ef96c4fb47b25a4cb7e94a2bbab5a84b06
|
4
|
+
data.tar.gz: 490d2fcd1442773d5c35e0c423e28597ffa33fcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f63ede8fdcb5bcd754f5b090bffcfbcf904cd167af88d68fc7d21434f78a65685f1b6f67dd3b8d3ceedbc67ee245ce46c135b25cb2a295175df9020f6e707d8
|
7
|
+
data.tar.gz: a9e72d86a83711bfdd87a15deea1e31cde0cfbf29a1555f83b0608cacdfa14fb6ffaacdd10db7ca57cedad15704cabec3bbe1e1dbf572e7e0b4158ed573b31da
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in acfs.gemspec
|
4
|
-
|
4
|
+
gemroot = File.dirname File.absolute_path __FILE__
|
5
|
+
gemspec path: gemroot
|
6
|
+
|
7
|
+
# Development gems
|
8
|
+
#
|
9
|
+
gem 'webmock', '~> 1.7'
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'guard-rspec'
|
13
|
+
gem 'coveralls'
|
14
|
+
|
15
|
+
|
16
|
+
# Platform specific development dependencies
|
17
|
+
#
|
18
|
+
gem 'msgpack', platform: :ruby
|
19
|
+
gem 'msgpack-jruby', require: 'msgpack', platform: :jruby
|
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.12.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.
|
data/acfs.gemspec
CHANGED
@@ -25,10 +25,4 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_runtime_dependency 'typhoeus'
|
26
26
|
|
27
27
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
28
|
-
spec.add_development_dependency 'webmock', '~> 1.7'
|
29
|
-
spec.add_development_dependency 'rake'
|
30
|
-
spec.add_development_dependency 'rspec'
|
31
|
-
spec.add_development_dependency 'guard-rspec'
|
32
|
-
spec.add_development_dependency 'coveralls'
|
33
|
-
spec.add_development_dependency 'msgpack'
|
34
28
|
end
|
data/gemfiles/Gemfile.rails-3-2
CHANGED
data/gemfiles/Gemfile.rails-4-0
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
#
|
4
|
-
|
3
|
+
# Load root Gemfile
|
4
|
+
self.instance_eval Bundler.read_file 'Gemfile'
|
5
5
|
|
6
|
-
gem 'activesupport', '~> 4.0.0.
|
7
|
-
gem 'activemodel', '~> 4.0.0.
|
8
|
-
gem 'actionpack', '~> 4.0.0.
|
6
|
+
gem 'activesupport', '~> 4.0.0.rc1'
|
7
|
+
gem 'activemodel', '~> 4.0.0.rc1'
|
8
|
+
gem 'actionpack', '~> 4.0.0.rc1'
|
data/lib/acfs/errors.rb
CHANGED
@@ -10,8 +10,8 @@ module Acfs
|
|
10
10
|
class ErroneousResponse < Error
|
11
11
|
attr_accessor :response
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
self.response = response
|
13
|
+
def initialize(data = {})
|
14
|
+
self.response = data[:response]
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -20,4 +20,12 @@ module Acfs
|
|
20
20
|
class ResourceNotFound < ErroneousResponse
|
21
21
|
end
|
22
22
|
|
23
|
+
class InvalidResource < ErroneousResponse
|
24
|
+
attr_accessor :errors
|
25
|
+
|
26
|
+
def initialize(data)
|
27
|
+
self.errors = data[:errors]
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
23
31
|
end
|
@@ -14,7 +14,7 @@ module Acfs
|
|
14
14
|
CONTENT_TYPES = %w(application/x-msgpack)
|
15
15
|
|
16
16
|
def response(response, nxt)
|
17
|
-
response.data = ::MessagePack.
|
17
|
+
response.data = ::MessagePack.unpack(response.body) if message_pack?(response)
|
18
18
|
nxt.call response
|
19
19
|
end
|
20
20
|
|
@@ -47,10 +47,18 @@ module Acfs
|
|
47
47
|
false
|
48
48
|
end
|
49
49
|
|
50
|
-
def save!(
|
51
|
-
|
50
|
+
def save!(opts = {}) # :nodoc:
|
51
|
+
#raise ::Acfs::InvalidResource errors: errors.to_a unless valid?
|
52
|
+
|
53
|
+
opts[:data] = attributes unless opts[:data]
|
54
|
+
|
55
|
+
request = new? ? create_request(opts) : put_request(opts)
|
52
56
|
request.on_complete do |response|
|
53
|
-
|
57
|
+
if response.success?
|
58
|
+
update_with response.data
|
59
|
+
else
|
60
|
+
self.class.raise! response
|
61
|
+
end
|
54
62
|
end
|
55
63
|
|
56
64
|
self.class.service.run request
|
@@ -58,17 +66,27 @@ module Acfs
|
|
58
66
|
|
59
67
|
module ClassMethods
|
60
68
|
|
61
|
-
# Create a new resource sending given data.
|
69
|
+
# Create a new resource sending given data. If resource cannot be
|
70
|
+
# created an error will be thrown.
|
71
|
+
#
|
72
|
+
def create!(data, opts = {})
|
73
|
+
new.tap do |model|
|
74
|
+
model.save! opts.merge data: data
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create a new resource sending given data. If resource cannot be
|
79
|
+
# create model will be returned and error hash contains response
|
80
|
+
# errors if available.
|
62
81
|
#
|
63
82
|
def create(data, opts = {})
|
64
83
|
model = new
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
84
|
+
model.save! opts.merge data: data
|
85
|
+
model
|
86
|
+
rescue InvalidResource => err
|
87
|
+
(err.errors || []).each do |field, errors|
|
88
|
+
model.errors.set field, errors
|
69
89
|
end
|
70
|
-
|
71
|
-
service.run request
|
72
90
|
model
|
73
91
|
end
|
74
92
|
end
|
@@ -79,12 +97,12 @@ module Acfs
|
|
79
97
|
loaded!
|
80
98
|
end
|
81
99
|
|
82
|
-
def create_request
|
83
|
-
Acfs::Request.new self.class.url, method: :post, data:
|
100
|
+
def create_request(opts = {})
|
101
|
+
Acfs::Request.new self.class.url, method: :post, data: opts[:data]
|
84
102
|
end
|
85
103
|
|
86
|
-
def put_request
|
87
|
-
Acfs::Request.new url, method: :put, data:
|
104
|
+
def put_request(opts = {})
|
105
|
+
Acfs::Request.new url, method: :put, data: opts[:data]
|
88
106
|
end
|
89
107
|
end
|
90
108
|
end
|
@@ -53,6 +53,17 @@ module Acfs::Model
|
|
53
53
|
end
|
54
54
|
alias :where :all
|
55
55
|
|
56
|
+
def raise!(response)
|
57
|
+
case response.code
|
58
|
+
when 404
|
59
|
+
raise ::Acfs::ResourceNotFound.new response: response
|
60
|
+
when 422
|
61
|
+
raise ::Acfs::InvalidResource.new response: response, errors: response.data['errors']
|
62
|
+
else
|
63
|
+
raise ::Acfs::ErroneousResponse.new response: response
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
56
67
|
private
|
57
68
|
def find_single(id, opts, &block)
|
58
69
|
model = self.new
|
@@ -63,7 +74,7 @@ module Acfs::Model
|
|
63
74
|
model.loaded!
|
64
75
|
block.call model unless block.nil?
|
65
76
|
else
|
66
|
-
|
77
|
+
raise! response
|
67
78
|
end
|
68
79
|
end
|
69
80
|
service.queue request
|
@@ -85,15 +96,6 @@ module Acfs::Model
|
|
85
96
|
end
|
86
97
|
end
|
87
98
|
end
|
88
|
-
|
89
|
-
def raise_error_for(response)
|
90
|
-
case response.code
|
91
|
-
when 404
|
92
|
-
raise ::Acfs::ResourceNotFound.new response
|
93
|
-
else
|
94
|
-
raise ::Acfs::ErroneousResponse.new response
|
95
|
-
end
|
96
|
-
end
|
97
99
|
end
|
98
100
|
end
|
99
101
|
end
|
data/lib/acfs/version.rb
CHANGED
@@ -14,7 +14,7 @@ describe Acfs::Middleware::MessagePackDecoder do
|
|
14
14
|
|
15
15
|
context 'with Message Pack response' do
|
16
16
|
let(:headers) { { 'Content-Type' => 'application/x-msgpack' } }
|
17
|
-
let(:body) { MessagePack.
|
17
|
+
let(:body) { MessagePack.pack data }
|
18
18
|
|
19
19
|
it 'should decode body data' do
|
20
20
|
request.complete! response
|
@@ -23,15 +23,6 @@ describe Acfs::Middleware::MessagePackDecoder do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
context 'with invalid response' do
|
27
|
-
let(:headers) { { 'Content-Type' => 'application/x-msgpack' } }
|
28
|
-
let(:body) { MessagePack.dump(data)[4..-4] }
|
29
|
-
|
30
|
-
it 'should raise an error' do
|
31
|
-
expect { request.complete! response }.to raise_error(MessagePack::MalformedFormatError)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
26
|
context 'without Message Pack response' do
|
36
27
|
let(:headers) { { 'Content-Type' => 'application/text' } }
|
37
28
|
let(:body) { data.to_json }
|
@@ -3,13 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Model::Dirty do
|
4
4
|
let(:model) { MyUser.new }
|
5
5
|
before do
|
6
|
-
stub_request(:get, "http://users.example.org/users/1").to_return(
|
7
|
-
|
8
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
9
|
-
|
10
|
-
stub_request(:post, 'http://users.example.org/users').to_return(
|
11
|
-
body: MessagePack.dump({ id: 5, name: 'dhh', age: 12 }),
|
12
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
6
|
+
stub_request(:get, "http://users.example.org/users/1").to_return response({ id: 1, name: 'Anon', age: 12 })
|
7
|
+
stub_request(:post, 'http://users.example.org/users').to_return response({ id: 5, name: 'dhh', age: 12 })
|
13
8
|
end
|
14
9
|
|
15
10
|
it 'includes ActiveModel::Dirty' do
|
@@ -3,9 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Model::Loadable do
|
4
4
|
let(:model) { MyUser.find 1 }
|
5
5
|
before do
|
6
|
-
stub_request(:get, "http://users.example.org/users/1").to_return(
|
7
|
-
body: MessagePack.dump({ id: 1, name: "Anon", age: 12 }),
|
8
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
6
|
+
stub_request(:get, "http://users.example.org/users/1").to_return response({ id: 1, name: "Anon", age: 12 })
|
9
7
|
end
|
10
8
|
|
11
9
|
describe '#loaded?' do
|
@@ -3,9 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Model::Locatable do
|
4
4
|
let(:model) { MyUser }
|
5
5
|
before do
|
6
|
-
stub_request(:get, "http://users.example.org/users/1").to_return(
|
7
|
-
body: MessagePack.dump({ id: 1, name: "Anon", age: 12 }),
|
8
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
6
|
+
stub_request(:get, "http://users.example.org/users/1").to_return response({ id: 1, name: "Anon", age: 12 })
|
9
7
|
end
|
10
8
|
|
11
9
|
describe '.url' do
|
@@ -3,20 +3,28 @@ require 'spec_helper'
|
|
3
3
|
describe Acfs::Model::Persistence do
|
4
4
|
let(:model_class) { MyUser }
|
5
5
|
before do
|
6
|
-
@get_stub = stub_request(:get, "http://users.example.org/users/1").to_return(
|
7
|
-
body: MessagePack.dump({ id: 1, name: "Anon", age: 12 }),
|
8
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
6
|
+
@get_stub = stub_request(:get, "http://users.example.org/users/1").to_return response({ id: 1, name: "Anon", age: 12 })
|
9
7
|
|
10
8
|
@patch_stub = stub_request(:put, 'http://users.example.org/users/1')
|
11
9
|
.with(
|
12
10
|
body: '{"id":1,"name":"Idefix","age":12}')
|
13
|
-
.to_return(
|
14
|
-
body: MessagePack.dump({ id: 1, name: 'Idefix', age: 12 }),
|
15
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
11
|
+
.to_return response({ id: 1, name: 'Idefix', age: 12 })
|
16
12
|
|
17
|
-
@post_stub = stub_request(:post, 'http://users.example.org/users')
|
18
|
-
|
19
|
-
|
13
|
+
@post_stub = stub_request(:post, 'http://users.example.org/users')
|
14
|
+
.with(body: '{"id":null,"name":"Idefix","age":12}')
|
15
|
+
.to_return response({ id: 5, name: 'Idefix', age: 12 })
|
16
|
+
|
17
|
+
stub_request(:post, 'http://users.example.org/users')
|
18
|
+
.with(body: '{"id":null,"name":"Anon","age":null}')
|
19
|
+
.to_return response({ id: 5, name: 'Anon', age: 12 })
|
20
|
+
|
21
|
+
stub_request(:post, 'http://users.example.org/users')
|
22
|
+
.with(body: '{"name":"Idefix","age":12}')
|
23
|
+
.to_return response({ id: 5, name: 'Idefix', age: 12 })
|
24
|
+
|
25
|
+
stub_request(:post, 'http://users.example.org/users')
|
26
|
+
.with(body: '{"age":12}')
|
27
|
+
.to_return response({ errors: { name: [ 'required' ] }}, status: 422)
|
20
28
|
end
|
21
29
|
|
22
30
|
context 'new model' do
|
@@ -77,4 +85,62 @@ describe Acfs::Model::Persistence do
|
|
77
85
|
it { expect(model).to_not be_new }
|
78
86
|
end
|
79
87
|
end
|
88
|
+
|
89
|
+
describe '.create!' do
|
90
|
+
context 'with valid data' do
|
91
|
+
let(:data) { { name: 'Idefix', age: 12 } }
|
92
|
+
|
93
|
+
it 'should create new resource' do
|
94
|
+
model = model_class.create! data
|
95
|
+
expect(model.name).to be == 'Idefix'
|
96
|
+
expect(model.age).to be == 12
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should be persisted' do
|
100
|
+
model = model_class.create! data
|
101
|
+
expect(model).to be_persisted
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'with invalid data' do
|
106
|
+
let(:data) { { age: 12 } }
|
107
|
+
|
108
|
+
it 'should raise an error' do
|
109
|
+
expect { model_class.create! data }.to raise_error ::Acfs::InvalidResource do |error|
|
110
|
+
expect(error.errors).to be == { name: ['required'] }.stringify_keys
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '.create' do
|
117
|
+
context 'with valid data' do
|
118
|
+
let(:data) { { name: 'Idefix', age: 12 } }
|
119
|
+
|
120
|
+
it 'should create new resource' do
|
121
|
+
model = model_class.create! data
|
122
|
+
expect(model.name).to be == 'Idefix'
|
123
|
+
expect(model.age).to be == 12
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should be persisted' do
|
127
|
+
model = model_class.create! data
|
128
|
+
expect(model).to be_persisted
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'with invalid data' do
|
133
|
+
let(:data) { { age: 12 } }
|
134
|
+
|
135
|
+
it 'should return not persisted resource' do
|
136
|
+
model = model_class.create data
|
137
|
+
expect(model).to_not be_persisted
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should contain error hash' do
|
141
|
+
model = model_class.create data
|
142
|
+
expect(model.errors.to_hash).to be == { name: [ "required" ]}.stringify_keys
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
80
146
|
end
|
@@ -7,9 +7,7 @@ describe Acfs::Model::QueryMethods do
|
|
7
7
|
context 'with single id' do
|
8
8
|
context 'with successful response' do
|
9
9
|
before do
|
10
|
-
stub_request(:get, 'http://users.example.org/users/1').to_return(
|
11
|
-
body: MessagePack.dump({ id: 1, name: 'Anon', age: 12 }),
|
12
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
10
|
+
stub_request(:get, 'http://users.example.org/users/1').to_return response({ id: 1, name: 'Anon', age: 12 })
|
13
11
|
end
|
14
12
|
|
15
13
|
it 'should load a single remote resource' do
|
@@ -33,10 +31,7 @@ describe Acfs::Model::QueryMethods do
|
|
33
31
|
|
34
32
|
context 'with 404 response' do
|
35
33
|
before do
|
36
|
-
stub_request(:get, 'http://users.example.org/users/1').to_return(
|
37
|
-
status: 404,
|
38
|
-
body: MessagePack.dump({ error: 'not found' }),
|
39
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
34
|
+
stub_request(:get, 'http://users.example.org/users/1').to_return response({ error: 'not found' }, status: 404)
|
40
35
|
end
|
41
36
|
|
42
37
|
it 'should raise a NotFound error' do
|
@@ -50,9 +45,7 @@ describe Acfs::Model::QueryMethods do
|
|
50
45
|
|
51
46
|
context 'with 500 response' do
|
52
47
|
before do
|
53
|
-
stub_request(:get, 'http://users.example.org/users/1').to_return(
|
54
|
-
status: 500,
|
55
|
-
headers: {'Content-Type' => 'text/plain'})
|
48
|
+
stub_request(:get, 'http://users.example.org/users/1').to_return response(nil, status: 500)
|
56
49
|
end
|
57
50
|
|
58
51
|
it 'should raise a response error' do
|
@@ -67,12 +60,8 @@ describe Acfs::Model::QueryMethods do
|
|
67
60
|
|
68
61
|
context 'with multiple ids' do
|
69
62
|
before do
|
70
|
-
stub_request(:get, 'http://users.example.org/users/1').to_return(
|
71
|
-
|
72
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
73
|
-
stub_request(:get, 'http://users.example.org/users/2').to_return(
|
74
|
-
body: MessagePack.dump({ id: 2, name: 'Johnny', age: 42 }),
|
75
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
63
|
+
stub_request(:get, 'http://users.example.org/users/1').to_return response({ id: 1, name: 'Anon', age: 12 })
|
64
|
+
stub_request(:get, 'http://users.example.org/users/2').to_return response({ id: 2, name: 'Johnny', age: 42 })
|
76
65
|
end
|
77
66
|
|
78
67
|
context 'with successful response' do
|
@@ -100,10 +89,7 @@ describe Acfs::Model::QueryMethods do
|
|
100
89
|
|
101
90
|
context 'with one 404 response' do
|
102
91
|
before do
|
103
|
-
stub_request(:get, 'http://users.example.org/users/1').to_return(
|
104
|
-
status: 404,
|
105
|
-
body: MessagePack.dump({ error: 'not found' }),
|
106
|
-
headers: {'Content-Type' => 'application/x-msgpack'})
|
92
|
+
stub_request(:get, 'http://users.example.org/users/1').to_return response({ error: 'not found' }, status: 404)
|
107
93
|
end
|
108
94
|
|
109
95
|
it 'should raise resource not found error' do
|
data/spec/acfs_spec.rb
CHANGED
@@ -4,24 +4,12 @@ describe "Acfs" do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
headers = {}
|
7
|
-
stub_request(:get, "http://users.example.org/users").to_return(
|
8
|
-
|
9
|
-
|
10
|
-
stub_request(:get, "http://users.example.org/users/
|
11
|
-
|
12
|
-
|
13
|
-
stub_request(:get, "http://users.example.org/users/3").to_return(
|
14
|
-
body: MessagePack.dump({ id: 3, name: "Miraculix", age: 122 }),
|
15
|
-
headers: headers.merge({'Content-Type' => 'application/x-msgpack'}))
|
16
|
-
stub_request(:get, "http://users.example.org/users/100").to_return(
|
17
|
-
body: '{"id":100,"name":"Jimmy","age":45}',
|
18
|
-
headers: headers.merge({'Content-Type' => 'application/json'}))
|
19
|
-
stub_request(:get, "http://users.example.org/users/2/friends").to_return(
|
20
|
-
body: '[{"id":1,"name":"Anon","age":12}]',
|
21
|
-
headers: headers.merge({'Content-Type' => 'application/json'}))
|
22
|
-
stub_request(:get, "http://comments.example.org/comments?user=2").to_return(
|
23
|
-
body: '[{"id":1,"text":"Comment #1"},{"id":2,"text":"Comment #2"}]',
|
24
|
-
headers: headers.merge({'Content-Type' => 'application/json'}))
|
7
|
+
stub_request(:get, "http://users.example.org/users").to_return response([{ id: 1, name: "Anon", age: 12 }, { id: 2, name: "John", age: 26 }])
|
8
|
+
stub_request(:get, "http://users.example.org/users/2").to_return response({ id: 2, name: "John", age: 26 })
|
9
|
+
stub_request(:get, "http://users.example.org/users/3").to_return response({ id: 3, name: "Miraculix", age: 122 })
|
10
|
+
stub_request(:get, "http://users.example.org/users/100").to_return response({ id:100, name: "Jimmy", age: 45 })
|
11
|
+
stub_request(:get, "http://users.example.org/users/2/friends").to_return response([{ id: 1, name: "Anon", age: 12 }])
|
12
|
+
stub_request(:get, "http://comments.example.org/comments?user=2").to_return response([{ id: 1, text: "Comment #1"}, { id: 2, text: "Comment #2" }])
|
25
13
|
end
|
26
14
|
|
27
15
|
it 'should update single resource synchronously' do
|
@@ -47,8 +35,7 @@ describe "Acfs" do
|
|
47
35
|
end
|
48
36
|
|
49
37
|
it 'should create a single resource synchronously' do
|
50
|
-
stub = stub_request(:post, "http://users.example.org/sessions")
|
51
|
-
.to_return body: '{"id":"sessionhash","user":1}', headers: {'Content-Type' => 'application/json'}
|
38
|
+
stub = stub_request(:post, "http://users.example.org/sessions").to_return response({id: 'sessionhash', user: 1})
|
52
39
|
|
53
40
|
session = Session.create ident: 'Anon'
|
54
41
|
|
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.
|
4
|
+
version: 0.12.0
|
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-05-
|
11
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,90 +94,6 @@ dependencies:
|
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.3'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: webmock
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ~>
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '1.7'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ~>
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '1.7'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rake
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - '>='
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rspec
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - '>='
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - '>='
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: guard-rspec
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - '>='
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - '>='
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: coveralls
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - '>='
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - '>='
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: msgpack
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - '>='
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - '>='
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
181
97
|
description: API Client For Services
|
182
98
|
email:
|
183
99
|
- jg@altimos.de
|
@@ -196,7 +112,6 @@ files:
|
|
196
112
|
- acfs.gemspec
|
197
113
|
- gemfiles/Gemfile.rails-3-2
|
198
114
|
- gemfiles/Gemfile.rails-4-0
|
199
|
-
- gemfiles/Gemfile.rails-head
|
200
115
|
- lib/acfs.rb
|
201
116
|
- lib/acfs/adapter/typhoeus.rb
|
202
117
|
- lib/acfs/collection.rb
|
@@ -246,6 +161,7 @@ files:
|
|
246
161
|
- spec/acfs/service_spec.rb
|
247
162
|
- spec/acfs_spec.rb
|
248
163
|
- spec/spec_helper.rb
|
164
|
+
- spec/support/response.rb
|
249
165
|
- spec/support/service.rb
|
250
166
|
homepage: ''
|
251
167
|
licenses:
|
@@ -288,4 +204,5 @@ test_files:
|
|
288
204
|
- spec/acfs/service_spec.rb
|
289
205
|
- spec/acfs_spec.rb
|
290
206
|
- spec/spec_helper.rb
|
207
|
+
- spec/support/response.rb
|
291
208
|
- spec/support/service.rb
|