reviewed 0.0.2 → 0.0.3
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.
- data/lib/reviewed/article.rb +6 -0
- data/lib/reviewed/version.rb +1 -1
- data/spec/article_spec.rb +25 -3
- data/spec/base_spec.rb +5 -5
- data/spec/collection_spec.rb +2 -2
- data/spec/fixtures/vcr/article/attachments.yml +174 -197
- data/spec/fixtures/vcr/article/find_page.yml +143 -128
- data/spec/fixtures/vcr/article/products.yml +258 -0
- data/spec/fixtures/vcr/base/find_error_key.yml +13 -131
- data/spec/fixtures/vcr/base/find_ok.yml +156 -202
- data/spec/fixtures/vcr/base/where_collection.yml +9544 -1678
- data/spec/fixtures/vcr/collection/products.yml +887 -1160
- data/spec/fixtures/vcr/product/attachments.yml +139 -18
- data/spec/fixtures/vcr/request/authors.yml +5 -5
- data/spec/fixtures/vcr/response/authors.yml +5 -5
- data/spec/product_spec.rb +9 -4
- metadata +4 -2
data/lib/reviewed/article.rb
CHANGED
@@ -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|
|
data/lib/reviewed/version.rb
CHANGED
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 ==
|
10
|
-
article.find_page('performance')
|
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
|
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('
|
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('
|
53
|
+
model = Reviewed::Example.find('506b0b46bd02862270000747')
|
54
54
|
model.class.should == Reviewed::Example
|
55
|
-
model.id.should == '
|
56
|
-
model.name.should == '
|
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
|
89
|
+
collection.total.should > 1
|
90
90
|
collection.current_page.should == 2
|
91
91
|
end
|
92
92
|
|
data/spec/collection_spec.rb
CHANGED
@@ -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
|
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
|
59
|
+
@collection.total_pages.should > 1
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'indicates whether this is the first or last page' do
|