rubocop corrections
This commit is contained in:
parent
c63c6bc448
commit
de29815686
72 changed files with 468 additions and 311 deletions
14
Gemfile
14
Gemfile
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
source 'https://rubygems.org'
|
||||
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
||||
|
||||
|
@ -32,12 +34,14 @@ gem 'jquery-rails'
|
|||
# Reduces boot times through caching; required in config/boot.rb
|
||||
gem 'bootsnap', '>= 1.4.4', require: false
|
||||
|
||||
gem 'rubocop', require: false
|
||||
|
||||
group :development, :test do
|
||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
|
||||
gem 'rspec'
|
||||
gem 'rspec-rails', ">= 2.0.0.beta"
|
||||
gem 'byebug', platforms: %i[mri mingw x64_mingw]
|
||||
gem 'rails-controller-testing'
|
||||
gem 'rspec'
|
||||
gem 'rspec-rails', '>= 2.0.0.beta'
|
||||
end
|
||||
|
||||
group :development do
|
||||
|
@ -45,8 +49,8 @@ group :development do
|
|||
gem 'web-console', '>= 4.1.0'
|
||||
# Display performance information such as SQL time and flame graphs for each request in your browser.
|
||||
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
|
||||
gem 'rack-mini-profiler', '~> 2.0'
|
||||
gem 'listen', '~> 3.3'
|
||||
gem 'rack-mini-profiler', '~> 2.0'
|
||||
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
||||
gem 'spring'
|
||||
end
|
||||
|
@ -60,4 +64,4 @@ group :test do
|
|||
end
|
||||
|
||||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
|
||||
|
|
20
Gemfile.lock
20
Gemfile.lock
|
@ -62,6 +62,7 @@ GEM
|
|||
zeitwerk (~> 2.3)
|
||||
addressable (2.7.0)
|
||||
public_suffix (>= 2.0.2, < 5.0)
|
||||
ast (2.4.2)
|
||||
autoprefixer-rails (10.2.4.0)
|
||||
execjs
|
||||
bcrypt (3.1.16)
|
||||
|
@ -117,6 +118,9 @@ GEM
|
|||
nokogiri (1.11.2)
|
||||
mini_portile2 (~> 2.5.0)
|
||||
racc (~> 1.4)
|
||||
parallel (1.20.1)
|
||||
parser (3.0.0.0)
|
||||
ast (~> 2.4.1)
|
||||
public_suffix (4.0.6)
|
||||
puma (5.2.2)
|
||||
nio4r (~> 2.0)
|
||||
|
@ -158,11 +162,13 @@ GEM
|
|||
method_source
|
||||
rake (>= 0.8.7)
|
||||
thor (~> 1.0)
|
||||
rainbow (3.0.0)
|
||||
rake (13.0.3)
|
||||
rb-fsevent (0.10.4)
|
||||
rb-inotify (0.10.1)
|
||||
ffi (~> 1.0)
|
||||
regexp_parser (2.1.1)
|
||||
rexml (3.2.4)
|
||||
rspec (3.10.0)
|
||||
rspec-core (~> 3.10.0)
|
||||
rspec-expectations (~> 3.10.0)
|
||||
|
@ -184,6 +190,18 @@ GEM
|
|||
rspec-mocks (~> 3.10)
|
||||
rspec-support (~> 3.10)
|
||||
rspec-support (3.10.2)
|
||||
rubocop (1.11.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.0.0.0)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
regexp_parser (>= 1.8, < 3.0)
|
||||
rexml
|
||||
rubocop-ast (>= 1.2.0, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 1.4.0, < 3.0)
|
||||
rubocop-ast (1.4.1)
|
||||
parser (>= 2.7.1.5)
|
||||
ruby-progressbar (1.11.0)
|
||||
rubyzip (2.3.0)
|
||||
sass-rails (6.0.0)
|
||||
sassc-rails (~> 2.1, >= 2.1.1)
|
||||
|
@ -215,6 +233,7 @@ GEM
|
|||
turbolinks-source (5.2.0)
|
||||
tzinfo (2.0.4)
|
||||
concurrent-ruby (~> 1.0)
|
||||
unicode-display_width (2.0.0)
|
||||
web-console (4.1.0)
|
||||
actionview (>= 6.0.0)
|
||||
activemodel (>= 6.0.0)
|
||||
|
@ -254,6 +273,7 @@ DEPENDENCIES
|
|||
rails-controller-testing
|
||||
rspec
|
||||
rspec-rails (>= 2.0.0.beta)
|
||||
rubocop
|
||||
sass-rails (>= 6)
|
||||
selenium-webdriver
|
||||
spring
|
||||
|
|
4
Rakefile
4
Rakefile
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
||||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
||||
|
||||
require_relative "config/application"
|
||||
require_relative 'config/application'
|
||||
|
||||
Rails.application.load_tasks
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ApplicationCable
|
||||
class Channel < ActionCable::Channel::Base
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ApplicationCable
|
||||
class Connection < ActionCable::Connection::Base
|
||||
end
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Base for application controllers
|
||||
class ApplicationController < ActionController::Base
|
||||
helper_method :current_user
|
||||
helper_method :logged_in?
|
||||
|
@ -5,7 +8,7 @@ class ApplicationController < ActionController::Base
|
|||
def current_user
|
||||
User.find_by(id: session[:user_id])
|
||||
end
|
||||
|
||||
|
||||
def logged_in?
|
||||
!current_user.nil?
|
||||
end
|
||||
|
@ -13,15 +16,13 @@ class ApplicationController < ActionController::Base
|
|||
protected
|
||||
|
||||
def notices_from_errors(record)
|
||||
messages = record.errors.messages.map do |attribute, messages|
|
||||
errors = record.errors.messages.map do |attribute, messages|
|
||||
messages.map { |message| "#{attribute} #{message}".capitalize }
|
||||
end
|
||||
messages.flatten
|
||||
errors.flatten
|
||||
end
|
||||
|
||||
def ensure_admin
|
||||
unless current_user&.admin?
|
||||
redirect_to '/welcome', notice: 'You are not allowed to perform this action'
|
||||
end
|
||||
redirect_to '/welcome', notice: 'You are not allowed to perform this action' unless current_user&.admin?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Authors controller
|
||||
class AuthorsController < ApplicationController
|
||||
before_action :ensure_admin
|
||||
before_action :set_author, only: [:edit, :update]
|
||||
before_action :set_author, only: %i[edit update]
|
||||
|
||||
def index
|
||||
@authors = Author.all
|
||||
|
@ -11,9 +14,7 @@ class AuthorsController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
if @author.update(author_params)
|
||||
redirect_to '/authors'
|
||||
end
|
||||
redirect_to '/authors' if @author.update(author_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Books controller
|
||||
class BooksController < ApplicationController
|
||||
before_action :set_book, only: [:show, :edit, :update, :add_to_cart]
|
||||
before_action :ensure_admin, only: [:edit, :update]
|
||||
before_action :set_book, only: %i[show edit update add_to_cart]
|
||||
before_action :ensure_admin, only: %i[edit update]
|
||||
|
||||
def index
|
||||
if current_user&.admin?
|
||||
books = Book.all
|
||||
else
|
||||
books = Book.published
|
||||
end
|
||||
books = if current_user&.admin?
|
||||
Book.all
|
||||
else
|
||||
Book.published
|
||||
end
|
||||
@books = books.map { |book| BooksPresenter.new(book) }
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @book.update(book_params)
|
||||
redirect_to '/books'
|
||||
end
|
||||
redirect_to '/books' if @book.update(book_params)
|
||||
end
|
||||
|
||||
def add_to_cart
|
||||
|
|
|
@ -1,23 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Sessions controller
|
||||
class SessionsController < ApplicationController
|
||||
def new
|
||||
end
|
||||
def new; end
|
||||
|
||||
def create
|
||||
@user = User.find_by(email: params[:email])
|
||||
unless @user
|
||||
redirect_to '/welcome', notice: 'Wrong email address'
|
||||
return
|
||||
problem = problem_with_login
|
||||
if problem
|
||||
redirect_to '/welcome', notice: problem
|
||||
else
|
||||
session[:user_id] = @user.id
|
||||
redirect_to '/welcome'
|
||||
end
|
||||
unless @user.authenticate(params[:password])
|
||||
redirect_to '/welcome', notice: 'Wrong password'
|
||||
return
|
||||
end
|
||||
if @user.blocked?
|
||||
redirect_to '/welcome', notice: 'You are blocked, please contact support'
|
||||
return
|
||||
end
|
||||
session[:user_id] = @user.id
|
||||
redirect_to '/welcome'
|
||||
end
|
||||
|
||||
def delete
|
||||
|
@ -25,6 +20,17 @@ class SessionsController < ApplicationController
|
|||
redirect_to '/welcome', notice: 'Logged out properly'
|
||||
end
|
||||
|
||||
def welcome
|
||||
def welcome; end
|
||||
|
||||
private
|
||||
|
||||
def problem_with_login
|
||||
if !@user
|
||||
'Wrong email address'
|
||||
elsif !@user.authenticate(params[:password])
|
||||
'Wrong password'
|
||||
elsif @user.blocked?
|
||||
'You are blocked, please contact support'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Users controller
|
||||
class UsersController < ApplicationController
|
||||
before_action :ensure_admin, only: [:destroy, :block]
|
||||
before_action :ensure_admin, only: %i[destroy block]
|
||||
|
||||
def index
|
||||
@users = User.all
|
||||
|
@ -21,15 +24,14 @@ class UsersController < ApplicationController
|
|||
|
||||
def password_recovery_request
|
||||
@user = User.where(email: params['email']).first
|
||||
recovery_password = ('a'..'z').to_a.shuffle[0,8].join
|
||||
recovery_password = ('a'..'z').to_a.sample(8).join
|
||||
@user.recovery_password = recovery_password
|
||||
@user.save
|
||||
UserMailer.with(user: @user, recovery_password: recovery_password).password_recovery.deliver_now
|
||||
redirect_to '/welcome', notice: "Recovery email sent to #{params['email']}"
|
||||
end
|
||||
|
||||
def password_recovery_request_form
|
||||
end
|
||||
def password_recovery_request_form; end
|
||||
|
||||
def recover_password_form
|
||||
@recovery_password = params[:recovery_password]
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ApplicationHelper
|
||||
end
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module BooksHelper
|
||||
def cart_summary
|
||||
number_to_currency(@books.map{ |b| b.price }.reduce(:+))
|
||||
number_to_currency(@books.map(&:price).reduce(:+))
|
||||
end
|
||||
|
||||
def can_book_be_added?(book)
|
||||
logged_in? && book.quantity.positive? && !current_user.books.exists?(book.id)
|
||||
end
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module SessionsHelper
|
||||
end
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module UsersHelper
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationJob < ActiveJob::Base
|
||||
# Automatically retry jobs that encountered a deadlock
|
||||
# retry_on ActiveRecord::Deadlocked
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: 'from@example.com'
|
||||
layout 'mailer'
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class UserMailer < ApplicationMailer
|
||||
def password_recovery
|
||||
@user = params[:user]
|
||||
|
|
|
@ -1,23 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
def update(*args)
|
||||
result = super(*args)
|
||||
AuditRecord.create(model: self.class, action: 'update', params: self.to_json)
|
||||
AuditRecord.create(model: self.class, action: 'update', params: to_json)
|
||||
result
|
||||
end
|
||||
|
||||
def save(*args)
|
||||
result = super(*args)
|
||||
AuditRecord.create(model: self.class, action: 'save', params: self.to_json)
|
||||
AuditRecord.create(model: self.class, action: 'save', params: to_json)
|
||||
result
|
||||
end
|
||||
|
||||
def self.create(*args)
|
||||
result = super(*args)
|
||||
AuditRecord.create(model: self.class, action: 'create', params: result.to_json)
|
||||
result
|
||||
end
|
||||
|
||||
def decrement!(*args)
|
||||
result = super(*args)
|
||||
AuditRecord.create(model: self.class, action: 'decrement!', params: self.to_json)
|
||||
AuditRecord.create(model: self.class, action: 'decrement!', params: to_json)
|
||||
result
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AuditRecord < ActiveRecord::Base
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Author < ApplicationRecord
|
||||
validates :first_name, presence: true
|
||||
validates :last_name, presence: true
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Book < ApplicationRecord
|
||||
has_and_belongs_to_many :authors
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class User < ApplicationRecord
|
||||
has_and_belongs_to_many :books
|
||||
|
||||
has_secure_password
|
||||
has_secure_password :recovery_password, validations: false
|
||||
enum role: [:customer, :admin], _default: :customer
|
||||
enum status: [:ready, :blocked], _default: :ready
|
||||
enum role: %i[customer admin], _default: :customer
|
||||
enum status: %i[ready blocked], _default: :ready
|
||||
|
||||
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
||||
validates :role, presence: true
|
||||
|
@ -12,6 +14,6 @@ class User < ApplicationRecord
|
|||
validates :password, {
|
||||
presence: true,
|
||||
length: { minimum: 8 },
|
||||
if: lambda{ new_record? || !password.nil? }
|
||||
if: -> { new_record? || !password.nil? }
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class BooksPresenter < SimpleDelegator
|
||||
include ActiveSupport::NumberHelper
|
||||
|
||||
|
|
46
bin/bundle
46
bin/bundle
|
@ -8,46 +8,46 @@
|
|||
# this file is here to facilitate running it.
|
||||
#
|
||||
|
||||
require "rubygems"
|
||||
require 'rubygems'
|
||||
|
||||
m = Module.new do
|
||||
module_function
|
||||
|
||||
def invoked_as_script?
|
||||
File.expand_path($0) == File.expand_path(__FILE__)
|
||||
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
|
||||
end
|
||||
|
||||
def env_var_version
|
||||
ENV["BUNDLER_VERSION"]
|
||||
ENV['BUNDLER_VERSION']
|
||||
end
|
||||
|
||||
def cli_arg_version
|
||||
return unless invoked_as_script? # don't want to hijack other binstubs
|
||||
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
||||
return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
|
||||
|
||||
bundler_version = nil
|
||||
update_index = nil
|
||||
ARGV.each_with_index do |a, i|
|
||||
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
||||
bundler_version = a
|
||||
end
|
||||
bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
||||
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
||||
bundler_version = $1
|
||||
|
||||
bundler_version = Regexp.last_match(1)
|
||||
update_index = i
|
||||
end
|
||||
bundler_version
|
||||
end
|
||||
|
||||
def gemfile
|
||||
gemfile = ENV["BUNDLE_GEMFILE"]
|
||||
gemfile = ENV['BUNDLE_GEMFILE']
|
||||
return gemfile if gemfile && !gemfile.empty?
|
||||
|
||||
File.expand_path("../../Gemfile", __FILE__)
|
||||
File.expand_path('../Gemfile', __dir__)
|
||||
end
|
||||
|
||||
def lockfile
|
||||
lockfile =
|
||||
case File.basename(gemfile)
|
||||
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
||||
when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
|
||||
else "#{gemfile}.lock"
|
||||
end
|
||||
File.expand_path(lockfile)
|
||||
|
@ -55,15 +55,17 @@ m = Module.new do
|
|||
|
||||
def lockfile_version
|
||||
return unless File.file?(lockfile)
|
||||
|
||||
lockfile_contents = File.read(lockfile)
|
||||
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
||||
|
||||
Regexp.last_match(1)
|
||||
end
|
||||
|
||||
def bundler_version
|
||||
@bundler_version ||=
|
||||
env_var_version || cli_arg_version ||
|
||||
lockfile_version
|
||||
lockfile_version
|
||||
end
|
||||
|
||||
def bundler_requirement
|
||||
|
@ -73,28 +75,32 @@ m = Module.new do
|
|||
|
||||
requirement = bundler_gem_version.approximate_recommendation
|
||||
|
||||
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
||||
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new('2.7.0')
|
||||
|
||||
requirement += ".a" if bundler_gem_version.prerelease?
|
||||
requirement += '.a' if bundler_gem_version.prerelease?
|
||||
|
||||
requirement
|
||||
end
|
||||
|
||||
def load_bundler!
|
||||
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
||||
ENV['BUNDLE_GEMFILE'] ||= gemfile
|
||||
|
||||
activate_bundler
|
||||
end
|
||||
|
||||
def activate_bundler
|
||||
gem_error = activation_error_handling do
|
||||
gem "bundler", bundler_requirement
|
||||
gem 'bundler', bundler_requirement
|
||||
end
|
||||
return if gem_error.nil?
|
||||
|
||||
require_error = activation_error_handling do
|
||||
require "bundler/version"
|
||||
require 'bundler/version'
|
||||
end
|
||||
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
||||
if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
||||
return
|
||||
end
|
||||
|
||||
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}'`"
|
||||
exit 42
|
||||
end
|
||||
|
@ -109,6 +115,4 @@ end
|
|||
|
||||
m.load_bundler!
|
||||
|
||||
if m.invoked_as_script?
|
||||
load Gem.bin_path("bundler", "bundle")
|
||||
end
|
||||
load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
load File.expand_path("spring", __dir__)
|
||||
# frozen_string_literal: true
|
||||
|
||||
load File.expand_path('spring', __dir__)
|
||||
APP_PATH = File.expand_path('../config/application', __dir__)
|
||||
require_relative "../config/boot"
|
||||
require "rails/commands"
|
||||
require_relative '../config/boot'
|
||||
require 'rails/commands'
|
||||
|
|
8
bin/rake
8
bin/rake
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
load File.expand_path("spring", __dir__)
|
||||
require_relative "../config/boot"
|
||||
require "rake"
|
||||
# frozen_string_literal: true
|
||||
|
||||
load File.expand_path('spring', __dir__)
|
||||
require_relative '../config/boot'
|
||||
require 'rake'
|
||||
Rake.application.run
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env ruby
|
||||
require "fileutils"
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'fileutils'
|
||||
|
||||
# path to your application root.
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
|
|
14
bin/spring
14
bin/spring
|
@ -1,13 +1,15 @@
|
|||
#!/usr/bin/env ruby
|
||||
if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
|
||||
gem "bundler"
|
||||
require "bundler"
|
||||
# frozen_string_literal: true
|
||||
|
||||
if !defined?(Spring) && [nil, 'development', 'test'].include?(ENV['RAILS_ENV'])
|
||||
gem 'bundler'
|
||||
require 'bundler'
|
||||
|
||||
# Load Spring without loading other gems in the Gemfile, for speed.
|
||||
Bundler.locked_gems&.specs&.find { |spec| spec.name == "spring" }&.tap do |spring|
|
||||
Bundler.locked_gems&.specs&.find { |spec| spec.name == 'spring' }&.tap do |spring|
|
||||
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
|
||||
gem "spring", spring.version
|
||||
require "spring/binstub"
|
||||
gem 'spring', spring.version
|
||||
require 'spring/binstub'
|
||||
rescue Gem::LoadError
|
||||
# Ignore when Spring is not installed.
|
||||
end
|
||||
|
|
19
bin/webpack
19
bin/webpack
|
@ -1,18 +1,19 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
||||
ENV["NODE_ENV"] ||= "development"
|
||||
ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
|
||||
ENV['NODE_ENV'] ||= 'development'
|
||||
|
||||
require "pathname"
|
||||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
||||
Pathname.new(__FILE__).realpath)
|
||||
require 'pathname'
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
||||
Pathname.new(__FILE__).realpath)
|
||||
|
||||
require "bundler/setup"
|
||||
require 'bundler/setup'
|
||||
|
||||
require "webpacker"
|
||||
require "webpacker/webpack_runner"
|
||||
require 'webpacker'
|
||||
require 'webpacker/webpack_runner'
|
||||
|
||||
APP_ROOT = File.expand_path("..", __dir__)
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
Dir.chdir(APP_ROOT) do
|
||||
Webpacker::WebpackRunner.run(ARGV)
|
||||
end
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
||||
ENV["NODE_ENV"] ||= "development"
|
||||
ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
|
||||
ENV['NODE_ENV'] ||= 'development'
|
||||
|
||||
require "pathname"
|
||||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
||||
Pathname.new(__FILE__).realpath)
|
||||
require 'pathname'
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
||||
Pathname.new(__FILE__).realpath)
|
||||
|
||||
require "bundler/setup"
|
||||
require 'bundler/setup'
|
||||
|
||||
require "webpacker"
|
||||
require "webpacker/dev_server_runner"
|
||||
require 'webpacker'
|
||||
require 'webpacker/dev_server_runner'
|
||||
|
||||
APP_ROOT = File.expand_path("..", __dir__)
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
Dir.chdir(APP_ROOT) do
|
||||
Webpacker::DevServerRunner.run(ARGV)
|
||||
end
|
||||
|
|
16
bin/yarn
16
bin/yarn
|
@ -1,17 +1,19 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
APP_ROOT = File.expand_path('..', __dir__)
|
||||
Dir.chdir(APP_ROOT) do
|
||||
yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
|
||||
select { |dir| File.expand_path(dir) != __dir__ }.
|
||||
product(["yarn", "yarn.cmd", "yarn.ps1"]).
|
||||
map { |dir, file| File.expand_path(file, dir) }.
|
||||
find { |file| File.executable?(file) }
|
||||
yarn = ENV['PATH'].split(File::PATH_SEPARATOR)
|
||||
.reject { |dir| File.expand_path(dir) == __dir__ }
|
||||
.product(['yarn', 'yarn.cmd', 'yarn.ps1'])
|
||||
.map { |dir, file| File.expand_path(file, dir) }
|
||||
.find { |file| File.executable?(file) }
|
||||
|
||||
if yarn
|
||||
exec yarn, *ARGV
|
||||
else
|
||||
$stderr.puts "Yarn executable was not detected in the system."
|
||||
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
|
||||
warn 'Yarn executable was not detected in the system.'
|
||||
warn 'Download Yarn at https://yarnpkg.com/en/docs/install'
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# This file is used by Rack-based servers to start the application.
|
||||
|
||||
require_relative "config/environment"
|
||||
require_relative 'config/environment'
|
||||
|
||||
run Rails.application
|
||||
Rails.application.load_server
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require_relative "boot"
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails/all"
|
||||
require_relative 'boot'
|
||||
|
||||
require 'rails/all'
|
||||
|
||||
# Require the gems listed in Gemfile, including any gems
|
||||
# you've limited to :test, :development, or :production.
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
||||
|
||||
require "bundler/setup" # Set up gems listed in the Gemfile.
|
||||
require "bootsnap/setup" # Speed up boot time by caching expensive operations.
|
||||
require 'bundler/setup' # Set up gems listed in the Gemfile.
|
||||
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Load the Rails application.
|
||||
require_relative "application"
|
||||
require_relative 'application'
|
||||
|
||||
# Initialize the Rails application.
|
||||
Rails.application.initialize!
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require "active_support/core_ext/integer/time"
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'active_support/core_ext/integer/time'
|
||||
|
||||
Rails.application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require "active_support/core_ext/integer/time"
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'active_support/core_ext/integer/time'
|
||||
|
||||
Rails.application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
@ -53,7 +55,7 @@ Rails.application.configure do
|
|||
config.log_level = :info
|
||||
|
||||
# Prepend all log lines with the following tags.
|
||||
config.log_tags = [ :request_id ]
|
||||
config.log_tags = [:request_id]
|
||||
|
||||
# Use a different cache store in production.
|
||||
# config.cache_store = :mem_cache_store
|
||||
|
@ -88,8 +90,8 @@ Rails.application.configure do
|
|||
# require "syslog/logger"
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
||||
|
||||
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
||||
logger = ActiveSupport::Logger.new(STDOUT)
|
||||
if ENV['RAILS_LOG_TO_STDOUT'].present?
|
||||
logger = ActiveSupport::Logger.new($stdout)
|
||||
logger.formatter = config.log_formatter
|
||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require "active_support/core_ext/integer/time"
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'active_support/core_ext/integer/time'
|
||||
|
||||
# The test environment is used exclusively to run your application's
|
||||
# test suite. You never need to work with it otherwise. Remember that
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# ActiveSupport::Reloader.to_prepare do
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Version of your assets, change this if you want to expire all your assets.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
||||
|
@ -5,4 +7,4 @@
|
|||
|
||||
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code
|
||||
# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'".
|
||||
Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
|
||||
Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE']
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Define an application-wide content security policy
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Specify a serializer for the signed and encrypted cookie jars.
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Configure sensitive parameters which will be filtered from the log file.
|
||||
Rails.application.config.filter_parameters += [
|
||||
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
|
||||
Rails.application.config.filter_parameters += %i[
|
||||
passw secret token _key crypt salt certificate otp ssn
|
||||
]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Add new inflection rules using the following format. Inflections
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Add new mime types for use in respond_to blocks:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
# Define an application-wide HTTP permissions policy. For further
|
||||
# information see https://developers.google.com/web/updates/2018/06/feature-policy
|
||||
#
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# This file contains settings for ActionController::ParamsWrapper which
|
||||
|
|
|
@ -1,28 +1,30 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Puma can serve each request in a thread from an internal thread pool.
|
||||
# The `threads` method setting takes two numbers: a minimum and maximum.
|
||||
# Any libraries that use thread pools should be configured to match
|
||||
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
||||
# and maximum; this matches the default thread size of Active Record.
|
||||
#
|
||||
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
|
||||
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
|
||||
max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
|
||||
min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
|
||||
threads min_threads_count, max_threads_count
|
||||
|
||||
# Specifies the `worker_timeout` threshold that Puma will use to wait before
|
||||
# terminating a worker in development environments.
|
||||
#
|
||||
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
|
||||
worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'
|
||||
|
||||
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
||||
#
|
||||
port ENV.fetch("PORT") { 3000 }
|
||||
port ENV.fetch('PORT', 3000)
|
||||
|
||||
# Specifies the `environment` that Puma will run in.
|
||||
#
|
||||
environment ENV.fetch("RAILS_ENV") { "development" }
|
||||
environment ENV.fetch('RAILS_ENV', 'development')
|
||||
|
||||
# Specifies the `pidfile` that Puma will use.
|
||||
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
|
||||
pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
|
||||
|
||||
# Specifies the number of `workers` to boot in clustered mode.
|
||||
# Workers are forked web server processes. If using threads and workers together
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Rails.application.routes.draw do
|
||||
resources :users
|
||||
get 'login', to: 'sessions#new'
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Spring.watch(
|
||||
".ruby-version",
|
||||
".rbenv-vars",
|
||||
"tmp/restart.txt",
|
||||
"tmp/caching-dev.txt"
|
||||
'.ruby-version',
|
||||
'.rbenv-vars',
|
||||
'tmp/restart.txt',
|
||||
'tmp/caching-dev.txt'
|
||||
)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateAuthors < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :authors do |t|
|
||||
|
@ -7,6 +9,6 @@ class CreateAuthors < ActiveRecord::Migration[6.1]
|
|||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :authors, [ :first_name, :last_name ]
|
||||
add_index :authors, %i[first_name last_name]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateBooks < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :books do |t|
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateAuthorsBooks < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :authors_books do |t|
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateUsers < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :users do |t|
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChangeUsernameToEmail < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
rename_column :users, :username, :email
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddPasswordRecoveryCodeToUsers < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :users, :password_recovery_code, :string
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChangePasswordRecoveryCodeToRecoveryPasswordDigest < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
rename_column :users, :password_recovery_code, :recovery_password_digest
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddRoleToUsers < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :users, :role, :integer
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddStatusToUsers < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :users, :status, :integer
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateAuditRecords < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :audit_records do |t|
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddQuantityToBooks < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :books, :quantity, :integer
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateBooksUsers < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :books_users do |t|
|
||||
|
|
90
db/schema.rb
generated
90
db/schema.rb
generated
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
|
@ -10,60 +12,58 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_03_22_002803) do
|
||||
|
||||
create_table "audit_records", force: :cascade do |t|
|
||||
t.string "model"
|
||||
t.string "action"
|
||||
t.string "params"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
ActiveRecord::Schema.define(version: 20_210_322_002_803) do
|
||||
create_table 'audit_records', force: :cascade do |t|
|
||||
t.string 'model'
|
||||
t.string 'action'
|
||||
t.string 'params'
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table "authors", force: :cascade do |t|
|
||||
t.string "first_name"
|
||||
t.string "last_name"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["first_name", "last_name"], name: "index_authors_on_first_name_and_last_name"
|
||||
create_table 'authors', force: :cascade do |t|
|
||||
t.string 'first_name'
|
||||
t.string 'last_name'
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
t.index %w[first_name last_name], name: 'index_authors_on_first_name_and_last_name'
|
||||
end
|
||||
|
||||
create_table "authors_books", force: :cascade do |t|
|
||||
t.integer "book_id"
|
||||
t.integer "author_id"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["author_id"], name: "index_authors_books_on_author_id"
|
||||
t.index ["book_id"], name: "index_authors_books_on_book_id"
|
||||
create_table 'authors_books', force: :cascade do |t|
|
||||
t.integer 'book_id'
|
||||
t.integer 'author_id'
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
t.index ['author_id'], name: 'index_authors_books_on_author_id'
|
||||
t.index ['book_id'], name: 'index_authors_books_on_book_id'
|
||||
end
|
||||
|
||||
create_table "books", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.decimal "price", precision: 10, scale: 2
|
||||
t.boolean "published"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.integer "quantity"
|
||||
t.index ["published"], name: "index_books_on_published"
|
||||
create_table 'books', force: :cascade do |t|
|
||||
t.string 'title'
|
||||
t.decimal 'price', precision: 10, scale: 2
|
||||
t.boolean 'published'
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
t.integer 'quantity'
|
||||
t.index ['published'], name: 'index_books_on_published'
|
||||
end
|
||||
|
||||
create_table "books_users", force: :cascade do |t|
|
||||
t.integer "book_id"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["book_id"], name: "index_books_users_on_book_id"
|
||||
t.index ["user_id"], name: "index_books_users_on_user_id"
|
||||
create_table 'books_users', force: :cascade do |t|
|
||||
t.integer 'book_id'
|
||||
t.integer 'user_id'
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
t.index ['book_id'], name: 'index_books_users_on_book_id'
|
||||
t.index ['user_id'], name: 'index_books_users_on_user_id'
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email"
|
||||
t.string "password_digest"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.string "recovery_password_digest"
|
||||
t.integer "role"
|
||||
t.integer "status"
|
||||
create_table 'users', force: :cascade do |t|
|
||||
t.string 'email'
|
||||
t.string 'password_digest'
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
t.string 'recovery_password_digest'
|
||||
t.integer 'role'
|
||||
t.integer 'status'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
124
db/seeds.rb
124
db/seeds.rb
|
@ -1,48 +1,50 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
books = Book.create([
|
||||
{
|
||||
title: 'Journey to the Center of the Earth',
|
||||
price: 10900,
|
||||
published: true,
|
||||
quantity: 100
|
||||
},
|
||||
{
|
||||
title: 'From the Earth to the Moon',
|
||||
price: 6300,
|
||||
published: false,
|
||||
quantity: 0
|
||||
},
|
||||
{
|
||||
title: 'Imaginary trip',
|
||||
price: 3600,
|
||||
published: true,
|
||||
quantity: 1
|
||||
},
|
||||
{
|
||||
title: 'Winnie the Pooh',
|
||||
price: 3700,
|
||||
published: true,
|
||||
quantity: 5
|
||||
},
|
||||
])
|
||||
{
|
||||
title: 'Journey to the Center of the Earth',
|
||||
price: 10_900,
|
||||
published: true,
|
||||
quantity: 100
|
||||
},
|
||||
{
|
||||
title: 'From the Earth to the Moon',
|
||||
price: 6300,
|
||||
published: false,
|
||||
quantity: 0
|
||||
},
|
||||
{
|
||||
title: 'Imaginary trip',
|
||||
price: 3600,
|
||||
published: true,
|
||||
quantity: 1
|
||||
},
|
||||
{
|
||||
title: 'Winnie the Pooh',
|
||||
price: 3700,
|
||||
published: true,
|
||||
quantity: 5
|
||||
}
|
||||
])
|
||||
|
||||
authors = Author.create([
|
||||
{
|
||||
first_name: 'Jules',
|
||||
last_name: 'Verne'
|
||||
},
|
||||
{
|
||||
first_name: 'Dick',
|
||||
last_name: 'Pick',
|
||||
},
|
||||
{
|
||||
first_name: 'Rick',
|
||||
last_name: 'Pickle'
|
||||
},
|
||||
{
|
||||
first_name: 'Alan',
|
||||
last_name: 'Milne'
|
||||
},
|
||||
])
|
||||
{
|
||||
first_name: 'Jules',
|
||||
last_name: 'Verne'
|
||||
},
|
||||
{
|
||||
first_name: 'Dick',
|
||||
last_name: 'Pick'
|
||||
},
|
||||
{
|
||||
first_name: 'Rick',
|
||||
last_name: 'Pickle'
|
||||
},
|
||||
{
|
||||
first_name: 'Alan',
|
||||
last_name: 'Milne'
|
||||
}
|
||||
])
|
||||
|
||||
books.first.authors << authors.first
|
||||
books.second.authors << authors.first
|
||||
|
@ -51,22 +53,22 @@ books.third.authors << authors.third
|
|||
books.fourth.authors << authors.fourth
|
||||
|
||||
User.create([
|
||||
{
|
||||
email: 'abc@o2.pl',
|
||||
password: 'aaaaaaaa',
|
||||
role: :admin,
|
||||
status: :ready
|
||||
},
|
||||
{
|
||||
email: 'abcd@o2.pl',
|
||||
password: 'aaaaaaaa',
|
||||
role: :customer,
|
||||
status: :ready
|
||||
},
|
||||
{
|
||||
email: 'abcde@o2.pl',
|
||||
password: 'aaaaaaaa',
|
||||
role: :customer,
|
||||
status: :ready
|
||||
},
|
||||
])
|
||||
{
|
||||
email: 'abc@o2.pl',
|
||||
password: 'aaaaaaaa',
|
||||
role: :admin,
|
||||
status: :ready
|
||||
},
|
||||
{
|
||||
email: 'abcd@o2.pl',
|
||||
password: 'aaaaaaaa',
|
||||
role: :customer,
|
||||
status: :ready
|
||||
},
|
||||
{
|
||||
email: 'abcde@o2.pl',
|
||||
password: 'aaaaaaaa',
|
||||
role: :customer,
|
||||
status: :ready
|
||||
}
|
||||
])
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ApplicationController do
|
||||
|
@ -15,4 +17,4 @@ RSpec.describe ApplicationController do
|
|||
describe 'logged_in?' do
|
||||
# TODO
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SessionsController do
|
||||
|
@ -8,14 +10,14 @@ RSpec.describe SessionsController do
|
|||
end
|
||||
end
|
||||
describe 'get create' do
|
||||
# TODO test session status
|
||||
# TODO: test session status
|
||||
subject { get 'create' }
|
||||
it 'redirects to /welcome' do
|
||||
expect(subject).to redirect_to('/welcome')
|
||||
end
|
||||
end
|
||||
describe 'get delete' do
|
||||
# TODO test session status
|
||||
# TODO: test session status
|
||||
subject { get 'delete' }
|
||||
it 'redirects to /welcome' do
|
||||
expect(subject).to redirect_to('/welcome')
|
||||
|
@ -27,4 +29,4 @@ RSpec.describe SessionsController do
|
|||
expect(subject).to render_template('sessions/welcome')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UsersController do
|
||||
before(:all) do # TODO change it to cleanup after each test
|
||||
before(:all) do # TODO: change it to cleanup after each test
|
||||
User.destroy_all
|
||||
end
|
||||
let(:user1) do
|
||||
|
@ -15,7 +17,7 @@ RSpec.describe UsersController do
|
|||
end
|
||||
describe 'get create' do
|
||||
subject do
|
||||
get :create, params: {user: {email: 'test2@example.com', password: 'abcdefgh'}}
|
||||
get :create, params: { user: { email: 'test2@example.com', password: 'abcdefgh' } }
|
||||
end
|
||||
it 'creates a user' do
|
||||
subject
|
||||
|
@ -34,13 +36,13 @@ RSpec.describe UsersController do
|
|||
end
|
||||
describe 'post password_recovery_request' do
|
||||
subject do
|
||||
get :password_recovery_request, params: {email: user1.email}
|
||||
get :password_recovery_request, params: { email: user1.email }
|
||||
end
|
||||
it 'sends the proper recovery email' do
|
||||
srand(10)
|
||||
subject
|
||||
email_text = ActionMailer::Base.deliveries.last.body.raw_source
|
||||
expect(email_text).to match("recover_password/#{user1.id}/tfohbclx")
|
||||
expect(email_text).to match("recover_password/#{user1.id}/jeravuxl")
|
||||
end
|
||||
it 'sends a recovery email to the proper email' do
|
||||
subject
|
||||
|
@ -53,7 +55,7 @@ RSpec.describe UsersController do
|
|||
end
|
||||
describe 'get recover_password_form' do
|
||||
subject do
|
||||
get :recover_password_form, params: {id: user1.id, recovery_password: 'recovery password'}
|
||||
get :recover_password_form, params: { id: user1.id, recovery_password: 'recovery password' }
|
||||
end
|
||||
it 'renders proper form' do
|
||||
subject
|
||||
|
@ -104,4 +106,4 @@ RSpec.describe UsersController do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Preview all emails at http://localhost:3000/rails/mailers/user
|
||||
class UserMailerPreview < ActionMailer::Preview
|
||||
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require "rails_helper"
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UserMailer, type: :mailer do
|
||||
# TODO
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||
require 'spec_helper'
|
||||
ENV['RAILS_ENV'] ||= 'test'
|
||||
require File.expand_path('../config/environment', __dir__)
|
||||
# Prevent database truncation if the environment is production
|
||||
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
||||
abort('The Rails environment is running in production mode!') if Rails.env.production?
|
||||
require 'rspec/rails'
|
||||
# Add additional requires below this line. Rails is not loaded until this point!
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
||||
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
||||
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
||||
|
@ -44,53 +46,51 @@ RSpec.configure do |config|
|
|||
# triggering implicit auto-inclusion in groups with matching metadata.
|
||||
config.shared_context_metadata_behavior = :apply_to_host_groups
|
||||
|
||||
# The settings below are suggested to provide a good initial experience
|
||||
# with RSpec, but feel free to customize to your heart's content.
|
||||
=begin
|
||||
# This allows you to limit a spec run to individual examples or groups
|
||||
# you care about by tagging them with `:focus` metadata. When nothing
|
||||
# is tagged with `:focus`, all examples get run. RSpec also provides
|
||||
# aliases for `it`, `describe`, and `context` that include `:focus`
|
||||
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
||||
config.filter_run_when_matching :focus
|
||||
|
||||
# Allows RSpec to persist some state between runs in order to support
|
||||
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
||||
# you configure your source control system to ignore this file.
|
||||
config.example_status_persistence_file_path = "spec/examples.txt"
|
||||
|
||||
# Limits the available syntax to the non-monkey patched syntax that is
|
||||
# recommended. For more details, see:
|
||||
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
||||
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
||||
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
||||
config.disable_monkey_patching!
|
||||
|
||||
# Many RSpec users commonly either run the entire suite or an individual
|
||||
# file, and it's useful to allow more verbose output when running an
|
||||
# individual spec file.
|
||||
if config.files_to_run.one?
|
||||
# Use the documentation formatter for detailed output,
|
||||
# unless a formatter has already been configured
|
||||
# (e.g. via a command-line flag).
|
||||
config.default_formatter = "doc"
|
||||
end
|
||||
|
||||
# Print the 10 slowest examples and example groups at the
|
||||
# end of the spec run, to help surface which specs are running
|
||||
# particularly slow.
|
||||
config.profile_examples = 10
|
||||
|
||||
# Run specs in random order to surface order dependencies. If you find an
|
||||
# order dependency and want to debug it, you can fix the order by providing
|
||||
# the seed, which is printed after each run.
|
||||
# --seed 1234
|
||||
config.order = :random
|
||||
|
||||
# Seed global randomization in this process using the `--seed` CLI option.
|
||||
# Setting this allows you to use `--seed` to deterministically reproduce
|
||||
# test failures related to randomization by passing the same `--seed` value
|
||||
# as the one that triggered the failure.
|
||||
Kernel.srand config.seed
|
||||
=end
|
||||
end
|
||||
# The settings below are suggested to provide a good initial experience
|
||||
# with RSpec, but feel free to customize to your heart's content.
|
||||
# # This allows you to limit a spec run to individual examples or groups
|
||||
# # you care about by tagging them with `:focus` metadata. When nothing
|
||||
# # is tagged with `:focus`, all examples get run. RSpec also provides
|
||||
# # aliases for `it`, `describe`, and `context` that include `:focus`
|
||||
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
||||
# config.filter_run_when_matching :focus
|
||||
#
|
||||
# # Allows RSpec to persist some state between runs in order to support
|
||||
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
||||
# # you configure your source control system to ignore this file.
|
||||
# config.example_status_persistence_file_path = "spec/examples.txt"
|
||||
#
|
||||
# # Limits the available syntax to the non-monkey patched syntax that is
|
||||
# # recommended. For more details, see:
|
||||
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
||||
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
||||
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
||||
# config.disable_monkey_patching!
|
||||
#
|
||||
# # Many RSpec users commonly either run the entire suite or an individual
|
||||
# # file, and it's useful to allow more verbose output when running an
|
||||
# # individual spec file.
|
||||
# if config.files_to_run.one?
|
||||
# # Use the documentation formatter for detailed output,
|
||||
# # unless a formatter has already been configured
|
||||
# # (e.g. via a command-line flag).
|
||||
# config.default_formatter = "doc"
|
||||
# end
|
||||
#
|
||||
# # Print the 10 slowest examples and example groups at the
|
||||
# # end of the spec run, to help surface which specs are running
|
||||
# # particularly slow.
|
||||
# config.profile_examples = 10
|
||||
#
|
||||
# # Run specs in random order to surface order dependencies. If you find an
|
||||
# # order dependency and want to debug it, you can fix the order by providing
|
||||
# # the seed, which is printed after each run.
|
||||
# # --seed 1234
|
||||
# config.order = :random
|
||||
#
|
||||
# # Seed global randomization in this process using the `--seed` CLI option.
|
||||
# # Setting this allows you to use `--seed` to deterministically reproduce
|
||||
# # test failures related to randomization by passing the same `--seed` value
|
||||
# # as the one that triggered the failure.
|
||||
# Kernel.srand config.seed
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue