Skip to content

Instantly share code, notes, and snippets.

@MaryKuz
Created March 28, 2019 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaryKuz/45983d7688b9aa78a884ff1e5d44f60d to your computer and use it in GitHub Desktop.
Save MaryKuz/45983d7688b9aa78a884ff1e5d44f60d to your computer and use it in GitHub Desktop.
Correct the test spec/models/product
RSpec.describe Product, type: :model do
it { should be_a PgSearch }
describe '.search_by' do
let(:relation) { double }
before { expect(Product).to receive(:page).with(1).and_return(relation) }
context do
it { expect { Product.search_by 'page' => 1 }.to_not raise_error }
end
context do
before { expect(relation).to receive(:where).with('name ILIKE ?', 'abc%') }
it { expect { Product.search_by 'page' => 1, 'term' => 'abc' }.to_not raise_error }
end
context do
before { expect(relation).to receive(:search).with('word') }
it { expect { Product.search_by 'page' => 1, 'name' => 'word' }.to_not raise_error }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment