Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rails_helper'
- RSpec.describe Product, type: :model do
- let!(:product) { create(:product) }
- let!(:cart) { create(:cart) }
- describe 'validations' do
- it { is_expected.to validate_presence_of :name }
- it { is_expected.to validate_numericality_of :price }
- end
- describe 'ActiveRecord associations' do
- it { is_expected.to have_many :line_items }
- it { is_expected.to belong_to :category }
- end
- describe "ensure_not_referenced_by_any_line_item" do
- context "item has no line items" do
- it "returns true" do
- expect(product.ensure_not_referenced_by_any_line_item).to eq true
- end
- end
- context "item has line items" do
- it "returns false" do
- LineItem.create!(product_id: product.id, cart_id: cart.id, quantity: 1)
- expect(product.ensure_not_referenced_by_any_line_item).to eq false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement