diff --git a/spec/factories/physical_ticket.rb b/spec/factories/physical_ticket.rb new file mode 100644 index 00000000..8b4f2a0e --- /dev/null +++ b/spec/factories/physical_ticket.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :physical_ticket do + ticket_purchase + end +end diff --git a/spec/factories/ticket_purchases.rb b/spec/factories/ticket_purchases.rb index 82103db3..bee365cf 100644 --- a/spec/factories/ticket_purchases.rb +++ b/spec/factories/ticket_purchases.rb @@ -4,5 +4,11 @@ FactoryGirl.define do conference ticket quantity 10 + factory :paid_ticket_purchase do + after(:build) do |ticket_purchase| + payment = create(:payment) + ticket_purchase.pay(payment) + end + end end end diff --git a/spec/models/physical_ticket_spec.rb b/spec/models/physical_ticket_spec.rb new file mode 100644 index 00000000..9910a4a3 --- /dev/null +++ b/spec/models/physical_ticket_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe PhysicalTicket do + + describe 'association' do + it { is_expected.to belong_to :ticket_purchase } + end + + describe 'validations' do + it 'has a valid factory' do + expect(build(:physical_ticket)).to be_valid + end + end +end diff --git a/spec/models/ticket_purchase_spec.rb b/spec/models/ticket_purchase_spec.rb index f11a8187..3ef9a861 100644 --- a/spec/models/ticket_purchase_spec.rb +++ b/spec/models/ticket_purchase_spec.rb @@ -114,22 +114,4 @@ describe TicketPurchase do expect(message.blank?).to be true end end - - describe 'after_create' do - let(:ticket_purchase) { create(:ticket_purchase, quantity: 4, paid: true) } - - it 'creates physical tickets equal to the quantity of purchase' do - expect(ticket_purchase.physical_tickets.count).to eq(4) - end - end - - describe 'after_update' do - let(:ticket_purchase) { create(:ticket_purchase, quantity: 5) } - - it 'creates physical tickets if the payment is made successfully' do - ticket_purchase - ticket_purchase.paid = true - expect{ ticket_purchase.save }.to change{ ticket_purchase.physical_tickets.count }.from(0).to(5) - end - end end