mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 10:29:53 +01:00
Appease the dog overlords
This commit is contained in:
parent
0555279cd2
commit
47120e8d24
3 changed files with 28 additions and 26 deletions
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Ajax::ListController < AjaxController
|
||||
before_action :authenticate_user!
|
||||
|
||||
|
@ -6,13 +8,13 @@ class Ajax::ListController < AjaxController
|
|||
|
||||
@response[:status] = :err
|
||||
|
||||
target_user = User.find_by_screen_name!(params[:user])
|
||||
target_user = User.find_by!(screen_name: params[:user])
|
||||
list = List.create! user: current_user, display_name: params[:name]
|
||||
|
||||
@response[:status] = :okay
|
||||
@response[:success] = true
|
||||
@response[:message] = t(".success")
|
||||
@response[:render] = render_to_string(partial: 'modal/list/item', locals: { list: list, user: target_user })
|
||||
@response[:render] = render_to_string(partial: "modal/list/item", locals: { list: list, user: target_user })
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -34,20 +36,20 @@ class Ajax::ListController < AjaxController
|
|||
|
||||
@response[:status] = :err
|
||||
|
||||
add = params[:add] == 'true'
|
||||
add = params[:add] == "true"
|
||||
|
||||
target_user = User.find_by_screen_name!(params[:user])
|
||||
list = current_user.lists.find_by_name!(params[:list])
|
||||
target_user = User.find_by!(screen_name: params[:user])
|
||||
list = current_user.lists.find_by!(name: params[:list])
|
||||
|
||||
raise Errors::ListingSelfBlockedOther if current_user.blocking?(target_user)
|
||||
raise Errors::ListingOtherBlockedSelf if target_user.blocking?(current_user)
|
||||
|
||||
if add
|
||||
list.add_member target_user if list.members.find_by_user_id(target_user.id).nil?
|
||||
list.add_member target_user if list.members.find_by(user_id: target_user.id).nil?
|
||||
@response[:checked] = true
|
||||
@response[:message] = t(".success.add")
|
||||
else
|
||||
list.remove_member target_user unless list.members.find_by_user_id(target_user.id).nil?
|
||||
list.remove_member target_user unless list.members.find_by(user_id: target_user.id).nil?
|
||||
@response[:checked] = false
|
||||
@response[:message] = t(".success.remove")
|
||||
end
|
||||
|
|
|
@ -7,14 +7,14 @@ class List < ApplicationRecord
|
|||
has_many :list_members, dependent: :destroy
|
||||
|
||||
validates :name,
|
||||
length: { minimum: 1 },
|
||||
length: { minimum: 1 },
|
||||
uniqueness: { scope: :user_id }
|
||||
validates :display_name, length: { maximum: 30 }
|
||||
|
||||
before_validation do
|
||||
self.display_name.strip!
|
||||
self.name = self.display_name.parameterize
|
||||
self.name = '-followers-' if self.name == 'followers'
|
||||
display_name.strip!
|
||||
self.name = display_name.parameterize
|
||||
self.name = "-followers-" if name == "followers"
|
||||
end
|
||||
|
||||
alias members list_members
|
||||
|
|
|
@ -21,9 +21,9 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => true,
|
||||
"status" => "okay",
|
||||
"status" => "okay",
|
||||
"message" => anything,
|
||||
"render" => anything
|
||||
"render" => anything
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -40,7 +40,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "parameter_error",
|
||||
"status" => "parameter_error",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "not_found",
|
||||
"status" => "not_found",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
@ -74,7 +74,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "err",
|
||||
"status" => "err",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
@ -91,7 +91,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "err",
|
||||
"status" => "err",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
@ -137,7 +137,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => true,
|
||||
"status" => "okay",
|
||||
"status" => "okay",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
@ -156,7 +156,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "parameter_error",
|
||||
"status" => "parameter_error",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
@ -173,7 +173,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "err",
|
||||
"status" => "err",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
@ -218,7 +218,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
{
|
||||
"list" => list_param,
|
||||
"user" => target_user_param,
|
||||
"add" => add_param
|
||||
"add" => add_param
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -228,7 +228,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => true,
|
||||
"status" => "okay",
|
||||
"status" => "okay",
|
||||
"message" => anything,
|
||||
"checked" => expected_checked
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
|
||||
it "does not do anything" do
|
||||
expect { subject }.not_to(change { list.members })
|
||||
expect(list.members.map { |gm| gm.user.id }.sort ).to eq([])
|
||||
expect(list.members.map { |gm| gm.user.id }.sort).to eq([])
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
|
@ -273,7 +273,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
|
||||
it "does not add the user to the list again" do
|
||||
expect { subject }.not_to(change { list.members })
|
||||
expect(list.members.map { |gm| gm.user.id }.sort ).to eq([target_user.id])
|
||||
expect(list.members.map { |gm| gm.user.id }.sort).to eq([target_user.id])
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
|
@ -286,7 +286,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "not_found",
|
||||
"status" => "not_found",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
@ -300,7 +300,7 @@ describe Ajax::ListController, :ajax_controller, type: :controller do
|
|||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "not_found",
|
||||
"status" => "not_found",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue