Skip to content

Commit ba4cdb8

Browse files
committed
lint: Fix rubocop offences.
1 parent bbc93e3 commit ba4cdb8

File tree

13 files changed

+27
-21
lines changed

13 files changed

+27
-21
lines changed

app/controllers/barcodes_controller.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ class BarcodesController < ApplicationController
1818
# Get a list of all barcodes
1919
# GET /barcodes
2020
def index
21-
@barcodes = Barcode.all.order(:code)
21+
@barcodes = Barcode.order(:code)
2222
respond_to do |format|
2323
format.json { render json: @barcodes }
2424
format.html {} # rubocop:disable Lint/EmptyBlock
2525
end
2626
end
2727

28+
# Get a barcode by id
29+
# GET /barcodes/{id}
30+
def show
31+
@barcode = Barcode.find_by(code: params[:id])
32+
render json: @barcode.try(:product)
33+
end
34+
2835
# Create a new barcode page
2936
# GET /barcodes/new
3037
def new; end
@@ -35,7 +42,7 @@ def create
3542
# If the barcode exists, redirect to the product page of that product
3643
if Barcode.exists?(code: @barcode.code)
3744
flash[:info] = "Barcode already exists! This product is linked to the given barcode."
38-
redirect_to edit_product_path(Barcode.where(code: @barcode.code).take.product)
45+
redirect_to edit_product_path(Barcode.find_by(code: @barcode.code).product)
3946
return
4047
end
4148

@@ -66,13 +73,6 @@ def create
6673
end
6774
end
6875

69-
# Get a barcode by id
70-
# GET /barcodes/{id}
71-
def show
72-
@barcode = Barcode.find_by(code: params[:id])
73-
render json: @barcode.try(:product)
74-
end
75-
7676
# Delete a barcode
7777
# POST(method: DELETE) /barcodes/{id}
7878
def destroy

app/controllers/concerns/statistics.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def products_group_by_id
2626
products
2727
.select("products.*", "sum(order_items.count) as count")
2828
.group(:product_id)
29+
# rubocop:disable Rails/OrderArguments
2930
.order("count")
31+
# rubocop:enable Rails/OrderArguments
3032
.reverse_order
3133
end
3234

app/controllers/products_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ProductsController < ApplicationController
2626
# GET /products
2727
def index
2828
# If the user is not an admin, only show products that are not deleted
29-
@products = (current_user.admin? ? Product.all : Product.for_sale).order("name asc")
29+
@products = (current_user.admin? ? Product.all : Product.for_sale).order(:name)
3030
@categories = Product.categories
3131

3232
respond_to do |format|

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ApplicationHelper
44
include ActionView::Helpers::NumberHelper
55

66
# Predicate for filtering the flash Hash for notifications
7-
def flash_is_notification(flash_type)
7+
def flash_is_notification?(flash_type)
88
!flash_class(flash_type).nil?
99
end
1010

app/models/ability.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def initialize_user(user)
6464
# * The user is trying to delete an order for himself
6565
# * The order is still deletable (there is a specific time interval for deleting orders)
6666
can :destroy, Order do |order|
67-
order.try(:user) == user && order.deletable
67+
order.try(:user) == user && order.deletable?
6868
end
6969
end
7070
end

app/models/barcode.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class Barcode < ApplicationRecord
1515
include FriendlyId
16+
1617
friendly_id :code, use: :finders
1718

1819
belongs_to :product

app/models/order.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class Order < ApplicationRecord
2020
has_many :products, through: :order_items
2121

2222
before_validation :calculate_price
23+
# rubocop:disable Style/CollectionQuerying
2324
before_save { |o| o.order_items = o.order_items.reject { |oi| oi.count.zero? } }
25+
# rubocop:enable Style/CollectionQuerying
2426
after_create :create_api_job, unless: -> { user.guest? }
2527

2628
after_create :update_user_frecency
@@ -42,7 +44,7 @@ def to_sentence
4244
end.to_sentence
4345
end
4446

45-
def deletable
47+
def deletable?
4648
Time.zone.now <= deletable_until
4749
end
4850

app/models/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class User < ApplicationRecord
2727
include FriendlyId
2828
include Avatarable
2929
include Statistics
30+
3031
friendly_id :name, use: :finders
3132

3233
devise :omniauthable, omniauth_providers: [:zeuswpi]

app/views/layouts/_flash.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% flash.each do |type, msg| %>
2-
<% if flash_is_notification(type) %>
2+
<% if flash_is_notification?(type) %>
33
<div v-scope="{ open: true }" class="notification <%= isLight ? 'is-light' : '' %> <%= flash_class(type) %>" v-show="open">
44
<!-- Close button -->
55
<button class="delete" @click="open = false"></button>

app/views/orders/_order.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<!-- Actions -->
2323
<td class="order-item-actions">
24-
<% if order.deletable %>
24+
<% if order.deletable? %>
2525
<%= button_to "Cancel order (until #{(order.deletable_until).strftime("%H:%M")})",
2626
user_order_path(@user, order),
2727
method: :delete,

0 commit comments

Comments
 (0)