Skip to content

Commit

Permalink
Merge pull request #29 from RileyManda/food-unit-testing
Browse files Browse the repository at this point in the history
Foodunit tests
  • Loading branch information
yin-ka authored Oct 18, 2023
2 parents 653ae14 + 758e75f commit 0c92e03
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions spec/models/food_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'rails_helper'

RSpec.describe Food, type: :model do
let(:food) { Food.new(name: 'Apple', measurement_unit: 'lb') }

it 'validates the presence of the name' do
food.name = nil
expect(food).to_not be_valid
end

it 'validates the presence of the measurement unit' do
food.measurement_unit = nil
expect(food).to_not be_valid
end

it 'combines the name and measurement unit' do
expect(food.name_with_measurement_unit).to eq 'Apple (lb)'
end

it 'validates the minimum name length of 2 characters' do
food.name = 'Y'
expect(food).to_not be_valid
end

it 'validates the maximum name length of 50 characters' do
food.name = 'a' * 51
expect(food).to_not be_valid
end

it 'validates the presence of a price' do
food.price = nil
expect(food).to_not be_valid
end

it 'validates a non-negative price' do
food.price = -1
expect(food).to_not be_valid
end

it 'validates the presence of a quantity' do
food.quantity = nil
expect(food).to_not be_valid
end

it 'validates a non-negative quantity' do
food.quantity = -1
expect(food).to_not be_valid
end
end

0 comments on commit 0c92e03

Please sign in to comment.