diff --git a/app/controllers/chat_channel_memberships_controller.rb b/app/controllers/chat_channel_memberships_controller.rb index f8e0aa10d..6aac18e5f 100644 --- a/app/controllers/chat_channel_memberships_controller.rb +++ b/app/controllers/chat_channel_memberships_controller.rb @@ -2,7 +2,7 @@ class ChatChannelMembershipsController < ApplicationController after_action :verify_authorized def find_by_chat_channel_id - @membership = ChatChannelMembership.where(chat_channel_id: params[:chat_channel_id], user_id: current_user.id).first + @membership = ChatChannelMembership.where(chat_channel_id: params[:chat_channel_id], user_id: current_user.id).first! authorize @membership render json: @membership.to_json( only: %i[id status viewable_by chat_channel_id last_opened_at], diff --git a/spec/requests/chat_channel_memberships_spec.rb b/spec/requests/chat_channel_memberships_spec.rb index d4fe8fe49..093c71b3b 100644 --- a/spec/requests/chat_channel_memberships_spec.rb +++ b/spec/requests/chat_channel_memberships_spec.rb @@ -88,4 +88,12 @@ RSpec.describe "ChatChannelMemberships", type: :request do expect(ChatChannelMembership.find(membership.id).status).to eq("left_channel") end end + + describe "GET /chat_channel_memberships/find_by_chat_channel_id" do + it "renders not_found" do + expect do + get "/chat_channel_memberships/find_by_chat_channel_id", params: {} + end.to raise_error(ActiveRecord::RecordNotFound) + end + end end