* Prevent need for eager loading
* Add initial implementation of user block
* Remove debugger oops
* Add index and foreign keys for user_block table
* Use private method instead of exists
* Move channel handling logic to service object
* Update styling a bit
* Use profileDropdown file for future proofing
* Remove commented out code
* Render json: { result } for all endpoints
* Add statuses for sad paths
* Add better sad path handling in the JS
* Remove accidentally committed spec file
* Don't wait for DOM to load block button
* Use equality for accuracy in slug query
* Add status code for unauthorized requests
* Add missing comma sigh
61 lines
1.5 KiB
Ruby
61 lines
1.5 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Messages", type: :request do
|
|
let(:user) { create(:user) }
|
|
let(:chat_channel) { create(:chat_channel) }
|
|
|
|
describe "POST /messages" do
|
|
let(:new_message) do
|
|
{
|
|
message_markdown: "hi",
|
|
user_id: user.id,
|
|
chat_channel_id: chat_channel.id
|
|
}
|
|
end
|
|
|
|
it "requires user to be signed in" do
|
|
post "/messages", params: { message: {} }
|
|
expect(response.status).to eq(302)
|
|
end
|
|
# Pusher::Error
|
|
|
|
context "when user is signed in" do
|
|
before do
|
|
allow(Pusher).to receive(:trigger).and_return(true)
|
|
sign_in user
|
|
post "/messages", params: { message: new_message }
|
|
end
|
|
|
|
it "returns 201 upon success" do
|
|
expect(response.status).to eq(201)
|
|
end
|
|
|
|
it "returns in json" do
|
|
expect(response.content_type).to eq("application/json")
|
|
end
|
|
end
|
|
|
|
context "when user is blocked" do
|
|
before do
|
|
sign_in user
|
|
chat_channel.update(status: "blocked")
|
|
end
|
|
|
|
it "raises an error" do
|
|
expect { post "/messages", params: { message: new_message } }.to raise_error
|
|
end
|
|
end
|
|
|
|
# context "when Pusher isn't cooperating" do
|
|
# before do
|
|
# allow(Pusher).to receive(:trigger).and_raise(Pusher::Error)
|
|
# sign_in user
|
|
# post "/messages", params: { message: new_message }
|
|
# end
|
|
|
|
# it "returns proper message" do
|
|
# expect(response.body).to include("could not trigger Pusher")
|
|
# end
|
|
# end
|
|
end
|
|
end
|