Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.90 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. RSpec.describe Product, type: :model do
  4.  
  5.   let!(:product) { create(:product) }
  6.   let!(:cart) { create(:cart) }
  7.  
  8.   describe 'validations' do
  9.     it { is_expected.to validate_presence_of :name }
  10.     it { is_expected.to validate_numericality_of :price }
  11.   end
  12.  
  13.   describe 'ActiveRecord associations' do
  14.     it { is_expected.to have_many :line_items }
  15.     it { is_expected.to belong_to :category }
  16.   end
  17.  
  18.   describe "ensure_not_referenced_by_any_line_item" do
  19.     context "item has no line items" do
  20.       it "returns true" do
  21.         expect(product.ensure_not_referenced_by_any_line_item).to eq true
  22.       end
  23.     end
  24.  
  25.     context "item has line items" do
  26.       it "returns false" do
  27.         LineItem.create!(product_id: product.id, cart_id: cart.id, quantity: 1)
  28.         expect(product.ensure_not_referenced_by_any_line_item).to eq false
  29.       end
  30.     end
  31.   end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement