Sha256: 5b33adf31102a19fb66b09ea5e5ace4e93abde458e7c8f721103302fd6f5b1bb

Contents?: true

Size: 969 Bytes

Versions: 4

Compression:

Stored size: 969 Bytes

Contents

require 'spec_helper'

describe Spree::User do
  before(:each) do
    @user = Spree::User.create! :email => 'test@example.com', :password => 'spree123'
    @product1 = Spree::Product.create! :name => 'product1', :price => 100, :shipping_category_id => 1
    @product2 = Spree::Product.create! :name => 'product2', :price => 100, :shipping_category_id => 1
    favorite = Spree::Favorite.new
    favorite.product_id = @product1.id
    favorite.user_id = @user.id
    favorite.save!
  end

  it { should have_many(:favorites).dependent(:destroy) }
  it { should have_many(:favorite_products).through(:favorites).class_name('Spree::Product') }

  describe "has_favorite_product?" do
    context "when product in user's favorite products" do
      it { @user.has_favorite_product?(@product1.id).should be_true }
    end

    context 'when product is not in users favorite products' do
      it { @user.has_favorite_product?(@product2.id).should be_false }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_favorite_products-2.3.0 spec/models/spree/user_decorator_spec.rb
spree_favorite_products-3.0.0 spec/models/spree/user_decorator_spec.rb
spree_favorite_products-2.0.3 spec/models/spree/user_decorator_spec.rb
spree_favorite_products-2.2.3 spec/models/spree/user_decorator_spec.rb