Skip to content

Commit

Permalink
Fixing a bunch of failing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
kigster committed Mar 11, 2024
1 parent c593bd0 commit 9390137
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ GEM
PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
4 changes: 0 additions & 4 deletions app/models/eald_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#
# index_eald_payments_on_event_id (event_id)
#
# Payment for early arrival/late departures passes.
#
# We only associate this with an event, as we want to treat these separately
# from ticket requests.
class EaldPayment < ApplicationRecord
include PaymentsHelper

Expand Down
1 change: 0 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# created_at :datetime not null
# updated_at :datetime not null
#
# Core object containing all information related to an actual event being held.
class Event < ApplicationRecord
has_many :event_admins
has_many :admins, through: :event_admins, source: :user
Expand Down
5 changes: 5 additions & 0 deletions app/models/event_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ class EventAdmin < ApplicationRecord

validates :user_id,
uniqueness: { scope: :event_id, message: 'already admin for this event' }

validate do |record|
raise ArgumentError, 'event_id is nil' if record.event_id.nil?
raise ArgumentError, 'user_id is nil' if record.user_id.nil?
end
end
2 changes: 0 additions & 2 deletions app/models/price_rule/kids_equal_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#
# index_price_rules_on_event_id (event_id)
#
# Applied when a ticket request has indicated that they are bringing a specific
# number of kids.
class PriceRule
class KidsEqualTo < PriceRule
def calc_price(ticket_request)
Expand Down
3 changes: 0 additions & 3 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
# event_id :integer not null
# user_id :integer not null
#
# Individual request for one or more tickets.
# This is intended to capture as much information as possible about the ticket,
# as well as the state of the request.
class TicketRequest < ApplicationRecord
STATUSES = [
STATUS_PENDING = 'P',
Expand Down
28 changes: 21 additions & 7 deletions spec/models/event_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,27 @@
describe EventAdmin do
describe 'validations' do
describe '#user' do
it { is_expected.to accept_values_for(:user_id, User.make!.id) }
it { is_expected.not_to accept_values_for(:user_id, nil) }
describe 'valid admin' do
subject(:event_admin) { EventAdmin.make! }

it { is_expected.to be_valid }
end

describe 'nil user id' do
subject(:event_admin_without_user) { EventAdmin.make!.tap { |ea| ea.user = nil }.validate! }

it 'invalidates nil user_id' do
expect { event_admin_without_user }.to raise_error(ArgumentError)
end
end

describe 'nil event id' do
subject(:event_admin_without_event) { EventAdmin.make!.tap { |ea| ea.event = nil }.validate! }

it 'invalidates nil event_id' do
expect { event_admin_without_event }.to raise_error(ArgumentError)
end
end

context 'when the user is already an admin for the event' do
subject { described_class.make event: }
Expand All @@ -33,10 +52,5 @@
it { is_expected.not_to accept_values_for(:user_id, user.id) }
end
end

describe '#event' do
it { is_expected.to accept_values_for(:event_id, Event.make!.id) }
it { is_expected.not_to accept_values_for(:event_id, nil) }
end
end
end
16 changes: 8 additions & 8 deletions spec/models/ticket_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,39 +317,39 @@
end

context 'when kid ticket price is not set on the event' do
it { is_expected.to == adult_price * adults }
it { is_expected.to eql(adult_price * adults) }
end

context 'when the ticket request includes kids' do
let(:kids) { 2 }
let(:kid_price) { 10 }

it { is_expected.to == (adult_price * adults) + (kid_price * kids) }
it { is_expected.to eql((adult_price * adults) + (kid_price * kids)) }
end

context 'when the ticket request does not include kids' do
let(:kids) { nil }

it { is_expected.to == adult_price * adults }
it { is_expected.to eql(adult_price * adults) }
end

context 'when the ticket request includes cabins' do
let(:cabins) { 2 }
let(:cabin_price) { 100 }

it { is_expected.to == (adult_price * adults) + (cabin_price * cabins) }
it { is_expected.to eql((adult_price * adults) + (cabin_price * cabins)) }
end

context 'when the ticket request does not include cabins' do
let(:cabins) { nil }

it { is_expected.to == adult_price * adults }
it { is_expected.to eql(adult_price * adults) }
end

context 'when a special price is set' do
let(:special_price) { BigDecimal(99.99, 10) }

it { is_expected.to == special_price }
it { is_expected.to eql(special_price) }
end

context 'when custom price rules are defined' do
Expand All @@ -366,13 +366,13 @@
context 'and the rule does not apply' do
let(:kids) { trigger_value - 1 }

it { is_expected.to == (adult_price * adults) + (kid_price * kids) }
it { is_expected.to eql((adult_price * adults) + (kid_price * kids)) }
end

context 'and the rule applies' do
let(:kids) { trigger_value }

it { is_expected.to == (adult_price * adults) + 5 }
it { is_expected.to eql((adult_price * adults) + 5) }
end
end
end
Expand Down

0 comments on commit 9390137

Please sign in to comment.