Skip to content

Commit acb8aca

Browse files
authored
Merge branch 'main' into 187121499_Enable_Default_Currency
2 parents 2605a94 + 438b7ff commit acb8aca

File tree

10 files changed

+145
-53
lines changed

10 files changed

+145
-53
lines changed

Gemfile.lock

+4
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ GEM
404404
nio4r (2.7.0)
405405
nokogiri (1.16.2-arm64-darwin)
406406
racc (~> 1.4)
407+
nokogiri (1.16.2-x86_64-darwin)
408+
racc (~> 1.4)
407409
nokogiri (1.16.2-x86_64-linux)
408410
racc (~> 1.4)
409411
oauth2 (2.0.9)
@@ -657,6 +659,7 @@ GEM
657659
activesupport (>= 5.2)
658660
sprockets (>= 3.0.0)
659661
sqlite3 (1.6.3-arm64-darwin)
662+
sqlite3 (1.6.3-x86_64-darwin)
660663
sqlite3 (1.6.3-x86_64-linux)
661664
ssrf_filter (1.1.2)
662665
stripe (5.55.0)
@@ -719,6 +722,7 @@ GEM
719722

720723
PLATFORMS
721724
arm64-darwin-23
725+
x86_64-darwin-21
722726
x86_64-linux
723727

724728
DEPENDENCIES

app/controllers/admin/currency_conversions_controller.rb

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Admin
22
class CurrencyConversionsController < Admin::BaseController
33
load_and_authorize_resource :conference, find_by: :short_title
44
load_and_authorize_resource :currency_conversion, through: :conference
5+
before_action :check_for_tickets, only: [:new, :create, :edit]
6+
before_action :set_currency_options, only: [:new, :create, :edit]
57

68
# GET /currency_conversions
79
def index; end
@@ -12,6 +14,7 @@ def show; end
1214
# GET /currency_conversions/new
1315
def new
1416
@currency_conversion = @conference.currency_conversions.new(conference_id: @conference.short_title)
17+
@currency_conversion.from_currency = @conference.tickets.first.price_currency
1518
end
1619

1720
# GET /currency_conversions/1/edit
@@ -20,7 +23,7 @@ def edit; end
2023
# POST /currency_conversions
2124
def create
2225
@currency_conversion = @conference.currency_conversions.new(currency_conversion_params)
23-
26+
@currency_conversion.from_currency = @conference.tickets.first.price_currency
2427
if @currency_conversion.save
2528
redirect_to admin_conference_currency_conversions_path(@conference.short_title), notice: 'Currency conversion was successfully created.'
2629
else
@@ -52,7 +55,18 @@ def destroy
5255

5356
# Only allow a list of trusted parameters through.
5457
def currency_conversion_params
55-
params.require(:currency_conversion).permit(:from_currency, :to_currency, :rate)
58+
params.require(:currency_conversion).permit(:to_currency, :rate)
59+
end
60+
61+
def set_currency_options
62+
@currency_conversion.from_currency = @conference.tickets.first.price_currency
63+
@to_currency_options = CurrencyConversion::VALID_CURRENCIES.reject { |i| i == @currency_conversion.from_currency }
64+
end
65+
66+
def check_for_tickets
67+
if @conference.tickets.empty?
68+
redirect_to admin_conference_currency_conversions_path, alert: 'No tickets available for this conference. Cannot create or edit currency conversions.'
69+
end
5670
end
5771
end
5872
end

app/views/admin/currency_conversions/_form.html.haml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
= form_for(@currency_conversion, url: (@currency_conversion.new_record? ? admin_conference_currency_conversions_path : admin_conference_currency_conversion_path(@conference.short_title, @currency_conversion))) do |f|
22
.form-group
3-
= f.label :from_currency
4-
= f.text_field :from_currency, autofocus: true , required: true, class: 'form-control'
3+
%label From currency
4+
= text_field_tag :from_currency, @currency_conversion.from_currency, disabled: true, class: 'form-control'
55
.form-group
66
= f.label :to_currency
7-
= f.text_field :to_currency, autofocus: true , required: true, class: 'form-control'
7+
= f.select :to_currency, @to_currency_options, {include_blank: 'Select Currency'}, autofocus: true, required: true, class: 'form-control'
88
.form-group
99
= f.label :rate
1010
= f.text_field :rate, autofocus: true, required: true, class: 'form-control', type: 'number', step: '0.01'

app/views/admin/currency_conversions/index.html.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
%table.table.table-hover#currency-conversions
1313
%thead
1414
%tr
15-
%th From Curr
16-
%th To Curr
15+
%th From Currency
16+
%th To Currency
1717
%th Rate
1818
%th Actions
1919
%tbody

app/views/admin/tickets/_form.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- if Ticket.where(conference: @conference).empty?
2727
.form-group
2828
= f.label :price_currency, 'Currency'
29-
= f.select :price_currency, ['USD', 'EUR', 'GBP', 'INR', 'CNY', 'CHF'], { include_blank: false }, { class: 'form-control' }
29+
= f.select :price_currency, CurrencyConversion::VALID_CURRENCIES, { include_blank: false }, { class: 'form-control' }
3030
- else
3131
= hidden_field_tag "ticket[price_currency]", f.object.conference.tickets.first.price_currency
3232
%span.help-block

db/schema.rb

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13+
1314
ActiveRecord::Schema[7.0].define(version: 2024_03_06_000725) do
15+
1416
# These are extensions that must be enabled in order to support this database
1517
enable_extension "pg_stat_statements"
1618
enable_extension "plpgsql"

spec/factories/event_types.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
description { 'Example Event Description\nThis event type is an example.' }
2525
minimum_abstract_length { 0 }
2626
maximum_abstract_length { 500 }
27-
submission_template { 'Example Event Instructions _with_ **markdown**' }
27+
submission_template { 'Example Event Template _with_ **markdown**' }
2828
color { '#ffffff' }
2929
program
3030
end

spec/features/currency_conversions_spec.rb

+78-43
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,95 @@
1515
sign_out
1616
end
1717

18-
it 'add a currency conversion', feature: true do
19-
visit admin_conference_currency_conversions_path(conference.short_title)
20-
click_link 'Add Currency Conversion'
21-
22-
fill_in 'currency_conversion_from_currency', with: 'USD'
23-
fill_in 'currency_conversion_to_currency', with: 'EUR'
24-
fill_in 'currency_conversion_rate', with: '0.89'
18+
context 'for a conference with no tickets' do
19+
before do
20+
conference.currency_conversions << create(:currency_conversion)
21+
conference.tickets.destroy_all
22+
end
2523

26-
click_button 'Create Currency conversion'
27-
page.find('#flash')
28-
expect(flash).to eq('Currency conversion was successfully created.')
29-
within('table#currency-conversions') do
30-
expect(page.has_content?('USD')).to be true
31-
expect(page.has_content?('EUR')).to be true
32-
expect(page.has_content?('0.89')).to be true
33-
expect(page.assert_selector('tbody tr', count: 1)).to be true
24+
it 'show error message when adding new currency conversion', feature: true, js: true do
25+
visit admin_conference_currency_conversions_path(conference.short_title)
26+
click_link 'Add Currency Conversion'
27+
page.find('#flash')
28+
expect(flash).to eq('No tickets available for this conference. Cannot create or edit currency conversions.')
3429
end
35-
end
3630

37-
it 'edit a currency conversion', feature: true do
38-
conference.currency_conversions << create(:currency_conversion)
39-
visit admin_conference_currency_conversions_path(conference.short_title)
40-
within('table tbody tr:nth-of-type(1) td:nth-of-type(4)') do
41-
click_link 'Edit'
31+
it 'show error message when editing a currency conversion', feature: true, js: true do
32+
visit admin_conference_currency_conversions_path(conference.short_title)
33+
within('table tbody tr:nth-of-type(1) td:nth-of-type(4)') do
34+
click_link 'Edit'
35+
end
36+
page.find('#flash')
37+
expect(flash).to eq('No tickets available for this conference. Cannot create or edit currency conversions.')
4238
end
43-
fill_in 'currency_conversion_from_currency', with: 'USD'
44-
fill_in 'currency_conversion_to_currency', with: 'RMB'
45-
fill_in 'currency_conversion_rate', with: '6.9'
46-
click_button 'Update Currency conversion'
47-
page.find('#flash')
48-
expect(flash).to eq('Currency conversion was successfully updated.')
49-
within('table#currency-conversions') do
50-
expect(page.has_content?('USD')).to be true
51-
expect(page.has_content?('RMB')).to be true
52-
expect(page.has_content?('6.9')).to be true
53-
expect(page.assert_selector('tbody tr', count: 1)).to be true
39+
40+
it 'does not show error message when deleting a currency conversion', feature: true, js: true do
41+
visit admin_conference_currency_conversions_path(conference.short_title)
42+
page.accept_alert do
43+
within('table tbody tr:nth-of-type(1) td:nth-of-type(4)') do
44+
click_link 'Delete'
45+
end
46+
end
47+
page.find('#flash')
48+
expect(flash).to eq('Currency conversion was successfully deleted.')
49+
within('table#currency-conversions') do
50+
expect(page.assert_selector('tbody tr', count: 0)).to be true
51+
end
5452
end
5553
end
5654

57-
it 'Deletes Currency Conversion', feature: true, js: true do
58-
conference.currency_conversions << create(:currency_conversion)
59-
visit admin_conference_currency_conversions_path(conference.short_title)
60-
# Remove currency conversion
61-
page.accept_alert do
55+
context 'for a conference with tickets' do
56+
it 'add a currency conversion', feature: true, js: true do
57+
visit admin_conference_currency_conversions_path(conference.short_title)
58+
click_link 'Add Currency Conversion'
59+
select 'EUR', from: 'currency_conversion_to_currency'
60+
fill_in 'currency_conversion_rate', with: '0.89'
61+
click_button 'Create Currency conversion'
62+
page.find('#flash')
63+
expect(flash).to eq('Currency conversion was successfully created.')
64+
within('table#currency-conversions') do
65+
expect(page.has_content?('USD')).to be true
66+
expect(page.has_content?('EUR')).to be true
67+
expect(page.has_content?('0.89')).to be true
68+
expect(page.assert_selector('tbody tr', count: 1)).to be true
69+
end
70+
end
71+
72+
it 'edit a currency conversion', feature: true, js: true do
73+
conference.currency_conversions << create(:currency_conversion)
74+
visit admin_conference_currency_conversions_path(conference.short_title)
6275
within('table tbody tr:nth-of-type(1) td:nth-of-type(4)') do
63-
click_link 'Delete'
76+
click_link 'Edit'
77+
end
78+
select 'JPY', from: 'currency_conversion_to_currency'
79+
fill_in 'currency_conversion_rate', with: '6.9'
80+
click_button 'Update Currency conversion'
81+
page.find('#flash')
82+
expect(flash).to eq('Currency conversion was successfully updated.')
83+
within('table#currency-conversions') do
84+
expect(page.has_content?('USD')).to be true
85+
expect(page.has_content?('JPY')).to be true
86+
expect(page.has_content?('6.9')).to be true
87+
expect(page.assert_selector('tbody tr', count: 1)).to be true
6488
end
6589
end
66-
page.find('#flash')
6790

68-
# Validations
69-
expect(flash).to eq('Currency conversion was successfully deleted.')
70-
within('table#currency-conversions') do
71-
expect(page.assert_selector('tbody tr', count: 0)).to be true
91+
it 'Deletes Currency Conversion', feature: true, js: true do
92+
conference.currency_conversions << create(:currency_conversion)
93+
visit admin_conference_currency_conversions_path(conference.short_title)
94+
# Remove currency conversion
95+
page.accept_alert do
96+
within('table tbody tr:nth-of-type(1) td:nth-of-type(4)') do
97+
click_link 'Delete'
98+
end
99+
end
100+
page.find('#flash')
101+
102+
# Validations
103+
expect(flash).to eq('Currency conversion was successfully deleted.')
104+
within('table#currency-conversions') do
105+
expect(page.assert_selector('tbody tr', count: 0)).to be true
106+
end
72107
end
73108
end
74109
end

spec/features/proposals_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
fill_in 'event_submission_text', with: 'Lorem ipsum submission_text'
180180
expect(page).to have_text('Submission text')
181181
# Submission Instructions content
182-
expect(page).to have_text('Example Event Instructions')
182+
expect(page).to have_text('Example Event Template')
183183

184184
# TODO-SNAPCON: (mb) this field is always shown.
185185
# click_link 'Do you require something special for your event?'
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
# == Schema Information
4+
#
5+
# Table name: currency_conversions
6+
#
7+
# id :bigint not null, primary key
8+
# from_currency :string
9+
# rate :decimal(, )
10+
# to_currency :string
11+
# created_at :datetime not null
12+
# updated_at :datetime not null
13+
# conference_id :bigint not null
14+
#
15+
# Indexes
16+
#
17+
# index_currency_conversions_on_conference_id (conference_id)
18+
#
19+
# Foreign Keys
20+
#
21+
# fk_rails_... (conference_id => conferences.id)
22+
#
23+
require 'spec_helper'
24+
25+
describe CurrencyConversion do
26+
let!(:conference) { create(:conference, title: 'ExampleCon') }
27+
28+
describe 'validations' do
29+
before do
30+
conference.currency_conversions << create(:currency_conversion)
31+
end
32+
33+
it { is_expected.to validate_numericality_of(:rate).is_greater_than(0) }
34+
35+
it { is_expected.to validate_uniqueness_of(:from_currency).scoped_to(:to_currency).on(:create) }
36+
end
37+
end

0 commit comments

Comments
 (0)