rubocop corrections

This commit is contained in:
Karol Selak 2021-03-22 03:16:29 +01:00
parent c63c6bc448
commit de29815686
72 changed files with 468 additions and 311 deletions

View file

@ -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

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateBooks < ActiveRecord::Migration[6.1]
def change
create_table :books do |t|

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateAuthorsBooks < ActiveRecord::Migration[6.1]
def change
create_table :authors_books do |t|

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateUsers < ActiveRecord::Migration[6.1]
def change
create_table :users do |t|

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ChangeUsernameToEmail < ActiveRecord::Migration[6.1]
def change
rename_column :users, :username, :email

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class AddPasswordRecoveryCodeToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :password_recovery_code, :string

View file

@ -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

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class AddRoleToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :role, :integer

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class AddStatusToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :status, :integer

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateAuditRecords < ActiveRecord::Migration[6.1]
def change
create_table :audit_records do |t|

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
class AddQuantityToBooks < ActiveRecord::Migration[6.1]
def change
add_column :books, :quantity, :integer

View file

@ -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
View file

@ -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

View file

@ -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
}
])