From f14d470738c7f94a9e8b1588caed6363ac2df6b3 Mon Sep 17 00:00:00 2001 From: Rishabh Saxena Date: Tue, 31 May 2016 21:25:29 +0530 Subject: [PATCH] add payment mode to conferences schema --- app/models/conference.rb | 3 +++ ...0603043546_add_payment_method_to_conferences.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories/conferences.rb | 1 + spec/models/conference_spec.rb | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160603043546_add_payment_method_to_conferences.rb diff --git a/app/models/conference.rb b/app/models/conference.rb index f0b73047..961e7b3b 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -57,6 +57,9 @@ class Conference < ActiveRecord::Base validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/ validates :registration_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0 } + validates :payment_method, presence: true, null: false, inclusion: {in: %w(online offline), + message: "'%{value}' is not a valid payment method"} + # This validation is needed since a conference with a start date greater than the end date is not possible validate :valid_date_range? before_create :generate_guid diff --git a/db/migrate/20160603043546_add_payment_method_to_conferences.rb b/db/migrate/20160603043546_add_payment_method_to_conferences.rb new file mode 100644 index 00000000..f0c06d9b --- /dev/null +++ b/db/migrate/20160603043546_add_payment_method_to_conferences.rb @@ -0,0 +1,5 @@ +class AddPaymentMethodToConferences < ActiveRecord::Migration + def change + add_column :conferences, :payment_method, :string, default: 'offline', null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 00e93609..2488dd87 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160427104236) do +ActiveRecord::Schema.define(version: 20160603043546) do create_table "ahoy_events", force: :cascade do |t| t.uuid "visit_id", limit: 16 @@ -102,6 +102,7 @@ ActiveRecord::Schema.define(version: 20160427104236) do t.text "description" t.integer "registration_limit", default: 0 t.string "picture" + t.string "payment_method", default: "offline", null: false end create_table "conferences_questions", id: false, force: :cascade do |t| diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index d92a7e88..8dc6da06 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -9,6 +9,7 @@ FactoryGirl.define do end_date { 6.days.from_now } registration_limit 0 description { Faker::Hipster.paragraph } + payment_method 'offline' after(:create) do |conference| Role.where(name: 'organizer', resource: conference).first_or_create(description: 'For the organizers of the conference (who shall have full access)') diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 95bd5440..637f3e79 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -1545,6 +1545,20 @@ describe Conference do should validate_presence_of(:end_date) end + it 'is not valid without payment mode' do + should validate_presence_of(:payment_method) + end + + it 'is valid with payment mode as Online' do + should allow_value('online').for(:payment_method). + with_message("'%{value}' is not a valid payment method") + end + + it 'is valid with payment mode as Offline' do + should allow_value('offline').for(:payment_method). + with_message("'%{value}' is not a valid payment method") + end + it 'is not valid with a duplicate short title' do should validate_uniqueness_of(:short_title) end