repair code reviews, improve environment configs

This commit is contained in:
Rishabh Saxena 2016-07-18 12:04:10 +05:30
parent 223a0eead9
commit 25c0046290
10 changed files with 65 additions and 67 deletions

View file

@ -16,7 +16,7 @@ feature Registration do
context 'who is not registered' do
scenario 'purchases and pays for a ticket', feature: true, js: true do
scenario 'purchases and pays for a ticket, with gateway producing error', feature: true, js: true do
visit root_path
click_link 'Register'
@ -37,56 +37,57 @@ feature Registration do
fill_in 'last_name', with: 'bar'
select Date.current.year + 2, from: 'expiration_year'
fill_in 'card_verification_value', with: '123'
fill_in 'credit_card_number', with: '4000000000000000'
fill_in 'credit_card_number', with: '3'
click_button 'Charge Card'
expect(flash).to eq('Your card number is incorrect.')
expect(Payment.count).to eq(0)
end
scenario 'purchases and pays for a ticket, with card producing a transaction failure', feature: true, js: true do
visit root_path
click_link 'Register'
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
click_button 'Register'
fill_in "tickets__#{ticket.id}", with: '2'
expect(current_path).to eq(conference_tickets_path(conference.short_title))
click_button 'Continue'
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
expect(flash).to eq('Please pay here to purchase tickets.')
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
expect(purchase.quantity).to eq(2)
fill_in 'first_name', with: 'foo'
fill_in 'last_name', with: 'bar'
select Date.current.year + 2, from: 'expiration_year'
fill_in 'card_verification_value', with: '123'
fill_in 'credit_card_number', with: '4000000000000002'
fill_in 'credit_card_number', with: '2'
click_button 'Charge Card'
expect(flash).to eq('Your card was declined.')
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
fill_in 'first_name', with: 'foo'
fill_in 'last_name', with: 'bar'
select Date.current.year + 2, from: 'expiration_year'
fill_in 'card_verification_value', with: '123'
fill_in 'credit_card_number', with: '4000000000000127'
click_button 'Charge Card'
expect(flash).to eq("Your card's security code is incorrect.")
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
fill_in 'first_name', with: 'foo'
fill_in 'last_name', with: 'bar'
select Date.current.year + 2, from: 'expiration_year'
fill_in 'card_verification_value', with: '123'
fill_in 'credit_card_number', with: '4000000000000069'
click_button 'Charge Card'
expect(flash).to eq('Your card has expired.')
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
fill_in 'first_name', with: 'foo'
fill_in 'last_name', with: 'bar'
select Date.current.year + 2, from: 'expiration_year'
fill_in 'card_verification_value', with: '123'
fill_in 'credit_card_number', with: '4000000000000119'
click_button 'Charge Card'
expect(flash).to eq('An error occurred while processing your card. Try again in a little bit.')
expect(Payment.count).to eq(0)
end
scenario 'purchases and pays for a ticket successfully', feature: true, js: true do
visit root_path
click_link 'Register'
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
click_button 'Register'
fill_in "tickets__#{ticket.id}", with: '2'
expect(current_path).to eq(conference_tickets_path(conference.short_title))
click_button 'Continue'
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
expect(flash).to eq('Please pay here to purchase tickets.')
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
expect(purchase.quantity).to eq(2)
fill_in 'first_name', with: 'foo'
fill_in 'last_name', with: 'bar'
@ -96,14 +97,15 @@ feature Registration do
click_button 'Charge Card'
expect(current_path).to eq(conference_conference_registration_path(conference.short_title))
expect(Payment.count).to eq(1)
payment = Payment.where(user_id: participant, conference_id: conference.id).first
expect(payment.amount).to eq(20)
expect(payment.status).to eq(1)
expect(payment.status).to eq('success')
expect(payment.first_name).to eq('foo')
expect(payment.first_name).to eq('bar')
expect(payment.last_name).to eq('bar')
expect(payment.last4).not_to be_empty
expect(payment.authorization_code).not_to be_empty
expect(current_path).to eq(conference_conference_registrations_path(conference.short_title))
expect(flash).to eq('Thanks! You have purchased your tickets successfully.')
end
end

View file

@ -39,24 +39,8 @@ describe Payment do
let!(:participant) { create(:user) }
let!(:ticket_1) { create(:ticket) }
let!(:conference) { create(:conference, tickets: [ticket_1]) }
it 'creates no ticket purchase or payment if amount is less than 1' do
tickets = { ticket_1.id.to_s => '-1' }
TicketPurchase.purchase(conference, participant, tickets)
expect(TicketPurchase.count).to eq(0)
expect(Payment.count).to eq(0)
end
it 'creates no ticket purchase or payment if amount is 0' do
tickets = { ticket_1.id.to_s => '0' }
TicketPurchase.purchase(conference, participant, tickets)
expect(TicketPurchase.count).to eq(0)
expect(Payment.count).to eq(0)
end
let(:payment) { create(:payment) }
it 'creates a purchase and payment for one ticket' do
tickets = { ticket_1.id.to_s => '1' }
message = TicketPurchase.purchase(conference, participant, tickets)
@ -68,8 +52,11 @@ describe Payment do
expect(purchase.quantity).to eq(1)
expect(message.blank?).to be true
payment = Payment.new
payment.purchase(participant, conference, 1000)
purchase = Payment.first
expect(Payment.count).to be(1)
expect(purchase.amount).to eq(10)
end
end
end