mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-28 13:31:06 +00:00
commit
6ddec8ef58
5 changed files with 150 additions and 2 deletions
|
@ -5,5 +5,5 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= namelink message.sender %> on <em><%= longdate message.created_at %></em>
|
To: <%= namelink message.recipient %> From: <%= namelink message.sender %> on <em><%= longdate message.created_at %></em></em>
|
||||||
</p>
|
</p>
|
23
spec/factories/ban.rb
Normal file
23
spec/factories/ban.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
factory :ban do
|
||||||
|
ban_type Ban::TYPE_SITE
|
||||||
|
expiry Date.today + 1
|
||||||
|
# Hack because of the awkward way bans are created (requires user_name)
|
||||||
|
before(:create) do |ban|
|
||||||
|
if ban.user.nil?
|
||||||
|
user = create :user
|
||||||
|
ban.user_name = user.username
|
||||||
|
else
|
||||||
|
ban.user_name = ban.user.username
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :mute do
|
||||||
|
ban_type Ban::TYPE_MUTE
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :expired do
|
||||||
|
expiry Date.yesterday - 1
|
||||||
|
end
|
||||||
|
end
|
9
spec/factories/message.rb
Normal file
9
spec/factories/message.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
factory :message do
|
||||||
|
association :sender, factory: :user
|
||||||
|
association :recipient, factory: :user
|
||||||
|
sequence(:text) { |n| "text-#{n}" }
|
||||||
|
sequence(:title) { |n| "title-#{n}" }
|
||||||
|
sequence(:text_parsed) { |n| "text-#{n}" }
|
||||||
|
end
|
||||||
|
end
|
59
spec/features/messages/user_messages.rb
Normal file
59
spec/features/messages/user_messages.rb
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
feature 'Message creation' do
|
||||||
|
let!(:sender) { create :user }
|
||||||
|
let!(:recipient) { create :user }
|
||||||
|
|
||||||
|
background do
|
||||||
|
sign_in_as sender
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'User creates a message' do
|
||||||
|
visit root_path
|
||||||
|
within '.links' do
|
||||||
|
click_link 'Messages'
|
||||||
|
end
|
||||||
|
expect(page).to have_content('Sent (0)')
|
||||||
|
visit user_path(recipient)
|
||||||
|
expect(page).to have_content(recipient.username)
|
||||||
|
click_link 'Send PM'
|
||||||
|
expect(page).to have_content('New Message')
|
||||||
|
title = "This is my title"
|
||||||
|
message = "This is my message"
|
||||||
|
fill_in 'Title', with: title
|
||||||
|
fill_in 'Text', with: message
|
||||||
|
click_button 'Send Message'
|
||||||
|
expect(page).to have_content('Message was successfully sent.')
|
||||||
|
expect(page).to have_content(title)
|
||||||
|
expect(page).to have_content(message)
|
||||||
|
within '.links' do
|
||||||
|
click_link 'Messages'
|
||||||
|
end
|
||||||
|
expect(page).to have_content('Sent (1)')
|
||||||
|
within '#sent' do
|
||||||
|
expect(page).to have_content(title)
|
||||||
|
expect(page).to have_content(message)
|
||||||
|
expect(page).to have_content(sender.username)
|
||||||
|
expect(page).to have_content(recipient.username)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
feature 'Message receiving' do
|
||||||
|
let!(:message) { create :message }
|
||||||
|
|
||||||
|
background do
|
||||||
|
sign_in_as message.recipient
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'User receives a message' do
|
||||||
|
visit root_path
|
||||||
|
within '.links' do
|
||||||
|
expect(page).to have_content('(1)')
|
||||||
|
click_link 'Messages'
|
||||||
|
end
|
||||||
|
expect(page).to have_content(message.title)
|
||||||
|
expect(page).to have_content(message.text)
|
||||||
|
expect(page).to have_content(message.sender.username)
|
||||||
|
end
|
||||||
|
end
|
57
spec/models/message_spec.rb
Normal file
57
spec/models/message_spec.rb
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: messages
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# sender_type :string(255)
|
||||||
|
# sender_id :integer
|
||||||
|
# recipient_type :string(255)
|
||||||
|
# recipient_id :integer
|
||||||
|
# title :string(255)
|
||||||
|
# text :text
|
||||||
|
# created_at :datetime
|
||||||
|
# updated_at :datetime
|
||||||
|
# text_parsed :text
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Message do
|
||||||
|
let!(:user) { create :user }
|
||||||
|
|
||||||
|
describe 'create' do
|
||||||
|
let(:message) { build :message }
|
||||||
|
it 'creates a new message' do
|
||||||
|
expect(message.valid?).to be_true
|
||||||
|
expect do
|
||||||
|
message.save!
|
||||||
|
end.to change(Message, :count).by(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Permissions' do
|
||||||
|
let(:message) { Message.new }
|
||||||
|
describe 'can_create?' do
|
||||||
|
it 'returns true for user' do
|
||||||
|
expect(message.can_create?(user)).to be_true
|
||||||
|
end
|
||||||
|
it 'returns false if user is banned' do
|
||||||
|
create :ban, :mute, user: user
|
||||||
|
expect(message.can_create?(user)).to be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'can_show?' do
|
||||||
|
let!(:message) { create :message }
|
||||||
|
it 'returns true if sender' do
|
||||||
|
expect(message.can_show?(message.sender)).to be_true
|
||||||
|
end
|
||||||
|
it 'returns true if receiver' do
|
||||||
|
expect(message.can_show?(message.recipient)).to be_true
|
||||||
|
end
|
||||||
|
it 'returns false if neither sender nor receiver' do
|
||||||
|
expect(message.can_show?(user)).to be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue