├── log └── .keep ├── storage └── .keep ├── tmp ├── .keep ├── pids │ └── .keep └── storage │ └── .keep ├── vendor ├── .keep └── javascript │ └── .keep ├── lib ├── assets │ └── .keep └── tasks │ └── .keep ├── public ├── favicon.ico ├── apple-touch-icon.png ├── apple-touch-icon-precomposed.png ├── robots.txt ├── 500.html ├── 422.html └── 404.html ├── test ├── helpers │ └── .keep ├── mailers │ └── .keep ├── models │ └── .keep ├── system │ └── .keep ├── controllers │ └── .keep ├── integration │ └── .keep ├── fixtures │ └── files │ │ └── .keep ├── application_system_test_case.rb ├── channels │ └── application_cable │ │ └── connection_test.rb └── test_helper.rb ├── .ruby-version ├── app ├── assets │ ├── images │ │ └── .keep │ ├── config │ │ └── manifest.js │ └── stylesheets │ │ └── application.css ├── models │ ├── concerns │ │ └── .keep │ ├── application_record.rb │ ├── recipe_food.rb │ ├── user.rb │ ├── food.rb │ └── recipe.rb ├── controllers │ ├── concerns │ │ └── .keep │ ├── user_controller.rb │ ├── public_recipes_controller.rb │ ├── application_controller.rb │ ├── shopping_list_controller.rb │ ├── foods_controller.rb │ ├── recipes_controller.rb │ └── recipe_foods_controller.rb ├── views │ ├── layouts │ │ ├── mailer.text.erb │ │ ├── mailer.html.erb │ │ └── application.html.erb │ ├── devise │ │ ├── mailer │ │ │ ├── password_change.html.erb │ │ │ ├── confirmation_instructions.html.erb │ │ │ ├── unlock_instructions.html.erb │ │ │ ├── email_changed.html.erb │ │ │ └── reset_password_instructions.html.erb │ │ ├── unlocks │ │ │ └── new.html.erb │ │ ├── shared │ │ │ ├── _error_messages.html.erb │ │ │ └── _links.html.erb │ │ ├── confirmations │ │ │ └── new.html.erb │ │ ├── passwords │ │ │ ├── new.html.erb │ │ │ └── edit.html.erb │ │ ├── sessions │ │ │ └── new.html.erb │ │ └── registrations │ │ │ ├── edit.html.erb │ │ │ └── new.html.erb │ ├── recipes │ │ ├── _button_add_ingredient.erb │ │ ├── _button_public.erb │ │ ├── show.html.erb │ │ ├── index.html.erb │ │ └── new.html.erb │ ├── recipe_foods │ │ ├── edit.html.erb │ │ ├── new.html.erb │ │ └── _recipe_foods_detail.erb │ ├── shopping_list │ │ └── index.html.erb │ ├── public_recipes │ │ └── index.html.erb │ ├── foods │ │ ├── index.html.erb │ │ └── new.html.erb │ └── menu │ │ └── _nav_bar.html.erb ├── helpers │ └── application_helper.rb ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── mailers │ └── application_mailer.rb ├── javascript │ ├── application.js │ └── controllers │ │ ├── hello_controller.js │ │ ├── application.js │ │ └── index.js └── jobs │ └── application_job.rb ├── .rspec ├── bin ├── rake ├── importmap ├── rails ├── setup └── bundle ├── config ├── environment.rb ├── boot.rb ├── cable.yml ├── routes.rb ├── importmap.rb ├── initializers │ ├── filter_parameter_logging.rb │ ├── permissions_policy.rb │ ├── assets.rb │ ├── inflections.rb │ ├── content_security_policy.rb │ └── devise.rb ├── credentials.yml.enc ├── application.rb ├── locales │ ├── en.yml │ └── devise.en.yml ├── storage.yml ├── puma.rb ├── environments │ ├── test.rb │ ├── development.rb │ └── production.rb └── database.yml ├── config.ru ├── package.json ├── db ├── migrate │ ├── 20231009211328_create_users.rb │ ├── 20231009215835_create_recipe_foods.rb │ ├── 20231009215717_create_foods.rb │ ├── 20231009215538_create_recipes.rb │ └── 20231010121114_add_devise_to_users.rb ├── seeds.rb └── schema.rb ├── Rakefile ├── .gitattributes ├── spec ├── features │ ├── food_new_spec.rb │ ├── recipe_new_spec.rb │ ├── recipe_food_new_spec.rb │ ├── shopping_list_spec.rb │ ├── recipe_food_edit_spec.rb │ ├── public_recipes_index_spec.rb │ ├── food_index_spec.rb │ ├── recipe_index_spec.rb │ └── recipe_show_spec.rb ├── food_spec.rb ├── recipe_food_spec.rb ├── recipe_spec.rb ├── rails_helper.rb └── spec_helper.rb ├── .gitignore ├── .stylelintrc.json ├── .rubocop.yml ├── .github └── workflows │ └── linters.yml ├── Gemfile ├── README.md └── Gemfile.lock /log/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/helpers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/system/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/pids/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tmp/storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.2.2 2 | -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/javascript/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/importmap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative "../config/application" 4 | require "importmap/commands" 5 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /app/views/devise/mailer/password_change.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

We're contacting you to notify you that your password has been changed.

4 | -------------------------------------------------------------------------------- /app/controllers/user_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def index; end 5 | 6 | def show; end 7 | end 8 | -------------------------------------------------------------------------------- /app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../stylesheets .css 3 | //= link_tree ../../javascript .js 4 | //= link_tree ../../../vendor/javascript .js 5 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /app/javascript/application.js: -------------------------------------------------------------------------------- 1 | // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails 2 | import "@hotwired/turbo-rails" 3 | import "controllers" 4 | -------------------------------------------------------------------------------- /app/views/recipes/_button_add_ingredient.erb: -------------------------------------------------------------------------------- 1 | <%= link_to new_recipe_food_path(recipe_id: @recipe.id), 2 | class:"btn btn-primary" do %> 3 |

Add a new ingredient

4 | <% end %> -------------------------------------------------------------------------------- /test/application_system_test_case.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase 4 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400] 5 | end 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "stylelint": "^13.13.1", 4 | "stylelint-config-standard": "^21.0.0", 5 | "stylelint-csstree-validator": "^1.9.0", 6 | "stylelint-scss": "^3.21.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /app/javascript/controllers/hello_controller.js: -------------------------------------------------------------------------------- 1 | import { Controller } from "@hotwired/stimulus" 2 | 3 | export default class extends Controller { 4 | connect() { 5 | this.element.textContent = "Hello World!" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /app/controllers/public_recipes_controller.rb: -------------------------------------------------------------------------------- 1 | class PublicRecipesController < ApplicationController 2 | def index 3 | @recipes = Recipe.where(public: true).includes(:user, :recipe_foods, recipe_foods: [:food]) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /db/migrate/20231009211328_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :users do |t| 4 | t.string :name, null: false 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/models/recipe_food.rb: -------------------------------------------------------------------------------- 1 | class RecipeFood < ApplicationRecord 2 | belongs_to :recipe, foreign_key: :recipe_id 3 | belongs_to :food, foreign_key: :food_id 4 | 5 | validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 } 6 | end 7 | -------------------------------------------------------------------------------- /app/views/devise/mailer/confirmation_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Welcome <%= @email %>!

2 | 3 |

You can confirm your account email through the link below:

4 | 5 |

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files. 2 | 3 | # Mark the database schema as having been generated. 4 | db/schema.rb linguist-generated 5 | 6 | # Mark any vendored files as having been vendored. 7 | vendor/* linguist-vendored 8 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: redis 3 | url: redis://localhost:6379/1 4 | 5 | test: 6 | adapter: test 7 | 8 | production: 9 | adapter: redis 10 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 11 | channel_prefix: Recipe_App_production 12 | -------------------------------------------------------------------------------- /app/javascript/controllers/application.js: -------------------------------------------------------------------------------- 1 | import { Application } from "@hotwired/stimulus" 2 | 3 | const application = Application.start() 4 | 5 | // Configure Stimulus development experience 6 | application.debug = false 7 | window.Stimulus = application 8 | 9 | export { application } 10 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | devise_for :users 3 | 4 | root "foods#index" 5 | 6 | resources :recipes do 7 | resources :shopping_list, only: %i[index] 8 | end 9 | resources :recipe_foods 10 | resources :foods 11 | resources :public_recipes, only: %i[index] 12 | end 13 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/views/devise/mailer/unlock_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

4 | 5 |

Click the link below to unlock your account:

6 | 7 |

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

8 | -------------------------------------------------------------------------------- /test/channels/application_cable/connection_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase 4 | # test "connects with cookies" do 5 | # cookies.signed[:user_id] = 42 6 | # 7 | # connect 8 | # 9 | # assert_equal connection.user_id, "42" 10 | # end 11 | end 12 | -------------------------------------------------------------------------------- /app/views/devise/mailer/email_changed.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @email %>!

2 | 3 | <% if @resource.try(:unconfirmed_email?) %> 4 |

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

5 | <% else %> 6 |

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

7 | <% end %> 8 | -------------------------------------------------------------------------------- /config/importmap.rb: -------------------------------------------------------------------------------- 1 | # Pin npm packages by running ./bin/importmap 2 | 3 | pin "application", preload: true 4 | pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true 5 | pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true 6 | pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true 7 | pin_all_from "app/javascript/controllers", under: "controllers" 8 | -------------------------------------------------------------------------------- /db/migrate/20231009215835_create_recipe_foods.rb: -------------------------------------------------------------------------------- 1 | class CreateRecipeFoods < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :recipe_foods do |t| 4 | t.integer :quantity 5 | t.references :recipe, null: false, foreign_key: true 6 | t.references :food, null: false, foreign_key: true 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20231009215717_create_foods.rb: -------------------------------------------------------------------------------- 1 | class CreateFoods < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :foods do |t| 4 | t.string :name 5 | t.string :measurement_unit 6 | t.decimal :price 7 | t.integer :quantity 8 | t.references :user, null: false, foreign_key: true 9 | 10 | t.timestamps 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) 7 | # Character.create(name: "Luke", movie: movies.first) 8 | -------------------------------------------------------------------------------- /app/views/recipes/_button_public.erb: -------------------------------------------------------------------------------- 1 |
2 | <% if @recipe.public %> 3 | <%= button_to 'Make Private', recipe_path(@recipe.id), method: :patch, params: { recipe: { public: false } }, class: 'btn btn-danger' %> 4 | <% else %> 5 | <%= button_to 'Make Public', recipe_path(@recipe.id), method: :patch, params: { recipe: { public: true } }, class: 'btn btn-primary' %> 6 | <% end %> 7 |
-------------------------------------------------------------------------------- /db/migrate/20231009215538_create_recipes.rb: -------------------------------------------------------------------------------- 1 | class CreateRecipes < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :recipes do |t| 4 | t.string :name 5 | t.integer :preparation_time 6 | t.integer :cooking_time 7 | t.text :description 8 | t.boolean :public 9 | t.references :user, null: false, foreign_key: true 10 | 11 | t.timestamps 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | # Include default devise modules. Others available are: 3 | # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 | devise :database_authenticatable, :registerable, 5 | :recoverable, :rememberable, :validatable 6 | has_many :foods, foreign_key: :user_id 7 | has_many :recipes, foreign_key: :user_id 8 | 9 | validates :name, presence: true 10 | end 11 | -------------------------------------------------------------------------------- /app/models/food.rb: -------------------------------------------------------------------------------- 1 | class Food < ApplicationRecord 2 | belongs_to :user, foreign_key: :user_id 3 | has_many :recipe_foods, foreign_key: :food_id 4 | has_many :recipes, through: :recipe_foods, dependent: :destroy 5 | 6 | validates :name, :measurement_unit, :price, :quantity, presence: true 7 | validates :price, numericality: { greater_than_or_equal_to: 0 } 8 | validates :quantity, numericality: { greater_than_or_equal_to: 0 } 9 | end 10 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require_relative '../config/environment' 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Run tests in parallel with specified workers 7 | parallelize(workers: :number_of_processors) 8 | 9 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 10 | fixtures :all 11 | 12 | # Add more helper methods to be used by all tests here... 13 | end 14 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /app/views/devise/mailer/reset_password_instructions.html.erb: -------------------------------------------------------------------------------- 1 |

Hello <%= @resource.email %>!

2 | 3 |

Someone has requested a link to change your password. You can do this through the link below.

4 | 5 |

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

6 | 7 |

If you didn't request this, please ignore this email.

8 |

Your password won't change until you access the link above and create a new one.

9 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | wjnvgMSAaA+tK6EwtrHwhy1q1y60NiJs1VpID1sl+HW3fAxXu86Jie7ap6oiaTP1HSxjxkVM5WF+UXOJVgCWbptfTZaLIeIos2PCDrM9PArxcS/XJuuEIjB16yZZ9zhdSpewsYntdnS+NmTqS6yIee5Q0bGRPMUdNQG3jA1gT5dbNV8uNOAIqOL9sN65utcT4/2qAO3H3OzyQ6/GdMnvkNmDTQA+u6QS1R008MMndHNGR+QyacZz+eUNLPYMOv57bk66oC5mwKls9J6lmlHjdPsL8NiAjKEENgBtmrhCJuf5sdEf6lwSD+dkrSfdOdk+wPIVx6WG4O8huIYKMqhb4ypWvpIDpGC7rO/JxHeTQzybuEv2+cW5BftXR9l+IgdQl8lCbCYbY9QgyGWpTLSIV6IvaoZblfcPR6lg--k55R5fkkuERk4QXq--wGkhHT0C5h2lJBtNzuoLEw== -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery with: :exception 3 | before_action :configure_permitted_parameters, if: :devise_controller? 4 | 5 | def configure_permitted_parameters 6 | devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) 7 | end 8 | 9 | def configure_devise_parameters 10 | devise_parameter_sanitizer.permit(:sign_up) do |user| 11 | user.permit(:name, :email, :password, :password_confirmation) 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /app/controllers/shopping_list_controller.rb: -------------------------------------------------------------------------------- 1 | class ShoppingListController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def index 5 | @recipe = Recipe.find(params[:recipe_id]) 6 | @recipe_foods = @recipe.recipe_foods.includes(:food) 7 | @food = @recipe.foods 8 | @total_price = sum(@recipe_foods) 9 | end 10 | 11 | private 12 | 13 | def sum(array) 14 | sum = 0 15 | array.each do |number| 16 | sum += number.quantity * number.food.price 17 | end 18 | 19 | sum.round(2) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = "1.0" 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in the app/assets 11 | # folder are already added. 12 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 13 | -------------------------------------------------------------------------------- /app/views/devise/unlocks/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend unlock instructions

