spec/article_spec.rb in reviewed-0.1.2 vs spec/article_spec.rb in reviewed-0.1.4

- old
+ new

@@ -1,26 +1,28 @@ require 'spec_helper' -describe Reviewed::Article do +describe Reviewed::Article, vcr: true do - describe 'associations' do + let(:client) do + Reviewed::Client.new(api_key: TEST_KEY, base_uri: TEST_URL) + end + before(:each) do + @article = client.articles.find('big-green-egg-medium-charcoal-grill-review', { with_attachments: true }) + end + + describe 'associations', vcr: true do + describe 'pages' do - use_vcr_cassette 'article/pages' it 'has_many :pages' do Reviewed::Article._embedded_many.should include({"pages"=>Reviewed::Page}) end end describe 'products' do - use_vcr_cassette 'article/products' - before(:each) do - @article = Reviewed::Article.find('big-green-egg-medium-charcoal-grill-review') - end - it 'has_many :products' do Reviewed::Article._embedded_many.should include({"products"=>Reviewed::Product}) end it 'returns products of the correct class' do @@ -29,16 +31,11 @@ end end end describe 'attachments' do - use_vcr_cassette 'article/attachments' - before(:each) do - @article = Reviewed::Article.find('big-green-egg-medium-charcoal-grill-review') - end - it 'has_many :attachments' do Reviewed::Article._embedded_many.should include({"attachments"=>Reviewed::Attachment}) end it 'returns all attachments' do @@ -50,11 +47,11 @@ attachment.should be_an_instance_of(Reviewed::Attachment) end end it 'finds attachments by tag' do - attachments = @article.attachments('hero') + attachments = @article.attachments('old-hero') attachments.length.should == 1 attachments.each do |attachment| attachment.tags.join(',').should match(/hero/i) end end @@ -64,35 +61,38 @@ attachments.length.should == 0 end end end - describe 'find_page' do - use_vcr_cassette 'article/find_page' + describe 'find_page', vcr: true do it 'finds a page with a matching slug' do - article = Reviewed::Article.find('minden-master-ii-grill-review') - article.pages.length.should == 9 + article = client.articles.find('minden-master-ii-grill-review') + article.pages.length.should == 4 page = article.find_page('performance') page.should == article.pages[2] page.name.should == 'Performance' end end - describe 'primary_product' do - use_vcr_cassette 'article/products' + describe 'primary_product', vcr: true do before(:each) do - @article = Reviewed::Article.find('big-green-egg-medium-charcoal-grill-review') + @article = client.articles.find('big-green-egg-medium-charcoal-grill-review') @product = @article.primary_product end it "returns the primary product" do @product.name.should eql('Big Green Egg Medium') end it "returns a product of the correct class" do @product.class.should == Reviewed::Product + end + + it 'returns nil if does not respond to products' do + @article.attributes.delete(:products) + @article.primary_product.should be_nil end end end