transactional db support for capybara tests!
This commit is contained in:
parent
1b9a12746d
commit
a9e8498abe
7 changed files with 43 additions and 30 deletions
1
Gemfile
1
Gemfile
|
|
@ -257,6 +257,7 @@ group :test do
|
||||||
gem 'geckodriver-helper'
|
gem 'geckodriver-helper'
|
||||||
gem 'rspec-rails', '~> 3.5', '>= 3.5.2'
|
gem 'rspec-rails', '~> 3.5', '>= 3.5.2'
|
||||||
gem 'selenium-webdriver'
|
gem 'selenium-webdriver'
|
||||||
|
gem 'transactional_capybara'
|
||||||
# for measuring test coverage
|
# for measuring test coverage
|
||||||
gem 'codecov', require: false
|
gem 'codecov', require: false
|
||||||
# for describing models
|
# for describing models
|
||||||
|
|
|
||||||
|
|
@ -548,6 +548,8 @@ GEM
|
||||||
thread_safe (0.3.6)
|
thread_safe (0.3.6)
|
||||||
tilt (2.0.8)
|
tilt (2.0.8)
|
||||||
timecop (0.9.1)
|
timecop (0.9.1)
|
||||||
|
transactional_capybara (0.2.0)
|
||||||
|
capybara
|
||||||
transitions (0.1.12)
|
transitions (0.1.12)
|
||||||
ttfunk (1.1.1)
|
ttfunk (1.1.1)
|
||||||
turbolinks (5.2.0)
|
turbolinks (5.2.0)
|
||||||
|
|
@ -696,6 +698,7 @@ DEPENDENCIES
|
||||||
stripe-ruby-mock
|
stripe-ruby-mock
|
||||||
thor (~> 0.19)
|
thor (~> 0.19)
|
||||||
timecop
|
timecop
|
||||||
|
transactional_capybara
|
||||||
transitions
|
transitions
|
||||||
turbolinks
|
turbolinks
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
|
|
|
||||||
|
|
@ -46,20 +46,15 @@ feature Commercial do
|
||||||
|
|
||||||
context 'in public area' do
|
context 'in public area' do
|
||||||
let!(:event) { create(:event, program: conference.program, title: 'Example Proposal') }
|
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
|
before(:each) do
|
||||||
event.event_users = [create(:event_user,
|
|
||||||
user_id: participant.id,
|
|
||||||
event_id: event.id,
|
|
||||||
event_role: 'submitter')]
|
|
||||||
sign_in participant
|
sign_in participant
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:each) do
|
scenario 'adds a valid commercial of an event', feature: true, js: true do
|
||||||
sign_out
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario 'adds a valid commercial of an event', feature: true, versioning: true, js: true do
|
|
||||||
visit edit_conference_program_proposal_path(conference.short_title, event.id)
|
visit edit_conference_program_proposal_path(conference.short_title, event.id)
|
||||||
click_link 'Commercials'
|
click_link 'Commercials'
|
||||||
fill_in 'commercial_url', with: 'https://www.youtube.com/watch?v=M9bq_alk-sw'
|
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'
|
click_button 'Create Commercial'
|
||||||
page.find('#flash')
|
page.find('#flash')
|
||||||
expect(flash).to eq('Commercial was successfully created.')
|
expect(flash).to eq('Commercial was successfully created.')
|
||||||
expect(event.commercials.count).to eq(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'does not add an invalid commercial of an event', feature: true, js: true do
|
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')
|
expect(page).to have_css("button[type='submit']:disabled", text: 'Create Commercial')
|
||||||
end
|
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,
|
commercial = create(:commercial,
|
||||||
commercialable_id: event.id,
|
commercialable_id: event.id,
|
||||||
commercialable_type: 'Event')
|
commercialable_type: 'Event')
|
||||||
|
|
@ -91,12 +85,13 @@ feature Commercial do
|
||||||
click_button 'Update'
|
click_button 'Update'
|
||||||
page.find('#flash')
|
page.find('#flash')
|
||||||
expect(flash).to eq('Commercial was successfully updated.')
|
expect(flash).to eq('Commercial was successfully updated.')
|
||||||
|
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
|
||||||
expect(event.commercials.count).to eq(1)
|
expect(event.commercials.count).to eq(1)
|
||||||
commercial.reload
|
commercial.reload
|
||||||
expect(commercial.url).to eq('https://www.youtube.com/watch?v=M9bq_alk-sw')
|
expect(commercial.url).to eq('https://www.youtube.com/watch?v=M9bq_alk-sw')
|
||||||
end
|
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,
|
commercial = create(:commercial,
|
||||||
commercialable_id: event.id,
|
commercialable_id: event.id,
|
||||||
commercialable_type: 'Event',
|
commercialable_type: 'Event',
|
||||||
|
|
@ -112,7 +107,7 @@ feature Commercial do
|
||||||
expect(commercial.url).to eq('https://www.youtube.com/watch?v=BTTygyxuGj8')
|
expect(commercial.url).to eq('https://www.youtube.com/watch?v=BTTygyxuGj8')
|
||||||
end
|
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,
|
create(:commercial,
|
||||||
commercialable_id: event.id,
|
commercialable_id: event.id,
|
||||||
commercialable_type: 'Event')
|
commercialable_type: 'Event')
|
||||||
|
|
@ -123,6 +118,7 @@ feature Commercial do
|
||||||
end
|
end
|
||||||
page.find('#flash')
|
page.find('#flash')
|
||||||
expect(flash).to eq('Commercial was successfully destroyed.')
|
expect(flash).to eq('Commercial was successfully destroyed.')
|
||||||
|
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
|
||||||
expect(event.commercials.count).to eq(0)
|
expect(event.commercials.count).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -111,21 +111,19 @@ feature Event do
|
||||||
scenario 'signed_in user submits a valid proposal', feature: true, js: true do
|
scenario 'signed_in user submits a valid proposal', feature: true, js: true do
|
||||||
sign_in participant_without_bio
|
sign_in participant_without_bio
|
||||||
expected_count = Event.count + 1
|
expected_count = Event.count + 1
|
||||||
|
|
||||||
visit conference_program_proposals_path(conference.short_title)
|
visit conference_program_proposals_path(conference.short_title)
|
||||||
click_link 'New Proposal'
|
click_link 'New Proposal'
|
||||||
|
|
||||||
fill_in 'event_title', with: 'Example Proposal'
|
fill_in 'event_title', with: 'Example Proposal'
|
||||||
|
|
||||||
select('Example Event Type', from: 'event[event_type_id]')
|
select('Example Event Type', from: 'event[event_type_id]')
|
||||||
|
|
||||||
fill_in 'event_abstract', with: 'Lorem ipsum abstract'
|
fill_in 'event_abstract', with: 'Lorem ipsum abstract'
|
||||||
click_link 'description_link'
|
click_link 'description_link'
|
||||||
fill_in 'event_description', with: 'Lorem ipsum description'
|
fill_in 'event_description', with: 'Lorem ipsum description'
|
||||||
|
|
||||||
click_button 'Create Proposal'
|
click_button 'Create Proposal'
|
||||||
page.find('#flash')
|
page.find('#flash')
|
||||||
expect(page).to have_content 'Proposal was successfully submitted.'
|
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(current_path).to eq(conference_program_proposals_path(conference.short_title))
|
||||||
expect(Event.count).to eq(expected_count)
|
expect(Event.count).to eq(expected_count)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -319,16 +319,28 @@ feature 'Version' do
|
||||||
expect(page).to have_text('created new organization New org')
|
expect(page).to have_text('created new organization New org')
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'display changes in users_role for organization role', feature: true, versioning: true, js: true do
|
context 'organization role', feature: true, versioning: true, js: true do
|
||||||
user = create(:user)
|
let!(:user) { create(:user) }
|
||||||
role = Role.find_by(resource_id: conference.organization.id, resource_type: 'Organization')
|
let!(:role) do
|
||||||
user.add_role :organization_admin, conference.organization
|
Role.find_by(
|
||||||
user_role = UsersRole.find_by(user_id: user.id, role_id: role.id)
|
resource_id: conference.organization.id,
|
||||||
user.remove_role :organization_admin, conference.organization
|
resource_type: 'Organization'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
visit admin_revision_history_path
|
setup do
|
||||||
expect(page).to have_text("added role organization_admin with ID #{user_role.id} to user #{user.name} in organization #{conference.organization.name}")
|
user.add_role :organization_admin, conference.organization
|
||||||
expect(page).to have_text("removed role organization_admin with ID #{user_role.id} from user #{user.name} in organization #{conference.organization.name}")
|
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
|
end
|
||||||
|
|
||||||
scenario 'display changes in users_role for conference role', feature: true, versioning: true, js: true do
|
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)'
|
click_link 'Comments (0)'
|
||||||
fill_in 'comment_body', with: 'Sample comment'
|
fill_in 'comment_body', with: 'Sample comment'
|
||||||
click_button 'Add Comment'
|
click_button 'Add Comment'
|
||||||
|
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
|
||||||
Comment.last.destroy
|
Comment.last.destroy
|
||||||
PaperTrail::Version.last.reify.save
|
PaperTrail::Version.last.reify.save
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ require 'shoulda/matchers'
|
||||||
# all migrations applied
|
# all migrations applied
|
||||||
ActiveRecord::Migration.maintain_test_schema!
|
ActiveRecord::Migration.maintain_test_schema!
|
||||||
|
|
||||||
|
# Keep capybara and the database on the same page
|
||||||
|
require 'transactional_capybara/rspec'
|
||||||
|
|
||||||
require 'selenium/webdriver'
|
require 'selenium/webdriver'
|
||||||
|
|
||||||
# Adds rspec helper provided by paper_trail
|
# Adds rspec helper provided by paper_trail
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,16 @@
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
DatabaseCleaner.clean_with(:truncation)
|
DatabaseCleaner.clean_with(:transaction)
|
||||||
Rails.application.load_seed
|
Rails.application.load_seed
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each) do |example|
|
config.before(:each) do
|
||||||
DatabaseCleaner.strategy = example.metadata[:js] == true ? :truncation : :transaction
|
|
||||||
DatabaseCleaner.start
|
DatabaseCleaner.start
|
||||||
end
|
end
|
||||||
|
|
||||||
config.after(:each) do |example|
|
config.after(:each) do |example|
|
||||||
|
TransactionalCapybara::AjaxHelpers.wait_for_ajax(page) if example.metadata[:js]
|
||||||
DatabaseCleaner.clean
|
DatabaseCleaner.clean
|
||||||
Rails.application.load_seed if example.metadata[:js] == true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue