diff --git a/app/controllers/modal_controller.rb b/app/controllers/modal_controller.rb index 16ae890e..a8d61d60 100644 --- a/app/controllers/modal_controller.rb +++ b/app/controllers/modal_controller.rb @@ -7,7 +7,7 @@ class ModalController < ApplicationController skip_before_action :find_active_announcements, :banned? def close - redirect_to root_path unless turbo_frame_request? + return redirect_to root_path unless turbo_frame_request? render inline: turbo_frame_tag("modal") end end diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb index ace2aad8..63812485 100644 --- a/spec/controllers/comment_controller_spec.rb +++ b/spec/controllers/comment_controller_spec.rb @@ -34,4 +34,33 @@ describe CommentController, 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 diff --git a/spec/controllers/modal_controller_spec.rb b/spec/controllers/modal_controller_spec.rb new file mode 100644 index 00000000..d927173a --- /dev/null +++ b/spec/controllers/modal_controller_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe ModalController, type: :controller do + describe "#close" do + context "a regular web navigation request" do + subject { get :close } + + it "should redirect to the root page" do + subject + + expect(response).to redirect_to root_path + end + end + + context "a Turbo Frame request" do + subject { get :close } + + it "renders the show_reaction template" do + @request.headers["Turbo-Frame"] = "some_id" + + subject + + expect(response.body).to include('') + end + end + end +end