Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foodunit tests #29

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading