repair code reviews, improve environment configs
This commit is contained in:
parent
223a0eead9
commit
25c0046290
10 changed files with 65 additions and 67 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
.price-tags {
|
.price-tags {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
padding-top: 2rem;
|
padding-top: 2rem;
|
||||||
// display: inline-block;
|
|
||||||
}
|
}
|
||||||
.price-tags li {
|
.price-tags li {
|
||||||
line-height: 40px;
|
line-height: 40px;
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ class Ability
|
||||||
|
|
||||||
can :index, Ticket
|
can :index, Ticket
|
||||||
can :manage, TicketPurchase, user_id: user.id
|
can :manage, TicketPurchase, user_id: user.id
|
||||||
can :manage, Payment, user_id: user.id
|
can [:new], Payment, user_id: user.id
|
||||||
|
|
||||||
can [:create, :destroy], Subscription, user_id: user.id
|
can [:create, :destroy], Subscription, user_id: user.id
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class Ticket < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def unpaid?(user)
|
def unpaid?(user)
|
||||||
ticket_purchases.find_by(user: user, paid: false).present?
|
ticket_purchases.unpaid.by_user(user).present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_price(user, paid: false)
|
def total_price(user, paid: false)
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@
|
||||||
-if @tickets.any?
|
-if @tickets.any?
|
||||||
= "(#{@tickets.first.price.symbol}#{humanized_money @total_price})"
|
= "(#{@tickets.first.price.symbol}#{humanized_money @total_price})"
|
||||||
%ul
|
%ul
|
||||||
.col.md-4
|
.col-md-12
|
||||||
- @ticket_payments.each_pair do |ticket_id, tickets|
|
- @ticket_payments.each_pair do |ticket_id, tickets|
|
||||||
%li
|
%li
|
||||||
= @total_quantity[ticket_id]
|
= @total_quantity[ticket_id]
|
||||||
|
|
@ -102,6 +102,7 @@
|
||||||
for
|
for
|
||||||
= tickets.first.price.symbol
|
= tickets.first.price.symbol
|
||||||
= humanized_money tickets.first.price
|
= humanized_money tickets.first.price
|
||||||
|
%br
|
||||||
- if @tickets.any?
|
- if @tickets.any?
|
||||||
= link_to 'Buy more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default"
|
= link_to 'Buy more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default"
|
||||||
- else
|
- else
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,4 @@
|
||||||
%tr
|
%tr
|
||||||
%td{:colspan => "5"} No payments have been attempted.
|
%td{:colspan => "5"} No payments have been attempted.
|
||||||
.pull-right
|
.pull-right
|
||||||
= link_to "Conference Registration", conference_conference_registrations_path(@conference.short_title), class: 'btn btn-primary'
|
= link_to "Conference Registration", conference_conference_registration_path(@conference.short_title), class: 'btn btn-primary'
|
||||||
|
|
|
||||||
|
|
@ -96,10 +96,10 @@ Osem::Application.configure do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Initialize Payment Gateway with valid credentials
|
||||||
|
ActiveMerchant::Billing::Base.mode = :test
|
||||||
|
::GATEWAY = ActiveMerchant::Billing::StripeGateway.new(:login => ENV['SECRET_KEY'])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
ActiveMerchant::Billing::Base.mode = :test
|
|
||||||
|
|
||||||
::GATEWAY = ActiveMerchant::Billing::StripeGateway.new(
|
|
||||||
:login => ENV['SECRET_KEY'])
|
|
||||||
|
|
|
||||||
|
|
@ -83,4 +83,8 @@ Osem::Application.configure do
|
||||||
|
|
||||||
# Set the secret_key_base from the env, if not set by any other means
|
# Set the secret_key_base from the env, if not set by any other means
|
||||||
config.secret_key_base ||= ENV["SECRET_KEY_BASE"]
|
config.secret_key_base ||= ENV["SECRET_KEY_BASE"]
|
||||||
|
|
||||||
|
# Initialize Payment Gateway with valid credentials
|
||||||
|
ActiveMerchant::Billing::Base.mode = :test
|
||||||
|
::GATEWAY = ActiveMerchant::Billing::StripeGateway.new(:login => ENV['SECRET_KEY'])
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -52,4 +52,9 @@ Osem::Application.configure do
|
||||||
ActiveSupport::Deprecation.silenced = true
|
ActiveSupport::Deprecation.silenced = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Initialize Payment Gateway with valid credentials
|
||||||
|
ActiveMerchant::Billing::Base.mode = :test
|
||||||
|
::GATEWAY = ActiveMerchant::Billing::BogusGateway.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ feature Registration do
|
||||||
|
|
||||||
context 'who is not registered' 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
|
visit root_path
|
||||||
click_link 'Register'
|
click_link 'Register'
|
||||||
|
|
||||||
|
|
@ -37,56 +37,57 @@ feature Registration do
|
||||||
fill_in 'last_name', with: 'bar'
|
fill_in 'last_name', with: 'bar'
|
||||||
select Date.current.year + 2, from: 'expiration_year'
|
select Date.current.year + 2, from: 'expiration_year'
|
||||||
fill_in 'card_verification_value', with: '123'
|
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'
|
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(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 'first_name', with: 'foo'
|
||||||
fill_in 'last_name', with: 'bar'
|
fill_in 'last_name', with: 'bar'
|
||||||
select Date.current.year + 2, from: 'expiration_year'
|
select Date.current.year + 2, from: 'expiration_year'
|
||||||
fill_in 'card_verification_value', with: '123'
|
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'
|
click_button 'Charge Card'
|
||||||
|
|
||||||
expect(flash).to eq('Your card was declined.')
|
expect(Payment.count).to eq(0)
|
||||||
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
|
end
|
||||||
|
|
||||||
fill_in 'first_name', with: 'foo'
|
scenario 'purchases and pays for a ticket successfully', feature: true, js: true do
|
||||||
fill_in 'last_name', with: 'bar'
|
visit root_path
|
||||||
select Date.current.year + 2, from: 'expiration_year'
|
click_link 'Register'
|
||||||
fill_in 'card_verification_value', with: '123'
|
|
||||||
fill_in 'credit_card_number', with: '4000000000000127'
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
||||||
|
click_button 'Register'
|
||||||
click_button 'Charge Card'
|
|
||||||
|
fill_in "tickets__#{ticket.id}", with: '2'
|
||||||
expect(flash).to eq("Your card's security code is incorrect.")
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
||||||
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
|
|
||||||
|
click_button 'Continue'
|
||||||
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(current_path).to eq(new_conference_payment_path(conference.short_title))
|
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 'first_name', with: 'foo'
|
||||||
fill_in 'last_name', with: 'bar'
|
fill_in 'last_name', with: 'bar'
|
||||||
|
|
@ -96,14 +97,15 @@ feature Registration do
|
||||||
|
|
||||||
click_button 'Charge Card'
|
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
|
payment = Payment.where(user_id: participant, conference_id: conference.id).first
|
||||||
expect(payment.amount).to eq(20)
|
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('foo')
|
||||||
expect(payment.first_name).to eq('bar')
|
expect(payment.last_name).to eq('bar')
|
||||||
expect(payment.last4).not_to be_empty
|
expect(payment.last4).not_to be_empty
|
||||||
expect(payment.authorization_code).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.')
|
expect(flash).to eq('Thanks! You have purchased your tickets successfully.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -39,24 +39,8 @@ describe Payment do
|
||||||
let!(:participant) { create(:user) }
|
let!(:participant) { create(:user) }
|
||||||
let!(:ticket_1) { create(:ticket) }
|
let!(:ticket_1) { create(:ticket) }
|
||||||
let!(:conference) { create(:conference, tickets: [ticket_1]) }
|
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) }
|
let(:payment) { create(:payment) }
|
||||||
|
|
||||||
it 'creates a purchase and payment for one ticket' do
|
it 'creates a purchase and payment for one ticket' do
|
||||||
tickets = { ticket_1.id.to_s => '1' }
|
tickets = { ticket_1.id.to_s => '1' }
|
||||||
message = TicketPurchase.purchase(conference, participant, tickets)
|
message = TicketPurchase.purchase(conference, participant, tickets)
|
||||||
|
|
@ -68,8 +52,11 @@ describe Payment do
|
||||||
expect(purchase.quantity).to eq(1)
|
expect(purchase.quantity).to eq(1)
|
||||||
expect(message.blank?).to be true
|
expect(message.blank?).to be true
|
||||||
|
|
||||||
payment = Payment.new
|
|
||||||
payment.purchase(participant, conference, 1000)
|
payment.purchase(participant, conference, 1000)
|
||||||
|
|
||||||
|
purchase = Payment.first
|
||||||
|
expect(Payment.count).to be(1)
|
||||||
|
expect(purchase.amount).to eq(10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue