chore: rubocop

chore: fix api test conventions

chore: rubocop -A spec/

chore: more rubocop -A

fix failing test

rubocop fixes

removes helper methods that are in my opinion dead code

more rubocop fixes

rubocop -a --auto-gen-config
This commit is contained in:
Philipp Rothmann 2023-05-12 13:01:12 +02:00 committed by Philipp Rothmann
parent f6fb804bbe
commit fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions

View file

@ -1,6 +1,6 @@
class CurrentOrders::ArticlesController < ApplicationController
before_action :authenticate_orders
before_action :find_order_and_order_article, only: [:index, :show]
before_action :find_order_and_order_article, only: %i[index show]
def index
# sometimes need to pass id as parameter for forms
@ -26,11 +26,11 @@ class CurrentOrders::ArticlesController < ApplicationController
def find_order_and_order_article
@current_orders = Order.finished_not_closed
unless params[:order_id].blank?
if params[:order_id].blank?
@order_articles = OrderArticle.where(order_id: @current_orders.all.map(&:id))
else
@order = Order.find(params[:order_id])
@order_articles = @order.order_articles
else
@order_articles = OrderArticle.where(order_id: @current_orders.all.map(&:id))
end
@q = OrderArticle.ransack(params[:q])
@order_articles = @order_articles.ordered.merge(@q.result).includes(:article, :article_price)

View file

@ -4,10 +4,10 @@ class CurrentOrders::GroupOrdersController < ApplicationController
def index
# XXX code duplication lib/foodsoft_current_orders/app/controllers/current_orders/ordergroups_controller.rb
@order_ids = Order.where(state: ['open', 'finished']).all.map(&:id)
@goas = GroupOrderArticle.includes(:group_order => :ordergroup).includes(:order_article)
@order_ids = Order.where(state: %w[open finished]).all.map(&:id)
@goas = GroupOrderArticle.includes(group_order: :ordergroup).includes(:order_article)
.where(group_orders: { order_id: @order_ids, ordergroup_id: @ordergroup.id }).ordered
@articles_grouped_by_category = @goas.includes(:order_article => { :article => :article_category })
@articles_grouped_by_category = @goas.includes(order_article: { article: :article_category })
.order('articles.name')
.group_by { |a| a.order_article.article.article_category.name }
.sort { |a, b| a[0] <=> b[0] }
@ -18,8 +18,8 @@ class CurrentOrders::GroupOrdersController < ApplicationController
# XXX code duplication from GroupOrdersController
def ensure_ordergroup_member
@ordergroup = @current_user.ordergroup
if @ordergroup.nil?
redirect_to root_url, :alert => I18n.t('group_orders.errors.no_member')
end
return unless @ordergroup.nil?
redirect_to root_url, alert: I18n.t('group_orders.errors.no_member')
end
end

View file

@ -1,6 +1,6 @@
class CurrentOrders::OrdergroupsController < ApplicationController
before_action :authenticate_orders
before_action :find_group_orders, only: [:index, :show]
before_action :find_group_orders, only: %i[index show]
def index
# sometimes need to pass id as parameter for forms
@ -34,8 +34,11 @@ class CurrentOrders::OrdergroupsController < ApplicationController
@all_ordergroups.sort_by! { |o| @ordered_group_ids.include?(o.id) ? o.name : "ZZZZZ#{o.name}" }
@ordergroup = Ordergroup.find(params[:id]) unless params[:id].nil?
@goas = GroupOrderArticle.includes(:group_order, :order_article => [:article, :article_price])
.where(group_orders: { order_id: @order_ids, ordergroup_id: @ordergroup.id }).ordered.all unless @ordergroup.nil?
return if @ordergroup.nil?
@goas = GroupOrderArticle.includes(:group_order, order_article: %i[article article_price])
.where(group_orders: { order_id: @order_ids,
ordergroup_id: @ordergroup.id }).ordered.all
end
helper_method \

View file

@ -77,11 +77,11 @@ class MultipleOrdersByArticles < OrderPdf
.includes(:article).references(:article)
.reorder('order_articles.order_id, articles.name')
.preload(:article_price) # preload not join, just in case it went missing
.preload(:order, :group_order_articles => { :group_order => :ordergroup })
.preload(:order, group_order_articles: { group_order: :ordergroup })
end
def each_order_article
order_articles.find_each_with_order(batch_size: BATCH_SIZE) { |oa| yield oa }
def each_order_article(&block)
order_articles.find_each_with_order(batch_size: BATCH_SIZE, &block)
end
def group_order_articles_for(order_article)
@ -90,7 +90,7 @@ class MultipleOrdersByArticles < OrderPdf
goas
end
def each_group_order_article_for(group_order)
group_order_articles_for(group_order).each { |goa| yield goa }
def each_group_order_article_for(group_order, &block)
group_order_articles_for(group_order).each(&block)
end
end

View file

@ -113,7 +113,7 @@ class MultipleOrdersByGroups < OrderPdf
s
end
def each_ordergroup
def each_ordergroup(&block)
ordergroups.find_in_batches_with_order(batch_size: BATCH_SIZE) do |ordergroups|
@group_order_article_batch = GroupOrderArticle
.joins(:group_order)
@ -121,8 +121,8 @@ class MultipleOrdersByGroups < OrderPdf
.where(group_orders: { ordergroup_id: ordergroups.map(&:id) })
.order('group_orders.order_id, group_order_articles.id')
.preload(group_orders: { order: :supplier })
.preload(order_article: [:article, :article_price, :order])
ordergroups.each { |ordergroup| yield ordergroup }
.preload(order_article: %i[article article_price order])
ordergroups.each(&block)
end
end
@ -130,7 +130,7 @@ class MultipleOrdersByGroups < OrderPdf
@group_order_article_batch.select { |goa| goa.group_order.ordergroup_id == ordergroup.id }
end
def each_group_order_article_for(ordergroup)
group_order_articles_for(ordergroup).each { |goa| yield goa }
def each_group_order_article_for(ordergroup, &block)
group_order_articles_for(ordergroup).each(&block)
end
end

View file

@ -6,7 +6,9 @@ module CurrentOrdersHelper
elsif funds == 0
I18n.t('helpers.current_orders.pay_none')
else
content_tag :b, I18n.t('helpers.current_orders.pay_amount', amount: number_to_currency(-ordergroup.get_available_funds))
content_tag :b,
I18n.t('helpers.current_orders.pay_amount',
amount: number_to_currency(-ordergroup.get_available_funds))
end
end
end