Fix lint errors

This commit is contained in:
Karina Kwiatek 2022-01-16 18:51:27 +01:00 committed by Karina Kwiatek
parent 0ab822c33a
commit b4e0699e82
15 changed files with 48 additions and 37 deletions

View File

@ -12,11 +12,11 @@ class Ajax::RelationshipController < AjaxController
UseCase::Relationship::Create.call(
current_user: current_user.screen_name,
target_user: params[:target_user],
type: params[:type]
target_user: params[:target_user],
type: params[:type]
)
@response[:success] = true
@response[:message] = t('messages.friend.create.success')
@response[:message] = t("messages.friend.create.success")
rescue Errors::Base => e
@response[:message] = t(e.locale_tag)
ensure
@ -26,11 +26,11 @@ class Ajax::RelationshipController < AjaxController
def destroy
UseCase::Relationship::Destroy.call(
current_user: current_user.screen_name,
target_user: params[:target_user],
type: params[:type]
target_user: params[:target_user],
type: params[:type]
)
@response[:success] = true
@response[:message] = t('messages.friend.create.success')
@response[:message] = t("messages.friend.create.success")
rescue Errors::Base => e
@response[:message] = t(e.locale_tag)
ensure

View File

@ -12,7 +12,7 @@ class AjaxController < ApplicationController
@response = {
success: false,
message: "Something went wrong",
status: :err
status: :err
}
return_response
@ -24,7 +24,7 @@ class AjaxController < ApplicationController
@response = {
success: false,
message: "Missing parameter: #{e.key}",
status: :err
status: :err
}
return_response
@ -36,7 +36,7 @@ class AjaxController < ApplicationController
@response = {
success: false,
message: "Invalid parameter",
status: :err
status: :err
}
return_response
@ -48,7 +48,7 @@ class AjaxController < ApplicationController
@response = {
success: false,
message: "Record not found",
status: :not_found
status: :not_found
}
return_response
@ -59,8 +59,8 @@ class AjaxController < ApplicationController
@response = {
success: false,
message: I18n.t('messages.parameter_error', parameter: e.param.capitalize),
status: :parameter_error
message: I18n.t("messages.parameter_error", parameter: e.param.capitalize),
status: :parameter_error
}
return_response
@ -75,8 +75,8 @@ class AjaxController < ApplicationController
def build_response
@response = {
success: false,
message: '',
status: 'unknown'
message: "",
status: "unknown"
}
end

View File

@ -96,6 +96,7 @@ class UserController < ApplicationController
end
end
# rubocop:disable Metrics/AbcSize
def followings
@title = 'Following'
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@ -109,6 +110,7 @@ class UserController < ApplicationController
format.js { render "show_follow", layout: false }
end
end
# rubocop:enable Metrics/AbcSize
def questions
@title = 'Questions'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Relationships::Follow < Relationship
after_create do
Notification.notify target, self

View File

@ -8,12 +8,12 @@ class User
extend ActiveSupport::Concern
included do
has_many :active_follow_relationships, class_name: "Relationships::Follow",
has_many :active_follow_relationships, class_name: "Relationships::Follow",
foreign_key: "source_id",
dependent: :destroy
has_many :passive_follow_relationships, class_name: "Relationships::Follow",
dependent: :destroy
has_many :passive_follow_relationships, class_name: "Relationships::Follow",
foreign_key: "target_id",
dependent: :destroy
dependent: :destroy
has_many :followings, through: :active_follow_relationships, source: :target
has_many :followers, through: :passive_follow_relationships, source: :source
end
@ -21,6 +21,7 @@ class User
# Follow an user
def follow(target_user)
raise Errors::FollowingSelf if target_user == self
create_relationship(active_follow_relationships, target_user)
end

View File

@ -7,6 +7,6 @@ module User::TimelineMethods
# @return [Array] the users' timeline
def timeline
Answer.where('user_id in (?) OR user_id = ?', following_ids, id).order(:created_at).reverse_order.includes(comments: [:user, :smiles], question: [:user], user: [:profile], smiles: [:user])
Answer.where("user_id in (?) OR user_id = ?", following_ids, id).order(:created_at).reverse_order.includes(comments: %i[user smiles], question: [:user], user: [:profile], smiles: [:user])
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class AddTypeToRelationships < ActiveRecord::Migration[5.2]
def up
add_column :relationships, :type, :string

View File

@ -1,6 +1,8 @@
# frozen_string_literal: true
class RemoveRelationshipCountersFromUsers < ActiveRecord::Migration[5.2]
def change
remove_column :users, :follower_count
remove_column :users, :friend_count
remove_column :users, :follower_count, :integer
remove_column :users, :friend_count, :integer
end
end

View File

@ -232,8 +232,8 @@ class Exporter
def user_stub(user)
uobj = {}
%i(answered_count asked_count comment_smiled_count commented_count created_at
id permanently_banned screen_name smiled_count).each do |f|
%i[answered_count asked_count comment_smiled_count commented_count created_at
id permanently_banned screen_name smiled_count].each do |f|
uobj[f] = user.send f
end

View File

@ -1,9 +1,9 @@
# frozen_string_literal: true
require 'dry-types'
require "dry-types"
module Types
include Dry.Types()
RelationshipTypes = Types::String.enum('follow')
RelationshipTypes = Types::String.enum("follow")
end

View File

@ -17,9 +17,9 @@ module UseCase
source_user.public_send(type, target_user)
{
status: 201,
status: 201,
resource: true,
extra: {
extra: {
target_user: target_user
}
}
@ -29,6 +29,7 @@ module UseCase
def find_source_user
return current_user if current_user.is_a?(::User)
::User.find_by!(screen_name: current_user)
rescue ActiveRecord::RecordNotFound
raise Errors::UserNotFound
@ -36,6 +37,7 @@ module UseCase
def find_target_user
return target_user if target_user.is_a?(::User)
::User.find_by!(screen_name: target_user)
rescue ActiveRecord::RecordNotFound
raise Errors::UserNotFound

View File

@ -17,9 +17,9 @@ module UseCase
source_user.public_send("un#{type}", target_user)
{
status: 204,
status: 204,
resource: nil,
extra: {
extra: {
target_user: target_user
}
}

View File

@ -5,7 +5,7 @@ require "rails_helper"
describe Ajax::RelationshipController, type: :controller do
shared_examples_for "params is empty" do
let(:params) { }
let(:params) { {} }
include_examples "ajax does not succeed", "is required"
end

View File

@ -40,9 +40,9 @@ describe UseCase::Relationship::Create do
let(:base_params) do
{
current_user: current_user,
target_user: target_user,
type: type
current_user: current_user,
target_user: target_user,
type: type
}
end
let(:params) { base_params }

View File

@ -28,14 +28,14 @@ describe UseCase::Relationship::Destroy do
context "current_user does not exist" do
let(:current_user) { "Schweinsbraten" }
let(:target_user) { user2.screen_name }
let(:target_user) { user2.screen_name }
include_examples "raises an error", Errors::UserNotFound
end
context "target_user does not exist" do
let(:current_user) { user1.screen_name }
let(:target_user) { "peterwitzig" }
let(:target_user) { "peterwitzig" }
include_examples "raises an error", Errors::UserNotFound
end
@ -44,8 +44,8 @@ describe UseCase::Relationship::Destroy do
let(:base_params) do
{
current_user: current_user,
target_user: target_user,
type: type
target_user: target_user,
type: type
}
end
let(:params) { base_params }