Move reactions to separate view/endpoint
This commit is contained in:
parent
9563a586c2
commit
81b271ab03
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ReactionController < ApplicationController
|
||||||
|
def index
|
||||||
|
answer = Answer.includes([smiles: { user: :profile }]).find(params[:id])
|
||||||
|
|
||||||
|
render "index", locals: { a: answer }
|
||||||
|
end
|
||||||
|
end
|
|
@ -35,6 +35,10 @@
|
||||||
.col-md-6.d-md-flex.answerbox__actions
|
.col-md-6.d-md-flex.answerbox__actions
|
||||||
= render "answerbox/actions", a:, display_all:, subscribed_answer_ids:
|
= render "answerbox/actions", a:, display_all:, subscribed_answer_ids:
|
||||||
.card-footer{ id: "ab-comments-section-#{a.id}", class: display_all.nil? ? "d-none" : nil }
|
.card-footer{ id: "ab-comments-section-#{a.id}", class: display_all.nil? ? "d-none" : nil }
|
||||||
|
= turbo_frame_tag("ab-reactions-list-#{a.id}", src: reactions_path(a.question, a), loading: :lazy) do
|
||||||
|
.d-flex.smiles
|
||||||
|
.flex-shrink-0.me-1
|
||||||
|
%i.fa.fa-smile-o
|
||||||
= turbo_frame_tag("ab-comments-list-#{a.id}", src: comments_path(a.question, a), loading: :lazy) do
|
= turbo_frame_tag("ab-comments-list-#{a.id}", src: comments_path(a.question, a), loading: :lazy) do
|
||||||
.d-flex.justify-content-center
|
.d-flex.justify-content-center
|
||||||
.spinner-border{ role: :status }
|
.spinner-border{ role: :status }
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
= turbo_frame_tag "ab-comments-list-#{a.id}" do
|
= turbo_frame_tag "ab-comments-list-#{a.id}" do
|
||||||
%div{ id: "ab-smiles-#{a.id}" }= render "answerbox/smiles", a:
|
|
||||||
%div{ id: "ab-comments-#{a.id}" }= render "answerbox/comments", a:, comments: @comments
|
%div{ id: "ab-comments-#{a.id}" }= render "answerbox/comments", a:, comments: @comments
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
= turbo_frame_tag "ab-reactions-list-#{a.id}" do
|
||||||
|
%div{ id: "ab-smiles-#{a.id}" }= render "answerbox/smiles", a:
|
|
@ -154,6 +154,7 @@ Rails.application.routes.draw do
|
||||||
post "/@:username/a/:id/pin", to: "answer#pin", as: :pin_answer
|
post "/@:username/a/:id/pin", to: "answer#pin", as: :pin_answer
|
||||||
delete "/@:username/a/:id/pin", to: "answer#unpin", as: :unpin_answer
|
delete "/@:username/a/:id/pin", to: "answer#unpin", as: :unpin_answer
|
||||||
get "/@:username/a/:id/comments", to: "comment#index", as: :comments
|
get "/@:username/a/:id/comments", to: "comment#index", as: :comments
|
||||||
|
get "/@:username/a/:id/reactions", to: "reaction#index", as: :reactions
|
||||||
get "/@:username/q/:id", to: "question#show", as: :question
|
get "/@:username/q/:id", to: "question#show", as: :question
|
||||||
get "/@:username/followers", to: "user#followers", as: :show_user_followers
|
get "/@:username/followers", to: "user#followers", as: :show_user_followers
|
||||||
get "/@:username/followings", to: "user#followings", as: :show_user_followings
|
get "/@:username/followings", to: "user#followings", as: :show_user_followings
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe ReactionController, type: :controller do
|
||||||
|
describe "#index" do
|
||||||
|
shared_examples_for "succeeds" do
|
||||||
|
it "returns the correct response" do
|
||||||
|
subject
|
||||||
|
expect(response).to have_rendered("reaction/index")
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { get :index, params: { username: answer_author.screen_name, id: answer.id } }
|
||||||
|
|
||||||
|
let(:answer_author) { FactoryBot.create(:user) }
|
||||||
|
let(:answer) { FactoryBot.create(:answer, user: answer_author) }
|
||||||
|
let!(:reactees) { FactoryBot.create_list(:user, num_comments) }
|
||||||
|
|
||||||
|
[0, 1, 5, 30].each do |num_comments|
|
||||||
|
context "#{num_comments} reactions" do
|
||||||
|
let(:num_comments) { num_comments }
|
||||||
|
|
||||||
|
before do
|
||||||
|
reactees.each { _1.smile(answer) }
|
||||||
|
end
|
||||||
|
|
||||||
|
include_examples "succeeds"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue