This commit is contained in:
Rishabh Saxena 2016-05-30 14:03:05 +00:00
commit c4a6a170a7
8 changed files with 19 additions and 4 deletions

View file

@ -48,7 +48,7 @@ module Admin
private private
def ticket_params def ticket_params
params.require(:ticket).permit(:conference, :title, :url, :description, :conference_id, :price_cents, :price_currency, :price) params.require(:ticket).permit(:conference, :title, :url, :description, :conference_id, :price_cents, :price_currency, :price, :payment_mode)
end end
end end
end end

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

@ -13,5 +13,6 @@
= f.input :description, input_html: { rows: 5, data: { provide: "markdown-editable" } } = f.input :description, input_html: { rows: 5, data: { provide: "markdown-editable" } }
= f.input :price = f.input :price
= f.input :price_currency, as: :select, class: 'form-control', collection: ['USD', 'EUR', 'GBP', 'INR', 'CNY'], include_blank: false = f.input :price_currency, as: :select, class: 'form-control', collection: ['USD', 'EUR', 'GBP', 'INR', 'CNY'], include_blank: false
= f.input :payment_mode, as: :select, class: 'form-control', collection: ['Online', 'Offline'], include_blank: false
%p.text-right %p.text-right
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -13,6 +13,7 @@
%th Price %th Price
%th Sold %th Sold
%th Turnover %th Turnover
%th Payment Mode
%th Actions %th Actions
%tbody %tbody
- @conference.tickets.each do |ticket| - @conference.tickets.each do |ticket|
@ -26,6 +27,8 @@
= ticket.tickets_sold = ticket.tickets_sold
%td %td
= humanized_money_with_symbol ticket.tickets_turnover = humanized_money_with_symbol ticket.tickets_turnover
%td
= ticket.payment_mode
%td %td
.btn-group .btn-group
= link_to 'Edit', edit_admin_conference_ticket_path(@conference.short_title, ticket.id), = link_to 'Edit', edit_admin_conference_ticket_path(@conference.short_title, ticket.id),

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