Move comment reactions into own controller
This commit is contained in:
parent
5afaef427c
commit
e8e833f9bd
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Comments::ReactionsController < ApplicationController
|
||||
def show
|
||||
comment = Comment.find(params[:id])
|
||||
@reactions = Reaction.where(parent_type: "Comment", parent: comment.id).includes([{ user: :profile }])
|
||||
|
||||
redirect_to answer_path(username: comment.answer.user.screen_name, id: comment.answer.id) unless turbo_frame_request?
|
||||
end
|
||||
end
|
|
@ -7,11 +7,4 @@ class CommentsController < ApplicationController
|
|||
|
||||
render "index", locals: { a: answer }
|
||||
end
|
||||
|
||||
def show_reactions
|
||||
comment = Comment.find(params[:id])
|
||||
@reactions = Reaction.where(parent_type: "Comment", parent: comment.id).includes([{ user: :profile }])
|
||||
|
||||
redirect_to answer_path(username: comment.answer.user.screen_name, id: comment.answer.id) unless turbo_frame_request?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -157,7 +157,7 @@ Rails.application.routes.draw do
|
|||
get "/@:username/a/:id/comments", to: "comments#index", as: :comments
|
||||
get "/@:username/a/:id/reactions", to: "reaction#index", as: :reactions
|
||||
get "/@:username/q/:id", to: "question#show", as: :question
|
||||
get "/@:username/c/:id/reactions", to: "comments#show_reactions", as: :comment_reactions
|
||||
get "/@:username/c/:id/reactions", to: "comments/reactions#show", as: :comment_reactions
|
||||
get "/@:username/followers", to: "user#followers", as: :show_user_followers
|
||||
get "/@:username/followings", to: "user#followings", as: :show_user_followings
|
||||
get "/@:username/friends", to: redirect("/@%{username}/followings")
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Comments::ReactionsController, type: :controller do
|
||||
describe "#show" do
|
||||
let(:answer_author) { FactoryBot.create(:user) }
|
||||
let(:answer) { FactoryBot.create(:answer, user: answer_author) }
|
||||
let(:commenter) { FactoryBot.create(:user) }
|
||||
let(:comment) { FactoryBot.create(:comment, answer:, user: commenter) }
|
||||
|
||||
context "a regular web navigation request" do
|
||||
subject { get :show, params: { username: commenter.screen_name, id: comment.id } }
|
||||
|
||||
it "should redirect to the answer page" do
|
||||
subject
|
||||
|
||||
expect(response).to redirect_to answer_path(username: answer_author.screen_name, id: answer.id)
|
||||
end
|
||||
end
|
||||
|
||||
context "a Turbo Frame request" do
|
||||
subject { get :show, params: { username: commenter.screen_name, id: comment.id } }
|
||||
|
||||
it "renders the show_reaction template" do
|
||||
@request.headers["Turbo-Frame"] = "some_id"
|
||||
|
||||
subject
|
||||
|
||||
expect(response).to render_template(:show)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -34,33 +34,4 @@ describe CommentsController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#show_reactions" do
|
||||
let(:answer_author) { FactoryBot.create(:user) }
|
||||
let(:answer) { FactoryBot.create(:answer, user: answer_author) }
|
||||
let(:commenter) { FactoryBot.create(:user) }
|
||||
let(:comment) { FactoryBot.create(:comment, answer:, user: commenter) }
|
||||
|
||||
context "a regular web navigation request" do
|
||||
subject { get :show_reactions, params: { username: commenter.screen_name, id: comment.id } }
|
||||
|
||||
it "should redirect to the answer page" do
|
||||
subject
|
||||
|
||||
expect(response).to redirect_to answer_path(username: answer_author.screen_name, id: answer.id)
|
||||
end
|
||||
end
|
||||
|
||||
context "a Turbo Frame request" do
|
||||
subject { get :show_reactions, params: { username: commenter.screen_name, id: comment.id } }
|
||||
|
||||
it "renders the show_reaction template" do
|
||||
@request.headers["Turbo-Frame"] = "some_id"
|
||||
|
||||
subject
|
||||
|
||||
expect(response).to render_template(:show_reactions)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue