-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix create event issues due to empty times in params (#91)
* Fix create event issues due to empty times in params Fix create event issue with empty times due to invalid check on hash elements Refactor to put convert for db times functionality into times helper Added test cases and Time validations * rubocop cleanup * Cleanup spec * Refactor test_helper_spec * spec fixes
- Loading branch information
1 parent
adbed3a
commit 0834a4f
Showing
7 changed files
with
126 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'stripe' | ||
|
||
TicketBooth::Application.config.x.stripe.secret_key = ENV.fetch('STRIPE_SECRET_KEY', | ||
Rails.application.credentials[Rails.env.to_sym].stripe.secret_api_key) | ||
TicketBooth::Application.config.x.stripe.public_key = ENV.fetch('STRIPE_PUBLIC_KEY', | ||
Rails.application.credentials[Rails.env.to_sym].stripe.publishable_api_key) | ||
|
||
Stripe.api_key = TicketBooth::Application.config.x.stripe.secret_key | ||
# | ||
# require 'stripe' | ||
# | ||
# TicketBooth::Application.config.x.stripe.secret_key = ENV.fetch('STRIPE_SECRET_KEY', | ||
# Rails.application.credentials[Rails.env.to_sym].stripe.secret_api_key) | ||
# TicketBooth::Application.config.x.stripe.public_key = ENV.fetch('STRIPE_PUBLIC_KEY', | ||
# Rails.application.credentials[Rails.env.to_sym].stripe.publishable_api_key) | ||
# | ||
# Stripe.api_key = TicketBooth::Application.config.x.stripe.secret_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe TimeHelper do | ||
let(:valid_input) { '04/20/2024, 4:20 PM' } | ||
|
||
describe '.to_string_for_flatpickr' do | ||
let(:date) { DateTime.new(2024, 4, 20, 8, 37, 48, -7) } | ||
|
||
it 'convert datetime to a string' do | ||
expect(described_class.to_string_for_flatpickr(date)).to be_a(String) | ||
end | ||
|
||
it 'handles nil' do | ||
expect(described_class.to_string_for_flatpickr(nil)).to be_nil | ||
end | ||
end | ||
|
||
describe '.to_datetime_from_picker' do | ||
let(:out) { described_class.to_datetime_from_picker(valid_input) } | ||
|
||
it 'converts string to Time' do | ||
expect(out).to be_a(Time) | ||
end | ||
|
||
it 'raises date error on empty' do | ||
expect { described_class.to_datetime_from_picker('') }.to raise_error(Date::Error) | ||
end | ||
|
||
it 'raises date error on bad format' do | ||
str = '04/17/2024' | ||
expect { described_class.to_datetime_from_picker(str) }.to raise_error(Date::Error) | ||
end | ||
|
||
it 'returns nil on nil' do | ||
expect(described_class.to_datetime_from_picker(nil)).to be_nil | ||
end | ||
end | ||
|
||
describe '.convert_times_for_db' do | ||
let(:test_hash) { { start_time: valid_input } } | ||
let(:date_epoch_string) { DateTime.parse('2024-04-20T16:20:00 -0700').to_time.to_i } | ||
|
||
describe 'empty aguments' do | ||
subject { described_class.convert_times_for_db(input) } | ||
|
||
describe 'nil' do | ||
let(:input) { nil } | ||
|
||
it { is_expected.to be_nil } | ||
end | ||
|
||
describe 'empty hash' do | ||
let(:input) { {} } | ||
|
||
it { is_expected.to be_empty } | ||
end | ||
end | ||
|
||
describe 'invalid non-empty arguments' do | ||
let(:invalid_input) { '04.17.2024' } | ||
|
||
it 'raises type error with bad type arg' do | ||
expect { described_class.convert_times_for_db(invalid_input) }.to raise_error(ArgumentError) | ||
end | ||
|
||
it 'raises date error on bad format' do | ||
expect { described_class.convert_times_for_db({ start_time: invalid_input }) }.to raise_error(Date::Error) | ||
end | ||
|
||
describe 'empty string for time' do | ||
let(:test_hash) { { start_time: '' } } | ||
|
||
it 'does not convert empty string for time key' do | ||
expect(described_class.convert_times_for_db(test_hash)).to eq(test_hash) | ||
end | ||
end | ||
end | ||
|
||
describe 'valid arguments' do | ||
let(:out_time) { described_class.convert_times_for_db(test_hash)[:start_time] } | ||
|
||
it 'converts time string to Time' do | ||
expect(out_time).to be_a(Time) | ||
end | ||
|
||
it 'converts to a correct time' do | ||
expect(out_time.to_i).to eq(date_epoch_string) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters