spec/article_spec.rb in reviewed-0.0.6 vs spec/article_spec.rb in reviewed-0.0.7

- old
+ new

@@ -1,8 +1,73 @@ require 'spec_helper' describe Reviewed::Article do + + describe 'associations' 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 + @article.products.each do |product| + product.should be_an_instance_of(Reviewed::Product) + 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 + @article.attachments.length.should >= 1 + end + + it 'returns attachments of the correct class' do + @article.attachments.each do |attachment| + attachment.should be_an_instance_of(Reviewed::Attachment) + end + end + + it 'finds attachments by tag' do + attachments = @article.attachments('hero') + attachments.length.should == 1 + attachments.each do |attachment| + attachment.tags.join(',').should match(/hero/i) + end + end + + it 'does not have any matching attachments' do + attachments = @article.attachments('doesnotcompute') + attachments.length.should == 0 + end + end + end + describe 'find_page' do use_vcr_cassette 'article/find_page' it 'finds a page with a matching slug' do article = Reviewed::Article.find('minden-master-ii-grill-review') @@ -11,25 +76,11 @@ page.should == article.pages[2] page.name.should == 'Performance' 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 'returns products of the correct class' do - @article.products.should_not be_empty - @article.products.each do |product| - product.class.should == Reviewed::Product - end - end - end - describe 'primary_product' do use_vcr_cassette 'article/products' before(:each) do @article = Reviewed::Article.find('big-green-egg-medium-charcoal-grill-review') @@ -41,32 +92,7 @@ end it "returns a product of the correct class" do @product.class.should == Reviewed::Product 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 'returns all attachments' do - @article.attachments.length.should >= 1 - end - - it 'finds attachments by tag' do - attachments = @article.attachments('hero') - attachments.length.should == 1 - attachments.each do |attachment| - attachment.tags.join(',').should match(/hero/i) - end - end - - it 'does not have any matching attachments' do - attachments = @article.attachments('doesnotcompute') - attachments.length.should == 0 - end end end