Sha256: a583af41dca0faaba058d8308312f2fd643b4dc3cc06d5bc857796837ce5ea5e
Contents?: true
Size: 1.93 KB
Versions: 2
Compression:
Stored size: 1.93 KB
Contents
require 'spec_helper' describe Spree::Product do before(:each) do shipping_category = Spree::ShippingCategory.create! name: 'shipping_category' @favorite_product1 = Spree::Product.create! name: 'favorite_product1', price: 100, shipping_category_id: shipping_category.id @favorite_product2 = Spree::Product.create! name: 'favorite_product2', price: 100, shipping_category_id: shipping_category.id @product1 = Spree::Product.create! name: 'product1', price: 100, shipping_category_id: shipping_category.id @product2 = Spree::Product.create! name: 'product2', price: 100, shipping_category_id: shipping_category.id @user1 = Spree::User.create! email: 'user1@example.com', password: 'example', password_confirmation: "example" @user2 = Spree::User.create! email: 'user2@example.com', password: "example", password_confirmation: 'example' @user1.favorites.create! product_id: @favorite_product1.id @user2.favorites.create! product_id: @favorite_product1.id @user2.favorites.create! product_id: @favorite_product2.id end it { is_expected.to have_many(:favorites).dependent(:destroy) } it { is_expected.to have_many(:favorite_users).through(:favorites).class_name('Spree::User') } describe "Spree::Product.favorite" do it "returns favorite products" do expect(Spree::Product.favorite).to match_array([@favorite_product1, @favorite_product2]) end end describe ".order_by_favorite_users_count" do context 'when order not passed' do it "returns products ordered by users_count in descending order" do expect(Spree::Product.favorite.order_by_favorite_users_count).to eq([@favorite_product1, @favorite_product2]) end end context 'when asc order passed' do it "returns products ordered by users_count in ascending order" do expect(Spree::Product.favorite.order_by_favorite_users_count(true)).to eq([@favorite_product2, @favorite_product1]) end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
spree_favorite_products-3.2.0 | spec/models/spree/product_decorator_spec.rb |
solidus_favorite_products-2.1.1 | spec/models/spree/product_decorator_spec.rb |