diff --git a/Gemfile b/Gemfile index 517ec5cb..894ba0cf 100644 --- a/Gemfile +++ b/Gemfile @@ -257,6 +257,7 @@ group :test do gem 'geckodriver-helper' gem 'rspec-rails', '~> 3.5', '>= 3.5.2' gem 'selenium-webdriver' + gem 'transactional_capybara' # for measuring test coverage gem 'codecov', require: false # for describing models diff --git a/Gemfile.lock b/Gemfile.lock index 8eb630d0..c3f0a9c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -548,6 +548,8 @@ GEM thread_safe (0.3.6) tilt (2.0.8) timecop (0.9.1) + transactional_capybara (0.2.0) + capybara transitions (0.1.12) ttfunk (1.1.1) turbolinks (5.2.0) @@ -696,6 +698,7 @@ DEPENDENCIES stripe-ruby-mock thor (~> 0.19) timecop + transactional_capybara transitions turbolinks uglifier (>= 1.3.0) diff --git a/spec/features/commercials_spec.rb b/spec/features/commercials_spec.rb index 814a9c26..289c4f07 100644 --- a/spec/features/commercials_spec.rb +++ b/spec/features/commercials_spec.rb @@ -46,20 +46,15 @@ feature Commercial do context 'in public area' do let!(:event) { create(:event, program: conference.program, title: 'Example Proposal') } + let!(:event_user) do + create(:event_user, user: participant, event: event, event_role: 'submitter') + end before(:each) do - event.event_users = [create(:event_user, - user_id: participant.id, - event_id: event.id, - event_role: 'submitter')] sign_in participant end - after(:each) do - sign_out - end - - scenario 'adds a valid commercial of an event', feature: true, versioning: true, js: true do + scenario 'adds a valid commercial of an event', feature: true, js: true do visit edit_conference_program_proposal_path(conference.short_title, event.id) click_link 'Commercials' fill_in 'commercial_url', with: 'https://www.youtube.com/watch?v=M9bq_alk-sw' @@ -70,7 +65,6 @@ feature Commercial do click_button 'Create Commercial' page.find('#flash') expect(flash).to eq('Commercial was successfully created.') - expect(event.commercials.count).to eq(1) end scenario 'does not add an invalid commercial of an event', feature: true, js: true do @@ -81,7 +75,7 @@ feature Commercial do expect(page).to have_css("button[type='submit']:disabled", text: 'Create Commercial') end - scenario 'updates a commercial of an event', feature: true, versioning: true, js: true do + scenario 'updates a commercial of an event', feature: true, js: true do commercial = create(:commercial, commercialable_id: event.id, commercialable_type: 'Event') @@ -91,12 +85,13 @@ feature Commercial do click_button 'Update' page.find('#flash') expect(flash).to eq('Commercial was successfully updated.') + TransactionalCapybara::AjaxHelpers.wait_for_ajax(page) expect(event.commercials.count).to eq(1) commercial.reload expect(commercial.url).to eq('https://www.youtube.com/watch?v=M9bq_alk-sw') end - scenario 'does not update a commercial of an event with invalid data', feature: true, versioning: true do + scenario 'does not update a commercial of an event with invalid data', feature: true do commercial = create(:commercial, commercialable_id: event.id, commercialable_type: 'Event', @@ -112,7 +107,7 @@ feature Commercial do expect(commercial.url).to eq('https://www.youtube.com/watch?v=BTTygyxuGj8') end - scenario 'deletes a commercial of an event', feature: true, versioning: true, js: true do + scenario 'deletes a commercial of an event', feature: true, js: true do create(:commercial, commercialable_id: event.id, commercialable_type: 'Event') @@ -123,6 +118,7 @@ feature Commercial do end page.find('#flash') expect(flash).to eq('Commercial was successfully destroyed.') + TransactionalCapybara::AjaxHelpers.wait_for_ajax(page) expect(event.commercials.count).to eq(0) end end diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 13cfc29e..f435c42f 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -111,21 +111,19 @@ feature Event do scenario 'signed_in user submits a valid proposal', feature: true, js: true do sign_in participant_without_bio expected_count = Event.count + 1 + visit conference_program_proposals_path(conference.short_title) click_link 'New Proposal' fill_in 'event_title', with: 'Example Proposal' - select('Example Event Type', from: 'event[event_type_id]') - fill_in 'event_abstract', with: 'Lorem ipsum abstract' click_link 'description_link' fill_in 'event_description', with: 'Lorem ipsum description' - click_button 'Create Proposal' page.find('#flash') expect(page).to have_content 'Proposal was successfully submitted.' - + TransactionalCapybara::AjaxHelpers.wait_for_ajax(page) expect(current_path).to eq(conference_program_proposals_path(conference.short_title)) expect(Event.count).to eq(expected_count) end diff --git a/spec/features/versions_spec.rb b/spec/features/versions_spec.rb index 479aa9a0..1c796fdd 100644 --- a/spec/features/versions_spec.rb +++ b/spec/features/versions_spec.rb @@ -319,16 +319,28 @@ feature 'Version' do expect(page).to have_text('created new organization New org') end - scenario 'display changes in users_role for organization role', feature: true, versioning: true, js: true do - user = create(:user) - role = Role.find_by(resource_id: conference.organization.id, resource_type: 'Organization') - user.add_role :organization_admin, conference.organization - user_role = UsersRole.find_by(user_id: user.id, role_id: role.id) - user.remove_role :organization_admin, conference.organization + context 'organization role', feature: true, versioning: true, js: true do + let!(:user) { create(:user) } + let!(:role) do + Role.find_by( + resource_id: conference.organization.id, + resource_type: 'Organization' + ) + end - visit admin_revision_history_path - expect(page).to have_text("added role organization_admin with ID #{user_role.id} to user #{user.name} in organization #{conference.organization.name}") - expect(page).to have_text("removed role organization_admin with ID #{user_role.id} from user #{user.name} in organization #{conference.organization.name}") + setup do + user.add_role :organization_admin, conference.organization + user.remove_role :organization_admin, conference.organization + visit admin_revision_history_path + end + + it 'is recorded to history when user is added' do + expect(page).to have_text(/added role organization_admin with ID \d+ to user #{user.name} in organization #{conference.organization.name}/) + end + + it 'is recorded to history when user is removed' do + expect(page).to have_text(/removed role organization_admin with ID \d+ from user #{user.name} in organization #{conference.organization.name}/) + end end scenario 'display changes in users_role for conference role', feature: true, versioning: true, js: true do @@ -383,6 +395,7 @@ feature 'Version' do click_link 'Comments (0)' fill_in 'comment_body', with: 'Sample comment' click_button 'Add Comment' + TransactionalCapybara::AjaxHelpers.wait_for_ajax(page) Comment.last.destroy PaperTrail::Version.last.reify.save diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c410a670..e9d32f4a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,9 @@ require 'shoulda/matchers' # all migrations applied ActiveRecord::Migration.maintain_test_schema! +# Keep capybara and the database on the same page +require 'transactional_capybara/rspec' + require 'selenium/webdriver' # Adds rspec helper provided by paper_trail diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 4162529c..c9d3073b 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -2,17 +2,16 @@ RSpec.configure do |config| config.before(:suite) do - DatabaseCleaner.clean_with(:truncation) + DatabaseCleaner.clean_with(:transaction) Rails.application.load_seed end - config.before(:each) do |example| - DatabaseCleaner.strategy = example.metadata[:js] == true ? :truncation : :transaction + config.before(:each) do DatabaseCleaner.start end config.after(:each) do |example| + TransactionalCapybara::AjaxHelpers.wait_for_ajax(page) if example.metadata[:js] DatabaseCleaner.clean - Rails.application.load_seed if example.metadata[:js] == true end end