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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1762a7ff061a439b273236b71942175c54e1128
4
- data.tar.gz: 55efb7f2e40abb882057e7ab60db6c33acf8693d
3
+ metadata.gz: bf38625358e68de2ee624c7c170301c74ddfb97c
4
+ data.tar.gz: ecca4a7cf4c99639b520b5f6a9a582a77c87dce9
5
5
  SHA512:
6
- metadata.gz: 0e225a57655c95cd7d261c0ed266d7fee28bc5c473f5163fa73d998ab663b538faa8b8eec4688f7f14ba4276b6fca9fd9a1eacf62d2fd29d339a8beb4d849c5a
7
- data.tar.gz: ebc9ed2155e2d18c08f365ae66710e0e04eaf8db7ee3f73cf789e2396d1247ee0b473b444746ea1536d925b993f2cebea72562c0185157e68c91e322db083a61
6
+ metadata.gz: 8092e4c14f8251322010b90da07ee2042f0d00560f298862682dc82073b0a60d35691ae6514c39b616bf92742222faecf4305d79f465dab0f699ee037877e9fa
7
+ data.tar.gz: e334ce6c786bd38fbe55104a56e28911d4ce4fdcedca011606b86f9d6cc801d63f0f172c8daedbf7d5c67d1933864b5fd0c24640fd3aab58a499e20aa810204f
@@ -21,7 +21,7 @@ module Reviewed
21
21
  end
22
22
 
23
23
  def fetch_attachments opts={}
24
- req = Request.new :resource => Attachment, :scope => self
24
+ req = client.attachments(scope: self)
25
25
  req.where opts
26
26
  end
27
27
  end
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
- self.attributes = objectify(data)
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
@@ -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
- Reviewed::Request.new(resource: resource(method), client: self)
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
@@ -19,7 +19,7 @@ module Reviewed
19
19
  @page_attributes = body.pagination || {}
20
20
 
21
21
  data.each do |obj|
22
- self.items << klass.new(obj)
22
+ self.items << klass.new(obj, client)
23
23
  end
24
24
  end
25
25
 
@@ -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)
@@ -1,4 +1,4 @@
1
1
  module Reviewed
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  API_VERSION = 'v1'
4
4
  end
@@ -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
- @request.should be_an_instance_of(Reviewed::Request)
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
- @request.resource.should eql(Reviewed::Article)
71
- @request.client.should eql(client)
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
 
@@ -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