reviewed 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,12 @@ module Reviewed
4
4
  pages.find { |page| page.slug.match(/#{slug}/i) }
5
5
  end
6
6
 
7
+ def products
8
+ (@attributes[:products] || []).map do |product|
9
+ Reviewed::Product.new(product)
10
+ end
11
+ end
12
+
7
13
  def attachments(tag=nil)
8
14
  if tag.present?
9
15
  @attributes[:attachments].select do |attachment|
@@ -1,4 +1,4 @@
1
1
  module Reviewed
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  API_VERSION = 'v1'
4
4
  end
data/spec/article_spec.rb CHANGED
@@ -6,8 +6,25 @@ describe Reviewed::Article do
6
6
 
7
7
  it 'finds a page with a matching slug' do
8
8
  article = Reviewed::Article.find('minden-master-ii-grill-review')
9
- article.pages.length.should == 4
10
- article.find_page('performance').should == article.pages[1]
9
+ article.pages.length.should == 10
10
+ page = article.find_page('performance')
11
+ page.should == article.pages[2]
12
+ page.name.should == 'Performance'
13
+ end
14
+ end
15
+
16
+ describe 'products' do
17
+ use_vcr_cassette 'article/products'
18
+
19
+ before(:each) do
20
+ @article = Reviewed::Article.find('big-green-egg-medium-charcoal-grill-review')
21
+ end
22
+
23
+ it 'returns products of the correct class' do
24
+ @article.products.should_not be_empty
25
+ @article.products.each do |product|
26
+ product.class.should == Reviewed::Product
27
+ end
11
28
  end
12
29
  end
13
30
 
@@ -19,7 +36,7 @@ describe Reviewed::Article do
19
36
  end
20
37
 
21
38
  it 'returns all attachments' do
22
- @article.attachments.length.should > 1
39
+ @article.attachments.length.should >= 1
23
40
  end
24
41
 
25
42
  it 'finds attachments by tag' do
@@ -29,5 +46,10 @@ describe Reviewed::Article do
29
46
  attachment.tags.join(',').should match(/hero/i)
30
47
  end
31
48
  end
49
+
50
+ it 'does not have any matching attachments' do
51
+ attachments = @article.attachments('doesnotcompute')
52
+ attachments.length.should == 0
53
+ end
32
54
  end
33
55
  end
data/spec/base_spec.rb CHANGED
@@ -45,15 +45,15 @@ describe Reviewed::Base do
45
45
  use_vcr_cassette 'base/find_ok'
46
46
 
47
47
  it 'fetches content from the api' do
48
- model = Reviewed::Example.find('5036d7dd60de7d2065075752')
48
+ model = Reviewed::Example.find('506b0b46bd02862270000747')
49
49
  model.raw_response.should_not be_nil
50
50
  end
51
51
 
52
52
  it 'parses response json and returns an object' do
53
- model = Reviewed::Example.find('5036d7dd60de7d2065075752')
53
+ model = Reviewed::Example.find('506b0b46bd02862270000747')
54
54
  model.class.should == Reviewed::Example
55
- model.id.should == '5036d7dd60de7d2065075752'
56
- model.name.should == 'Fast Appliances To Save You Time'
55
+ model.id.should == '506b0b46bd02862270000747'
56
+ model.name.should == 'Minden Master II Grill Review'
57
57
  end
58
58
  end
59
59
 
@@ -86,7 +86,7 @@ describe Reviewed::Base do
86
86
 
87
87
  it 'returns the appropriate page of results' do
88
88
  collection = Reviewed::Article.where(:page => 2)
89
- collection.total.should == 7141
89
+ collection.total.should > 1
90
90
  collection.current_page.should == 2
91
91
  end
92
92
 
@@ -52,11 +52,11 @@ describe Reviewed::Collection do
52
52
 
53
53
  describe 'page attributes (pagination)' do
54
54
  it 'returns the total item count' do
55
- @collection.total.should == 15060
55
+ @collection.total.should > 1
56
56
  end
57
57
 
58
58
  it 'returns the total number of pages' do
59
- @collection.total_pages.should == 753
59
+ @collection.total_pages.should > 1
60
60
  end
61
61
 
62
62
  it 'indicates whether this is the first or last page' do