Skip to content

Commit 39da8a6

Browse files
committed
migration to add currency in model
1 parent 6fa5fdd commit 39da8a6

7 files changed

+45
-4
lines changed

app/models/payment.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# id :bigint not null, primary key
88
# amount :integer
99
# authorization_code :string
10+
# currency :string
1011
# last4 :string
1112
# status :integer default("unpaid"), not null
1213
# created_at :datetime not null
@@ -24,6 +25,7 @@ class Payment < ApplicationRecord
2425
validates :status, presence: true
2526
validates :user_id, presence: true
2627
validates :conference_id, presence: true
28+
validates :currency, presence: true
2729

2830
enum status: {
2931
unpaid: 0,
@@ -44,7 +46,7 @@ def purchase
4446
receipt_email: stripe_customer_email,
4547
description: stripe_description,
4648
amount: amount_to_pay,
47-
currency: conference.tickets.first.price_currency
49+
currency: currency
4850

4951
self.amount = gateway_response[:amount]
5052
self.last4 = gateway_response[:source][:last4]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddCurrencyToPayments < ActiveRecord::Migration[7.0]
2+
def change
3+
add_column :payments, :currency, :string
4+
end
5+
end

db/schema.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2023_04_18_211400) do
13+
ActiveRecord::Schema[7.0].define(version: 2024_03_08_190204) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_stat_statements"
1616
enable_extension "plpgsql"
@@ -329,6 +329,7 @@
329329
t.integer "conference_id", null: false
330330
t.datetime "created_at", precision: nil, null: false
331331
t.datetime "updated_at", precision: nil, null: false
332+
t.string "currency"
332333
end
333334

334335
create_table "physical_tickets", force: :cascade do |t|

spec/factories/currency_conversions.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44
#
55
# Table name: currency_conversions
66
#
7-
# rate :decimal
7+
# id :bigint not null, primary key
88
# from_currency :string
9+
# rate :decimal(, )
910
# to_currency :string
10-
# conference_id :integer
11+
# created_at :datetime not null
12+
# updated_at :datetime not null
13+
# conference_id :bigint not null
14+
#
15+
# Indexes
16+
#
17+
# index_currency_conversions_on_conference_id (conference_id)
18+
#
19+
# Foreign Keys
20+
#
21+
# fk_rails_... (conference_id => conferences.id)
1122
#
1223
FactoryBot.define do
1324
factory :currency_conversion do

spec/factories/payments.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# id :bigint not null, primary key
88
# amount :integer
99
# authorization_code :string
10+
# currency :string
1011
# last4 :string
1112
# status :integer default("unpaid"), not null
1213
# created_at :datetime not null

spec/models/payment_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# id :bigint not null, primary key
88
# amount :integer
99
# authorization_code :string
10+
# currency :string
1011
# last4 :string
1112
# status :integer default("unpaid"), not null
1213
# created_at :datetime not null

spec/serializers/event_schedule_serializer_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: event_schedules
6+
#
7+
# id :bigint not null, primary key
8+
# enabled :boolean default(TRUE)
9+
# start_time :datetime
10+
# created_at :datetime not null
11+
# updated_at :datetime not null
12+
# event_id :integer
13+
# room_id :integer
14+
# schedule_id :integer
15+
#
16+
# Indexes
17+
#
18+
# index_event_schedules_on_event_id (event_id)
19+
# index_event_schedules_on_event_id_and_schedule_id (event_id,schedule_id) UNIQUE
20+
# index_event_schedules_on_room_id (room_id)
21+
# index_event_schedules_on_schedule_id (schedule_id)
22+
#
323
require 'spec_helper'
424

525
describe EventScheduleSerializer, type: :serializer do

0 commit comments

Comments
 (0)