spec/attachable_spec.rb in reviewed-0.8.0 vs spec/attachable_spec.rb in reviewed-0.9.0

- old
+ new

@@ -10,15 +10,29 @@ @article = client.articles.find('50fb9a81bd0286d55504b952') end it 'returns local attachments when available' do Reviewed::Request.should_not_receive(:new) - @article.attachments('hero').first.tags.should eql(['hero']) + @article.attachments(tags: 'hero').first.tags.should eql(['hero']) end it 'fetches when a tag is not in pre-loaded set' do - @article.should_receive(:fetch_attachments).with({tags: 'foobar'}) - @article.attachments('foobar').should eql([]) + @article.should_receive(:fetch_attachments).with({tags: ['foobar']}) + @article.attachments(tags: 'foobar').should eql([]) + end + + it 'merges local and fetched tags' do + @article.stub(:fetch_attachments). + and_return(Reviewed::Article.new(tags: ['fetched'])) + @article.should_receive(:fetch_attachments).with({tags: ['foobar']}) + attachments = @article.attachments(tags: ['hero', 'foobar']) + attachments.count.should eql(2) + attachments.map(&:tags).flatten.should eql(['hero', 'fetched']) + end + + it 'passes options to fetch_attachments when no tags present' do + @article.should_receive(:fetch_attachments).with({test: 'test'}) + @article.attachments(test: 'test') end it 'uses the client to fetch scoped attachments' do @article.attachments.count.should eql(1) end