2 | 3 | <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 9 |
10 | 11 |
12 | <%= f.submit "Resend unlock instructions" %> 13 |
14 | <% end %> 15 | 16 | <%= render "devise/shared/links" %> 17 | -------------------------------------------------------------------------------- /app/views/devise/shared/_error_messages.html.erb: -------------------------------------------------------------------------------- 1 | <% if resource.errors.any? %> 2 |
3 |

4 | <%= I18n.t("errors.messages.not_saved", 5 | count: resource.errors.count, 6 | resource: resource.class.model_name.human.downcase) 7 | %> 8 |

9 | 14 |
15 | <% end %> 16 | -------------------------------------------------------------------------------- /app/models/recipe.rb: -------------------------------------------------------------------------------- 1 | class Recipe < ApplicationRecord 2 | belongs_to :user, foreign_key: 'user_id' 3 | has_many :recipe_foods, foreign_key: 'recipe_id', dependent: :destroy 4 | has_many :foods, through: :recipe_foods, foreign_key: 'food_id' 5 | 6 | validates :name, :preparation_time, :cooking_time, :description, presence: true 7 | validates :public, inclusion: { in: [true, false] } 8 | 9 | def total_food_items 10 | recipe_foods.length 11 | end 12 | 13 | def total_price 14 | recipe_foods.reduce(0) { |sum, recipe_food| sum + (recipe_food.quantity * recipe_food.food.price) } 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/features/food_new_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Add new Food form', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'User name', email: 'email@test.com', password: '123456') 6 | 7 | sign_in @user 8 | visit new_food_path 9 | end 10 | 11 | scenario 'User shoul create a new food' do 12 | fill_in 'Name', with: 'Food name' 13 | fill_in 'Quantity', with: '10' 14 | fill_in 'Measurement unit', with: 'kg' 15 | fill_in 'Price', with: '10.0' 16 | click_button 'Create Food' 17 | expect(page).to have_content('Foods List') 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/javascript/controllers/index.js: -------------------------------------------------------------------------------- 1 | // Import and register all your controllers from the importmap under controllers/* 2 | 3 | import { application } from "controllers/application" 4 | 5 | // Eager load all controllers defined in the import map under controllers/**/*_controller 6 | import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" 7 | eagerLoadControllersFrom("controllers", application) 8 | 9 | // Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) 10 | // import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" 11 | // lazyLoadControllersFrom("controllers", application) 12 | -------------------------------------------------------------------------------- /spec/features/recipe_new_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'New Recipe page', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'User name', email: 'email@test.com', password: 'password123') 6 | 7 | sign_in @user 8 | visit new_recipe_path 9 | end 10 | 11 | scenario 'User creates a new recipe' do 12 | fill_in 'Name', with: 'My new recipe' 13 | fill_in 'Description', with: 'My new recipe description' 14 | fill_in 'Preparation time', with: '10' 15 | fill_in 'Cooking time', with: '20' 16 | click_button 'Create Recipe' 17 | expect(page).to have_content('Recipe created successfully') 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/views/devise/confirmations/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend confirmation instructions

2 | 3 | <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> 9 |
10 | 11 |
12 | <%= f.submit "Resend confirmation instructions" %> 13 |
14 | <% end %> 15 | 16 | <%= render "devise/shared/links" %> 17 | -------------------------------------------------------------------------------- /app/views/recipe_foods/edit.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Add ingredients

3 | 4 | <%= form_with model: @recipe_food, method: :patch do |form| %> 5 |
6 | <%= form.label :food_id %>
7 | <%= form.select :food_id, options_from_collection_for_select(@foods, 'id', 'name'), {}, { class: 'form-control' } %> 8 |
9 | 10 | <%= form.hidden_field :recipe_id, value: @recipe.id %> 11 | 12 |
13 | <%= form.label :quantity %>
14 | <%= form.number_field :quantity, class: 'form-control' %> 15 |
16 | 17 | <%= form.submit 'Modify', class: 'btn btn-primary' %> 18 | <% end %> 19 |
20 | -------------------------------------------------------------------------------- /app/views/recipe_foods/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Add ingredients

3 | 4 | <%= form_with model: @recipe_food, method: :post do |form| %> 5 |
6 | <%= form.label :food_id %>
7 | <%= form.select :food_id, options_from_collection_for_select(@foods, 'id', 'name'), {}, { class: 'form-control' } %> 8 |
9 | 10 | <%= form.hidden_field :recipe_id, value: @recipe.id %> 11 | 12 |
13 | <%= form.label :quantity %>
14 | <%= form.number_field :quantity, class: 'form-control' %> 15 |
16 | 17 | <%= form.submit 'Add Ingredient', class: 'btn btn-primary' %> 18 | <% end %> 19 |
20 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's 6 | * vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module RecipeApp 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 7.0 13 | 14 | # Configuration for the application, engines, and railties goes here. 15 | # 16 | # These settings can be overridden in specific environments using the files 17 | # in config/environments, which are processed later. 18 | # 19 | # config.time_zone = "Central Time (US & Canada)" 20 | # config.eager_load_paths << Rails.root.join("extras") 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all logfiles and tempfiles. 11 | /log/* 12 | /tmp/* 13 | !/log/.keep 14 | !/tmp/.keep 15 | 16 | # Ignore pidfiles, but keep the directory. 17 | /tmp/pids/* 18 | !/tmp/pids/ 19 | !/tmp/pids/.keep 20 | 21 | # Ignore uploaded files in development. 22 | /storage/* 23 | !/storage/.keep 24 | /tmp/storage/* 25 | !/tmp/storage/ 26 | !/tmp/storage/.keep 27 | 28 | /public/assets 29 | 30 | # Ignore master key for decrypting credentials and more. 31 | /config/master.key 32 | node_modules/ -------------------------------------------------------------------------------- /spec/features/recipe_food_new_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'New food for a especific recipe ', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'User name', email: 'email@test.com', password: 'password123') 6 | @recipe = Recipe.create(name: 'My new recipe', user: @user, preparation_time: 15, cooking_time: 15, 7 | description: 'description 1', public: true) 8 | @food = Food.create(name: 'Food name', user: @user, quantity: 1, measurement_unit: 'kg', price: 10.0) 9 | 10 | sign_in @user 11 | visit new_recipe_food_path(recipe_id: @recipe.id) 12 | end 13 | 14 | scenario 'User creates a new recipe' do 15 | fill_in 'Quantity', with: 12 16 | click_button 'Add Ingredient' 17 | expect(page).to have_content('Recipe food created successfully') 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /.stylelintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["stylelint-config-standard"], 3 | "plugins": ["stylelint-scss", "stylelint-csstree-validator"], 4 | "rules": { 5 | "at-rule-no-unknown": [ 6 | true, 7 | { 8 | "ignoreAtRules": [ 9 | "tailwind", 10 | "apply", 11 | "variants", 12 | "responsive", 13 | "screen" 14 | ] 15 | } 16 | ], 17 | "scss/at-rule-no-unknown": [ 18 | true, 19 | { 20 | "ignoreAtRules": [ 21 | "tailwind", 22 | "apply", 23 | "variants", 24 | "responsive", 25 | "screen" 26 | ] 27 | } 28 | ], 29 | "csstree/validator": true 30 | }, 31 | "ignoreFiles": ["build/**", "dist/**", "**/reset*.css", "**/bootstrap*.css"] 32 | } -------------------------------------------------------------------------------- /spec/features/shopping_list_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Visit shopping list page', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'User name', email: 'email@test.com', password: 'password123') 6 | @recipe = Recipe.create(name: 'My new recipe', user: @user, preparation_time: 15, cooking_time: 15, 7 | description: 'description 1', public: true) 8 | @food = Food.create(name: 'Food name', user: @user, quantity: 1, measurement_unit: 'kg', price: 10.0) 9 | @recipe_food = RecipeFood.create(recipe: @recipe, food: @food, quantity: 8) 10 | 11 | sign_in @user 12 | visit recipe_shopping_list_index_path(@recipe) 13 | end 14 | 15 | it 'Should render a list of foods' do 16 | expect(page).to have_content('Shopping List') 17 | expect(page).to have_content('Food name') 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/controllers/foods_controller.rb: -------------------------------------------------------------------------------- 1 | class FoodsController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def index 5 | @foods = Food.includes(:user).all 6 | @current_user = current_user 7 | end 8 | 9 | def new 10 | @food = Food.new 11 | end 12 | 13 | def create 14 | @food = current_user.foods.new(food_params) 15 | 16 | if @food.valid? && @food.save 17 | flash[:success] = 'Food has been added successfully' 18 | redirect_to foods_path 19 | else 20 | Rails.logger.error("Failed to create food: #{@food.errors.full_messages}") 21 | render :new 22 | end 23 | end 24 | 25 | def destroy 26 | @food = Food.find(params[:id]) 27 | @food.destroy 28 | redirect_to foods_path 29 | end 30 | 31 | private 32 | 33 | def food_params 34 | params.require(:food).permit(:name, :measurement_unit, :price, :quantity) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /app/views/devise/passwords/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Forgot your password?

3 | 4 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | 7 |
8 | <%= f.email_field :email, 9 | class: "form-control", 10 | placeholder: "Email", 11 | autofocus: true, 12 | autocomplete: "email", 13 | "aria-label": "email" %> 14 |
15 | 16 |
17 | <%= f.submit "Send me reset password instructions", class: "btn btn-primary btn-lg container mt-4" %> 18 |
19 | <% end %> 20 |
21 | <%= render "devise/shared/links" %> 22 |
23 | -------------------------------------------------------------------------------- /spec/features/recipe_food_edit_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Edit an ingredient of a especific recipe ', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'User name', email: 'email@test.com', password: 'password123') 6 | @recipe = Recipe.create(name: 'My new recipe', user: @user, preparation_time: 15, cooking_time: 15, 7 | description: 'description 1', public: true) 8 | @food = Food.create(name: 'Food name', user: @user, quantity: 1, measurement_unit: 'kg', price: 10.0) 9 | @recipe_food = RecipeFood.create(recipe: @recipe, food: @food, quantity: 8) 10 | 11 | sign_in @user 12 | visit edit_recipe_food_path(@recipe_food.id) 13 | end 14 | 15 | scenario 'User creates a new recipe' do 16 | fill_in 'Quantity', with: 6 17 | click_button 'Modify' 18 | expect(page).to have_content('Recipe food updated successfully') 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /spec/food_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | RSpec.describe Food, type: :model do 3 | before :each do 4 | @user = User.create(name: 'Nick Jhons', email: 'test@test.com', password: '123456') 5 | @recipe = Recipe.create(name: 'Pasta', user: @user, preparation_time: 15, cooking_time: 15, 6 | description: 'description 1', public: false) 7 | @food = Food.create(name: 'Tomato', measurement_unit: 'kg', price: 1.5, quantity: 10, user: @user) 8 | @recipe_food = RecipeFood.create(recipe: @recipe, food: @food, quantity: 2) 9 | end 10 | describe 'Validations' do 11 | it 'Should be valid with a quatity greater or equal than 0' do 12 | expect(@recipe_food).to be_valid 13 | end 14 | it 'Should be invalid if quantity is not a number greater or equal to 0' do 15 | recipe_food = RecipeFood.create(recipe: @recipe, food: @food, quantity: -2) 16 | expect(recipe_food).not_to be_valid 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/recipe_food_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | RSpec.describe RecipeFood, type: :model do 3 | before :each do 4 | @user = User.create(name: 'Nick Jhons', email: 'test@test.com', password: '123456') 5 | @recipe = Recipe.create(name: 'Pasta', user: @user, preparation_time: 15, cooking_time: 15, 6 | description: 'description 1', public: false) 7 | @food = Food.create(name: 'Tomato', measurement_unit: 'kg', price: 1.5, quantity: 10, user: @user) 8 | @recipe_food = RecipeFood.create(recipe: @recipe, food: @food, quantity: 2) 9 | end 10 | describe 'Validations' do 11 | it 'Should be valid with a quatity greater or equal than 0' do 12 | expect(@recipe_food).to be_valid 13 | end 14 | it 'Should be invalid if quantity is not a number greater or equal to 0' do 15 | recipe_food = RecipeFood.create(recipe: @recipe, food: @food, quantity: -2) 16 | expect(recipe_food).not_to be_valid 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # "true": "foo" 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /app/views/shopping_list/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Shopping List

4 | 5 |
6 |

Amount of food items to buy: <%= @recipe.recipe_foods.length %>

7 |

Total value of food needed: <%= @total_price %>

8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | <% @recipe.recipe_foods.each do |r| %> 20 | 21 | 22 | 23 | 24 | 25 | <% end %> 26 | 27 |
FoodQuantityPrice
<%= r.food.name %><%= r.quantity %><%= r.food.price * r.quantity %> $
28 | 29 |
-------------------------------------------------------------------------------- /app/views/recipes/show.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Recipe name: <%= @recipe.name.capitalize%>

3 |
4 |

Preparation time: <%= @recipe.preparation_time%> hours

5 |

Cooking time: <%= @recipe.cooking_time%> hours

6 |

Description: <%= @recipe.description%>

7 |
8 | 9 | <% if current_user == @recipe.user %> 10 | <%= render 'button_public' %> 11 | <% end %> 12 | 13 | <% if current_user == @recipe.user %> 14 |
15 | 16 | <%= link_to 'Generate shopping list', recipe_shopping_list_index_path(@recipe), class: 'btn btn-outline-dark mt-5 ' %> 17 | <%= render 'button_add_ingredient' %> 18 | 19 |
20 | <% end %> 21 | 22 |
23 |
24 |

Ingredients

25 | 26 | <%= render 'recipe_foods/recipe_foods_detail' %> 27 | 28 |
29 | <%= button_to "Back to recipes", recipes_path(@recipe), method: :get, 30 | class: 'btn btn-primary px-4 mx-1' %> 31 |
32 | -------------------------------------------------------------------------------- /spec/features/public_recipes_index_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Visit Public recipes index', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'User name', email: 'user@mail.com', password: 'password123') 6 | @recipe1 = Recipe.create(name: 'My new recipe', user: @user, preparation_time: 15, cooking_time: 15, description: 7 | 'description 1', public: true) 8 | @recipe2 = Recipe.create(name: 'My new recipe 2', user: @user, preparation_time: 15, cooking_time: 15, description: 9 | 'description 2', public: false) 10 | @recipe3 = Recipe.create(name: 'My new recipe 3', user: @user, preparation_time: 15, cooking_time: 15, description: 11 | 'description 3', public: true) 12 | 13 | sign_in @user 14 | end 15 | 16 | scenario 'User visits public recipes index' do 17 | visit public_recipes_path 18 | expect(page).to have_content('My new recipe') 19 | expect(page).to have_content('My new recipe 3') 20 | expect(page).not_to have_content('My new recipe 2') 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /app/views/recipes/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Recipes

3 | 4 | <%= link_to new_recipe_path(@recipe), 5 | class:"btn btn-primary left position-absolute top-0 end-0" do %> 6 |

Add a new Recipe

7 | <% end %> 8 | 9 | 31 |
32 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | RecipeApp 5 | 6 | 7 | 8 | <%= csrf_meta_tags %> 9 | <%= csp_meta_tag %> 10 | 11 | 12 | <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> 13 | <%= javascript_importmap_tags %> 14 | 15 | 16 | 17 |
18 | <%= render 'menu/nav_bar' %> 19 |
20 | 21 |

<%= notice %>

22 |

<%= alert %>

23 | <%= yield %> 24 | <%# Bootstrap5 JavaScript %> 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy. 4 | # See the Securing Rails Applications Guide for more information: 5 | # https://guides.rubyonrails.org/security.html#content-security-policy-header 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap and inline scripts 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src) 22 | # 23 | # # Report violations without enforcing the policy. 24 | # # config.content_security_policy_report_only = true 25 | # end 26 | -------------------------------------------------------------------------------- /app/views/devise/shared/_links.html.erb: -------------------------------------------------------------------------------- 1 | <%- if controller_name != 'sessions' %> 2 | <%= link_to "Log in", new_session_path(resource_name) %>
3 | <% end %> 4 | 5 | <%- if devise_mapping.registerable? && controller_name != 'registrations' %> 6 | <%= link_to "Sign up", new_registration_path(resource_name) %>
7 | <% end %> 8 | 9 | <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> 10 | <%= link_to "Forgot your password?", new_password_path(resource_name) %>
11 | <% end %> 12 | 13 | <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> 14 | <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
15 | <% end %> 16 | 17 | <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> 18 | <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
19 | <% end %> 20 | 21 | <%- if devise_mapping.omniauthable? %> 22 | <%- resource_class.omniauth_providers.each do |provider| %> 23 | <%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), data: { turbo: false } %>
24 | <% end %> 25 | <% end %> 26 | -------------------------------------------------------------------------------- /config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /app/views/recipes/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

3 | Add a new Recipe for current user (<%= @user.name %>) 4 |

5 |
6 | <%= form_with model: [@recipe], method: :post do |form| %> 7 |
8 | <%= form.label :name %>
9 | <%= form.text_field :name, class: 'form-control' %> 10 |
11 | 12 |
13 | <%= form.label :preparation_time %>
14 | <%= form.number_field :preparation_time, step: 0.01, class: 'form-control' %> 15 |
16 | 17 |
18 | <%= form.label :cooking_time %>
19 | <%= form.number_field :cooking_time, step: 0.01, class: 'form-control' %> 20 |
21 | 22 |
23 | <%= form.label :description %>
24 | <%= form.text_area :description, class: 'form-control' %> 25 |
26 | 27 |
28 | <%= form.label :public, "Public" %>
29 | <%= form.check_box :public, class: 'form-check-input' %> 30 |
31 | 32 |

33 | <%= form.submit 'Create Recipe', class: "btn btn-primary btn-lg container mt-4" %> 34 |
35 | <% end %> 36 |
37 |
-------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | NewCops: enable 3 | Exclude: 4 | - "db/**/*" 5 | - "bin/*" 6 | - "config/**/*" 7 | - "Guardfile" 8 | - "Rakefile" 9 | - "node_modules/**/*" 10 | 11 | DisplayCopNames: true 12 | 13 | Layout/LineLength: 14 | Max: 120 15 | Metrics/MethodLength: 16 | Include: 17 | - "app/controllers/*" 18 | - "app/models/*" 19 | Max: 20 20 | Metrics/AbcSize: 21 | Include: 22 | - "app/controllers/*" 23 | - "app/models/*" 24 | Max: 50 25 | Metrics/ClassLength: 26 | Max: 150 27 | Metrics/BlockLength: 28 | AllowedMethods: ['describe'] 29 | Max: 30 30 | 31 | Style/Documentation: 32 | Enabled: false 33 | Style/ClassAndModuleChildren: 34 | Enabled: false 35 | Style/EachForSimpleLoop: 36 | Enabled: false 37 | Style/AndOr: 38 | Enabled: false 39 | Style/DefWithParentheses: 40 | Enabled: false 41 | Style/FrozenStringLiteralComment: 42 | EnforcedStyle: never 43 | 44 | Layout/HashAlignment: 45 | EnforcedColonStyle: key 46 | Layout/ExtraSpacing: 47 | AllowForAlignment: false 48 | Layout/MultilineMethodCallIndentation: 49 | Enabled: true 50 | EnforcedStyle: indented 51 | Lint/RaiseException: 52 | Enabled: false 53 | Lint/StructNewOverride: 54 | Enabled: false 55 | Style/HashEachMethods: 56 | Enabled: false 57 | Style/HashTransformKeys: 58 | Enabled: false 59 | Style/HashTransformValues: 60 | Enabled: false -------------------------------------------------------------------------------- /app/views/devise/sessions/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Log in

3 | 4 | <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 5 | 6 |
7 | <%= f.email_field :email, 8 | class: "form-control", 9 | placeholder: "Email", 10 | autofocus: true, 11 | autocomplete: "email", 12 | "aria-label": "email" %> 13 |
14 | 15 |
16 | <%= f.password_field :password, 17 | class: "form-control", 18 | placeholder: "Password", 19 | autocomplete: "current-password", 20 | "aria-label": "password" %> 21 |
22 | 23 | <% if devise_mapping.rememberable? %> 24 |
25 | <%= f.check_box :remember_me, class: "form-check-input" %> 26 | <%= f.label :remember_me, class: "form-check-label" %> 27 |
28 | <% end %> 29 | 30 |
31 | <%= f.submit "Log in", class: "btn btn-primary btn-lg container mt-4" %> 32 |
33 | <% end %> 34 | 35 |
36 | <%= render "devise/shared/links" %> 37 |
38 | -------------------------------------------------------------------------------- /app/views/public_recipes/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Public Recipes

4 | 5 | <%@recipes.each do |recipe|%> 6 |
7 |
8 |
9 |

10 | <%= link_to recipe.name, recipe_path(recipe),method: :get, class:"link-secondary" %> 11 |

12 |

by <%= recipe.user.name %> 13 |

14 |
15 |
16 |
17 |

Total Food Item: 18 | <%= recipe.total_food_items %> 19 |

20 |

Total Price: 21 | <%= recipe.total_price %> 22 |

23 |
24 |
25 |
26 |
27 | <%end%> 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/views/recipe_foods/_recipe_foods_detail.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <% @recipe.recipe_foods.each do |recipe_food| %> 13 | 14 | 17 | 20 | 23 | 33 | 34 | 35 | <% end %> 36 |
FoodQuantityValueActions
15 | <%= recipe_food.food.name %> 16 | 18 | <%= recipe_food.quantity %> 19 | 21 | <%= recipe_food.food.price * recipe_food.quantity %> 22 | 24 | 25 | <% if current_user == @recipe.user %> 26 | <%= button_to "Remove" , recipe_food_path(recipe_food.id) , method: :delete, 27 | class: 'btn btn-danger' %> 28 | <%= button_to "Modify" , edit_recipe_food_path(recipe_food.id) , method: :get, 29 | class: 'btn btn-primary px-4 mx-1' %> 30 | <% end %> 31 | 32 |
-------------------------------------------------------------------------------- /spec/features/food_index_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Visit food index page', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'User name', email: 'email@test.com', password: '123456') 6 | @food1 = Food.create(name: 'Food name 1', user: @user, quantity: 10, measurement_unit: 'kg', price: 10.0) 7 | @food2 = Food.create(name: 'Food name 2', user: @user, quantity: 12, measurement_unit: 'kg', price: 12.0) 8 | @food3 = Food.create(name: 'Food name 3', user: @user, quantity: 14, measurement_unit: 'kg', price: 14.0) 9 | 10 | sign_in @user 11 | visit foods_path 12 | end 13 | 14 | it 'Should render a list of foods' do 15 | expect(page).to have_content('Foods List') 16 | expect(page).to have_content('Food name 1') 17 | expect(page).to have_content('Food name 2') 18 | expect(page).to have_content('Food name 3') 19 | end 20 | 21 | it 'Should find buttons "Delete" and "Add food"' do 22 | expect(page).to have_content('Delete') 23 | expect(page).to have_content('Add Food') 24 | end 25 | 26 | it 'When click on "Delete", should remove the food' do 27 | click_button 'Delete', match: :first 28 | expect(page).not_to have_content('Food name 1') 29 | end 30 | 31 | it 'When click on "Add food", should redirects to a form to add a new food' do 32 | click_link 'Add Food' 33 | expect(page).to have_current_path(new_food_path) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/features/recipe_index_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Visit recipes index page', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'Nick Jhons', email: 'test@test.com', password: '123456') 6 | @recipe1 = Recipe.create(name: 'Pasta', user: @user, preparation_time: 15, cooking_time: 15, 7 | description: 'description 1', public: true) 8 | @recipe2 = Recipe.create(name: 'Hamburguer', user_id: @user.id, preparation_time: 10, cooking_time: 15, 9 | description: 'description 2', public: false) 10 | 11 | sign_in @user 12 | visit recipes_path 13 | end 14 | 15 | # it 'Should see your name after sign in' do 16 | # expect(page).to have_content 'Welcome Nick Jhons' 17 | # end 18 | 19 | it 'Should see a list of recipes' do 20 | expect(page).to have_content 'Recipes' 21 | expect(page).to have_content 'Name: Pasta' 22 | expect(page).to have_content 'Name: Hamburguer' 23 | end 24 | 25 | it 'Should find a button or link to add a new recipe' do 26 | expect(page).to have_content 'Recipes' 27 | expect(page).to have_content 'Add a new Recipe' 28 | expect(page).to have_selector('a') 29 | end 30 | 31 | it "When click on 'Add a new Recipe', should redirects to a form to add a new" do 32 | click_link 'Add a new Recipe' 33 | expect(page).to have_current_path(new_recipe_path) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/recipe_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | RSpec.describe Recipe, type: :model do 3 | before :each do 4 | @user = User.create(name: 'Nick Jhons', email: 'test@test.com', password: '123456') 5 | @recipe = Recipe.create(name: 'Pasta', user: @user, preparation_time: 15, cooking_time: 15, 6 | description: 'description 1', public: false) 7 | end 8 | describe 'Validations' do 9 | it 'Should be valid with a name, preparation_time, cooking_time, and description' do 10 | expect(@recipe).to be_valid 11 | end 12 | it 'Should be invalid without a name' do 13 | recipe = Recipe.create(name: '', user: @user, preparation_time: 15, cooking_time: 15, 14 | description: 'description 1', public: false) 15 | expect(recipe).not_to be_valid 16 | end 17 | it 'Public can just be true or false' do 18 | recipe = Recipe.create(name: 'tomato', user: @user, preparation_time: 15, cooking_time: 15, 19 | description: 'description 1', public: 'yes') 20 | expect(recipe).not_to eq('yes') 21 | end 22 | describe 'callbacks' do 23 | it 'Should receive the recipe_foods length' do 24 | @food = Food.create(name: 'Tomato', measurement_unit: 'kg', price: 1.5, quantity: 10, user: @user) 25 | @recipe_food = RecipeFood.create(recipe: @recipe, food: @food, quantity: 2) 26 | expect(@recipe.total_food_items).to eq(1) 27 | end 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /app/views/devise/passwords/edit.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Change your password

