* Initial automatic cleanup with rubocop * Fix syntax error introduced by rubocop * Cleanup seeds file * Cleanup lib folder * Exclude bin folder because it contains auto generated files * Make Rubocop a little bit more chatty * Block length should not include comments in the count * Cleanup config folder * Cleanup specs * Updated Rubocop version and generated a todo file * Fix broken ArticlesApi spec * Fix tests * Restored rubocop pre-commit hook
37 lines
1.2 KiB
Ruby
37 lines
1.2 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Message, type: :model do
|
|
let(:user) { create(:user) }
|
|
let(:chat_channel) { create(:chat_channel) }
|
|
let(:user2) { create(:user) }
|
|
|
|
describe "validations" do
|
|
subject { build(:message, :ignore_after_callback) }
|
|
|
|
it { is_expected.to belong_to(:user) }
|
|
it { is_expected.to belong_to(:chat_channel) }
|
|
it { is_expected.to validate_presence_of(:message_html) }
|
|
it { is_expected.to validate_presence_of(:message_markdown) }
|
|
end
|
|
|
|
it "is invalid without channel permission for non-open channels" do
|
|
chat_channel.update(channel_type: "invite_only")
|
|
message = build(:message, chat_channel_id: chat_channel.id, user_id: user2.id)
|
|
expect(message).not_to be_valid
|
|
end
|
|
|
|
it "is valid with channel permission" do
|
|
chat_channel.add_users([user2])
|
|
message = build(:message, chat_channel_id: chat_channel.id, user_id: user2.id)
|
|
expect(message).to be_valid
|
|
end
|
|
|
|
it "is invalid if over 1024 chars" do
|
|
long_text = Faker::Hipster.words(1500)
|
|
p long_text.size
|
|
message = build(:message, chat_channel_id: chat_channel.id, user_id: user.id, message_markdown: long_text)
|
|
expect(message).to_not be_valid
|
|
message.message_markdown = "hello"
|
|
expect(message).to be_valid
|
|
end
|
|
end
|