parent
c24904fbe3
commit
eba58fc191
4 changed files with 99 additions and 1 deletions
12
plugins/messages/spec/factories/message.rb
Normal file
12
plugins/messages/spec/factories/message.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
require 'factory_bot'
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :message do
|
||||||
|
sender {create :user}
|
||||||
|
subject { Faker::Lorem.words(number: 7) }
|
||||||
|
body { Faker::Lorem.words(number: 42)}
|
||||||
|
created_at {Time.now}
|
||||||
|
private { false }
|
||||||
|
send_method { 'recipients' }
|
||||||
|
end
|
||||||
|
end
|
50
plugins/messages/spec/integration/messages_spec.rb
Normal file
50
plugins/messages/spec/integration/messages_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
require_relative '../../../../spec/spec_helper'
|
||||||
|
|
||||||
|
feature 'messages' do
|
||||||
|
let(:sending_user) { create :user }
|
||||||
|
let(:receiving_user) { create :user }
|
||||||
|
let(:message){ create :message }
|
||||||
|
before {
|
||||||
|
login sending_user
|
||||||
|
message.add_recipients([receiving_user])
|
||||||
|
}
|
||||||
|
describe 'index' do
|
||||||
|
before { visit messages_path }
|
||||||
|
|
||||||
|
it 'shows subject of message' do
|
||||||
|
expect(page).to have_content 'New message'
|
||||||
|
expect(page).to have_content message.subject
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can open message when clicked on subject' do
|
||||||
|
click_link(message.subject)
|
||||||
|
expect(page).to have_content message.body.to_plain_text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'create new', js: true do
|
||||||
|
before {
|
||||||
|
login sending_user
|
||||||
|
visit new_message_path
|
||||||
|
}
|
||||||
|
after { page.save_screenshot('screenshot.png') }
|
||||||
|
|
||||||
|
# TODO: fix trix-editor stuff
|
||||||
|
# https://stackoverflow.com/questions/45962746/rails-capybara-populate-hidden-field-from-trix-editor
|
||||||
|
it 'shows input elements' do
|
||||||
|
choose 'Send to all members'
|
||||||
|
fill_in 'message_subject', with: 'hello friend'
|
||||||
|
# print page.body()
|
||||||
|
expect(page).to have_selector('trix-editor')
|
||||||
|
foo = find('#message_body_trix_input_message', visible: false)
|
||||||
|
puts foo.inspect
|
||||||
|
editor = find('trix-editor')
|
||||||
|
editor.click.set('foo bar 123')
|
||||||
|
# find('.message_body', visible: false).set("some value here")
|
||||||
|
click_button 'send message'
|
||||||
|
expect(page).to have_current_path(messages_path)
|
||||||
|
expect(page).to have_selector '.alert-success'
|
||||||
|
expect(page).to have_content 'hello friend'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
33
plugins/messages/spec/models/message_spec.rb
Normal file
33
plugins/messages/spec/models/message_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
require_relative '../../../../spec/spec_helper'
|
||||||
|
|
||||||
|
describe Message do
|
||||||
|
|
||||||
|
let(:sender) { create :user }
|
||||||
|
let(:receiver) { create :user }
|
||||||
|
let(:another) { create :user }
|
||||||
|
let(:message) { create :message,
|
||||||
|
sender: sender,
|
||||||
|
recipients: [receiver],
|
||||||
|
subject: 'hello friend',
|
||||||
|
body: 'hi how are you?',
|
||||||
|
private: false,
|
||||||
|
send_method: 'recipients'
|
||||||
|
}
|
||||||
|
|
||||||
|
it 'can be created' do
|
||||||
|
expect(message.recipients).to eq([receiver])
|
||||||
|
expect(message.subject).to eq('hello friend')
|
||||||
|
expect(message.body.to_plain_text).to eq('hi how are you?')
|
||||||
|
puts message.message_recipients.inspect
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can be private' do
|
||||||
|
expect(message.is_readable_for?(receiver)).to be_truthy
|
||||||
|
expect(message.is_readable_for?(sender)).to be_truthy
|
||||||
|
expect(message.is_readable_for?(another)).to be_truthy
|
||||||
|
message.update_attribute :private, true
|
||||||
|
expect(message.is_readable_for?(another)).to be_falsey
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -12,7 +12,7 @@ Capybara.javascript_driver = :apparition
|
||||||
|
|
||||||
# TODO: Remove temporary fix to ignore JavaScript errors
|
# TODO: Remove temporary fix to ignore JavaScript errors
|
||||||
Capybara.register_driver :apparition do |app|
|
Capybara.register_driver :apparition do |app|
|
||||||
Capybara::Apparition::Driver.new(app, { js_errors: false })
|
Capybara::Apparition::Driver.new(app, { js_errors: false, window_size: [1920, 1080] })
|
||||||
end
|
end
|
||||||
|
|
||||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||||
|
@ -78,3 +78,6 @@ class ActionDispatch::Routing::RouteSet
|
||||||
{ foodcoop: FoodsoftConfig.scope }.merge(options)
|
{ foodcoop: FoodsoftConfig.scope }.merge(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
FactoryBot.definition_file_paths = %w(plugins/messages/spec/factories)
|
||||||
|
FactoryBot.find_definitions
|
Loading…
Reference in a new issue