spec/ravelry/pattern_spec.rb in ravelry-0.0.6 vs spec/ravelry/pattern_spec.rb in ravelry-0.0.7
- old
+ new
@@ -1,8 +1,11 @@
require_relative '../spec_helper'
describe Ravelry::Pattern do
+ before do
+ stub_patterns_show_paid
+ end
it 'should be an instance of Patterns' do
pattern = p_initialize_paid_with_fetch
expect(pattern).to be_instance_of(Ravelry::Pattern)
end
@@ -20,9 +23,48 @@
expect(@api.data).to be
end
it 'should return a hash' do
expect(@api.data).to be_kind_of(Hash)
+ end
+ end
+
+ context '#search' do
+ let(:result) { Ravelry::Pattern.search('hello') }
+ before { stub_patterns_search }
+
+ it 'should succeed' do
+ expect(result).to be
+ end
+
+ it 'should send a request to /patterns/search.json' do
+ expect(Ravelry::Utils::Request).to receive(:get)
+ .with('patterns/search.json', :patterns, {:query => 'hello'})
+ .and_call_original
+
+ Ravelry::Pattern.search('hello')
+ end
+
+ it 'should set params' do
+ expect(Ravelry::Utils::Request).to receive(:get)
+ .with('patterns/search.json', :patterns, {
+ :query => 'hello',
+ :personal_attributes => 1,
+ :page => 123,
+ :page_size => 2
+ })
+ .and_call_original
+
+ Ravelry::Pattern
+ .search('hello', personal_attributes: true, page: 123, page_size: 2)
+ end
+
+ it 'should return an array' do
+ expect(result).to be_kind_of(Array)
+ end
+
+ it 'should return an array of Patterns' do
+ expect(result[0]).to be_kind_of(Ravelry::Pattern)
end
end
context 'class methods' do
before do