Created
November 4, 2017 02:09
-
-
Save mattmartini/5504c9ed41369378bd96b410b9f86a43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == 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