* Setup Pusher gem * Create ChatChannel and Message model * Create ChatChannelController * Add back fix-db-schema-conflicts gem * Add pusher-js package * Add validations on Message & ChatChannel models * Update Route * Create MessageController * Update ChatChannelController * Create Chat app WIP * Extract messenger render to Message Component * Implement live chat WIP * Implement live chat WIP (2) * Add style and scrollToBottom feature for chat * Create getUserDataAndCsrfToken function * Add feature toggle to the new live chat * Clean up ChatChannelsController & create spec * Update ChatChannel spec * Update Message spec * Create MessagesController spec & refactor * Clean up Chat app * Fix lint * Add character limit to Message
50 lines
1.2 KiB
Ruby
50 lines
1.2 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_html: "hi",
|
|
user_id: user.id,
|
|
chat_channel_id: chat_channel.id,
|
|
}
|
|
end
|
|
|
|
it "requires user to be signed in" do
|
|
post "/messages", params: { message: new_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 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
|