diff --git a/app/admin/category.rb b/app/admin/category.rb
index bb07c7e69..009b14c12 100644
--- a/app/admin/category.rb
+++ b/app/admin/category.rb
@@ -13,8 +13,7 @@
form do |f|
f.inputs do
f.input :name
- f.input :icon_name,
- hint: "See all available icons here".html_safe
+ f.input :icon_name, hint: "See all available icons here".html_safe
end
f.actions
end
diff --git a/app/admin/organization.rb b/app/admin/organization.rb
index b04e18587..62f85c35d 100644
--- a/app/admin/organization.rb
+++ b/app/admin/organization.rb
@@ -73,5 +73,5 @@ def destroy
filter :updated_at
permit_params :name, :email, :web, :phone, :city, :neighborhood,
- :address, :description, :public_opening_times, :logo
+ :address, :description, :public_opening_times, :logo
end
diff --git a/app/admin/post.rb b/app/admin/post.rb
index cdfdf9527..c0d0e5057 100644
--- a/app/admin/post.rb
+++ b/app/admin/post.rb
@@ -46,7 +46,7 @@
end
permit_params :type, :tag_list, :title, :category_id, :user_id,
- :description, :organization_id, :active, :is_group
+ :description, :organization_id, :active, :is_group
filter :type, as: :select, collection: -> { Post.subclasses }
filter :id
diff --git a/app/admin/transfer.rb b/app/admin/transfer.rb
index 88b752a93..7857e1422 100644
--- a/app/admin/transfer.rb
+++ b/app/admin/transfer.rb
@@ -1,5 +1,5 @@
ActiveAdmin.register Transfer do
- includes :post, movements: { account: %i[accountable organization] }
+ includes :post, movements: { account: [:accountable, :organization] }
actions :index, :destroy
diff --git a/app/admin/user.rb b/app/admin/user.rb
index 83faec2f3..060f9e844 100644
--- a/app/admin/user.rb
+++ b/app/admin/user.rb
@@ -85,5 +85,5 @@
end
permit_params :username, :email, :phone, :postcode, :gender, :locale,
- members_attributes: %i[id organization_id active manager _destroy]
+ members_attributes: [:id, :organization_id, :active, :manager, :_destroy]
end
diff --git a/app/assets/javascripts/libs.js b/app/assets/javascripts/libs.js
index c304764cd..1c941bd13 100644
--- a/app/assets/javascripts/libs.js
+++ b/app/assets/javascripts/libs.js
@@ -1,7 +1,7 @@
//= require jquery2
//= require jquery_ujs
-//= require vendor/jquery.validate
+//= require jquery.validate
//= require bootstrap
-//= require ./vendor/highcharts
-//= require ./vendor/highcharts-exporting
+//= require highcharts
+//= require highcharts-exporting
//= require select2
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e90142817..a8823c0c8 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -114,18 +114,18 @@ def set_locale
def user_not_authorized
flash[:error] = "You are not authorized to perform this action."
- redirect_to(request.referer || root_path)
+ redirect_to(request.referrer || root_path)
end
def resource_not_found
- render "errors/not_found", status: :not_found
+ render 'errors/not_found', status: 404
end
def member_should_exist_and_be_active
if !current_member
redirect_to organizations_path
elsif !current_member.active
- flash[:error] = I18n.t("users.index.account_deactivated")
+ flash[:error] = I18n.t('users.index.account_deactivated')
redirect_to select_organization_path
end
end
diff --git a/app/controllers/concerns/with_transfer_params.rb b/app/controllers/concerns/with_transfer_params.rb
index 934cf6e8c..a9b766369 100644
--- a/app/controllers/concerns/with_transfer_params.rb
+++ b/app/controllers/concerns/with_transfer_params.rb
@@ -1,10 +1,10 @@
module WithTransferParams
def transfer_params
- permitted_transfer_params = %i[
- destination
- amount
- reason
- post_id
+ permitted_transfer_params = [
+ :destination,
+ :amount,
+ :reason,
+ :post_id,
]
permitted_transfer_params.push(:source) if admin?
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
index c000e9c97..479fe79df 100644
--- a/app/controllers/errors_controller.rb
+++ b/app/controllers/errors_controller.rb
@@ -1,9 +1,9 @@
class ErrorsController < ApplicationController
def not_found
- render status: :not_found
+ render status: 404
end
def internal_server_error
- render status: :internal_server_error
+ render status: 500
end
end
diff --git a/app/controllers/multi_transfers_controller.rb b/app/controllers/multi_transfers_controller.rb
index e78a6bc54..91f45a0b9 100644
--- a/app/controllers/multi_transfers_controller.rb
+++ b/app/controllers/multi_transfers_controller.rb
@@ -1,12 +1,12 @@
class MultiTransfersController < ApplicationController
include WithTransferParams
- STEPS = %w[
- select_type
- select_source
- select_target
- set_params
- confirm
+ STEPS = [
+ 'select_type',
+ 'select_source',
+ 'select_target',
+ 'set_params',
+ 'confirm'
]
def step
@@ -60,10 +60,11 @@ def prepare_template_vars
@target_accountable = Account.find(@to.first).accountable
end
- @should_render_offer_selector =
+ @should_render_offer_selector = (
@type_of_transfer.to_sym == :many_to_one &&
@target_accountable &&
@target_accountable.offers.length > 0
+ )
@from_names = Account.find(@from).map(&:accountable).map(&:to_s)
@to_names = Account.find(@to).map(&:accountable).map(&:to_s)
diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb
index 45d1b747c..37daeafcc 100644
--- a/app/controllers/organizations_controller.rb
+++ b/app/controllers/organizations_controller.rb
@@ -1,5 +1,5 @@
class OrganizationsController < ApplicationController
- before_action :load_resource, only: %i[show edit update set_current]
+ before_action :load_resource, only: [:show, :edit, :update, :set_current]
before_action :user_should_be_confirmed
def index
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index f4264dbae..771445e51 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -1,7 +1,9 @@
class PagesController < ApplicationController
def show
- render template: "pages/#{params[:page]}"
- rescue ActionView::MissingTemplate
- render "errors/not_found", status: :not_found
+ begin
+ render template: "pages/#{params[:page]}"
+ rescue ActionView::MissingTemplate
+ render "errors/not_found", status: 404
+ end
end
end
diff --git a/app/controllers/petitions_controller.rb b/app/controllers/petitions_controller.rb
index a897f4e9a..8dc4d432b 100644
--- a/app/controllers/petitions_controller.rb
+++ b/app/controllers/petitions_controller.rb
@@ -9,9 +9,9 @@ def create
OrganizationNotifier.new_petition(petition).deliver_now
OrganizationNotifier.petition_sent(petition).deliver_now
- flash[:notice] = t("petitions.application_status", status: t("petitions.status.sent"))
+ flash[:notice] = t('petitions.application_status', status: t("petitions.status.sent"))
else
- flash[:error] = t("errors.internal_server_error.description")
+ flash[:error] = t('errors.internal_server_error.description')
end
redirect_back fallback_location: organization_path(petition.organization)
@@ -22,19 +22,18 @@ def update
status = params[:status]
if petition.update(status: status)
- petition.user.add_to_organization(petition.organization) if status == "accepted"
- flash[:notice] = t("petitions.application_status", status: t("petitions.status.#{status}"))
+ petition.user.add_to_organization(petition.organization) if status == 'accepted'
+ flash[:notice] = t('petitions.application_status', status: t("petitions.status.#{status}"))
else
- flash[:error] = t("errors.internal_server_error.description")
+ flash[:error] = t('errors.internal_server_error.description')
end
redirect_to manage_petitions_path
end
def manage
- @status = params[:status] || "pending"
- @users = User.joins(:petitions).where(petitions: { organization_id: current_organization.id,
- status: @status }).page(params[:page]).per(20)
+ @status = params[:status] || 'pending'
+ @users = User.joins(:petitions).where(petitions: { organization_id: current_organization.id, status: @status }).page(params[:page]).per(20)
end
private
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 2e45c608a..5a8e3616b 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb
@@ -1,4 +1,4 @@
-class PostsController < ApplicationController
+class PostsController < ApplicationController
has_scope :by_category, as: :cat
has_scope :tagged_with, as: :tag
has_scope :by_organization, as: :org
@@ -91,7 +91,7 @@ def set_user_id(p)
def post_params
permitted_fields = [:description, :end_on, :start_on, :title, :category_id,
- :user_id, :is_group, :active, { tag_list: [] }]
+ :user_id, :is_group, :active, tag_list: []]
params.fetch(resource, {}).permit(*permitted_fields).tap do |p|
set_user_id(p)
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb
index d7749ea35..5b2b271fa 100644
--- a/app/controllers/reports_controller.rb
+++ b/app/controllers/reports_controller.rb
@@ -1,4 +1,4 @@
-require "zip"
+require 'zip'
class ReportsController < ApplicationController
before_action :authenticate_user!
@@ -8,20 +8,20 @@ class ReportsController < ApplicationController
def user_list
@members = report_collection("Member")
- report_responder("Member", current_organization, @members)
+ report_responder('Member', current_organization, @members)
end
def post_list
@post_type = (params[:type] || "offer").capitalize.constantize
@posts = report_collection(@post_type)
- report_responder("Post", current_organization, @posts, @post_type)
+ report_responder('Post', current_organization, @posts, @post_type)
end
def transfer_list
- @transfers = report_collection("Transfer")
+ @transfers = report_collection('Transfer')
- report_responder("Transfer", current_organization, @transfers)
+ report_responder('Transfer', current_organization, @transfers)
end
def download_all
@@ -35,7 +35,7 @@ def download_all
end
end
zip_data = File.read(temp_file.path)
- send_data(zip_data, type: "application/zip", disposition: "attachment", filename: filename)
+ send_data(zip_data, type: 'application/zip', disposition: 'attachment', filename: filename)
rescue Errno::ENOENT
redirect_to download_all_report_path
ensure
@@ -65,11 +65,11 @@ def get_report(report_class, *args)
def report_collection(report_class)
case report_class.to_s
- when "Member"
- current_organization.members.active.includes(:user).order("members.member_uid")
- when "Transfer"
+ when 'Member'
+ current_organization.members.active.includes(:user).order('members.member_uid')
+ when 'Transfer'
current_organization.all_transfers_with_accounts
- when "Inquiry", "Offer"
+ when 'Inquiry', 'Offer'
report_class = report_class.constantize if report_class.is_a?(String)
current_organization.posts.of_active_members.active.
@@ -84,10 +84,10 @@ def add_csv_to_zip(report_class, zip)
collection = report_collection(report_class)
report = if report_class.in? %w(Inquiry Offer)
- get_report("Csv::Post", current_organization, collection, report_class.constantize)
- else
- get_report("Csv::#{report_class}", current_organization, collection)
- end
+ get_report("Csv::Post", current_organization, collection, report_class.constantize)
+ else
+ get_report("Csv::#{report_class}", current_organization, collection)
+ end
file = Tempfile.new
file.write(report.run)
diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb
index 8d705c327..aa719b219 100644
--- a/app/controllers/statistics_controller.rb
+++ b/app/controllers/statistics_controller.rb
@@ -8,16 +8,16 @@ def global_activity
@total_hours = num_movements = 0
members.each do |m|
num_movements += m.account.movements.count
- @total_hours += m.account.movements.map do |a|
- a.amount > 0 ? a.amount : 0
+ @total_hours += m.account.movements.map do
+ |a| (a.amount > 0) ? a.amount : 0
end.inject(0, :+)
end
@total_hours += current_organization.account.movements.
- map { |a| a.amount > 0 ? a.amount : 0 }.inject(0, :+)
+ map { |a| (a.amount > 0) ? a.amount : 0 }.inject(0, :+)
@num_swaps = (num_movements + current_organization.account.movements.count) / 2
- from = params[:from].presence.try(:to_date) || DateTime.now.to_date - 5.months
+ from = params[:from].presence.try(:to_date) || DateTime.now.to_date - 5.month
to = params[:to].presence.try(:to_date) || DateTime.now.to_date
num_months = (to.year * 12 + to.month) - (from.year * 12 + from.month) + 1
date = from
@@ -38,10 +38,10 @@ def global_activity
sum_hours = 0
swaps_members.flatten.each do |s|
- sum_hours += s.amount > 0 ? s.amount : 0
+ sum_hours += (s.amount > 0) ? s.amount : 0
end
- sum_hours += swaps_organization.map do |a|
- a.amount > 0 ? a.amount : 0
+ sum_hours += swaps_organization.map do
+ |a| (a.amount > 0) ? a.amount : 0
end.inject(0, :+)
sum_hours = sum_hours / 3600.0 if sum_hours > 0
@hours_swaps_months << sum_hours
@@ -147,12 +147,12 @@ def compute_age(date_of_birth)
def age_group_labels
{
- 0..17 => "-17",
- 18..24 => "18-24",
- 25..34 => "25-34",
- 35..44 => "35-44",
- 45..54 => "45-54",
- 55..64 => "55-64",
+ 0..17 => "-17",
+ 18..24 => "18-24",
+ 25..34 => "25-34",
+ 35..44 => "35-44",
+ 45..54 => "45-54",
+ 55..64 => "55-64",
65..100 => "65+",
}
end
@@ -161,10 +161,10 @@ def gender_counts(members)
members.each_with_object(Hash.new(0)) do |member, counts|
gender = member.user_gender
gender_label = if gender.present?
- t("simple_form.options.user.gender.#{gender}")
- else
- t("statistics.demographics.unknown")
- end
+ t("simple_form.options.user.gender.#{gender}")
+ else
+ t("statistics.demographics.unknown")
+ end
counts[gender_label] += 1
end
end
diff --git a/app/controllers/transfers_controller.rb b/app/controllers/transfers_controller.rb
index 5baf275ba..e65506566 100644
--- a/app/controllers/transfers_controller.rb
+++ b/app/controllers/transfers_controller.rb
@@ -14,8 +14,7 @@ def create
if persister.save
redirect_to redirect_target
else
- redirect_back fallback_location: redirect_target,
- alert: transfer.errors.full_messages.to_sentence
+ redirect_back fallback_location: redirect_target, alert: transfer.errors.full_messages.to_sentence
end
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c464d76bd..689adef37 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,8 +1,7 @@
class UsersController < ApplicationController
before_action :authenticate_user!, except: %i[signup create]
before_action :user_should_be_confirmed, except: %i[signup create please_confirm]
- before_action :member_should_exist_and_be_active,
- except: %i[signup create edit show update please_confirm]
+ before_action :member_should_exist_and_be_active, except: %i[signup create edit show update please_confirm]
has_scope :tagged_with, as: :tag
@@ -10,11 +9,11 @@ def index
members = current_organization.members.active
members = apply_scopes(members)
- search_and_load_members members, { s: "user_last_sign_in_at DESC" }
+ search_and_load_members members, { s: 'user_last_sign_in_at DESC' }
end
def manage
- search_and_load_members current_organization.members, { s: "member_uid ASC" }
+ search_and_load_members current_organization.members, { s: 'member_uid ASC' }
end
def show
@@ -56,7 +55,7 @@ def create
else
@user.email = "" if empty_email
- render action: @user.from_signup ? "signup" : "new"
+ render action: @user.from_signup ? 'signup' : 'new'
end
end
@@ -99,9 +98,7 @@ def search_and_load_members(members_scope, default_search_params)
@search = members_scope.ransack(default_search_params.merge(params.to_unsafe_h.fetch(:q, {})))
result = @search.result
- orders = result.order_values.map do |order|
- order.direction == :asc ? "#{order.to_sql} NULLS FIRST" : "#{order.to_sql} NULLS LAST"
- end
+ orders = result.order_values.map { |order| order.direction == :asc ? "#{order.to_sql} NULLS FIRST" : "#{order.to_sql} NULLS LAST" }
result = result.except(:order).order(orders.join(", ")) if orders.count > 0
@members = result.eager_load(:account, :user).page(params[:page]).per(20)
@@ -117,10 +114,8 @@ def scoped_users
def user_params
fields_to_permit = %w"gender username email date_of_birth phone alt_phone active
locale description notifications push_notifications postcode"
- if admin?
- fields_to_permit += %w"admin registration_number
- registration_date"
- end
+ fields_to_permit += %w"admin registration_number
+ registration_date" if admin?
fields_to_permit += %w"organization_id superadmin" if superadmin?
fields_to_permit += %w"password" if params[:from_signup].present?
@@ -144,13 +139,13 @@ def redirect_to_after_create
if params[:more]
redirect_to new_user_path,
notice: I18n.t("users.new.user_created_add",
- uid: id,
- name: @user.username)
+ uid: id,
+ name: @user.username)
else
redirect_to users_path,
notice: I18n.t("users.index.user_created",
- uid: id,
- name: @user.username)
+ uid: id,
+ name: @user.username)
end
end
end
diff --git a/app/decorators/member_decorator.rb b/app/decorators/member_decorator.rb
index f522da9b1..c3d0aaefe 100644
--- a/app/decorators/member_decorator.rb
+++ b/app/decorators/member_decorator.rb
@@ -7,11 +7,11 @@ def manager?
end
def row_css_class
- "bg-danger" unless active?
+ 'bg-danger' unless active?
end
def inactive_icon
- view.glyph("time") unless active?
+ view.glyph('time') unless active?
end
def link_to_self
@@ -20,7 +20,7 @@ def link_to_self
def mail_to
email = user.unconfirmed_email || user.email
- view.mail_to(email) if email && !email.end_with?("example.com")
+ view.mail_to(email) if email && !email.end_with?('example.com')
end
def account_balance
diff --git a/app/decorators/report/transfer_decorator.rb b/app/decorators/report/transfer_decorator.rb
index 323bfea53..305a4dcdc 100644
--- a/app/decorators/report/transfer_decorator.rb
+++ b/app/decorators/report/transfer_decorator.rb
@@ -1,8 +1,7 @@
class Report::TransferDecorator
include Rails.application.routes.url_helpers
include ActionView::Helpers
- include TransfersHelper
- include ApplicationHelper
+ include ApplicationHelper, TransfersHelper
def initialize(org, collection)
@org = org
@@ -18,11 +17,11 @@ def name(extension)
def headers
[
- I18n.t("statistics.all_transfers.date"),
- I18n.t("statistics.all_transfers.from"),
- I18n.t("statistics.all_transfers.to"),
- I18n.t("statistics.all_transfers.post"),
- I18n.t("statistics.all_transfers.quantity")
+ I18n.t('statistics.all_transfers.date'),
+ I18n.t('statistics.all_transfers.from'),
+ I18n.t('statistics.all_transfers.to'),
+ I18n.t('statistics.all_transfers.post'),
+ I18n.t('statistics.all_transfers.quantity')
]
end
diff --git a/app/decorators/view_model.rb b/app/decorators/view_model.rb
index ee45101bf..8de925637 100644
--- a/app/decorators/view_model.rb
+++ b/app/decorators/view_model.rb
@@ -26,7 +26,7 @@
#
# From controllers, one can pass `self.class.helpers`, and from tests it is
# enough to use ApplicationController.new.view_context.
-#
+#
class ViewModel
attr_reader :object, :view, :routes
@@ -36,3 +36,4 @@ def initialize(object, view)
@routes = Rails.application.routes.url_helpers
end
end
+
diff --git a/app/helpers/active_admin_helper.rb b/app/helpers/active_admin_helper.rb
index ea899b730..8e43496a7 100644
--- a/app/helpers/active_admin_helper.rb
+++ b/app/helpers/active_admin_helper.rb
@@ -1,8 +1,8 @@
module ActiveAdminHelper
def render_translations(attribute, joiner = " | ")
- attribute.map do |locale, translation|
+ attribute.map do |locale, translation|
tag.strong("#{I18n.t("locales.#{locale}", locale: locale)}: ") +
- tag.span(translation)
+ tag.span(translation)
end.join(joiner).html_safe
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index b655d9407..5fe37cdd8 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,17 +1,15 @@
module ApplicationHelper
- TEXT_SUCCESS = "text-success".freeze
- TEXT_DANGER = "text-danger".freeze
+ TEXT_SUCCESS = 'text-success'.freeze
+ TEXT_DANGER = 'text-danger'.freeze
def page_title
- current_organization || "TimeOverflow"
+ current_organization || 'TimeOverflow'
end
def avatar_url(user, size = 32)
- if user.avatar.attached?
- user.avatar.variant(resize: "#{size}x#{size}")
- else
+ user.avatar.attached? ?
+ user.avatar.variant(resize: "#{size}x#{size}") :
gravatar_url(user, size)
- end
end
def gravatar_url(user, size = 32)
@@ -78,7 +76,7 @@ def show_error_messages!(resource)
# Content can be nil, in that case
# it will be the same as an empty string.
def markdown(content)
- RDiscount.new(content || "".freeze).to_html.html_safe
+ RDiscount.new(content || ''.freeze).to_html.html_safe
end
alias m markdown
@@ -94,12 +92,12 @@ def green_red(amount)
def get_body_css_class(controller)
classes = {
- "home" => "landing-page",
- "sessions" => "login-page",
- "pages" => "pages",
- "unlocks" => "unlocks-page",
- "passwords" => "passwords-page",
- "confirmations" => "confirmations-page"
+ 'home' => 'landing-page',
+ 'sessions' => 'login-page',
+ 'pages' => 'pages',
+ 'unlocks' => 'unlocks-page',
+ 'passwords' => 'passwords-page',
+ 'confirmations' => 'confirmations-page'
}
"#{classes[controller]}"
@@ -107,12 +105,12 @@ def get_body_css_class(controller)
def alert_class(alert)
case alert
- when "error", "alert"
- "alert-danger"
- when "notice"
- "alert-success"
+ when 'error', 'alert'
+ 'alert-danger'
+ when 'notice'
+ 'alert-success'
else
- "alert-info"
+ 'alert-info'
end
end
end
diff --git a/app/helpers/glyph_helper.rb b/app/helpers/glyph_helper.rb
index 56640eb71..ddff8d266 100644
--- a/app/helpers/glyph_helper.rb
+++ b/app/helpers/glyph_helper.rb
@@ -8,7 +8,7 @@ module GlyphHelper
"organization" => "tower"
}
- def glyph(kind, title = nil)
+ def glyph(kind, title=nil)
kind = kind.to_s.underscore
content_tag :span, "",
class: "glyphicon glyphicon-#{glyph_name(kind)}",
diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb
index 079fce2b2..bc8f14619 100644
--- a/app/helpers/posts_helper.rb
+++ b/app/helpers/posts_helper.rb
@@ -1,7 +1,7 @@
module PostsHelper
def members_for_select(post)
members = current_organization.members.active.order("members.member_uid").
- map { |mem| ["#{mem.member_uid} #{mem.user}", mem.user_id] }
+ map { |mem| ["#{mem.member_uid} #{mem.user.to_s}", mem.user_id] }
options_for_select(members, selected: post.user.id || current_user.id)
end
diff --git a/app/helpers/transfers_helper.rb b/app/helpers/transfers_helper.rb
index acf960f1a..7e6cf20f0 100644
--- a/app/helpers/transfers_helper.rb
+++ b/app/helpers/transfers_helper.rb
@@ -12,14 +12,13 @@ def accounts_from_movements(transfer, with_links: false)
account = movement.account
if account.accountable.blank?
- I18n.t("users.show.deleted_user")
- elsif account.accountable_type == "Organization"
+ I18n.t('users.show.deleted_user')
+ elsif account.accountable_type == 'Organization'
link_to_if(with_links, account, organization_path(account.accountable))
elsif account.accountable.active
- link_to_if(with_links, account.accountable.display_name_with_uid,
- user_path(account.accountable.user))
+ link_to_if(with_links, account.accountable.display_name_with_uid, user_path(account.accountable.user))
else
- I18n.t("users.show.inactive_user")
+ I18n.t('users.show.inactive_user')
end
end
end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 0c5b937c7..e0562469b 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -40,6 +40,6 @@ def can_toggle_active?(_member)
end
def status_applications(status)
- t("petitions.status_applications", status: t("petitions.status.#{status}").humanize)
+ t('petitions.status_applications', status: t("petitions.status.#{status}").humanize)
end
end
diff --git a/app/jobs/create_push_notifications_job.rb b/app/jobs/create_push_notifications_job.rb
index 049da2bb9..64a7ab5a6 100644
--- a/app/jobs/create_push_notifications_job.rb
+++ b/app/jobs/create_push_notifications_job.rb
@@ -4,7 +4,7 @@ class CreatePushNotificationsJob < ActiveJob::Base
def perform(event_id:)
event = ::Event.find_by_id(event_id)
- raise "A valid Event must be provided" unless event
+ raise 'A valid Event must be provided' unless event
if event.post_id
::PushNotifications::Creator::Post.new(event: event).create!
diff --git a/app/jobs/organization_notifier_job.rb b/app/jobs/organization_notifier_job.rb
index fac2df25d..e8949bba6 100644
--- a/app/jobs/organization_notifier_job.rb
+++ b/app/jobs/organization_notifier_job.rb
@@ -27,8 +27,8 @@ def users_by_locale(organization)
with_notifications = organization.users.online_active.actives.notifications
org_locales = with_notifications.pluck(:locale).uniq
- org_locales.index_with do |locale|
- with_notifications.where(locale: locale)
+ org_locales.each_with_object({}) do |locale, hash|
+ hash[locale] = with_notifications.where(locale: locale)
end
end
end
diff --git a/app/mailers/organization_notifier.rb b/app/mailers/organization_notifier.rb
index 6579fbcd7..d3ed1fcd5 100644
--- a/app/mailers/organization_notifier.rb
+++ b/app/mailers/organization_notifier.rb
@@ -19,7 +19,7 @@ def new_petition(petition)
I18n.with_locale(locale) do
mail(
- subject: "New Application",
+ subject: 'New Application',
to: organization.users.joins(:members).where(members: { manager: true }).pluck(:email).uniq
)
end
@@ -30,7 +30,7 @@ def petition_sent(petition)
I18n.with_locale(locale) do
mail(
- subject: "Application sent correctly",
+ subject: 'Application sent correctly',
to: petition.user.email
)
end
diff --git a/app/models/account.rb b/app/models/account.rb
index 012534264..c441349ba 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -23,7 +23,9 @@ def update_balance
end
# Print the account as its accountable reference
- delegate :to_s, to: :accountable
+ def to_s
+ accountable.to_s
+ end
protected
diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb
index 2bec8aaa5..4dba82ec7 100644
--- a/app/models/concerns/taggable.rb
+++ b/app/models/concerns/taggable.rb
@@ -34,18 +34,16 @@ def tag_list
# @return [Hash Integer>]
def tag_cloud
Hash[
- all_tags.
- group_by(&:to_s).
- map { |tag_name, values| [tag_name, values.size] }.
- sort_by { |array| array.first.downcase }
+ all_tags
+ .group_by(&:to_s)
+ .map { |tag_name, values| [tag_name, values.size] }
+ .sort_by { |array| array.first.downcase }
]
end
def find_like_tag(pattern)
transliterated_pattern = pattern.present? ? ActiveSupport::Inflector.transliterate(pattern) : ""
- all_tags.uniq.select do |t|
- ActiveSupport::Inflector.transliterate(t) =~ /#{transliterated_pattern}/i
- end
+ all_tags.uniq.select { |t| ActiveSupport::Inflector.transliterate(t) =~ /#{transliterated_pattern}/i }
end
# Builds a hash where the keys are the capital letters of the tags and the
diff --git a/app/models/event.rb b/app/models/event.rb
index 0b2fd0cea..fa05bfd21 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -16,6 +16,6 @@ class Event < ApplicationRecord
def resource_presence
return if post_id.present? ^ member_id.present? ^ transfer_id.present?
- errors.add(:base, "Specify only one resource id: `post_id`, `member_id` or `transfer_id`")
+ errors.add(:base, 'Specify only one resource id: `post_id`, `member_id` or `transfer_id`')
end
end
diff --git a/app/models/member.rb b/app/models/member.rb
index c97b54902..28285f486 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -27,7 +27,7 @@ class Member < ApplicationRecord
delegate :balance, to: :account, prefix: true, allow_nil: true
delegate :gender, :date_of_birth, to: :user, prefix: true, allow_nil: true
- scope :by_month, ->(month) { where(created_at: month.beginning_of_month..month.end_of_month) }
+ scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) }
scope :active, -> { where active: true }
scope :by_organization, ->(org) { where(organization_id: org) if org }
diff --git a/app/models/movement.rb b/app/models/movement.rb
index 3cad5edde..078a427c7 100644
--- a/app/models/movement.rb
+++ b/app/models/movement.rb
@@ -9,7 +9,7 @@ class Movement < ApplicationRecord
belongs_to :account, optional: true
belongs_to :transfer, optional: true
- scope :by_month, ->(month) { where(created_at: month.beginning_of_month..month.end_of_month) }
+ scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) }
validates :amount, numericality: { other_than: 0 }
diff --git a/app/models/organization.rb b/app/models/organization.rb
index d97efc08d..cec867101 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -2,13 +2,13 @@ class Organization < ApplicationRecord
include PgSearch::Model
pg_search_scope :search_by_query,
- against: %i[city neighborhood address name],
- ignoring: :accents,
- using: {
- tsearch: {
- prefix: true
- }
- }
+ against: %i[city neighborhood address name],
+ ignoring: :accents,
+ using: {
+ tsearch: {
+ prefix: true
+ }
+ }
has_one_attached :logo
@@ -73,7 +73,7 @@ def next_reg_number_seq
def ensure_url
return if web.blank? || URI.parse(web).is_a?(URI::HTTP)
- rescue StandardError
+ rescue
errors.add(:web, :url_format_invalid)
else
if URI.parse("http://#{web}").is_a?(URI::HTTP)
diff --git a/app/models/petition.rb b/app/models/petition.rb
index dbad7ee41..24ad28376 100644
--- a/app/models/petition.rb
+++ b/app/models/petition.rb
@@ -1,5 +1,5 @@
class Petition < ApplicationRecord
- enum status: { pending: 0, accepted: 1, declined: 2 }
+ enum status: %i[pending accepted declined]
belongs_to :user
belongs_to :organization
diff --git a/app/models/post.rb b/app/models/post.rb
index 0c63f5486..199755bf3 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -3,14 +3,14 @@ class Post < ApplicationRecord
include PgSearch::Model
pg_search_scope :search_by_query,
- against: %i[title description tags],
- ignoring: :accents,
- using: {
- tsearch: {
- prefix: true,
- tsvector_column: "tsv"
- }
- }
+ against: [:title, :description, :tags],
+ ignoring: :accents,
+ using: {
+ tsearch: {
+ prefix: true,
+ tsvector_column: 'tsv'
+ }
+ }
attr_reader :member_id
@@ -47,7 +47,7 @@ class Post < ApplicationRecord
validates :title, presence: true
def as_indexed_json(*)
- as_json(only: %i[title description tags organization_id])
+ as_json(only: [:title, :description, :tags, :organization_id])
end
def to_s
@@ -71,6 +71,6 @@ def member
end
def rendered_description
- RDiscount.new(description || "", :autolink)
+ RDiscount.new(description || '', :autolink)
end
end
diff --git a/app/models/push_notification.rb b/app/models/push_notification.rb
index 26872ed82..8344537b8 100644
--- a/app/models/push_notification.rb
+++ b/app/models/push_notification.rb
@@ -1,6 +1,6 @@
class PushNotification < ApplicationRecord
- belongs_to :event
- belongs_to :device_token
+ belongs_to :event, foreign_key: 'event_id'
+ belongs_to :device_token, foreign_key: 'device_token_id'
validates :title, :body, presence: true, allow_blank: false
diff --git a/app/models/transfer.rb b/app/models/transfer.rb
index 10419f19b..41e4db8ca 100644
--- a/app/models/transfer.rb
+++ b/app/models/transfer.rb
@@ -24,8 +24,7 @@ class Transfer < ApplicationRecord
def make_movements
movements.create(account: Account.find(source_id), amount: -amount.to_i, created_at: created_at)
- movements.create(account: Account.find(destination_id), amount: amount.to_i,
- created_at: created_at)
+ movements.create(account: Account.find(destination_id), amount: amount.to_i, created_at: created_at)
end
def source_id
@@ -38,7 +37,6 @@ def destination_id
def different_source_and_destination
return unless source == destination
-
errors.add(:base, :same_account)
end
end
diff --git a/app/models/transfer_factory.rb b/app/models/transfer_factory.rb
index 29769d8d2..a093299cd 100644
--- a/app/models/transfer_factory.rb
+++ b/app/models/transfer_factory.rb
@@ -73,8 +73,8 @@ def admin?
#
# @return [Account]
def destination_account
- @destination_account ||= current_organization.
- all_accounts.
- find(destination_account_id)
+ @destination_account ||= current_organization
+ .all_accounts
+ .find(destination_account_id)
end
end
diff --git a/app/models/transfer_sources_options.rb b/app/models/transfer_sources_options.rb
index 252d5fda2..f9c2b2a9d 100644
--- a/app/models/transfer_sources_options.rb
+++ b/app/models/transfer_sources_options.rb
@@ -13,9 +13,9 @@ def initialize(sources)
#
# @return [Array]
def to_a
- sources.
- sort_by { |account| to_accountable_type_and_uid(account) }.
- map { |account| to_text_and_value(account) }
+ sources
+ .sort_by { |account| to_accountable_type_and_uid(account) }
+ .map { |account| to_text_and_value(account) }
end
private
diff --git a/app/models/user.rb b/app/models/user.rb
index 8a3b58cd0..49f462f19 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,9 +1,16 @@
class User < ApplicationRecord
- devise :database_authenticatable, :recoverable, :rememberable, :confirmable, :lockable,
- :trackable, :timeoutable
+ devise *[
+ :database_authenticatable,
+ :recoverable,
+ :rememberable,
+ :confirmable,
+ :lockable,
+ :trackable,
+ :timeoutable
+ ]
ransacker :username do
- Arel.sql("unaccent(users.username)")
+ Arel.sql('unaccent(users.username)')
end
GENDERS = %w(
@@ -13,7 +20,8 @@ class User < ApplicationRecord
prefer_not_to_answer
)
- attr_accessor :empty_email, :from_signup
+ attr_accessor :empty_email
+ attr_accessor :from_signup
has_one_attached :avatar
@@ -39,8 +47,8 @@ class User < ApplicationRecord
validates :password, presence: true, if: :from_signup?
# Allows @domain.com for dummy emails but does not allow pure invalid
# emails like 'without email'
- validates :email,
- format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
+ validates_format_of :email,
+ with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates :gender, inclusion: { in: GENDERS, allow_blank: true }
def as_member_of(organization)
@@ -77,7 +85,7 @@ def add_to_organization(organization)
persister = ::Persister::MemberPersister.new(member)
persister.save
- member if member.persisted?
+ return member if member.persisted?
end
def active?(organization)
@@ -125,8 +133,7 @@ def email_if_real
end
def was_member?(petition)
- petition.status == "accepted" && Member.where(organization: petition.organization,
- user: self).none?
+ petition.status == 'accepted' && Member.where(organization: petition.organization, user: self).none?
end
def from_signup?
diff --git a/app/services/operations/transfers.rb b/app/services/operations/transfers.rb
index 003f78c8c..8bd56a59b 100644
--- a/app/services/operations/transfers.rb
+++ b/app/services/operations/transfers.rb
@@ -11,11 +11,12 @@ def create(from:, to:, transfer_params:)
end
def transfer_klass(from:, to:)
- if from.length == 1 && to.length == 1
+ case
+ when from.length == 1 && to.length == 1
OneToOne
- elsif from.length > 1 && to.length == 1
+ when from.length > 1 && to.length == 1
ManyToOne
- elsif from.length == 1 && to.length > 1
+ when from.length == 1 && to.length > 1
OneToMany
else
raise ArgumentError, "Unknown type of transfer"
diff --git a/app/services/operations/transfers/base.rb b/app/services/operations/transfers/base.rb
index 67d265424..7950b069b 100644
--- a/app/services/operations/transfers/base.rb
+++ b/app/services/operations/transfers/base.rb
@@ -37,9 +37,9 @@ def transfers
def build_transfer(source:, destination:)
::Transfer.new(transfer_params_for(
- source: source,
- destination: destination
- ))
+ source: source,
+ destination: destination
+ ))
end
def transfer_params_for(source:, destination:)
diff --git a/app/services/operations/transfers/one_to_many.rb b/app/services/operations/transfers/one_to_many.rb
index 629e749b6..f24f4e9ae 100644
--- a/app/services/operations/transfers/one_to_many.rb
+++ b/app/services/operations/transfers/one_to_many.rb
@@ -22,3 +22,4 @@ def destinations
end
end
end
+
diff --git a/app/services/persister/member_persister.rb b/app/services/persister/member_persister.rb
index b790740c6..c03bcd201 100644
--- a/app/services/persister/member_persister.rb
+++ b/app/services/persister/member_persister.rb
@@ -12,7 +12,7 @@ def save
create_save_event!
member
end
- rescue ActiveRecord::RecordInvalid => _e
+ rescue ActiveRecord::RecordInvalid => _exception
false
end
@@ -22,7 +22,7 @@ def update(params)
create_update_event!
member
end
- rescue ActiveRecord::RecordInvalid => _e
+ rescue ActiveRecord::RecordInvalid => _exception
false
end
diff --git a/app/services/persister/post_persister.rb b/app/services/persister/post_persister.rb
index c9bea3a34..c5287647c 100644
--- a/app/services/persister/post_persister.rb
+++ b/app/services/persister/post_persister.rb
@@ -13,7 +13,7 @@ def save
enqueue_push_notification_job!
post
end
- rescue ActiveRecord::RecordInvalid => _e
+ rescue ActiveRecord::RecordInvalid => _exception
false
end
@@ -24,7 +24,7 @@ def update(params)
enqueue_push_notification_job!
post
end
- rescue ActiveRecord::RecordInvalid => _e
+ rescue ActiveRecord::RecordInvalid => _exception
false
end
diff --git a/app/services/persister/transfer_persister.rb b/app/services/persister/transfer_persister.rb
index c540d6f6f..2a48cfa20 100644
--- a/app/services/persister/transfer_persister.rb
+++ b/app/services/persister/transfer_persister.rb
@@ -12,7 +12,7 @@ def save
create_save_event!
transfer
end
- rescue ActiveRecord::RecordInvalid => _e
+ rescue ActiveRecord::RecordInvalid => _exception
false
end
@@ -22,7 +22,7 @@ def update(params)
create_update_event!
transfer
end
- rescue ActiveRecord::RecordInvalid => _e
+ rescue ActiveRecord::RecordInvalid => _exception
false
end
diff --git a/app/services/push_notifications/broadcast.rb b/app/services/push_notifications/broadcast.rb
index 09f07c987..9681ea9d2 100644
--- a/app/services/push_notifications/broadcast.rb
+++ b/app/services/push_notifications/broadcast.rb
@@ -46,7 +46,7 @@ def client
end
def uri
- URI("https://exp.host/--/api/v2/push/send")
+ URI('https://exp.host/--/api/v2/push/send')
end
def headers
diff --git a/app/services/push_notifications/creator/base.rb b/app/services/push_notifications/creator/base.rb
index f08f0eef9..b7fdec805 100644
--- a/app/services/push_notifications/creator/base.rb
+++ b/app/services/push_notifications/creator/base.rb
@@ -27,15 +27,15 @@ def create!
attr_accessor :event
def title
- raise "implement the private method `title`"
+ raise 'implement the private method `title`'
end
def body
- raise "implement the private method `body`"
+ raise 'implement the private method `body`'
end
def data
- raise "implement the private method `data`"
+ raise 'implement the private method `data`'
end
end
end
diff --git a/app/services/push_notifications/creator/post.rb b/app/services/push_notifications/creator/post.rb
index 6a2fdf94d..66e047d6e 100644
--- a/app/services/push_notifications/creator/post.rb
+++ b/app/services/push_notifications/creator/post.rb
@@ -11,16 +11,16 @@ def body
description = event.post.description
if description.blank?
- "No description"
+ 'No description'
else
description.truncate(20)
end
end
def data
- if event.post.class.to_s == "Offer"
+ if event.post.class.to_s == 'Offer'
{ url: Rails.application.routes.url_helpers.offer_path(event.post) }
- elsif event.post.class.to_s == "Inquiry"
+ elsif event.post.class.to_s == 'Inquiry'
{ url: Rails.application.routes.url_helpers.inquiry_path(event.post) }
else
{}
diff --git a/app/services/push_notifications/event_notifier/post.rb b/app/services/push_notifications/event_notifier/post.rb
index 9ed81e156..0a685c03e 100644
--- a/app/services/push_notifications/event_notifier/post.rb
+++ b/app/services/push_notifications/event_notifier/post.rb
@@ -29,12 +29,12 @@ def device_tokens
#
# @return
def user_ids
- post.
- organization.
- users.
- select(:id).
- where("members.active = true").
- where("users.push_notifications = true")
+ post
+ .organization
+ .users
+ .select(:id)
+ .where('members.active = true')
+ .where('users.push_notifications = true')
end
end
end
diff --git a/app/services/push_notifications/event_notifier_factory.rb b/app/services/push_notifications/event_notifier_factory.rb
index 2f0a4e480..092583084 100644
--- a/app/services/push_notifications/event_notifier_factory.rb
+++ b/app/services/push_notifications/event_notifier_factory.rb
@@ -7,7 +7,7 @@ def initialize(event:)
def build
return EventNotifier::Post.new(event: event) if event.post_id
- raise "The resource associated to the Event is not supported"
+ raise 'The resource associated to the Event is not supported'
end
private
diff --git a/app/services/transfer_importer.rb b/app/services/transfer_importer.rb
index 617909c51..93acbc135 100644
--- a/app/services/transfer_importer.rb
+++ b/app/services/transfer_importer.rb
@@ -15,9 +15,8 @@ class TransferImporter
:post_id
) do
def transfer_from_row(organization_id, errors)
- source = find_account(source_id, source_type, organization_id, errors, "source")
- destination = find_account(destination_id, destination_type, organization_id, errors,
- "destination")
+ source = find_account(source_id, source_type, organization_id, errors, 'source')
+ destination = find_account(destination_id, destination_type, organization_id, errors, 'destination')
return unless source && destination
Transfer.new(
@@ -33,15 +32,14 @@ def transfer_from_row(organization_id, errors)
private
def find_account(id, type, organization_id, errors, direction)
- acc = if type.downcase == "organization"
+ acc = if type.downcase == 'organization'
Organization.find(organization_id).account
else
Member.find_by(member_uid: id, organization_id: organization_id)&.account
end
unless acc
- errors.push(account_id: id,
- errors: "#{direction}_id #{id} not found in organization #{organization_id}")
+ errors.push(account_id: id, errors: "#{direction}_id #{id} not found in organization #{organization_id}")
return false
end
acc
diff --git a/app/services/user_importer.rb b/app/services/user_importer.rb
index 8a9c2f1e6..b75ac273c 100644
--- a/app/services/user_importer.rb
+++ b/app/services/user_importer.rb
@@ -68,10 +68,9 @@ def member_from_row(row, user, organization, errors)
entry_date: row.entry_date,
user_id: user.id)
- if member.errors.present?
- errors.push(member_id: row.member_id, email: row.email,
- errors: member.errors.full_messages)
- end
+ errors.push(member_id: row.member_id, email: row.email,
+ errors: member.errors.full_messages
+ ) if member.errors.present?
end
end
end