add payment mode to ticket schema

This commit is contained in:
Rishabh Saxena 2016-05-26 23:01:36 +05:30
parent 301ad1c722
commit a8fd1a7903
5 changed files with 14 additions and 3 deletions

View file

@ -9,7 +9,7 @@ class Ticket < ActiveRecord::Base
# If we would allow different currencies per conference we also have to handle convertions between currencies! # If we would allow different currencies per conference we also have to handle convertions between currencies!
validate :tickets_of_conference_have_same_currency validate :tickets_of_conference_have_same_currency
validates :price_cents, :price_currency, :title, presence: true validates :price_cents, :price_currency, :payment_mode, :title, presence: true
validates_numericality_of :price_cents, greater_than: 0 validates_numericality_of :price_cents, greater_than: 0

View file

@ -0,0 +1,5 @@
class AddPaymentModeToTickets < ActiveRecord::Migration
def change
add_column :tickets, :payment_mode, :string
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160427104236) do ActiveRecord::Schema.define(version: 20160526142456) do
create_table "ahoy_events", force: :cascade do |t| create_table "ahoy_events", force: :cascade do |t|
t.uuid "visit_id", limit: 16 t.uuid "visit_id", limit: 16
@ -411,6 +411,7 @@ ActiveRecord::Schema.define(version: 20160427104236) do
t.text "description" t.text "description"
t.integer "price_cents", default: 0, null: false t.integer "price_cents", default: 0, null: false
t.string "price_currency", default: "USD", null: false t.string "price_currency", default: "USD", null: false
t.string "payment_mode"
end end
create_table "tracks", force: :cascade do |t| create_table "tracks", force: :cascade do |t|

View file

@ -3,5 +3,6 @@ FactoryGirl.define do
title { "#{Faker::Hipster.word} Ticket" } title { "#{Faker::Hipster.word} Ticket" }
price_cents 1000 price_cents 1000
price_currency 'USD' price_currency 'USD'
payment_mode 'Online'
end end
end end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe Ticket do describe Ticket do
let(:conference) { create(:conference) } let(:conference) { create(:conference) }
let(:ticket) { create(:ticket, price: 50, price_currency: 'USD', conference: conference) } let(:ticket) { create(:ticket, price: 50, price_currency: 'USD', payment_mode: 'Online', conference: conference) }
let(:user) { create(:user) } let(:user) { create(:user) }
describe 'validation' do describe 'validation' do
@ -22,6 +22,10 @@ describe Ticket do
should validate_presence_of(:price_currency) should validate_presence_of(:price_currency)
end end
it 'is not valid without a payment_mode' do
should validate_presence_of(:payment_mode)
end
it 'is not valid with a price_cents equals zero' do it 'is not valid with a price_cents equals zero' do
should_not allow_value(0).for(:price_cents) should_not allow_value(0).for(:price_cents)
end end