Skip to content

Commit

Permalink
rubocop -a.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoto2000 committed Sep 9, 2024
1 parent 08227f3 commit d4fb34d
Show file tree
Hide file tree
Showing 24 changed files with 187 additions and 176 deletions.
2 changes: 1 addition & 1 deletion app/controllers/book_masters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def set_book_master

# Only allow a list of trusted parameters through.
def book_master_params
params.require(:book_master).permit(:isbn, :title, :publication_date, :ndc_category_id, {author_ids: []})
params.require(:book_master).permit(:isbn, :title, :publication_date, :ndc_category_id, { author_ids: [] })
end
end
3 changes: 2 additions & 1 deletion app/controllers/book_stock_statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def update
# DELETE /book_stock_statuses/1
def destroy
@book_stock_status.destroy!
redirect_to book_stock_statuses_url, notice: t("controller.destroy.success", model: BookStockStatus.model_name.human)
redirect_to book_stock_statuses_url,
notice: t("controller.destroy.success", model: BookStockStatus.model_name.human)
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/lending_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def set_lending_set

# Only allow a list of trusted parameters through.
def lending_set_params
params.require(:lending_set).permit(:customer_id, :lending_status_id, :lend_start_date, :return_deadline_date, :return_date, :memo, {book_stock_ids: []})
params.require(:lending_set).permit(:customer_id, :lending_status_id, :lend_start_date, :return_deadline_date,
:return_date, :memo, { book_stock_ids: [] })
end
end
2 changes: 1 addition & 1 deletion app/models/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def self.ransackable_attributes(_auth_object = nil)
%w[name id created_at updated_at]
end

validates :name, presence: true, uniqueness:true
validates :name, presence: true, uniqueness: true

Check failure on line 6 in app/models/author.rb

View workflow job for this annotation

GitHub Actions / lint

Rails/UniqueValidationWithoutIndex: Uniqueness validation should have a unique index on the database column.

has_many :book_author_relationship

Check failure on line 8 in app/models/author.rb

View workflow job for this annotation

GitHub Actions / lint

Rails/HasManyOrHasOneDependent: Specify a `:dependent` option.
has_many :book_masters, through: :book_author_relationship
Expand Down
5 changes: 3 additions & 2 deletions app/models/book_master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class BookMaster < ApplicationRecord
def self.ransackable_attributes(_auth_object = nil)
%w[isbn title publication_date ndc_category_id author_id id created_at updated_at]
end
def self.ransackable_associations(auth_object = nil)
["authors", "book_author_relationship", "ndc_category"]

def self.ransackable_associations(_auth_object = nil)
%w[authors book_author_relationship ndc_category]
end

# TODO: ちゃんとした判定ロジックを作る
Expand Down
5 changes: 3 additions & 2 deletions app/models/lending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class Lending < ApplicationRecord
def self.ransackable_attributes(_auth_object = nil)
%w[lending_set_id book_stock_id id created_at updated_at]
end
def self.ransackable_associations(auth_object = nil)
["lending_set_id", "book_stock_id", "id", "created_at", "updated_at"]

def self.ransackable_associations(_auth_object = nil)
%w[lending_set_id book_stock_id id created_at updated_at]
end
belongs_to :lending_set
belongs_to :book_stock
Expand Down
28 changes: 15 additions & 13 deletions app/models/lending_set.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
class LendingSet < ApplicationRecord
def self.ransackable_attributes(_auth_object = nil)
%w[customer_id book_stock_id lending_status_id lend_start_date return_deadline_date return_date memo id created_at updated_at]
%w[customer_id book_stock_id lending_status_id lend_start_date return_deadline_date return_date memo id created_at
updated_at]
end
def self.ransackable_associations(auth_object = nil)
["book_stocks", "customer", "lending", "lending_status"]

def self.ransackable_associations(_auth_object = nil)
%w[book_stocks customer lending lending_status]
end

after_save do
if self.lending_status.name === "貸出中"
self.book_stocks.each {|bs|
bs.book_stock_status_id = 2
bs.save
}
elsif self.lending_status.name === "返却済"
self.book_stocks.each {|bs|
bs.book_stock_status_id = 1
bs.save
}
if lending_status.name === "貸出中"

Check failure on line 12 in app/models/lending_set.rb

View workflow job for this annotation

GitHub Actions / lint

Style/CaseEquality: Avoid the use of the case equality operator `===`.
book_stocks.each do |bs|
bs.book_stock_status_id = 2
bs.save
end
elsif lending_status.name === "返却済"

Check failure on line 17 in app/models/lending_set.rb

View workflow job for this annotation

GitHub Actions / lint

Style/CaseEquality: Avoid the use of the case equality operator `===`.
book_stocks.each do |bs|
bs.book_stock_status_id = 1
bs.save
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/views/lending_sets/_lending_set.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
json.extract! lending_set, :id, :customer_id, :lending_status_id, :lend_start_date, :return_deadline_date, :return_date, :memo, :created_at, :updated_at
json.extract! lending_set, :id, :customer_id, :lending_status_id, :lend_start_date, :return_deadline_date,
:return_date, :memo, :created_at, :updated_at
json.url lending_set_url(lending_set, format: :json)
4 changes: 2 additions & 2 deletions db/migrate/20240905113117_create_ndc_categories.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class CreateNdcCategories < ActiveRecord::Migration[7.2]
def change
create_table :ndc_categories do |t|
t.string :name, :null => false
t.integer :number, :null => false
t.string :name, null: false
t.integer :number, null: false

t.timestamps
end
Expand Down
6 changes: 3 additions & 3 deletions db/migrate/20240905114943_create_book_masters.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class CreateBookMasters < ActiveRecord::Migration[7.2]
def change
create_table :book_masters do |t|
t.string :isbn, :null => false
t.string :title, :null => false
t.date :publication_date, :null => false
t.string :isbn, null: false
t.string :title, null: false
t.date :publication_date, null: false
t.references :ndc_category, null: false, foreign_key: true

t.timestamps
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20240906035618_create_authors.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateAuthors < ActiveRecord::Migration[7.2]
def change
create_table :authors do |t|
t.string :name, :null => false
t.string :name, null: false

t.timestamps
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20240907021517_create_book_stock_statuses.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateBookStockStatuses < ActiveRecord::Migration[7.2]
def change
create_table :book_stock_statuses do |t|
t.string :name, :null => false
t.string :name, null: false

t.timestamps
end
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20240907053532_create_customers.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class CreateCustomers < ActiveRecord::Migration[7.2]
def change
create_table :customers do |t|
t.string :name, :null => false
t.string :email_address, :null => false
t.string :name, null: false
t.string :email_address, null: false

t.timestamps
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20240907053536_create_lending_statuses.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateLendingStatuses < ActiveRecord::Migration[7.2]
def change
create_table :lending_statuses do |t|
t.string :name, :null => false
t.string :name, null: false

t.timestamps
end
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20240907053810_create_lending_sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ def change
create_table :lending_sets do |t|
t.references :customer, null: false, foreign_key: true
t.references :lending_status, null: false, foreign_key: true
t.date :lend_start_date, :null => false
t.date :return_deadline_date, :null => false
t.date :lend_start_date, null: false
t.date :return_deadline_date, null: false
t.date :return_date
t.text :memo

Expand Down
Loading

0 comments on commit d4fb34d

Please sign in to comment.