3 | 4 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | <%= f.hidden_field :reset_password_token %> 7 | 8 |
9 | <% if @minimum_password_length %> 10 | (<%= @minimum_password_length %> characters minimum) 11 | <% end %> 12 | <%= f.password_field :password, 13 | class: "form-control", 14 | autofocus: true, 15 | autocomplete: "new-password", 16 | placeholder: "New password", 17 | "aria-label": "new password" %> 18 |
19 | 20 |
21 | <%= f.password_field :password_confirmation, 22 | class: "form-control", 23 | autocomplete: "new-password", 24 | placeholder: "Password confirmation", 25 | "aria-label": "password confirmation" %> 26 |
27 | 28 |
29 | <%= f.submit "Change my password", class: "btn btn-primary btn-lg container mt-4" %> 30 |
31 | <% end %> 32 |
33 | <%= render "devise/shared/links" %> 34 |
-------------------------------------------------------------------------------- /app/controllers/recipes_controller.rb: -------------------------------------------------------------------------------- 1 | class RecipesController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :find_user_by_id 4 | 5 | def show 6 | @recipe = Recipe.includes(:recipe_foods).find(params[:id]) 7 | end 8 | 9 | def index 10 | @recipes = @user.recipes 11 | end 12 | 13 | def new 14 | @recipe = Recipe.new 15 | end 16 | 17 | def create 18 | @recipe = @user.recipes.new(recipe_params) 19 | if @recipe.save 20 | flash[:notice] = 'Recipe created successfully' 21 | redirect_to recipes_path 22 | else 23 | flash[:alert] = 'Error! Recipe not created' 24 | redirect_to new_recipe_path 25 | end 26 | end 27 | 28 | def destroy 29 | @recipe = @user.recipes.find_by(id: params[:id]) 30 | if @recipe.destroy 31 | flash[:notice] = 'Recipe deleted successfully' 32 | else 33 | flash[:alert] = 'Error! Recipe not deleted' 34 | end 35 | redirect_to recipes_path 36 | end 37 | 38 | def update 39 | @recipe = @user.recipes.find(params[:id]) 40 | if @recipe.update(recipe_params) 41 | flash[:notice] = 'Recipe updated successfully' 42 | else 43 | flash[:alert] = 'Error! Recipe not updated' 44 | end 45 | redirect_to @recipe 46 | end 47 | 48 | private 49 | 50 | def find_user_by_id 51 | @user = current_user 52 | rescue ActiveRecord::RecordNotFound 53 | flash[:alert] = 'Error! User not found' 54 | redirect_to users_url 55 | end 56 | 57 | def recipe_params 58 | params.require(:recipe).permit(:name, :description, :cooking_time, :preparation_time, :public) 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /app/controllers/recipe_foods_controller.rb: -------------------------------------------------------------------------------- 1 | class RecipeFoodsController < ApplicationController 2 | def show; end 3 | 4 | def index; end 5 | 6 | def new 7 | @recipe_food = RecipeFood.new 8 | @recipe = Recipe.find(params[:recipe_id]) 9 | @foods = current_user.foods 10 | end 11 | 12 | def create 13 | @recipe_food = RecipeFood.new(recipe_food_params) 14 | @recipe = @recipe_food.recipe 15 | if @recipe_food.save 16 | flash[:notice] = 'Recipe food created successfully' 17 | redirect_to recipe_path(@recipe) 18 | else 19 | flash[:alert] = 'Error! Recipe food not created' 20 | puts @recipe_food.errors.full_messages 21 | redirect_to new_recipe_food_path(recipe_id: @recipe.id) 22 | end 23 | end 24 | 25 | def destroy 26 | @recipe_food = RecipeFood.find(params[:id]) 27 | @recipe = @recipe_food.recipe 28 | if @recipe_food.destroy 29 | flash[:notice] = 'Recipe food deleted successfully' 30 | else 31 | flash[:alert] = 'Error! Recipe food not deleted' 32 | end 33 | redirect_to recipe_path(@recipe) 34 | end 35 | 36 | def edit 37 | @recipe_food = RecipeFood.find(params[:id]) 38 | @recipe = @recipe_food.recipe 39 | @foods = Food.all 40 | end 41 | 42 | def update 43 | @recipe_food = RecipeFood.find(params[:id]) 44 | @recipe = @recipe_food.recipe 45 | if @recipe_food.update(recipe_food_params) 46 | flash[:notice] = 'Recipe food updated successfully' 47 | else 48 | flash[:alert] = 'Error! Recipe food not updated' 49 | end 50 | redirect_to recipe_path(@recipe) 51 | end 52 | 53 | def recipe_food_params 54 | params.require(:recipe_food).permit(:food_id, :recipe_id, :quantity) 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /app/views/devise/registrations/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Edit <%= resource_name.to_s.humanize %>

