Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions spec/apps/kitchen_sink/app/main/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ class User < Volt::User
validate login_field, unique: true, length: 8
validate :email, email: true

unless RUBY_PLATFORM == "opal"
Volt.current_app.on("user_connect") do |user_id|
begin
Volt.current_app.store.users.where(id: user_id).first.sync._event_triggered = "user_connect"
rescue
#we rescue as this callback will also get called from the SocketConnectionHandler specs (and will fail)
end
end
unless RUBY_PLATFORM == 'opal'
Volt.current_app.on('user_connect') do |user_id|
begin
Volt.current_app.store.users.where(id: user_id).first.sync._event_triggered = 'user_connect'
rescue
# we rescue as this callback will also get called from the SocketConnectionHandler specs (and will fail)
end
end

Volt.current_app.on("user_disconnect") do |user_id|
begin
Volt.current_app.store.users.where(id: user_id).first.sync._event_triggered = "user_disconnect"
rescue
#we rescue as this callback will also get called from the SocketConnectionHandler specs (and will fail)
end
end
Volt.current_app.on('user_disconnect') do |user_id|
begin
Volt.current_app.store.users.where(id: user_id).first.sync._event_triggered = 'user_disconnect'
rescue
# we rescue as this callback will also get called from the SocketConnectionHandler specs (and will fail)
end
end
end
end
41 changes: 20 additions & 21 deletions spec/integration/callbacks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
require 'spec_helper'

describe 'lifecycle callbacks', type: :feature, sauce: true do
context 'with a user' do
before do
# Add the user
store._users! << { email: '[email protected]', password: 'awes0mesEcRet', name: 'Test Account 9550' }
end

context 'with a user' do
before do
# Add the user
store._users! << { email: '[email protected]', password: 'awes0mesEcRet', name: 'Test Account 9550' }
end
it 'should trigger a user_connect event when a user logs in and a user_disconnect event when a user logs out' do
visit '/'

it 'should trigger a user_connect event when a user logs in and a user_disconnect event when a user logs out' do
visit '/'
click_link 'Login'

click_link 'Login'
fields = all(:css, 'form .form-control')
fields[0].set('[email protected]')
fields[1].set('awes0mesEcRet')
click_button 'Login'

fields = all(:css, 'form .form-control')
fields[0].set('[email protected]')
fields[1].set('awes0mesEcRet')
click_button 'Login'
visit '/callbacks'

visit '/callbacks'
expect(page).to have_content('user_connect')

expect(page).to have_content('user_connect')
click_link 'Test Account 9550'
click_link 'Logout'

click_link 'Test Account 9550'
click_link 'Logout'

expect(page).to have_content('user_disconnect')
end
end
end
expect(page).to have_content('user_disconnect')
end
end
end