reviewed 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reviewed/attachable.rb +1 -1
- data/lib/reviewed/base.rb +4 -3
- data/lib/reviewed/client.rb +6 -1
- data/lib/reviewed/collection.rb +1 -1
- data/lib/reviewed/request.rb +5 -5
- data/lib/reviewed/version.rb +1 -1
- data/spec/attachable_spec.rb +4 -0
- data/spec/base_spec.rb +10 -0
- data/spec/client_spec.rb +10 -7
- data/spec/collection_spec.rb +6 -0
- data/spec/fixtures/vcr/Reviewed_Article/uses_the_client_to_fetch.yml +1678 -0
- data/spec/fixtures/vcr/Reviewed_Article/uses_the_client_to_fetch_scoped_attachments.yml +797 -0
- data/spec/fixtures/vcr/Reviewed_Collection/collection_data/passes_the_client_to_each_object.yml +85 -0
- data/spec/fixtures/vcr/Reviewed_Request/object_from_response/passes_the_client_to_the_object.yml +499 -0
- data/spec/request_spec.rb +7 -1
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf38625358e68de2ee624c7c170301c74ddfb97c
|
4
|
+
data.tar.gz: ecca4a7cf4c99639b520b5f6a9a582a77c87dce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8092e4c14f8251322010b90da07ee2042f0d00560f298862682dc82073b0a60d35691ae6514c39b616bf92742222faecf4305d79f465dab0f699ee037877e9fa
|
7
|
+
data.tar.gz: e334ce6c786bd38fbe55104a56e28911d4ce4fdcedca011606b86f9d6cc801d63f0f172c8daedbf7d5c67d1933864b5fd0c24640fd3aab58a499e20aa810204f
|
data/lib/reviewed/attachable.rb
CHANGED
data/lib/reviewed/base.rb
CHANGED
@@ -7,10 +7,11 @@ module Reviewed
|
|
7
7
|
|
8
8
|
extend ::ActiveModel::Naming
|
9
9
|
|
10
|
-
attr_accessor :attributes
|
10
|
+
attr_accessor :attributes, :client
|
11
11
|
|
12
|
-
def initialize(data)
|
13
|
-
|
12
|
+
def initialize(data, client = Reviewed::Client.new)
|
13
|
+
@attributes = objectify(data)
|
14
|
+
@client = client
|
14
15
|
end
|
15
16
|
|
16
17
|
def created_at
|
data/lib/reviewed/client.rb
CHANGED
@@ -53,8 +53,13 @@ module Reviewed
|
|
53
53
|
klass_string.constantize rescue name
|
54
54
|
end
|
55
55
|
|
56
|
+
# args are options passed to request object, for example in:
|
57
|
+
# client.attachments(scope: 'article')
|
58
|
+
# args = [{scope: 'article'}]
|
56
59
|
def method_missing(method, *args, &block)
|
57
|
-
|
60
|
+
opts = { client: self, resource: resource(method) }
|
61
|
+
opts = opts.merge!(args[0]) if args[0]
|
62
|
+
Reviewed::Request.new(opts)
|
58
63
|
end
|
59
64
|
|
60
65
|
def connection
|
data/lib/reviewed/collection.rb
CHANGED
data/lib/reviewed/request.rb
CHANGED
@@ -34,11 +34,6 @@ module Reviewed
|
|
34
34
|
where({})
|
35
35
|
end
|
36
36
|
|
37
|
-
def object_from_response(method, url, params={})
|
38
|
-
response = client.send(method, url, params.merge(cache_control_params))
|
39
|
-
resource.new(response.body)
|
40
|
-
end
|
41
|
-
|
42
37
|
def cached?
|
43
38
|
!uncached?
|
44
39
|
end
|
@@ -57,6 +52,11 @@ module Reviewed
|
|
57
52
|
self
|
58
53
|
end
|
59
54
|
|
55
|
+
def object_from_response(method, url, params={})
|
56
|
+
response = client.send(method, url, params.merge(cache_control_params))
|
57
|
+
resource.new(response.body, client)
|
58
|
+
end
|
59
|
+
|
60
60
|
def collection_from_response(method, url, params={})
|
61
61
|
response = client.send(method, url, params.merge(cache_control_params))
|
62
62
|
Reviewed::Collection.new(client, resource, response, params)
|
data/lib/reviewed/version.rb
CHANGED
data/spec/attachable_spec.rb
CHANGED
@@ -19,4 +19,8 @@ describe Reviewed::Article, vcr: true do
|
|
19
19
|
@article.should_receive(:fetch_attachments).with({tags: 'foobar'})
|
20
20
|
@article.attachments('foobar').should eql([])
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'uses the client to fetch scoped attachments' do
|
24
|
+
@article.attachments.count.should eql(1)
|
25
|
+
end
|
22
26
|
end
|
data/spec/base_spec.rb
CHANGED
@@ -24,6 +24,16 @@ describe Reviewed::Base do
|
|
24
24
|
obj = Example.new( { foo: 'bar' } )
|
25
25
|
obj.instance_variable_get(:@attributes).should eql( { foo: 'bar' } )
|
26
26
|
end
|
27
|
+
|
28
|
+
it 'should have a default client if one is not passed' do
|
29
|
+
obj = Example.new( { foo: 'bar' })
|
30
|
+
obj.client.should be_an_instance_of(Reviewed::Client)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should have a client if passed in' do
|
34
|
+
obj = Example.new( { foo: 'bar' }, "client" )
|
35
|
+
obj.client.should eql('client')
|
36
|
+
end
|
27
37
|
end
|
28
38
|
|
29
39
|
describe 'to_path' do
|
data/spec/client_spec.rb
CHANGED
@@ -58,17 +58,20 @@ describe Reviewed::Client do
|
|
58
58
|
|
59
59
|
describe '#method_missing' do
|
60
60
|
|
61
|
-
before(:each) do
|
62
|
-
@request = client.articles
|
63
|
-
end
|
64
|
-
|
65
61
|
it 'returns a Reviewed::Request instance' do
|
66
|
-
|
62
|
+
request = client.articles
|
63
|
+
request.should be_an_instance_of(Reviewed::Request)
|
67
64
|
end
|
68
65
|
|
69
66
|
it 'sets the correct instance variables' do
|
70
|
-
|
71
|
-
|
67
|
+
request = client.articles
|
68
|
+
request.resource.should eql(Reviewed::Article)
|
69
|
+
request.client.should eql(client)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'passes arguments to the request' do
|
73
|
+
request = client.articles(scope: "faux_scope")
|
74
|
+
request.instance_variable_get(:@scope).should eql('faux_scope')
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
data/spec/collection_spec.rb
CHANGED
@@ -25,6 +25,12 @@ describe Reviewed::Collection, vcr: true do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
it 'passes the client to each object' do
|
29
|
+
@collection.each do |product|
|
30
|
+
product.client.should eql(client)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
28
34
|
it 'fetches the first page by default' do
|
29
35
|
@collection.current_page.should == 1
|
30
36
|
end
|