Use ApiController for ChatChannels and return not_found error if channel cant be accessed by user (#5194) [deploy]
This commit is contained in:
parent
2d6df70dea
commit
448adfdd23
2 changed files with 29 additions and 2 deletions
|
|
@ -1,9 +1,9 @@
|
|||
module Api
|
||||
module V0
|
||||
class ChatChannelsController < ApplicationController
|
||||
class ChatChannelsController < ApiController
|
||||
def show
|
||||
@chat_channel = ChatChannel.find(params[:id])
|
||||
raise unless @chat_channel.has_member?(current_user)
|
||||
error_not_found unless @chat_channel.has_member?(current_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
27
spec/requests/api/v0/chat_channels_spec.rb
Normal file
27
spec/requests/api/v0/chat_channels_spec.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Api::V0::ChatChannels", type: :request do
|
||||
let(:user) { create(:user) }
|
||||
let(:chat_channel) { create(:chat_channel) }
|
||||
let(:invite_channel) { create(:chat_channel, channel_type: "invite_only") }
|
||||
|
||||
before { sign_in user }
|
||||
|
||||
describe "GET /api/chat_channels/:id" do
|
||||
it "returns 200 if user is a member of the channel" do
|
||||
chat_channel.add_users([user])
|
||||
get "/api/chat_channels/#{chat_channel.id}"
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it "returns a 404 if user is not a memeber of the channel" do
|
||||
get "/api/chat_channels/#{invite_channel.id}"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "returns a 404 if channel is not found" do
|
||||
get "/api/chat_channels/#{invite_channel.id + 100}"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue