Skip to content

Commit

Permalink
fix tests by replacing string Gram with gram(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
anas599 committed May 25, 2023
1 parent 28d238a commit 851fefb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
3 changes: 1 addition & 2 deletions app/models/food.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 12 additions & 7 deletions spec/models/food_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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
Expand All @@ -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
Expand All @@ -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: '[email protected]',
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)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/public_resipe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
email: '[email protected]',
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',
Expand Down
3 changes: 2 additions & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
password: '111111')
password: '111111',
password_confirmation: '111111')
end

it 'should have the correct name' do
Expand Down
7 changes: 4 additions & 3 deletions test/system/foods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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',
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions test/system/public_resipe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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,
Expand Down
5 changes: 3 additions & 2 deletions test/system/recipe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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
Expand Down

0 comments on commit 851fefb

Please sign in to comment.