diff --git a/spec/apps/kitchen_sink/app/main/models/user.rb b/spec/apps/kitchen_sink/app/main/models/user.rb index 0d315f1d..a573bd09 100644 --- a/spec/apps/kitchen_sink/app/main/models/user.rb +++ b/spec/apps/kitchen_sink/app/main/models/user.rb @@ -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 diff --git a/spec/integration/callbacks_spec.rb b/spec/integration/callbacks_spec.rb index eb923581..21eecf48 100644 --- a/spec/integration/callbacks_spec.rb +++ b/spec/integration/callbacks_spec.rb @@ -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: 'test@test.com', password: 'awes0mesEcRet', name: 'Test Account 9550' } + end - context 'with a user' do - before do - # Add the user - store._users! << { email: 'test@test.com', 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('test@test.com') + fields[1].set('awes0mesEcRet') + click_button 'Login' - fields = all(:css, 'form .form-control') - fields[0].set('test@test.com') - 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 \ No newline at end of file + expect(page).to have_content('user_disconnect') + end + end +end