Introducing delegation for city and country name (Conference - Venue
Using ActiveSupport delegate macro.
This commit is contained in:
parent
f50a92bf53
commit
fd2635509f
2 changed files with 45 additions and 0 deletions
|
|
@ -25,6 +25,9 @@ class Conference < ApplicationRecord
|
||||||
has_one :email_settings, dependent: :destroy
|
has_one :email_settings, dependent: :destroy
|
||||||
has_one :program, dependent: :destroy
|
has_one :program, dependent: :destroy
|
||||||
has_one :venue, dependent: :destroy
|
has_one :venue, dependent: :destroy
|
||||||
|
delegate :city, :country_name, to: :venue, allow_nil: true
|
||||||
|
delegate :name, :street, to: :venue, prefix: true, allow_nil: true
|
||||||
|
|
||||||
has_many :physical_tickets, through: :ticket_purchases
|
has_many :physical_tickets, through: :ticket_purchases
|
||||||
has_many :ticket_purchases, dependent: :destroy
|
has_many :ticket_purchases, dependent: :destroy
|
||||||
has_many :payments, dependent: :destroy
|
has_many :payments, dependent: :destroy
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,48 @@ describe Conference do
|
||||||
|
|
||||||
let(:subject) { create(:conference, start_date: Date.new(2014, 06, 30), end_date: Date.new(2014, 06, 30)) }
|
let(:subject) { create(:conference, start_date: Date.new(2014, 06, 30), end_date: Date.new(2014, 06, 30)) }
|
||||||
|
|
||||||
|
context 'Delegation' do
|
||||||
|
context 'Venue' do
|
||||||
|
context 'when venue has not been set' do
|
||||||
|
it do
|
||||||
|
expect(subject.city).to eq(nil)
|
||||||
|
end
|
||||||
|
it do
|
||||||
|
expect(subject.country_name).to eq(nil)
|
||||||
|
end
|
||||||
|
it do
|
||||||
|
expect(subject.venue_name).to eq(nil)
|
||||||
|
end
|
||||||
|
it do
|
||||||
|
expect(subject.venue_street).to eq(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when venue has been set' do
|
||||||
|
before(:each) do
|
||||||
|
subject.update(venue: venue)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:venue) do
|
||||||
|
FactoryBot.create(:venue)
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
expect(subject.city).to eq(venue.city)
|
||||||
|
end
|
||||||
|
it do
|
||||||
|
expect(subject.country_name).to eq(venue.country_name)
|
||||||
|
end
|
||||||
|
it do
|
||||||
|
expect(subject.venue_name).to eq(venue.name)
|
||||||
|
end
|
||||||
|
it do
|
||||||
|
expect(subject.venue_street).to eq(venue.street)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#write_event_distribution_to_db' do
|
describe '#write_event_distribution_to_db' do
|
||||||
|
|
||||||
it 'updates pending conferences' do
|
it 'updates pending conferences' do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue