Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloBona committed Oct 10, 2023
1 parent b49ea5a commit e99537a
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 51 deletions.
9 changes: 3 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ gem 'devise'
gem 'bullet'
gem 'rails', '~> 7.0.8'
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem 'sprockets-rails'
gem 'faker'
gem 'sprockets-rails'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
gem 'shoulda-matchers'


# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '~> 5.0'

Expand All @@ -28,8 +27,8 @@ gem 'importmap-rails'
gem 'turbo-rails'

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem 'stimulus-rails'
gem 'factory_bot_rails'
gem 'stimulus-rails'

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem 'jbuilder'
Expand Down Expand Up @@ -58,6 +57,7 @@ gem 'rspec'
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'rspec-rails', '~> 6.0.0'
end

group :development do
Expand All @@ -77,6 +77,3 @@ group :test do
gem 'selenium-webdriver'
end
# Run against this stable release
group :development, :test do
gem 'rspec-rails', '~> 6.0.0'
end
2 changes: 0 additions & 2 deletions app/controllers/foods_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ def index
session[:sort_direction] = order_direction
@foods = @user.foods.order("LOWER(name) #{order_direction}")
end



def show; end

Expand Down
8 changes: 2 additions & 6 deletions app/models/food.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ class Food < ApplicationRecord
has_many :recipes, through: :recipe_foods

validates :name, presence: true
validates :price, presence: true
validates :quantity, presence: true
validates :price, presence: true
validates :quantity, presence: true
validates :measurement_unit, presence: true


private

end
15 changes: 6 additions & 9 deletions spec/controllers/foods_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
get :index
expect(response).to be_successful
end


end

describe 'GET #show' do
it 'returns a successful response' do
food = create(:food, user: user)
food = create(:food, user:)
get :show, params: { id: food.id }
expect(response).to be_successful
end
Expand All @@ -33,20 +31,19 @@

describe 'POST #create' do
it 'creates a new food with valid params' do
expect {
expect do
post :create, params: { food: attributes_for(:food) }
}.to change(Food, :count).by(1)
end.to change(Food, :count).by(1)
expect(response).to redirect_to(foods_path)
end

end

describe 'DELETE #destroy' do
it 'destroys the food' do
food = create(:food, user: user)
expect {
food = create(:food, user:)
expect do
delete :destroy, params: { id: food.id }
}.to change(Food, :count).by(-1)
end.to change(Food, :count).by(-1)
expect(response).to redirect_to(foods_path)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
password_confirmation { 'password' }
name { Faker::Name.name }
end
end
end
9 changes: 3 additions & 6 deletions spec/models/food_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

RSpec.describe Food, type: :model do
let(:user) { TestConfiguration.create_example_user }
# En tu prueba
let(:food) { create(:food) } # Crea una instancia de Food con precios y cantidades predeterminados
let(:food_with_custom_values) { create(:food_with_price_and_quantity, price: 5, quantity: 10) } # Crea una instancia de Food con precios y cantidades específicos

let(:food) { create(:food) }
let(:food_with_custom_values) { create(:food_with_price_and_quantity, price: 5, quantity: 10) }
describe 'Associations' do
it { should have_many(:recipe_foods).dependent(:destroy) }
it { should have_many(:recipes).through(:recipe_foods) }
Expand All @@ -16,6 +14,5 @@
it { should validate_presence_of(:measurement_unit) }
it { should validate_presence_of(:price) }
it { should validate_presence_of(:quantity) }
end

end
end
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
it 'has password' do
expect(user.password).to be_present
end
end
end
21 changes: 9 additions & 12 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,32 @@
end
end
class TestConfiguration
@@example_user = nil
@example_user = nil

def self.example_user
@@example_user ||= create_example_user
@example_user ||= create_example_user
end

def self.create_example_user
# Crea el usuario de ejemplo y devuélvelo
user = User.create!(
name: "Ejemplo Usuario",
email: "[email protected]",
password: "password123",
name: 'Ejemplo Usuario',
email: '[email protected]',
password: 'password123',
confirmed_at: Time.now
)
# Crea las comidas "Banana" y "Apple" asociadas al usuario

create_food(user, 'Banana')
create_food(user, 'Apple')
user
end

private

def self.create_food(user, name)
Food.create!(
name: name,
measurement_unit: "unit",
name:,
measurement_unit: 'unit',
price: 1,
quantity: 1,
user: user
user:
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/controller_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def login_user
sign_in user
end
end
end
end
4 changes: 2 additions & 2 deletions spec/support/devise.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative './controller_auth'
require_relative 'controller_auth'

RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
# config.extend ControllerAuth, type: :controller
end
end
2 changes: 1 addition & 1 deletion spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
end
8 changes: 4 additions & 4 deletions spec/views/food_view_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'rails_helper'

RSpec.describe "foods/index", type: :view do
RSpec.describe 'foods/index', type: :view do
let(:user) { TestConfiguration.create_example_user }

before do
assign(:user, user)
assign(:foods, [Food.new(name: "Pizza", measurement_unit: "Slice", price: 10, quantity: 2)])
assign(:foods, [Food.new(name: 'Pizza', measurement_unit: 'Slice', price: 10, quantity: 2)])
render
end

Expand All @@ -14,7 +14,7 @@
expect(rendered).to match(/Food List/)
end

it "renders a table with food details" do
it 'renders a table with food details' do
expect(rendered).to have_selector('table')
expect(rendered).to have_selector('th.food-name', text: 'Name')
expect(rendered).to have_selector('th', text: 'Measurement Unit')
Expand All @@ -27,7 +27,7 @@
expect(rendered).to have_selector('td', text: '2')
end

it "renders Add New Food button" do
it 'renders Add New Food button' do
expect(rendered).to have_selector('a.btn.btn-primary', text: 'Add New Food')
end
end

0 comments on commit e99537a

Please sign in to comment.