Sha256: f18966946ca5061f3bc5bb5a5b7495fe8cb050e99fa30d490cb25f62f6b5a0fd

Contents?: true

Size: 877 Bytes

Versions: 9

Compression:

Stored size: 877 Bytes

Contents

require 'spec_helper'

describe Spree::Favorite do
  it { should belong_to(:product) }
  it { should belong_to(:user) }
  it { should validate_uniqueness_of(:product_id).scoped_to(:user_id).with_message("already marked as favorite") }
  it { should validate_presence_of(:user_id) }
  it { should validate_presence_of(:product_id) }

  context "when product_id is present" do
    before(:each) do
      @favorite = Spree::Favorite.new :product_id => 'invalid product id'
    end
    it "checks for the presence of product" do
      @favorite.valid?
      @favorite.errors[:product].should eq(["is invalid"])
    end
  end

  context "when product_id is not present" do
    before(:each) do
      @favorite = Spree::Favorite.new
    end

    it "does not validate the presence of product" do
      @favorite.valid?
      @favorite.errors[:product].should eq([])
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_favorite_products-2.3.0 spec/models/spree/favorite_spec.rb
spree_favorite_products-3.0.0 spec/models/spree/favorite_spec.rb
spree_favorite_products-2.0.3 spec/models/spree/favorite_spec.rb
spree_favorite_products-2.2.3 spec/models/spree/favorite_spec.rb
spree_favorite_products-2.2.2 spec/models/spree/favorite_spec.rb
spree_favorite_products-2.0.2 spec/models/spree/favorite_spec.rb
spree_favorite_products-2.2.0 spec/models/spree/favorite_spec.rb
spree_favorite_products-2.0.1 spec/models/spree/favorite_spec.rb
spree_favorite_products-2.0.0 spec/models/spree/favorite_spec.rb