2015-06-02 16:55:08 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: messages
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# recipient_type :string(255)
|
2020-03-18 03:38:17 +00:00
|
|
|
# sender_type :string(255)
|
|
|
|
# text :text(65535)
|
|
|
|
# text_parsed :text(65535)
|
2015-06-02 16:55:08 +00:00
|
|
|
# title :string(255)
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2020-03-18 03:38:17 +00:00
|
|
|
# recipient_id :integer
|
|
|
|
# sender_id :integer
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_messages_on_recipient_id_and_recipient_type (recipient_id,recipient_type)
|
|
|
|
# index_messages_on_sender_id_and_sender_type (sender_id,sender_type)
|
2015-06-02 16:55:08 +00:00
|
|
|
#
|
|
|
|
|
2019-10-17 18:29:15 +00:00
|
|
|
require "rails_helper"
|
2015-06-02 16:55:08 +00:00
|
|
|
|
|
|
|
describe Message do
|
2015-08-15 11:50:28 +00:00
|
|
|
let!(:user) { create :user }
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "create" do
|
2015-08-15 11:50:28 +00:00
|
|
|
let(:message) { build :message }
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
it "creates a new message" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(message.valid?).to eq(true)
|
|
|
|
expect do
|
|
|
|
message.save!
|
|
|
|
end.to change(Message, :count).by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "Permissions" do
|
2015-08-15 11:50:28 +00:00
|
|
|
let(:message) { Message.new }
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "can_create?" do
|
|
|
|
it "returns true for user" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(message.can_create?(user)).to be_truthy
|
|
|
|
end
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
it "returns false if user is banned" do
|
2015-08-15 11:50:28 +00:00
|
|
|
create :ban, :mute, user: user
|
|
|
|
expect(message.can_create?(user)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
describe "can_show?" do
|
2015-08-15 11:50:28 +00:00
|
|
|
let!(:message) { create :message }
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
it "returns true if sender" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(message.can_show?(message.sender)).to be_truthy
|
|
|
|
end
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
it "returns true if receiver" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(message.can_show?(message.recipient)).to be_truthy
|
|
|
|
end
|
|
|
|
|
2015-08-15 18:23:42 +00:00
|
|
|
it "returns false if neither sender nor receiver" do
|
2015-08-15 11:50:28 +00:00
|
|
|
expect(message.can_show?(user)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|