Return NotFound error if ChatChannelMembership is not found (#5806)

This commit is contained in:
Maja Komel 2020-02-05 18:24:40 +01:00 committed by GitHub
parent 7270d5ab4c
commit 28440d1fa1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -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],

View file

@ -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