Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe "product search by price and name" do
- before(:each) do
- @product1 = Product.create(name: "Acura", price: 100, category_id: 1)
- @product2 = Product.create(name: "BMV", price: 50, category_id: 2)
- @product3 = Product.create(name: "Ferrari", price: 150, category_id: 3)
- end
- context "when name 'Fiat'" do
- it "returns an empty array" do
- search_hash = { keyword: "Fiat" }
- expect(Product.search(search_hash)).to be_empty
- end
- end
- context "when price '10'" do
- it "returns an empty array" do
- search_hash = { price: 10 }
- expect(Product.search(search_hash)).to be_empty
- end
- end
- context "when name 'Acura'" do
- it "returns the product1" do
- search_hash = { keyword: "Acura" }
- expect(Product.search(search_hash)).to match_array([@product1])
- end
- end
- context "when price '150'" do
- it "returns the product3" do
- search_hash = { price: 150 }
- expect(Product.search(search_hash)).to match_array([@product3])
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement