I'm trying to test the confirmation page after a user clicks register on the form. In development, when a user registers they are redirected to a confirmation page such as /entrants/(some number)/confirm
. However when I run the test it doesn't hit that page. it only hits /entrants
. I tried using using visit
capybara syntax with no success.
sign_in_steps.rb
Given(/^there is a entrant sign in page$/) do
@campaign = create(:campaign)
@entrant = create(:entrant, campaign: @campaign)
@entry = create(:entry, campaign: @campaign, entrant: @entrant)
end
Then(/^I should see confirmation login when I click the register button$/) do
within '#entrant_create' do
fill_in('entrant_first_name', with: @entrant.first_name)
fill_in('entrant_last_name', with: @entrant.last_name)
fill_in('entrant_email', with: @entrant.email)
fill_in('entrant_password', with: @entrant.password)
fill_in('entrant_password_confirmation', with: @entrant.password)
fill_in('entrant_dob', with: @entrant.dob)
end
click_button('REGISTER')
expect(current_path).to eq "/entrants/#{@entrant.id}/confirm"
end
After running cucumber feature
expected: "/entrants/1/confirm"
got: "/entrants"
entrant.rb
FactoryGirl.define do
factory :entrant do
first_name 'John'
last_name 'Smith'
email "test@msn.com"
dob Time.now - 60.years
password 'password'
end
end
entrant controller
def confirm
@entrant = Entrant.find params[:id]
set_confirmation_message
end
def set_confirmation_message
if @entrant.entries.present?
@title = "Complete Your Contest Entry"
@message = 'Thank you for your entry! To complete submission, please check your email and click the confirmation link.'
else
@message = "To be allowed to enter this contest, please check your email and click the confirmation link."
end
end
The issue is not with the after register is being clicked. It's because when entrant creates an email address to database, when capybara fills in the email, it sees that it's already taken. So I just fill it in manually with another email address.
fill_in('entrant_email', with: 'test@example.com')