Skip to content

Instantly share code, notes, and snippets.

@mattmartini
Created November 4, 2017 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmartini/5504c9ed41369378bd96b410b9f86a43 to your computer and use it in GitHub Desktop.
Save mattmartini/5504c9ed41369378bd96b410b9f86a43 to your computer and use it in GitHub Desktop.
# == Schema Information
#
# Table name: dishes
#
# id :integer not null, primary key
# name :string
# category_id :integer
# description :string
# small_size_price :decimal(, )
# large_size_price :decimal(, )
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_dishes_on_category_id (category_id)
#
require 'rails_helper'
RSpec.describe Dish, type: :model do
describe "Model" do
it { should be_a ActiveRecord::Base }
it { should belong_to(:category) }
it { should validate_presence_of(:name) }
it "generic factory should be valid" do
dish = FactoryGirl.create(:dish)
expect(dish).to be_valid
end
context "model validations" do
it "is invalid without a name" do
dishNoName = FactoryGirl.build(:dish, name: nil)
expect(dishNoName).to_not be_valid
end
it "is invalid with an unknown category" do
dishNoCategtory = FactoryGirl.build(:dish, category_id: nil)
expect(dishNoCategtory).to_not be_valid
end
it "is valid with a large_size_price " do
dish = FactoryGirl.build(:dish)
expect(dish).to be_valid
end
it "is invalid without a large_size_price " do
dish = FactoryGirl.build(:dish, large_size_price: nil)
expect(dish).to_not be_valid
end
context "when multi_size is true" do
it "is valid with a small_size_price " do
dishMStrue = FactoryGirl.build(:dish_mstc, small_size_price: 9.99)
expect(dishMStrue).to be_valid
end
it "is invalid without a small_size_price " do
dishMStrue = FactoryGirl.build(:dish_mstc, small_size_price: nil)
expect(dishMStrue).to_not be_valid
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment