Replace cfps feature tests by controller tests

It doesn't make sense to test this with a feature test as it is just
testing that the controller actions work properly. Moreover, there are
problems with updating datapickers in feature tests. I reported those
problems upstream:

https://github.com/TrevorS/bootstrap3-datetimepicker-rails/issues/66
https://github.com/akarzim/capybara-bootstrap-datepicker/issues/14
This commit is contained in:
Ana María Martínez Gómez 2019-03-06 15:55:10 +01:00
parent 1a3e3f433d
commit ae53fe86f1
No known key found for this signature in database
GPG key ID: EACB9B4BC80C0347
2 changed files with 29 additions and 86 deletions

View file

@ -0,0 +1,29 @@
require 'pry'
# frozen_string_literal: true
require 'spec_helper'
describe Admin::CfpsController do
let!(:today) { Date.today }
let!(:conference) { create(:conference, start_date: today + 20.days, end_date: today + 30.days) }
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
let!(:organizer) { create(:user, role_ids: organizer_role.id) }
let(:cfp) { create(:cfp, program: conference.program) }
before { sign_in(organizer) }
describe 'POST #create' do
it 'successes' do
post :create, conference_id: conference.short_title, cfp: { cfp_type: 'events', start_date: today, end_date: today + 6.days, description: 'We call for papers, or tabak, or you know what!' }
expect(flash[:notice]).to match('Call for papers successfully created.')
end
end
describe 'POST #update' do
it 'successes' do
patch :update, conference_id: conference.short_title, id: cfp.id, cfp: { end_date: today + 10.days }
expect(flash[:notice]).to match('Call for papers successfully updated.')
end
end
end

View file

@ -1,86 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
feature Conference do
let!(:conference) { create(:conference) }
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
let!(:organizer) { create(:user, role_ids: [organizer_role.id]) }
shared_examples 'add and update cfp' do
scenario 'adds a new cfp', feature: true, js: true do
expected_count = Cfp.count + 1
sign_in organizer
visit new_admin_conference_program_cfp_path(conference.short_title)
click_button 'Create Cfp'
page.find('#flash')
expect(flash)
.to eq('Creating the call for papers failed. ' +
"Start date can't be blank. End date can't be blank.")
today = Date.today - 1
page.execute_script(
"$('#registration-period-start-datepicker').val('#{today.strftime('%d/%m/%Y')}')")
page.execute_script(
"$('#registration-period-end-datepicker').val('#{(today + 6).strftime('%d/%m/%Y')}')")
click_button 'Create Cfp'
# Validations
expect(flash)
.to eq('Call for papers successfully created.')
visit admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)
expect(find('#start-date').text).to eq(today.strftime('%A, %B %-d. %Y'))
expect(find('#end-date').text).to eq((today + 6).strftime('%A, %B %-d. %Y'))
expect(Cfp.count).to eq(expected_count)
end
scenario 'update cfp', feature: true, js: true do
create(:cfp, program: conference.program)
expected_count = Cfp.count
sign_in organizer
visit admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)
click_link 'Edit'
# Validate update with empty start date will not saved
page.execute_script(
"$('#registration-period-start-datepicker').val('')")
click_button 'Update Cfp'
page.find('#flash')
expect(flash)
.to eq('Updating call for papers failed. ' +
"Start date can't be blank.")
# Fill in date
today = Date.today - 9
page.execute_script(
"$('#registration-period-start-datepicker').val('#{today.strftime('%d/%m/%Y')}')")
page.execute_script(
"$('#registration-period-end-datepicker').val('#{(today + 14).strftime('%d/%m/%Y')}')")
click_button 'Update Cfp'
# Validations
page.find('#flash')
expect(flash)
.to eq('Call for papers successfully updated.')
visit admin_conference_program_cfp_path(conference.short_title, conference.program.cfp)
expect(find('#start-date').text).to eq(today.strftime('%A, %B %-d. %Y'))
expect(find('#end-date').text).to eq((today + 14).strftime('%A, %B %-d. %Y'))
expect(Cfp.count).to eq(expected_count)
end
end
describe 'organizer' do
it_behaves_like 'add and update cfp'
end
end