From 9390137b926206e04c33a579d700b2282e49de89 Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Thu, 7 Mar 2024 22:51:08 -0800 Subject: [PATCH] Fixing a bunch of failing specs --- Gemfile.lock | 1 + app/models/eald_payment.rb | 4 ---- app/models/event.rb | 1 - app/models/event_admin.rb | 5 +++++ app/models/price_rule/kids_equal_to.rb | 2 -- app/models/ticket_request.rb | 3 --- spec/models/event_admin_spec.rb | 28 +++++++++++++++++++------- spec/models/ticket_request_spec.rb | 16 +++++++-------- 8 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1084b572..62f33dce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -383,6 +383,7 @@ GEM PLATFORMS arm64-darwin-21 arm64-darwin-22 + arm64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/app/models/eald_payment.rb b/app/models/eald_payment.rb index de764a29..e5702ed2 100644 --- a/app/models/eald_payment.rb +++ b/app/models/eald_payment.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index edd35be5..dcbf6caa 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 diff --git a/app/models/event_admin.rb b/app/models/event_admin.rb index 408a2c09..5e1dd4dc 100644 --- a/app/models/event_admin.rb +++ b/app/models/event_admin.rb @@ -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 diff --git a/app/models/price_rule/kids_equal_to.rb b/app/models/price_rule/kids_equal_to.rb index 93521fbb..28be29c9 100644 --- a/app/models/price_rule/kids_equal_to.rb +++ b/app/models/price_rule/kids_equal_to.rb @@ -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) diff --git a/app/models/ticket_request.rb b/app/models/ticket_request.rb index ba3437a2..dfd5b235 100644 --- a/app/models/ticket_request.rb +++ b/app/models/ticket_request.rb @@ -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', diff --git a/spec/models/event_admin_spec.rb b/spec/models/event_admin_spec.rb index 606bf59e..1f64ee5b 100644 --- a/spec/models/event_admin_spec.rb +++ b/spec/models/event_admin_spec.rb @@ -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: } @@ -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 diff --git a/spec/models/ticket_request_spec.rb b/spec/models/ticket_request_spec.rb index 3bcb8073..d92705b2 100644 --- a/spec/models/ticket_request_spec.rb +++ b/spec/models/ticket_request_spec.rb @@ -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 @@ -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