2 | 3 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 9 |
10 | 11 | <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 12 |
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
13 | <% end %> 14 | 15 |
16 | <%= f.label :password %> (leave blank if you don't want to change it)
17 | <%= f.password_field :password, autocomplete: "new-password" %> 18 | <% if @minimum_password_length %> 19 |
20 | <%= @minimum_password_length %> characters minimum 21 | <% end %> 22 |
23 | 24 |
25 | <%= f.label :password_confirmation %>
26 | <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 27 |
28 | 29 |
30 | <%= f.label :current_password %> (we need your current password to confirm your changes)
31 | <%= f.password_field :current_password, autocomplete: "current-password" %> 32 |
33 | 34 |
35 | <%= f.submit "Update" %> 36 |
37 | <% end %> 38 | 39 |

Cancel my account

40 | 41 |
Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete %>
42 | 43 | <%= link_to "Back", :back %> 44 | -------------------------------------------------------------------------------- /app/views/foods/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Foods List

4 | <%= link_to 'Add Food' , new_food_path, class: 'btn btn-primary' %> 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | <% if @current_user.foods.length> 0 %> 19 | <% @current_user.foods.each do |food| %> 20 | 21 | 24 | 27 | 30 | 34 | 35 | <% end %> 36 | <% else %> 37 | 38 | 39 | 40 | <% end %> 41 | 42 |
FoodMeasurement UnitUnit PriceActions
22 | <%= food.name %> 23 | 25 | <%= food.measurement_unit %> 26 | 28 | <%= food.price %> 29 | 31 | <%= button_to "Delete" , "foods/#{food.id}" , method: :delete, 32 | class: 'btn btn-danger' %> 33 |
There Is No Food
43 | 44 |
-------------------------------------------------------------------------------- /app/views/foods/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Add New Food

4 | <%= link_to "Back to Foods List" , foods_path, class: 'btn btn-outline-secondary' %> 5 |
6 | 7 | <%= form_for @food do |form| %> 8 | <% if @food.errors.any? %> 9 | 14 | <% end %> 15 | 16 |
17 | <%= form.label :name %> 18 | <%= form.text_field :name, class: "form-control" , placeholder: "Enter the name of food" %> 19 |
20 | 21 |
22 | <%= form.label :measurement_unit %> 23 | <%= form.text_field :measurement_unit, class: "form-control" , 24 | placeholder: "Enter the measurement unit" %> 25 |
26 | 27 |
28 | <%= form.label :price %> 29 | <%= form.number_field :price, class: "form-control" , placeholder: "Enter the price" %> 30 |
31 | 32 |
33 | <%= form.label :quantity %> 34 | <%= form.number_field :quantity, class: "form-control" , placeholder: "Enter the quantity" %> 35 |
36 | 37 |
38 | <%= form.submit "Create Food" , class: "btn btn-outline-dark w-25" %> 39 |
40 | <% end %> 41 |
-------------------------------------------------------------------------------- /.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | name: Linters 2 | 3 | on: pull_request 4 | 5 | env: 6 | FORCE_COLOR: 1 7 | 8 | jobs: 9 | rubocop: 10 | name: Rubocop 11 | runs-on: ubuntu-22.04 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions/setup-ruby@v1 15 | with: 16 | ruby-version: 3.1.x 17 | - name: Setup Rubocop 18 | run: | 19 | gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ 20 | [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.rubocop.yml 21 | - name: Rubocop Report 22 | run: rubocop --color 23 | stylelint: 24 | name: Stylelint 25 | runs-on: ubuntu-22.04 26 | steps: 27 | - uses: actions/checkout@v3 28 | - uses: actions/setup-node@v3 29 | with: 30 | node-version: "18.x" 31 | - name: Setup Stylelint 32 | run: | 33 | npm install --save-dev stylelint@13.x stylelint-scss@3.x stylelint-config-standard@21.x stylelint-csstree-validator@1.x 34 | [ -f .stylelintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ror/.stylelintrc.json 35 | - name: Stylelint Report 36 | run: npx stylelint "**/*.{css,scss}" 37 | nodechecker: 38 | name: node_modules checker 39 | runs-on: ubuntu-22.04 40 | steps: 41 | - uses: actions/checkout@v3 42 | - name: Check node_modules existence 43 | run: | 44 | if [ -d "node_modules/" ]; then echo -e "\e[1;31mThe node_modules/ folder was pushed to the repo. Please remove it from the GitHub repository and try again."; echo -e "\e[1;32mYou can set up a .gitignore file with this folder included on it to prevent this from happening in the future." && exit 1; fi -------------------------------------------------------------------------------- /app/views/menu/_nav_bar.html.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT") { 3000 } 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `bin/rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /db/migrate/20231010121114_add_devise_to_users.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class AddDeviseToUsers < ActiveRecord::Migration[7.0] 4 | def self.up 5 | change_table :users do |t| 6 | ## Database authenticatable 7 | t.string :email, null: false, default: "" 8 | t.string :encrypted_password, null: false, default: "" 9 | 10 | ## Recoverable 11 | t.string :reset_password_token 12 | t.datetime :reset_password_sent_at 13 | 14 | ## Rememberable 15 | t.datetime :remember_created_at 16 | 17 | ## Trackable 18 | # t.integer :sign_in_count, default: 0, null: false 19 | # t.datetime :current_sign_in_at 20 | # t.datetime :last_sign_in_at 21 | # t.string :current_sign_in_ip 22 | # t.string :last_sign_in_ip 23 | 24 | ## Confirmable 25 | # t.string :confirmation_token 26 | # t.datetime :confirmed_at 27 | # t.datetime :confirmation_sent_at 28 | # t.string :unconfirmed_email # Only if using reconfirmable 29 | 30 | ## Lockable 31 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 32 | # t.string :unlock_token # Only if unlock strategy is :email or :both 33 | # t.datetime :locked_at 34 | 35 | 36 | # Uncomment below if timestamps were not included in your original model. 37 | # t.timestamps null: false 38 | end 39 | 40 | add_index :users, :email, unique: true 41 | add_index :users, :reset_password_token, unique: true 42 | # add_index :users, :confirmation_token, unique: true 43 | # add_index :users, :unlock_token, unique: true 44 | end 45 | 46 | def self.down 47 | # By default, we don't want to make any assumption about how to roll back a migration when your 48 | # model already existed. Please edit below which fields you would like to remove in this migration. 49 | raise ActiveRecord::IrreversibleMigration 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /app/views/devise/registrations/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Sign up

3 | 4 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 5 | <%= render "devise/shared/error_messages", resource: resource %> 6 | 7 |
8 | <%= f.text_field :name, 9 | autofocus: true, 10 | placeholder:"Name", 11 | autocomplete: "name", 12 | class: "form-control", 13 | "aria-label": "name"%> 14 |
15 | 16 | 17 |
18 | <%= f.email_field :email, 19 | autofocus: true, 20 | placeholder: "Email", 21 | autocomplete: "email", 22 | class: "form-control", 23 | "aria-label": "email" %> 24 |
25 | 26 |
27 | <% if @minimum_password_length %> 28 | (<%= @minimum_password_length %> characters minimum) 29 | <% end %> 30 | <%= f.password_field :password, 31 | autocomplete: "new-password", 32 | placeholder: "New password", 33 | class: "form-control", 34 | "aria-label": "new password"%> 35 |
36 | 37 |
38 | <%= f.password_field :password_confirmation, 39 | autocomplete: "new-password", 40 | placeholder: "New password", 41 | class: "form-control", 42 | "aria-label": "new password"%> 43 |
44 | 45 |
46 | <%= f.submit "Sign up", class: "btn btn-primary btn-lg container mt-4" %> 47 |
48 | <% end %> 49 |
50 | <%= render "devise/shared/links" %> 51 |
52 | 53 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # Turn false under Spring and add config.action_view.cache_template_loading = true. 12 | config.cache_classes = true 13 | 14 | # Eager loading loads your whole application. When running a single test locally, 15 | # this probably isn't necessary. It's a good idea to do in a continuous integration 16 | # system, or in some way before deploying your code. 17 | config.eager_load = ENV["CI"].present? 18 | 19 | # Configure public file server for tests with Cache-Control for performance. 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 23 | } 24 | 25 | # Show full error reports and disable caching. 26 | config.consider_all_requests_local = true 27 | config.action_controller.perform_caching = false 28 | config.cache_store = :null_store 29 | 30 | # Raise exceptions instead of rendering exception templates. 31 | config.action_dispatch.show_exceptions = false 32 | 33 | # Disable request forgery protection in test environment. 34 | config.action_controller.allow_forgery_protection = false 35 | 36 | # Store uploaded files on the local file system in a temporary directory. 37 | config.active_storage.service = :test 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Tell Action Mailer not to deliver emails to the real world. 42 | # The :test delivery method accumulates sent emails in the 43 | # ActionMailer::Base.deliveries array. 44 | config.action_mailer.delivery_method = :test 45 | 46 | # Print deprecation notices to the stderr. 47 | config.active_support.deprecation = :stderr 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raises error for missing translations. 56 | # config.i18n.raise_on_missing_translations = true 57 | 58 | # Annotate rendered view with file names. 59 | # config.action_view.annotate_rendered_view_with_filenames = true 60 | end 61 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | ruby '3.2.2' 5 | 6 | gem 'devise' 7 | 8 | # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" 9 | gem 'rails', '~> 7.0.8' 10 | 11 | # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] 12 | gem 'sprockets-rails' 13 | 14 | # Use postgresql as the database for Active Record 15 | gem 'pg', '~> 1.1' 16 | 17 | # Use the Puma web server [https://github.com/puma/puma] 18 | gem 'puma', '~> 5.0' 19 | 20 | # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] 21 | gem 'importmap-rails' 22 | 23 | # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] 24 | gem 'turbo-rails' 25 | 26 | # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] 27 | gem 'stimulus-rails' 28 | 29 | # Build JSON APIs with ease [https://github.com/rails/jbuilder] 30 | gem 'jbuilder' 31 | 32 | # Use Redis adapter to run Action Cable in production 33 | gem 'redis', '~> 4.0' 34 | 35 | gem 'rubocop', '>= 1.0', '< 2.0' 36 | 37 | # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] 38 | # gem "kredis" 39 | 40 | # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] 41 | # gem "bcrypt", "~> 3.1.7" 42 | 43 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 44 | gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] 45 | 46 | # Reduces boot times through caching; required in config/boot.rb 47 | gem 'bootsnap', require: false 48 | 49 | # Use Sass to process CSS 50 | # gem "sassc-rails" 51 | 52 | # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] 53 | # gem "image_processing", "~> 1.2" 54 | 55 | group :development, :test do 56 | # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem 57 | gem 'debug', platforms: %i[mri mingw x64_mingw] 58 | 59 | gem 'rspec-rails' 60 | 61 | gem 'capybara' 62 | 63 | gem 'webdrivers' 64 | end 65 | 66 | group :development do 67 | # Use console on exceptions pages [https://github.com/rails/web-console] 68 | gem 'web-console' 69 | 70 | # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] 71 | # gem "rack-mini-profiler" 72 | 73 | # Speed up commands on slow machines / big apps [https://github.com/rails/spring] 74 | # gem "spring" 75 | end 76 | 77 | group :test do 78 | # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] 79 | gem 'selenium-webdriver' 80 | end 81 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.cache_classes = false 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.action_controller.perform_caching = true 24 | config.action_controller.enable_fragment_cache_logging = true 25 | 26 | config.cache_store = :memory_store 27 | config.public_file_server.headers = { 28 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 29 | } 30 | else 31 | config.action_controller.perform_caching = false 32 | 33 | config.cache_store = :null_store 34 | end 35 | 36 | # Store uploaded files on the local file system (see config/storage.yml for options). 37 | config.active_storage.service = :local 38 | 39 | # Don't care if the mailer can't send. 40 | config.action_mailer.raise_delivery_errors = false 41 | 42 | config.action_mailer.perform_caching = false 43 | 44 | config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 45 | 46 | # Print deprecation notices to the Rails logger. 47 | config.active_support.deprecation = :log 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raise an error on page load if there are pending migrations. 56 | config.active_record.migration_error = :page_load 57 | 58 | # Highlight code that triggered database queries in logs. 59 | config.active_record.verbose_query_logs = true 60 | 61 | # Suppress logger output for asset requests. 62 | config.assets.quiet = true 63 | 64 | # Raises error for missing translations. 65 | # config.i18n.raise_on_missing_translations = true 66 | 67 | # Annotate rendered view with file names. 68 | # config.action_view.annotate_rendered_view_with_filenames = true 69 | 70 | # Uncomment if you wish to allow Action Cable access from any origin. 71 | # config.action_cable.disable_request_forgery_protection = true 72 | end 73 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[7.0].define(version: 2023_10_10_121114) do 14 | # These are extensions that must be enabled in order to support this database 15 | enable_extension "plpgsql" 16 | 17 | create_table "foods", force: :cascade do |t| 18 | t.string "name" 19 | t.string "measurement_unit" 20 | t.decimal "price" 21 | t.integer "quantity" 22 | t.bigint "user_id", null: false 23 | t.datetime "created_at", null: false 24 | t.datetime "updated_at", null: false 25 | t.index ["user_id"], name: "index_foods_on_user_id" 26 | end 27 | 28 | create_table "recipe_foods", force: :cascade do |t| 29 | t.integer "quantity" 30 | t.bigint "recipe_id", null: false 31 | t.bigint "food_id", null: false 32 | t.datetime "created_at", null: false 33 | t.datetime "updated_at", null: false 34 | t.index ["food_id"], name: "index_recipe_foods_on_food_id" 35 | t.index ["recipe_id"], name: "index_recipe_foods_on_recipe_id" 36 | end 37 | 38 | create_table "recipes", force: :cascade do |t| 39 | t.string "name" 40 | t.integer "preparation_time" 41 | t.integer "cooking_time" 42 | t.text "description" 43 | t.boolean "public" 44 | t.bigint "user_id", null: false 45 | t.datetime "created_at", null: false 46 | t.datetime "updated_at", null: false 47 | t.index ["user_id"], name: "index_recipes_on_user_id" 48 | end 49 | 50 | create_table "users", force: :cascade do |t| 51 | t.string "name", null: false 52 | t.datetime "created_at", null: false 53 | t.datetime "updated_at", null: false 54 | t.string "email", default: "", null: false 55 | t.string "encrypted_password", default: "", null: false 56 | t.string "reset_password_token" 57 | t.datetime "reset_password_sent_at" 58 | t.datetime "remember_created_at" 59 | t.index ["email"], name: "index_users_on_email", unique: true 60 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 61 | end 62 | 63 | add_foreign_key "foods", "users" 64 | add_foreign_key "recipe_foods", "foods" 65 | add_foreign_key "recipe_foods", "recipes" 66 | add_foreign_key "recipes", "users" 67 | end 68 | -------------------------------------------------------------------------------- /spec/features/recipe_show_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | RSpec.describe 'Visit recipes show page (recipe detail)', type: :feature do 4 | before :each do 5 | @user = User.create(name: 'Nick Jhons', email: 'test@test.com', password: '123456') 6 | @recipe = Recipe.create(name: 'Pasta', user: @user, preparation_time: 15, cooking_time: 15, 7 | description: 'description 1', public: false) 8 | @food1 = Food.create(name: 'Tomato', measurement_unit: 'kg', price: 1.5, quantity: 10, user: @user) 9 | @recipe_food = RecipeFood.create(recipe: @recipe, food: @food1, quantity: 2) 10 | 11 | sign_in @user 12 | visit recipe_path(@recipe) 13 | end 14 | 15 | # it 'Should see your name after sign in' do 16 | # expect(page).to have_content 'Welcome Nick Jhons' 17 | # end 18 | 19 | it 'Should see a Recipe details' do 20 | expect(page).to have_content 'Recipe name: Pasta' 21 | expect(page).to have_content 'Cooking time: 15' 22 | expect(page).to have_content 'Preparation time: 15' 23 | expect(page).to have_content 'Description: description 1' 24 | end 25 | 26 | it 'Should see a list of ingredients' do 27 | expect(page).to have_content 'Ingredients' 28 | expect(page).to have_content 'Tomato' 29 | end 30 | 31 | it 'Should see a actions buttons for ingredients, remove and modify' do 32 | expect(page).to have_content 'Actions' 33 | expect(page).to have_content 'Remove' 34 | expect(page).to have_content 'Modify' 35 | expect(page).to have_selector('button') 36 | end 37 | 38 | it 'When click on Remove, should remove the ingredient' do 39 | click_button 'Remove' 40 | expect(page).not_to have_content 'Tomato' 41 | end 42 | 43 | it 'When click on Modify, should redirects to a form to modify the ingredient' do 44 | click_button 'Modify' 45 | expect(page).to have_current_path(edit_recipe_food_path(@recipe_food)) 46 | end 47 | 48 | it "Should find buttons or links to Make public de recipe, for add a new ingredient, and for 49 | generate shoping list" do 50 | expect(page).to have_content 'Make Public' 51 | expect(page).to have_content 'Add a new ingredient' 52 | expect(page).to have_content 'Generate shopping list' 53 | end 54 | 55 | it "When click on 'Make Public', should toogle from private to public and viceverse" do 56 | click_button 'Make Public' 57 | expect(page).to have_content 'Make Private' 58 | end 59 | 60 | it "When click on 'Add a new ingredient', should redirects to a form to add a new ingredient" do 61 | click_link 'Add a new ingredient' 62 | expect(page).to have_current_path(new_recipe_food_path(recipe_id: @recipe.id)) 63 | end 64 | 65 | it "When click on 'Generate shopping list', should redirects to a shoping list" do 66 | click_link 'Generate shopping list' 67 | expect(page).to have_current_path(recipe_shopping_list_index_path(@recipe)) 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require 'spec_helper' 3 | ENV['RAILS_ENV'] ||= 'test' 4 | require_relative '../config/environment' 5 | # Prevent database truncation if the environment is production 6 | abort('The Rails environment is running in production mode!') if Rails.env.production? 7 | require 'rspec/rails' 8 | # Add additional requires below this line. Rails is not loaded until this point! 9 | 10 | # Requires supporting ruby files with custom matchers and macros, etc, in 11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 12 | # run as spec files by default. This means that files in spec/support that end 13 | # in _spec.rb will both be required and run as specs, causing the specs to be 14 | # run twice. It is recommended that you do not name files matching this glob to 15 | # end with _spec.rb. You can configure this pattern with the --pattern 16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 17 | # 18 | # The following line is provided for convenience purposes. It has the downside 19 | # of increasing the boot-up time by auto-requiring all files in the support 20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 21 | # require only the support files necessary. 22 | # 23 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } 24 | 25 | # Checks for pending migrations and applies them before tests are run. 26 | # If you are not using ActiveRecord, you can remove these lines. 27 | begin 28 | ActiveRecord::Migration.maintain_test_schema! 29 | rescue ActiveRecord::PendingMigrationError => e 30 | abort e.to_s.strip 31 | end 32 | RSpec.configure do |config| 33 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 34 | config.fixture_path = "#{Rails.root}/spec/fixtures" 35 | 36 | config.include Devise::Test::IntegrationHelpers, type: :feature 37 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 38 | # examples within a transaction, remove the following line or assign false 39 | # instead of true. 40 | config.use_transactional_fixtures = true 41 | 42 | # You can uncomment this line to turn off ActiveRecord support entirely. 43 | # config.use_active_record = false 44 | 45 | # RSpec Rails can automatically mix in different behaviours to your tests 46 | # based on their file location, for example enabling you to call `get` and 47 | # `post` in specs under `spec/controllers`. 48 | # 49 | # You can disable this behaviour by removing the line below, and instead 50 | # explicitly tag your specs with their type, e.g.: 51 | # 52 | # RSpec.describe UsersController, type: :controller do 53 | # # ... 54 | # end 55 | # 56 | # The different available types are documented in the features, such as in 57 | # https://rspec.info/features/6-0/rspec-rails 58 | config.infer_spec_type_from_file_location! 59 | 60 | # Filter lines from Rails gems in backtraces. 61 | config.filter_rails_from_backtrace! 62 | # arbitrary gems may also be filtered via: 63 | # config.filter_gems_from_backtrace("gem name") 64 | end 65 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'bundle' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "rubygems" 12 | 13 | m = Module.new do 14 | module_function 15 | 16 | def invoked_as_script? 17 | File.expand_path($0) == File.expand_path(__FILE__) 18 | end 19 | 20 | def env_var_version 21 | ENV["BUNDLER_VERSION"] 22 | end 23 | 24 | def cli_arg_version 25 | return unless invoked_as_script? # don't want to hijack other binstubs 26 | return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` 27 | bundler_version = nil 28 | update_index = nil 29 | ARGV.each_with_index do |a, i| 30 | if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN 31 | bundler_version = a 32 | end 33 | next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ 34 | bundler_version = $1 35 | update_index = i 36 | end 37 | bundler_version 38 | end 39 | 40 | def gemfile 41 | gemfile = ENV["BUNDLE_GEMFILE"] 42 | return gemfile if gemfile && !gemfile.empty? 43 | 44 | File.expand_path("../Gemfile", __dir__) 45 | end 46 | 47 | def lockfile 48 | lockfile = 49 | case File.basename(gemfile) 50 | when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") 51 | else "#{gemfile}.lock" 52 | end 53 | File.expand_path(lockfile) 54 | end 55 | 56 | def lockfile_version 57 | return unless File.file?(lockfile) 58 | lockfile_contents = File.read(lockfile) 59 | return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ 60 | Regexp.last_match(1) 61 | end 62 | 63 | def bundler_requirement 64 | @bundler_requirement ||= 65 | env_var_version || 66 | cli_arg_version || 67 | bundler_requirement_for(lockfile_version) 68 | end 69 | 70 | def bundler_requirement_for(version) 71 | return "#{Gem::Requirement.default}.a" unless version 72 | 73 | bundler_gem_version = Gem::Version.new(version) 74 | 75 | bundler_gem_version.approximate_recommendation 76 | end 77 | 78 | def load_bundler! 79 | ENV["BUNDLE_GEMFILE"] ||= gemfile 80 | 81 | activate_bundler 82 | end 83 | 84 | def activate_bundler 85 | gem_error = activation_error_handling do 86 | gem "bundler", bundler_requirement 87 | end 88 | return if gem_error.nil? 89 | require_error = activation_error_handling do 90 | require "bundler/version" 91 | end 92 | return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) 93 | warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" 94 | exit 42 95 | end 96 | 97 | def activation_error_handling 98 | yield 99 | nil 100 | rescue StandardError, LoadError => e 101 | e 102 | end 103 | end 104 | 105 | m.load_bundler! 106 | 107 | if m.invoked_as_script? 108 | load Gem.bin_path("bundler", "bundle") 109 | end 110 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 9.3 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On macOS with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On macOS with MacPorts: 8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9 | # On Windows: 10 | # gem install pg 11 | # Choose the win32 build. 12 | # Install PostgreSQL and put its /bin directory on your path. 13 | # 14 | # Configure Using Gemfile 15 | # gem "pg" 16 | # 17 | default: &default 18 | adapter: postgresql 19 | encoding: unicode 20 | # For details on connection pooling, see Rails configuration guide 21 | # https://guides.rubyonrails.org/configuring.html#database-pooling 22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 23 | 24 | development: 25 | <<: *default 26 | database: Recipe_App_development 27 | 28 | # The specified database role being used to connect to postgres. 29 | # To create additional roles in postgres see `$ createuser --help`. 30 | # When left blank, postgres will use the default role. This is 31 | # the same name as the operating system user running Rails. 32 | #username: Recipe_App 33 | 34 | # The password associated with the postgres role (username). 35 | #password: 36 | 37 | # Connect on a TCP socket. Omitted by default since the client uses a 38 | # domain socket that doesn't need configuration. Windows does not have 39 | # domain sockets, so uncomment these lines. 40 | #host: localhost 41 | 42 | # The TCP port the server listens on. Defaults to 5432. 43 | # If your server runs on a different port number, change accordingly. 44 | #port: 5432 45 | 46 | # Schema search path. The server defaults to $user,public 47 | #schema_search_path: myapp,sharedapp,public 48 | 49 | # Minimum log levels, in increasing order: 50 | # debug5, debug4, debug3, debug2, debug1, 51 | # log, notice, warning, error, fatal, and panic 52 | # Defaults to warning. 53 | #min_messages: notice 54 | 55 | # Warning: The database defined as "test" will be erased and 56 | # re-generated from your development database when you run "rake". 57 | # Do not set this db to the same as development or production. 58 | test: 59 | <<: *default 60 | database: Recipe_App_test 61 | 62 | # As with config/credentials.yml, you never want to store sensitive information, 63 | # like your database password, in your source code. If your source code is 64 | # ever seen by anyone, they now have access to your database. 65 | # 66 | # Instead, provide the password or a full connection URL as an environment 67 | # variable when you boot the app. For example: 68 | # 69 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 70 | # 71 | # If the connection URL is provided in the special DATABASE_URL environment 72 | # variable, Rails will automatically merge its configuration values on top of 73 | # the values provided in this file. Alternatively, you can specify a connection 74 | # URL environment variable explicitly: 75 | # 76 | # production: 77 | # url: <%= ENV["MY_APP_DATABASE_URL"] %> 78 | # 79 | # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 80 | # for a full overview on how database connection configuration can be specified. 81 | # 82 | production: 83 | <<: *default 84 | database: Recipe_App_production 85 | username: Recipe_App 86 | password: <%= ENV["RECIPE_APP_DATABASE_PASSWORD"] %> 87 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.cache_classes = true 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | config.action_controller.perform_caching = true 18 | 19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 21 | # config.require_master_key = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? 26 | 27 | # Compress CSS using a preprocessor. 28 | # config.assets.css_compressor = :sass 29 | 30 | # Do not fallback to assets pipeline if a precompiled asset is missed. 31 | config.assets.compile = false 32 | 33 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 34 | # config.asset_host = "http://assets.example.com" 35 | 36 | # Specifies the header that your server uses for sending files. 37 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 38 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 39 | 40 | # Store uploaded files on the local file system (see config/storage.yml for options). 41 | config.active_storage.service = :local 42 | 43 | # Mount Action Cable outside main process or domain. 44 | # config.action_cable.mount_path = nil 45 | # config.action_cable.url = "wss://example.com/cable" 46 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 47 | 48 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 49 | # config.force_ssl = true 50 | 51 | # Include generic and useful information about system operation, but avoid logging too much 52 | # information to avoid inadvertent exposure of personally identifiable information (PII). 53 | config.log_level = :info 54 | 55 | # Prepend all log lines with the following tags. 56 | config.log_tags = [ :request_id ] 57 | 58 | # Use a different cache store in production. 59 | # config.cache_store = :mem_cache_store 60 | 61 | # Use a real queuing backend for Active Job (and separate queues per environment). 62 | # config.active_job.queue_adapter = :resque 63 | # config.active_job.queue_name_prefix = "Recipe_App_production" 64 | 65 | config.action_mailer.perform_caching = false 66 | 67 | # Ignore bad email addresses and do not raise email delivery errors. 68 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 69 | # config.action_mailer.raise_delivery_errors = false 70 | 71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 72 | # the I18n.default_locale when a translation cannot be found). 73 | config.i18n.fallbacks = true 74 | 75 | # Don't log any deprecations. 76 | config.active_support.report_deprecations = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | 81 | # Use a different logger for distributed setups. 82 | # require "syslog/logger" 83 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 84 | 85 | if ENV["RAILS_LOG_TO_STDOUT"].present? 86 | logger = ActiveSupport::Logger.new(STDOUT) 87 | logger.formatter = config.log_formatter 88 | config.logger = ActiveSupport::TaggedLogging.new(logger) 89 | end 90 | 91 | # Do not dump schema after migrations. 92 | config.active_record.dump_schema_after_migration = false 93 | end 94 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/heartcombo/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your email address has been successfully confirmed." 7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." 8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." 9 | failure: 10 | already_authenticated: "You are already signed in." 11 | inactive: "Your account is not activated yet." 12 | invalid: "Invalid %{authentication_keys} or password." 13 | locked: "Your account is locked." 14 | last_attempt: "You have one more attempt before your account is locked." 15 | not_found_in_database: "Invalid %{authentication_keys} or password." 16 | timeout: "Your session expired. Please sign in again to continue." 17 | unauthenticated: "You need to sign in or sign up before continuing." 18 | unconfirmed: "You have to confirm your email address before continuing." 19 | mailer: 20 | confirmation_instructions: 21 | subject: "Confirmation instructions" 22 | reset_password_instructions: 23 | subject: "Reset password instructions" 24 | unlock_instructions: 25 | subject: "Unlock instructions" 26 | email_changed: 27 | subject: "Email Changed" 28 | password_change: 29 | subject: "Password Changed" 30 | omniauth_callbacks: 31 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 32 | success: "Successfully authenticated from %{kind} account." 33 | passwords: 34 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." 35 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." 36 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." 37 | updated: "Your password has been changed successfully. You are now signed in." 38 | updated_not_active: "Your password has been changed successfully." 39 | registrations: 40 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." 41 | signed_up: "Welcome! You have signed up successfully." 42 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 43 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 44 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." 45 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address." 46 | updated: "Your account has been updated successfully." 47 | updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again." 48 | sessions: 49 | signed_in: "Signed in successfully." 50 | signed_out: "Signed out successfully." 51 | already_signed_out: "Signed out successfully." 52 | unlocks: 53 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." 54 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." 55 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 56 | errors: 57 | messages: 58 | already_confirmed: "was already confirmed, please try signing in" 59 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 60 | expired: "has expired, please request a new one" 61 | not_found: "not found" 62 | not_locked: "was not locked" 63 | not_saved: 64 | one: "1 error prohibited this %{resource} from being saved:" 65 | other: "%{count} errors prohibited this %{resource} from being saved:" 66 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'capybara/rspec' 2 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 3 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 4 | # The generated `.rspec` file contains `--require spec_helper` which will cause 5 | # this file to always be loaded, without a need to explicitly require it in any 6 | # files. 7 | # 8 | # Given that it is always loaded, you are encouraged to keep this file as 9 | # light-weight as possible. Requiring heavyweight dependencies from this file 10 | # will add to the boot time of your test suite on EVERY test run, even for an 11 | # individual file that may not need all of that loaded. Instead, consider making 12 | # a separate helper file that requires the additional dependencies and performs 13 | # the additional setup, and require it from the spec files that actually need 14 | # it. 15 | # 16 | # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 17 | RSpec.configure do |config| 18 | # rspec-expectations config goes here. You can use an alternate 19 | # assertion/expectation library such as wrong or the stdlib/minitest 20 | # assertions if you prefer. 21 | config.expect_with :rspec do |expectations| 22 | # This option will default to `true` in RSpec 4. It makes the `description` 23 | # and `failure_message` of custom matchers include text for helper methods 24 | # defined using `chain`, e.g.: 25 | # be_bigger_than(2).and_smaller_than(4).description 26 | # # => "be bigger than 2 and smaller than 4" 27 | # ...rather than: 28 | # # => "be bigger than 2" 29 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 30 | end 31 | 32 | # rspec-mocks config goes here. You can use an alternate test double 33 | # library (such as bogus or mocha) by changing the `mock_with` option here. 34 | config.mock_with :rspec do |mocks| 35 | # Prevents you from mocking or stubbing a method that does not exist on 36 | # a real object. This is generally recommended, and will default to 37 | # `true` in RSpec 4. 38 | mocks.verify_partial_doubles = true 39 | end 40 | 41 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 42 | # have no way to turn it off -- the option exists only for backwards 43 | # compatibility in RSpec 3). It causes shared context metadata to be 44 | # inherited by the metadata hash of host groups and examples, rather than 45 | # triggering implicit auto-inclusion in groups with matching metadata. 46 | config.shared_context_metadata_behavior = :apply_to_host_groups 47 | 48 | # The settings below are suggested to provide a good initial experience 49 | # with RSpec, but feel free to customize to your heart's content. 50 | # # This allows you to limit a spec run to individual examples or groups 51 | # # you care about by tagging them with `:focus` metadata. When nothing 52 | # # is tagged with `:focus`, all examples get run. RSpec also provides 53 | # # aliases for `it`, `describe`, and `context` that include `:focus` 54 | # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 55 | # config.filter_run_when_matching :focus 56 | # 57 | # # Allows RSpec to persist some state between runs in order to support 58 | # # the `--only-failures` and `--next-failure` CLI options. We recommend 59 | # # you configure your source control system to ignore this file. 60 | # config.example_status_persistence_file_path = "spec/examples.txt" 61 | # 62 | # # Limits the available syntax to the non-monkey patched syntax that is 63 | # # recommended. For more details, see: 64 | # # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ 65 | # config.disable_monkey_patching! 66 | # 67 | # # Many RSpec users commonly either run the entire suite or an individual 68 | # # file, and it's useful to allow more verbose output when running an 69 | # # individual spec file. 70 | # if config.files_to_run.one? 71 | # # Use the documentation formatter for detailed output, 72 | # # unless a formatter has already been configured 73 | # # (e.g. via a command-line flag). 74 | # config.default_formatter = "doc" 75 | # end 76 | # 77 | # # Print the 10 slowest examples and example groups at the 78 | # # end of the spec run, to help surface which specs are running 79 | # # particularly slow. 80 | # config.profile_examples = 10 81 | # 82 | # # Run specs in random order to surface order dependencies. If you find an 83 | # # order dependency and want to debug it, you can fix the order by providing 84 | # # the seed, which is printed after each run. 85 | # # --seed 1234 86 | # config.order = :random 87 | # 88 | # # Seed global randomization in this process using the `--seed` CLI option. 89 | # # Setting this allows you to use `--seed` to deterministically reproduce 90 | # # test failures related to randomization by passing the same `--seed` value 91 | # # as the one that triggered the failure. 92 | # Kernel.srand config.seed 93 | end 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |

Recipe App

5 |
6 | 7 | 8 | 9 | 10 | # 📗 Table of Contents 11 | 12 | - [📖 About the Project](#about-project) 13 | - [🛠 Built With](#built-with) 14 | - [Tech Stack](#tech-stack) 15 | - [💻 Getting Started](#getting-started) 16 | - [Setup](#setup) 17 | - [Prerequisites](#prerequisites) 18 | - [Install](#install) 19 | - [Usage](#usage) 20 | - [Run tests](#run-tests) 21 | - [Deployment](#triangular_flag_on_post-deployment) 22 | - [👥 Authors](#authors) 23 | - [🔭 Future Features](#future-features) 24 | - [🤝 Contributing](#contributing) 25 | - [⭐️ Show your support](#support) 26 | - [🙏 Acknowledgements](#acknowledgements) 27 | - [📝 License](#license) 28 | 29 | 30 | 31 | # 📖 Recipe App 32 | 33 | **Recipe App** 34 | 35 | The Recipe app keeps track of all your recipes, ingredients, and inventory. It will allow you to save ingredients, keep track of what you have, create recipes, and generate a shopping list based on what you have and what you are missing from a recipe. 36 | 37 | 38 | ## 🛠 Built With 39 | 40 | ### Tech Stack 41 | 42 |
43 | Ruby on Rails 44 | 47 |
48 | 49 |
50 | Rspec 51 | 54 |
55 | 56 |
57 | Capybara 58 | 61 |
62 | 63 |
64 | Bootstrap 65 | 68 |
69 | 70 |

(back to top)

71 | 72 | ## 💻 Getting Started 73 | The result should look similar to the following data model (this is an Entity Relationship Diagram that you are already familiar with). 74 | ![ERD Recipe App](https://github.com/microverseinc/curriculum-rails/raw/main/recipe-app/images/recipe_erd_2_members.png) 75 | 76 | ### Setup 77 | 78 | 1. Ensure you have Ruby 3.2.2 at least, installed on your system. You can check your Ruby version in the terminal by running: 79 | 80 | ``` 81 | ruby -v 82 | ``` 83 | 84 | 2. You can clone the project : 85 | 86 | Using HTTPS: 87 | 88 | ``` 89 | git clone https://github.com/ahmedeid6842/Recipe_App.git 90 | ``` 91 | 92 | ### Installation 93 | 94 | To run this project locally, follow these steps: 95 | 96 | 1. Open your terminal or command prompt. 97 | 98 | 2. Navigate to the directory where you have cloned or downloaded the Recipe App repository. 99 | 100 | 3. Run the following command to install any required dependencies: 101 | 102 | ``` 103 | bundle install 104 | ``` 105 | 4. You need to make sure you have PostgreSQL installed and configured on your local computer beforehand, then create the database for the project: 106 | 107 | ``` 108 | rails db:create 109 | ``` 110 | 111 | 5. Now you need to create the tables and relationships that the project needs: 112 | 113 | ``` 114 | rails db:migrate 115 | ``` 116 | 117 | ### Usage 118 | 119 | 1. Once the setup is complete, ensure you are still in the directory containing the Recipe App files. 120 | 121 | 2. To run the app, execute the following command: 122 | 123 | ``` 124 | rails s 125 | ``` 126 | 127 | ### Tests 128 | 129 | To run the tests ensure you are in the directory containing the test files. 130 | 131 | 1. Run the tests using the following command: 132 | 133 | ``` 134 | rspec 135 | ``` 136 | 137 | (optional) If you have problem with a different version of 'regexp_parser', you can run the tests with the 138 | version of the gemfile with this command: 139 | 140 | ``` 141 | bundle exec rspec 142 | ``` 143 | 144 | - All tests should pass without any errors or failures, ensuring that the code and its methods are functioning correctly. 145 | 146 |

(back to top)

147 | 148 | 149 | ## 👥 Authors 150 | 151 | 👤 **Ahmed Eid** 152 | - Github: [@ahmedeid6842](https://github.com/ahmedeid6842/) 153 | - LinkedIn : [Ahmed Eid](https://www.linkedin.com/in/ahmed-eid-0018571b1/) 154 | - Twitter: [@ahmedeid2684](https://twitter.com/ahmedeid2684) 155 | 156 | 👤 **César Herrera** 157 | 158 | - GitHub: [@cesarherr](https://github.com/cesarherr) 159 | - LinkedIn: [CesarHerr](https://www.linkedin.com/in/cesarherr/) 160 | 161 |

(back to top)

162 | 163 | 164 | ## 🔭 Features 165 | 166 | - [x] **Create a Database** 167 | - [x] **Add Migrations** 168 | - [x] **Add Models** 169 | - [x] **Add Controllers** 170 | - [x] **Add Views** 171 | - [x] **Add tests** 172 | - [x] **Show Foods at index page** 173 | - [x] **Show Recipes by users** 174 | - [x] **Show Public Recipes** 175 | - [x] **Authentication User** 176 | - [x] **Show shopping list** 177 | 178 |

(back to top)

179 | 180 | 181 | ## 🤝 Contributing 182 | 183 | Contributions, issues, and feature requests are welcome! 184 | 185 | Feel free to check the [issues page](https://github.com/ahmedeid6842/Recipe_App/issues). 186 | 187 |

(back to top)

188 | 189 | 190 | ## ⭐️ Show your support 191 | 192 | If you like this project give it a star ⭐️ 193 | 194 |

(back to top)

195 | 196 | 197 | ## 🙏 Acknowledgments 198 | 199 | **I would like to thank Microverse for giving us the opportunity to learn and grow as developers and also I like to thank my family, they are all my support. 🌟** 200 | 201 |

(back to top)

202 | 203 | 204 | ## 📝 License 205 | 206 | This project is [MIT](./LICENSE) licensed. 207 | 208 |

(back to top)

-------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (7.0.8) 5 | actionpack (= 7.0.8) 6 | activesupport (= 7.0.8) 7 | nio4r (~> 2.0) 8 | websocket-driver (>= 0.6.1) 9 | actionmailbox (7.0.8) 10 | actionpack (= 7.0.8) 11 | activejob (= 7.0.8) 12 | activerecord (= 7.0.8) 13 | activestorage (= 7.0.8) 14 | activesupport (= 7.0.8) 15 | mail (>= 2.7.1) 16 | net-imap 17 | net-pop 18 | net-smtp 19 | actionmailer (7.0.8) 20 | actionpack (= 7.0.8) 21 | actionview (= 7.0.8) 22 | activejob (= 7.0.8) 23 | activesupport (= 7.0.8) 24 | mail (~> 2.5, >= 2.5.4) 25 | net-imap 26 | net-pop 27 | net-smtp 28 | rails-dom-testing (~> 2.0) 29 | actionpack (7.0.8) 30 | actionview (= 7.0.8) 31 | activesupport (= 7.0.8) 32 | rack (~> 2.0, >= 2.2.4) 33 | rack-test (>= 0.6.3) 34 | rails-dom-testing (~> 2.0) 35 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 36 | actiontext (7.0.8) 37 | actionpack (= 7.0.8) 38 | activerecord (= 7.0.8) 39 | activestorage (= 7.0.8) 40 | activesupport (= 7.0.8) 41 | globalid (>= 0.6.0) 42 | nokogiri (>= 1.8.5) 43 | actionview (7.0.8) 44 | activesupport (= 7.0.8) 45 | builder (~> 3.1) 46 | erubi (~> 1.4) 47 | rails-dom-testing (~> 2.0) 48 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 49 | activejob (7.0.8) 50 | activesupport (= 7.0.8) 51 | globalid (>= 0.3.6) 52 | activemodel (7.0.8) 53 | activesupport (= 7.0.8) 54 | activerecord (7.0.8) 55 | activemodel (= 7.0.8) 56 | activesupport (= 7.0.8) 57 | activestorage (7.0.8) 58 | actionpack (= 7.0.8) 59 | activejob (= 7.0.8) 60 | activerecord (= 7.0.8) 61 | activesupport (= 7.0.8) 62 | marcel (~> 1.0) 63 | mini_mime (>= 1.1.0) 64 | activesupport (7.0.8) 65 | concurrent-ruby (~> 1.0, >= 1.0.2) 66 | i18n (>= 1.6, < 2) 67 | minitest (>= 5.1) 68 | tzinfo (~> 2.0) 69 | addressable (2.8.5) 70 | public_suffix (>= 2.0.2, < 6.0) 71 | ast (2.4.2) 72 | base64 (0.1.1) 73 | bcrypt (3.1.19) 74 | bindex (0.8.1) 75 | bootsnap (1.16.0) 76 | msgpack (~> 1.2) 77 | builder (3.2.4) 78 | capybara (3.39.2) 79 | addressable 80 | matrix 81 | mini_mime (>= 0.1.3) 82 | nokogiri (~> 1.8) 83 | rack (>= 1.6.0) 84 | rack-test (>= 0.6.3) 85 | regexp_parser (>= 1.5, < 3.0) 86 | xpath (~> 3.2) 87 | concurrent-ruby (1.2.2) 88 | crass (1.0.6) 89 | date (3.3.3) 90 | debug (1.8.0) 91 | irb (>= 1.5.0) 92 | reline (>= 0.3.1) 93 | devise (4.9.2) 94 | bcrypt (~> 3.0) 95 | orm_adapter (~> 0.1) 96 | railties (>= 4.1.0) 97 | responders 98 | warden (~> 1.2.3) 99 | diff-lcs (1.5.0) 100 | erubi (1.12.0) 101 | globalid (1.2.1) 102 | activesupport (>= 6.1) 103 | i18n (1.14.1) 104 | concurrent-ruby (~> 1.0) 105 | importmap-rails (1.2.1) 106 | actionpack (>= 6.0.0) 107 | railties (>= 6.0.0) 108 | io-console (0.6.0) 109 | irb (1.8.1) 110 | rdoc 111 | reline (>= 0.3.8) 112 | jbuilder (2.11.5) 113 | actionview (>= 5.0.0) 114 | activesupport (>= 5.0.0) 115 | json (2.6.3) 116 | language_server-protocol (3.17.0.3) 117 | loofah (2.21.3) 118 | crass (~> 1.0.2) 119 | nokogiri (>= 1.12.0) 120 | mail (2.8.1) 121 | mini_mime (>= 0.1.1) 122 | net-imap 123 | net-pop 124 | net-smtp 125 | marcel (1.0.2) 126 | matrix (0.4.2) 127 | method_source (1.0.0) 128 | mini_mime (1.1.5) 129 | minitest (5.20.0) 130 | msgpack (1.7.2) 131 | net-imap (0.4.0) 132 | date 133 | net-protocol 134 | net-pop (0.1.2) 135 | net-protocol 136 | net-protocol (0.2.1) 137 | timeout 138 | net-smtp (0.4.0) 139 | net-protocol 140 | nio4r (2.5.9) 141 | nokogiri (1.15.4-x86_64-linux) 142 | racc (~> 1.4) 143 | orm_adapter (0.5.0) 144 | parallel (1.23.0) 145 | parser (3.2.2.4) 146 | ast (~> 2.4.1) 147 | racc 148 | pg (1.5.4) 149 | psych (5.1.0) 150 | stringio 151 | public_suffix (5.0.3) 152 | puma (5.6.7) 153 | nio4r (~> 2.0) 154 | racc (1.7.1) 155 | rack (2.2.8) 156 | rack-test (2.1.0) 157 | rack (>= 1.3) 158 | rails (7.0.8) 159 | actioncable (= 7.0.8) 160 | actionmailbox (= 7.0.8) 161 | actionmailer (= 7.0.8) 162 | actionpack (= 7.0.8) 163 | actiontext (= 7.0.8) 164 | actionview (= 7.0.8) 165 | activejob (= 7.0.8) 166 | activemodel (= 7.0.8) 167 | activerecord (= 7.0.8) 168 | activestorage (= 7.0.8) 169 | activesupport (= 7.0.8) 170 | bundler (>= 1.15.0) 171 | railties (= 7.0.8) 172 | rails-dom-testing (2.2.0) 173 | activesupport (>= 5.0.0) 174 | minitest 175 | nokogiri (>= 1.6) 176 | rails-html-sanitizer (1.6.0) 177 | loofah (~> 2.21) 178 | nokogiri (~> 1.14) 179 | railties (7.0.8) 180 | actionpack (= 7.0.8) 181 | activesupport (= 7.0.8) 182 | method_source 183 | rake (>= 12.2) 184 | thor (~> 1.0) 185 | zeitwerk (~> 2.5) 186 | rainbow (3.1.1) 187 | rake (13.0.6) 188 | rdoc (6.5.0) 189 | psych (>= 4.0.0) 190 | redis (4.8.1) 191 | regexp_parser (2.8.1) 192 | reline (0.3.9) 193 | io-console (~> 0.5) 194 | responders (3.1.0) 195 | actionpack (>= 5.2) 196 | railties (>= 5.2) 197 | rexml (3.2.6) 198 | rspec-core (3.12.2) 199 | rspec-support (~> 3.12.0) 200 | rspec-expectations (3.12.3) 201 | diff-lcs (>= 1.2.0, < 2.0) 202 | rspec-support (~> 3.12.0) 203 | rspec-mocks (3.12.6) 204 | diff-lcs (>= 1.2.0, < 2.0) 205 | rspec-support (~> 3.12.0) 206 | rspec-rails (6.0.3) 207 | actionpack (>= 6.1) 208 | activesupport (>= 6.1) 209 | railties (>= 6.1) 210 | rspec-core (~> 3.12) 211 | rspec-expectations (~> 3.12) 212 | rspec-mocks (~> 3.12) 213 | rspec-support (~> 3.12) 214 | rspec-support (3.12.1) 215 | rubocop (1.56.4) 216 | base64 (~> 0.1.1) 217 | json (~> 2.3) 218 | language_server-protocol (>= 3.17.0) 219 | parallel (~> 1.10) 220 | parser (>= 3.2.2.3) 221 | rainbow (>= 2.2.2, < 4.0) 222 | regexp_parser (>= 1.8, < 3.0) 223 | rexml (>= 3.2.5, < 4.0) 224 | rubocop-ast (>= 1.28.1, < 2.0) 225 | ruby-progressbar (~> 1.7) 226 | unicode-display_width (>= 2.4.0, < 3.0) 227 | rubocop-ast (1.29.0) 228 | parser (>= 3.2.1.0) 229 | ruby-progressbar (1.13.0) 230 | rubyzip (2.3.2) 231 | selenium-webdriver (4.13.1) 232 | rexml (~> 3.2, >= 3.2.5) 233 | rubyzip (>= 1.2.2, < 3.0) 234 | websocket (~> 1.0) 235 | sprockets (4.2.1) 236 | concurrent-ruby (~> 1.0) 237 | rack (>= 2.2.4, < 4) 238 | sprockets-rails (3.4.2) 239 | actionpack (>= 5.2) 240 | activesupport (>= 5.2) 241 | sprockets (>= 3.0.0) 242 | stimulus-rails (1.2.2) 243 | railties (>= 6.0.0) 244 | stringio (3.0.8) 245 | thor (1.2.2) 246 | timeout (0.4.0) 247 | turbo-rails (1.4.0) 248 | actionpack (>= 6.0.0) 249 | activejob (>= 6.0.0) 250 | railties (>= 6.0.0) 251 | tzinfo (2.0.6) 252 | concurrent-ruby (~> 1.0) 253 | unicode-display_width (2.5.0) 254 | warden (1.2.9) 255 | rack (>= 2.0.9) 256 | web-console (4.2.1) 257 | actionview (>= 6.0.0) 258 | activemodel (>= 6.0.0) 259 | bindex (>= 0.4.0) 260 | railties (>= 6.0.0) 261 | webdrivers (5.2.0) 262 | nokogiri (~> 1.6) 263 | rubyzip (>= 1.3.0) 264 | selenium-webdriver (~> 4.0) 265 | websocket (1.2.10) 266 | websocket-driver (0.7.6) 267 | websocket-extensions (>= 0.1.0) 268 | websocket-extensions (0.1.5) 269 | xpath (3.2.0) 270 | nokogiri (~> 1.8) 271 | zeitwerk (2.6.12) 272 | 273 | PLATFORMS 274 | x86_64-linux 275 | 276 | DEPENDENCIES 277 | bootsnap 278 | capybara 279 | debug 280 | devise 281 | importmap-rails 282 | jbuilder 283 | pg (~> 1.1) 284 | puma (~> 5.0) 285 | rails (~> 7.0.8) 286 | redis (~> 4.0) 287 | rspec-rails 288 | rubocop (>= 1.0, < 2.0) 289 | selenium-webdriver 290 | sprockets-rails 291 | stimulus-rails 292 | turbo-rails 293 | tzinfo-data 294 | web-console 295 | webdrivers 296 | 297 | RUBY VERSION 298 | ruby 3.2.2p53 299 | 300 | BUNDLED WITH 301 | 2.4.19 302 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Assuming you have not yet modified this file, each configuration option below 4 | # is set to its default value. Note that some are commented out while others 5 | # are not: uncommented lines are intended to protect your configuration from 6 | # breaking changes in upgrades (i.e., in the event that future versions of 7 | # Devise change the default values for those options). 8 | # 9 | # Use this hook to configure devise mailer, warden hooks and so forth. 10 | # Many of these configuration options can be set straight in your model. 11 | Devise.setup do |config| 12 | # The secret key used by Devise. Devise uses this key to generate 13 | # random tokens. Changing this key will render invalid all existing 14 | # confirmation, reset password and unlock tokens in the database. 15 | # Devise will use the `secret_key_base` as its `secret_key` 16 | # by default. You can change it below and use your own secret key. 17 | # config.secret_key = 'a672e535d2a34cd6af7af942c9ed90c1b568d76585289811cf1cb1ca59627f9d130f0c125efba64e12bae817d698418e21c5ee0f26711b14169d2229ea865e96' 18 | 19 | # ==> Controller configuration 20 | # Configure the parent class to the devise controllers. 21 | # config.parent_controller = 'DeviseController' 22 | 23 | # ==> Mailer Configuration 24 | # Configure the e-mail address which will be shown in Devise::Mailer, 25 | # note that it will be overwritten if you use your own mailer class 26 | # with default "from" parameter. 27 | config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' 28 | 29 | # Configure the class responsible to send e-mails. 30 | # config.mailer = 'Devise::Mailer' 31 | 32 | # Configure the parent class responsible to send e-mails. 33 | # config.parent_mailer = 'ActionMailer::Base' 34 | 35 | # ==> ORM configuration 36 | # Load and configure the ORM. Supports :active_record (default) and 37 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 38 | # available as additional gems. 39 | require 'devise/orm/active_record' 40 | 41 | # ==> Configuration for any authentication mechanism 42 | # Configure which keys are used when authenticating a user. The default is 43 | # just :email. You can configure it to use [:username, :subdomain], so for 44 | # authenticating a user, both parameters are required. Remember that those 45 | # parameters are used only when authenticating and not when retrieving from 46 | # session. If you need permissions, you should implement that in a before filter. 47 | # You can also supply a hash where the value is a boolean determining whether 48 | # or not authentication should be aborted when the value is not present. 49 | # config.authentication_keys = [:email] 50 | 51 | # Configure parameters from the request object used for authentication. Each entry 52 | # given should be a request method and it will automatically be passed to the 53 | # find_for_authentication method and considered in your model lookup. For instance, 54 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 55 | # The same considerations mentioned for authentication_keys also apply to request_keys. 56 | # config.request_keys = [] 57 | 58 | # Configure which authentication keys should be case-insensitive. 59 | # These keys will be downcased upon creating or modifying a user and when used 60 | # to authenticate or find a user. Default is :email. 61 | config.case_insensitive_keys = [:email] 62 | 63 | # Configure which authentication keys should have whitespace stripped. 64 | # These keys will have whitespace before and after removed upon creating or 65 | # modifying a user and when used to authenticate or find a user. Default is :email. 66 | config.strip_whitespace_keys = [:email] 67 | 68 | # Tell if authentication through request.params is enabled. True by default. 69 | # It can be set to an array that will enable params authentication only for the 70 | # given strategies, for example, `config.params_authenticatable = [:database]` will 71 | # enable it only for database (email + password) authentication. 72 | # config.params_authenticatable = true 73 | 74 | # Tell if authentication through HTTP Auth is enabled. False by default. 75 | # It can be set to an array that will enable http authentication only for the 76 | # given strategies, for example, `config.http_authenticatable = [:database]` will 77 | # enable it only for database authentication. 78 | # For API-only applications to support authentication "out-of-the-box", you will likely want to 79 | # enable this with :database unless you are using a custom strategy. 80 | # The supported strategies are: 81 | # :database = Support basic authentication with authentication key + password 82 | # config.http_authenticatable = false 83 | 84 | # If 401 status code should be returned for AJAX requests. True by default. 85 | # config.http_authenticatable_on_xhr = true 86 | 87 | # The realm used in Http Basic Authentication. 'Application' by default. 88 | # config.http_authentication_realm = 'Application' 89 | 90 | # It will change confirmation, password recovery and other workflows 91 | # to behave the same regardless if the e-mail provided was right or wrong. 92 | # Does not affect registerable. 93 | # config.paranoid = true 94 | 95 | # By default Devise will store the user in session. You can skip storage for 96 | # particular strategies by setting this option. 97 | # Notice that if you are skipping storage for all authentication paths, you 98 | # may want to disable generating routes to Devise's sessions controller by 99 | # passing skip: :sessions to `devise_for` in your config/routes.rb 100 | config.skip_session_storage = [:http_auth] 101 | 102 | # By default, Devise cleans up the CSRF token on authentication to 103 | # avoid CSRF token fixation attacks. This means that, when using AJAX 104 | # requests for sign in and sign up, you need to get a new CSRF token 105 | # from the server. You can disable this option at your own risk. 106 | # config.clean_up_csrf_token_on_authentication = true 107 | 108 | # When false, Devise will not attempt to reload routes on eager load. 109 | # This can reduce the time taken to boot the app but if your application 110 | # requires the Devise mappings to be loaded during boot time the application 111 | # won't boot properly. 112 | # config.reload_routes = true 113 | 114 | # ==> Configuration for :database_authenticatable 115 | # For bcrypt, this is the cost for hashing the password and defaults to 12. If 116 | # using other algorithms, it sets how many times you want the password to be hashed. 117 | # The number of stretches used for generating the hashed password are stored 118 | # with the hashed password. This allows you to change the stretches without 119 | # invalidating existing passwords. 120 | # 121 | # Limiting the stretches to just one in testing will increase the performance of 122 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 123 | # a value less than 10 in other environments. Note that, for bcrypt (the default 124 | # algorithm), the cost increases exponentially with the number of stretches (e.g. 125 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). 126 | config.stretches = Rails.env.test? ? 1 : 12 127 | 128 | # Set up a pepper to generate the hashed password. 129 | # config.pepper = '09a37c082d5817aeccdcf0cac0e2cf2bfbcd36db228987b49e1534be8ad1fe54f6b9714d625eabed9570b961bf9a61a5872b0954bf538f234f774c0a6e70bfed' 130 | 131 | # Send a notification to the original email when the user's email is changed. 132 | # config.send_email_changed_notification = false 133 | 134 | # Send a notification email when the user's password is changed. 135 | # config.send_password_change_notification = false 136 | 137 | # ==> Configuration for :confirmable 138 | # A period that the user is allowed to access the website even without 139 | # confirming their account. For instance, if set to 2.days, the user will be 140 | # able to access the website for two days without confirming their account, 141 | # access will be blocked just in the third day. 142 | # You can also set it to nil, which will allow the user to access the website 143 | # without confirming their account. 144 | # Default is 0.days, meaning the user cannot access the website without 145 | # confirming their account. 146 | # config.allow_unconfirmed_access_for = 2.days 147 | 148 | # A period that the user is allowed to confirm their account before their 149 | # token becomes invalid. For example, if set to 3.days, the user can confirm 150 | # their account within 3 days after the mail was sent, but on the fourth day 151 | # their account can't be confirmed with the token any more. 152 | # Default is nil, meaning there is no restriction on how long a user can take 153 | # before confirming their account. 154 | # config.confirm_within = 3.days 155 | 156 | # If true, requires any email changes to be confirmed (exactly the same way as 157 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 158 | # db field (see migrations). Until confirmed, new email is stored in 159 | # unconfirmed_email column, and copied to email column on successful confirmation. 160 | config.reconfirmable = true 161 | 162 | # Defines which key will be used when confirming an account 163 | # config.confirmation_keys = [:email] 164 | 165 | # ==> Configuration for :rememberable 166 | # The time the user will be remembered without asking for credentials again. 167 | # config.remember_for = 2.weeks 168 | 169 | # Invalidates all the remember me tokens when the user signs out. 170 | config.expire_all_remember_me_on_sign_out = true 171 | 172 | # If true, extends the user's remember period when remembered via cookie. 173 | # config.extend_remember_period = false 174 | 175 | # Options to be passed to the created cookie. For instance, you can set 176 | # secure: true in order to force SSL only cookies. 177 | # config.rememberable_options = {} 178 | 179 | # ==> Configuration for :validatable 180 | # Range for password length. 181 | config.password_length = 6..128 182 | 183 | # Email regex used to validate email formats. It simply asserts that 184 | # one (and only one) @ exists in the given string. This is mainly 185 | # to give user feedback and not to assert the e-mail validity. 186 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ 187 | 188 | # ==> Configuration for :timeoutable 189 | # The time you want to timeout the user session without activity. After this 190 | # time the user will be asked for credentials again. Default is 30 minutes. 191 | # config.timeout_in = 30.minutes 192 | 193 | # ==> Configuration for :lockable 194 | # Defines which strategy will be used to lock an account. 195 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 196 | # :none = No lock strategy. You should handle locking by yourself. 197 | # config.lock_strategy = :failed_attempts 198 | 199 | # Defines which key will be used when locking and unlocking an account 200 | # config.unlock_keys = [:email] 201 | 202 | # Defines which strategy will be used to unlock an account. 203 | # :email = Sends an unlock link to the user email 204 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 205 | # :both = Enables both strategies 206 | # :none = No unlock strategy. You should handle unlocking by yourself. 207 | # config.unlock_strategy = :both 208 | 209 | # Number of authentication tries before locking an account if lock_strategy 210 | # is failed attempts. 211 | # config.maximum_attempts = 20 212 | 213 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 214 | # config.unlock_in = 1.hour 215 | 216 | # Warn on the last attempt before the account is locked. 217 | # config.last_attempt_warning = true 218 | 219 | # ==> Configuration for :recoverable 220 | # 221 | # Defines which key will be used when recovering the password for an account 222 | # config.reset_password_keys = [:email] 223 | 224 | # Time interval you can reset your password with a reset password key. 225 | # Don't put a too small interval or your users won't have the time to 226 | # change their passwords. 227 | config.reset_password_within = 6.hours 228 | 229 | # When set to false, does not sign a user in automatically after their password is 230 | # reset. Defaults to true, so a user is signed in automatically after a reset. 231 | # config.sign_in_after_reset_password = true 232 | 233 | # ==> Configuration for :encryptable 234 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default). 235 | # You can use :sha1, :sha512 or algorithms from others authentication tools as 236 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 237 | # for default behavior) and :restful_authentication_sha1 (then you should set 238 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). 239 | # 240 | # Require the `devise-encryptable` gem when using anything other than bcrypt 241 | # config.encryptor = :sha512 242 | 243 | # ==> Scopes configuration 244 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 245 | # "users/sessions/new". It's turned off by default because it's slower if you 246 | # are using only default views. 247 | # config.scoped_views = false 248 | 249 | # Configure the default scope given to Warden. By default it's the first 250 | # devise role declared in your routes (usually :user). 251 | # config.default_scope = :user 252 | 253 | # Set this configuration to false if you want /users/sign_out to sign out 254 | # only the current scope. By default, Devise signs out all scopes. 255 | # config.sign_out_all_scopes = true 256 | 257 | # ==> Navigation configuration 258 | # Lists the formats that should be treated as navigational. Formats like 259 | # :html should redirect to the sign in page when the user does not have 260 | # access, but formats like :xml or :json, should return 401. 261 | # 262 | # If you have any extra navigational formats, like :iphone or :mobile, you 263 | # should add them to the navigational formats lists. 264 | # 265 | # The "*/*" below is required to match Internet Explorer requests. 266 | config.navigational_formats = ['*/*', :html, :turbo_stream] 267 | 268 | # The default HTTP method used to sign out a resource. Default is :delete. 269 | config.sign_out_via = :delete 270 | 271 | # ==> OmniAuth 272 | # Add a new OmniAuth provider. Check the wiki for more information on setting 273 | # up on your models and hooks. 274 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 275 | 276 | # ==> Warden configuration 277 | # If you want to use other strategies, that are not supported by Devise, or 278 | # change the failure app, you can configure them inside the config.warden block. 279 | # 280 | # config.warden do |manager| 281 | # manager.intercept_401 = false 282 | # manager.default_strategies(scope: :user).unshift :some_external_strategy 283 | # end 284 | 285 | # ==> Mountable engine configurations 286 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 287 | # is mountable, there are some extra configurations to be taken into account. 288 | # The following options are available, assuming the engine is mounted as: 289 | # 290 | # mount MyEngine, at: '/my_engine' 291 | # 292 | # The router that invoked `devise_for`, in the example above, would be: 293 | # config.router_name = :my_engine 294 | # 295 | # When using OmniAuth, Devise cannot automatically set OmniAuth path, 296 | # so you need to do it manually. For the users scope, it would be: 297 | # config.omniauth_path_prefix = '/my_engine/users/auth' 298 | 299 | # ==> Hotwire/Turbo configuration 300 | # When using Devise with Hotwire/Turbo, the http status for error responses 301 | # and some redirects must match the following. The default in Devise for existing 302 | # apps is `200 OK` and `302 Found respectively`, but new apps are generated with 303 | # these new defaults that match Hotwire/Turbo behavior. 304 | # Note: These might become the new default in future versions of Devise. 305 | config.responder.error_status = :unprocessable_entity 306 | config.responder.redirect_status = :see_other 307 | 308 | # ==> Configuration for :registerable 309 | 310 | # When set to false, does not sign a user in automatically after their password is 311 | # changed. Defaults to true, so a user is signed in automatically after changing a password. 312 | # config.sign_in_after_change_password = true 313 | end 314 | --------------------------------------------------------------------------------