Appease the dog overlords
This commit is contained in:
parent
0555279cd2
commit
47120e8d24
|
@ -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
|
||||
|
|
|
@ -12,9 +12,9 @@ class List < ApplicationRecord
|
|||
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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue