From 851fefb20261d5b39dc872f497e084c29c63d3b6 Mon Sep 17 00:00:00 2001 From: anas599 Date: Fri, 26 May 2023 02:39:31 +0300 Subject: [PATCH] fix tests by replacing string Gram with gram(s) --- app/models/food.rb | 3 +-- spec/models/food_spec.rb | 19 ++++++++++++------- spec/models/public_resipe_spec.rb | 2 +- spec/models/user_spec.rb | 3 ++- test/system/foods_spec.rb | 7 ++++--- test/system/public_resipe_spec.rb | 5 +++-- test/system/recipe_spec.rb | 5 +++-- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/models/food.rb b/app/models/food.rb index 1678ba2..55e3d57 100644 --- a/app/models/food.rb +++ b/app/models/food.rb @@ -1,7 +1,6 @@ class Food < ApplicationRecord belongs_to :user validates :name, presence: true - validates :measure_unit, presence: true, inclusion: { in: %w[Gram Pound Unit] } - validates :price, presence: true, numericality: { only_integer: true } + validates :measure_unit, presence: true, inclusion: { in: %w[gram(s) pound(s) unit(s)] } validates :quantity, presence: true, numericality: { only_integer: true } end diff --git a/spec/models/food_spec.rb b/spec/models/food_spec.rb index 8a3b702..e904c33 100644 --- a/spec/models/food_spec.rb +++ b/spec/models/food_spec.rb @@ -8,10 +8,14 @@ created_at: '2023-05-22 16:34:29.347120000 +0000', updated_at: '2023-05-22 16:34:29.347120000 +0000', email: 'rails@railsmail.com', - password: '111111') + password: '111111', + password_confirmation: '111111') + end + let(:f1) { Food.create(name: 'Burger', measure_unit: 'gram(s)', price: 2, quantity: 2, user_id: u1.id) } + before(:each) do + u1.save + f1.save end - let(:f1) { Food.new(name: 'Burger', measure_unit: 'Gram', price: 2, quantity: 2, user_id: u1.id) } - it 'should have the correct name' do expect(f1.name).to eq('Burger') end @@ -20,7 +24,7 @@ end it 'should have the correct measure unit' do - expect(f1.measure_unit).to eq('Gram') + expect(f1.measure_unit).to eq('gram(s)') end it 'should have the correct price' do @@ -45,14 +49,15 @@ created_at: '2023-05-22 16:34:29.347120000 +0000', updated_at: '2023-05-22 16:34:29.347120000 +0000', email: 'rails2@railsmail.com', - password: '111111') + password: '111111', + password_confirmation: '111111') end - let(:f1) { Food.new(name: 'Burger', measure_unit: 'Gram', price: 2, quantity: 2, user_id: u2.id) } + let(:f1) { Food.new(name: 'Burger', measure_unit: 'gram(s)', price: 2, quantity: 2, user_id: u2.id) } it 'should have name of food' do expect(f1.name).to eq('Burger') end it 'should have measute unit of food' do - expect(f1.measure_unit).to eq('Gram') + expect(f1.measure_unit).to eq('gram(s)') end it 'should have price of food' do expect(f1.price).to eq(2) diff --git a/spec/models/public_resipe_spec.rb b/spec/models/public_resipe_spec.rb index 36e4632..c4a71a3 100644 --- a/spec/models/public_resipe_spec.rb +++ b/spec/models/public_resipe_spec.rb @@ -10,7 +10,7 @@ email: 'rails@railsmail.com', password: '111111') end - let(:f1) { Food.new(name: 'Burger', measure_unit: 'Gram', price: 2, quantity: 2, user_id: u1.id) } + let(:f1) { Food.new(name: 'Burger', measure_unit: 'gram(s)', price: 2, quantity: 2, user_id: u1.id) } let(:r1) do Recipe.create(id: 12, name: 'BBQ Burger', diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 49abeee..3ddd3f4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -8,7 +8,8 @@ created_at: '2023-05-22 16:34:29.347120000 +0000', updated_at: '2023-05-22 16:34:29.347120000 +0000', email: 'rails@railsmail.com', - password: '111111') + password: '111111', + password_confirmation: '111111') end it 'should have the correct name' do diff --git a/test/system/foods_spec.rb b/test/system/foods_spec.rb index 9ab2a66..45c7424 100644 --- a/test/system/foods_spec.rb +++ b/test/system/foods_spec.rb @@ -8,9 +8,10 @@ created_at: '2023-05-22 16:34:29.347120000 +0000', updated_at: '2023-05-22 16:34:29.347120000 +0000', email: 'rails@railsmail.com', - password: '111111') + password: '111111', + password_confirmation: '111111') end - let(:f1) { Food.new(name: 'Burger', measure_unit: 'Gram', price: 2, quantity: 2, user_id: u1.id) } + let(:f1) { Food.new(name: 'Burger', measure_unit: 'gram(s)', price: 2, quantity: 2, user_id: u1.id) } let(:r1) do Recipe.create(id: 1, name: 'BBQ Burger', @@ -45,7 +46,7 @@ expect(page).to have_content('Burger') expect(page).to have_content('Price: 2') expect(page).to have_content('Quantity: 2') - expect(page).to have_content('Measure unit: Gram') + expect(page).to have_content('Measure unit: gram(s)') end end end diff --git a/test/system/public_resipe_spec.rb b/test/system/public_resipe_spec.rb index 27cf167..1d07bd9 100644 --- a/test/system/public_resipe_spec.rb +++ b/test/system/public_resipe_spec.rb @@ -8,10 +8,11 @@ created_at: '2023-05-22 16:34:29.347120000 +0000', updated_at: '2023-05-22 16:34:29.347120000 +0000', email: 'rails@railsmail.com', - password: '111111') + password: '111111', + password_confirmation: '111111') end let(:f1) do - Food.new(name: 'Burger', measure_unit: 'Gram', price: 2, quantity: 2, user_id: u1.id) + Food.new(name: 'Burger', measure_unit: 'gram(s)', price: 2, quantity: 2, user_id: u1.id) end let(:r1) do Recipe.create(id: 12, diff --git a/test/system/recipe_spec.rb b/test/system/recipe_spec.rb index ab993ee..2bc7f38 100644 --- a/test/system/recipe_spec.rb +++ b/test/system/recipe_spec.rb @@ -8,9 +8,10 @@ created_at: '2023-05-22 16:34:29.347120000 +0000', updated_at: '2023-05-22 16:34:29.347120000 +0000', email: 'rails@railsmail.com', - password: '111111') + password: '111111', + password_confirmation: '111111') end - let(:f1) { Food.new(name: 'Burger', measure_unit: 'Gram', price: 2, quantity: 2, user_id: u1.id) } + let(:f1) { Food.new(name: 'Burger', measure_unit: 'gram(s)', price: 2, quantity: 2, user_id: u1.id) } before(:each) do f1.save end