Use `screen_name` instead of `target_user` param in `Ajax::RelationshipController`

This commit is contained in:
Karina Kwiatek 2022-01-19 19:24:54 +01:00 committed by Karina Kwiatek
parent b4e0699e82
commit 8d59ef9398
2 changed files with 20 additions and 20 deletions

View File

@ -8,15 +8,15 @@ class Ajax::RelationshipController < AjaxController
before_action :authenticate_user! before_action :authenticate_user!
def create def create
params.require :target_user params.require :screen_name
UseCase::Relationship::Create.call( UseCase::Relationship::Create.call(
current_user: current_user.screen_name, current_user: current_user.screen_name,
target_user: params[:target_user], target_user: params[:screen_name],
type: params[:type] type: params[:type]
) )
@response[:success] = true @response[:success] = true
@response[:message] = t("messages.friend.create.success") @response[:message] = t("messages.friend.create.okay")
rescue Errors::Base => e rescue Errors::Base => e
@response[:message] = t(e.locale_tag) @response[:message] = t(e.locale_tag)
ensure ensure
@ -26,13 +26,13 @@ class Ajax::RelationshipController < AjaxController
def destroy def destroy
UseCase::Relationship::Destroy.call( UseCase::Relationship::Destroy.call(
current_user: current_user.screen_name, current_user: current_user.screen_name,
target_user: params[:target_user], target_user: params[:screen_name],
type: params[:type] type: params[:type]
) )
@response[:success] = true @response[:success] = true
@response[:message] = t("messages.friend.create.success") @response[:message] = t("messages.friend.destroy.okay")
rescue Errors::Base => e rescue Errors::Base => e
@response[:message] = t(e.locale_tag) @response[:message] = t("messages.friend.destroy.fail")
ensure ensure
return_response return_response
end end

View File

@ -17,31 +17,31 @@ describe Ajax::RelationshipController, type: :controller do
shared_examples_for "valid relationship type" do shared_examples_for "valid relationship type" do
it_behaves_like "params is empty" it_behaves_like "params is empty"
context "target_user does not exist" do context "screen_name does not exist" do
let(:target_user) { "peter-witzig" } let(:screen_name) { "peter-witzig" }
include_examples "ajax does not succeed", "not found" include_examples "ajax does not succeed", "not found"
end end
context "target_user is current user" do context "screen_name is current user" do
let(:target_user) { user.screen_name } let(:screen_name) { user.screen_name }
include_examples "ajax does not succeed", "yourself" include_examples "ajax does not succeed", "yourself"
end end
context "target_user is different from current_user" do context "screen_name is different from current_user" do
let(:target_user) { user2.screen_name } let(:screen_name) { user2.screen_name }
it "creates the relationship" do it "creates the relationship" do
expect { subject }.to change { Relationship.count }.by(1) expect { subject }.to change { Relationship.count }.by(1)
expect(Relationship.last.target.screen_name).to eq(target_user) expect(Relationship.last.target.screen_name).to eq(screen_name)
end end
end end
end end
let(:type) { "Sauerkraut" } let(:type) { "Sauerkraut" }
let(:target_user) { user2.screen_name } let(:screen_name) { user2.screen_name }
let(:params) { { type: type, target_user: target_user } } let(:params) { { type: type, screen_name: screen_name } }
subject { post(:create, params: params) } subject { post(:create, params: params) }
@ -67,7 +67,7 @@ describe Ajax::RelationshipController, type: :controller do
describe "#destroy" do describe "#destroy" do
shared_examples_for "valid relationship type" do shared_examples_for "valid relationship type" do
let(:target_user) { user2.screen_name } let(:screen_name) { user2.screen_name }
context "relationship exists" do context "relationship exists" do
before do before do
@ -85,16 +85,16 @@ describe Ajax::RelationshipController, type: :controller do
end end
end end
context "target_user does not exist" do context "screen_name does not exist" do
let(:target_user) { "peter-witzig" } let(:screen_name) { "peter-witzig" }
include_examples "ajax does not succeed", "not found" include_examples "ajax does not succeed", "not found"
end end
end end
let(:type) { "Sauerkraut" } let(:type) { "Sauerkraut" }
let(:target_user) { user2.screen_name } let(:screen_name) { user2.screen_name }
let(:params) { { type: type, target_user: target_user } } let(:params) { { type: type, screen_name: screen_name } }
subject { delete(:destroy, params: params) } subject { delete(:destroy, params: params) }