diff --git a/app/controllers/answer_controller.rb b/app/controllers/answer_controller.rb index 2748c0e2..f9398899 100644 --- a/app/controllers/answer_controller.rb +++ b/app/controllers/answer_controller.rb @@ -1,6 +1,6 @@ class AnswerController < ApplicationController def show - @answer = Answer.find(params[:id]).include(comments: [:user, :smiles], question: [:user], smiles: [:user]) + @answer = Answer.includes(comments: [:user, :smiles], question: [:user], smiles: [:user]).find(params[:id]) @display_all = true if user_signed_in? diff --git a/spec/controllers/answer_controller_spec.rb b/spec/controllers/answer_controller_spec.rb new file mode 100644 index 00000000..bca4b142 --- /dev/null +++ b/spec/controllers/answer_controller_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +describe AnswerController do + let(:user) { FactoryBot.create :user, + otp_module: :disabled, + otp_secret_key: 'AAAAAAAA'} + let(:answer) { FactoryBot.create :answer, user: user } + + describe "#show" do + subject { get :show, params: { username: user.screen_name, id: answer.id } } + + context "user signed in" do + before(:each) { sign_in user } + + it "renders the answer/show template" do + subject + expect(assigns(:answer)).to eq(answer) + expect(response).to render_template("answer/show") + end + end + end +end diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 8635d9d3..128d4e68 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -7,13 +7,27 @@ describe UserController, type: :controller do otp_module: :disabled, otp_secret_key: 'EJFNIJPYXXTCQSRTQY6AG7XQLAT2IDG5H7NGLJE3'} + describe "#show" do + subject { get :show, params: { username: user.screen_name } } + + context "user signed in" do + before(:each) { sign_in user } + + it "renders the user/show template" do + subject + expect(assigns(:user)).to eq(user) + expect(response).to render_template("user/show") + end + end + end + describe "#edit" do subject { get :edit } context "user signed in" do before(:each) { sign_in user } - it "renders the edit_profile_picture template" do + it "renders the user/edit template" do subject expect(response).to render_template("user/edit") end