diff --git a/app/controllers/country_bands_controller.rb b/app/controllers/country_bands_controller.rb index 6ea3937743b..5307169b01d 100644 --- a/app/controllers/country_bands_controller.rb +++ b/app/controllers/country_bands_controller.rb @@ -10,7 +10,7 @@ def index def edit @number = id_from_params - unless CountryBandDetail.distinct.pluck(:number).include?(@number) + unless CountryBandDetail.exists?(number: @number) flash[:danger] = "Unknown band number" return redirect_to country_bands_path end diff --git a/db/migrate/20241225031242_populate_country_band_details.rb b/db/migrate/20241225031242_populate_country_band_details.rb index f87ce794eb4..9aec86245af 100644 --- a/db/migrate/20241225031242_populate_country_band_details.rb +++ b/db/migrate/20241225031242_populate_country_band_details.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class PopulateCountryBandDetails < ActiveRecord::Migration[7.2] - def change + def up CountryBandDetail.create!( number: 0, start_date: '2018-01-01', @@ -39,4 +39,8 @@ def change due_percent_registration_fee: 15, ) end + + def down + CountryBandDetail.delete_all + end end diff --git a/db/seeds/country_band_details.seeds.rb b/db/seeds/country_band_details.seeds.rb new file mode 100644 index 00000000000..b36bc9813b9 --- /dev/null +++ b/db/seeds/country_band_details.seeds.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +CountryBandDetail.create!( + number: 0, + start_date: '2018-01-01', + due_amount_per_competitor_in_cents: 0, + due_percent_registration_fee: 0, +) +CountryBandDetail.create!( + number: 1, + start_date: '2018-01-01', + due_amount_per_competitor_in_cents: 19, + due_percent_registration_fee: 5, +) +CountryBandDetail.create!( + number: 2, + start_date: '2018-01-01', + due_amount_per_competitor_in_cents: 32, + due_percent_registration_fee: 5, +) +CountryBandDetail.create!( + number: 3, + start_date: '2018-01-01', + due_amount_per_competitor_in_cents: 45, + due_percent_registration_fee: 15, +) +CountryBandDetail.create!( + number: 4, + start_date: '2018-01-01', + due_amount_per_competitor_in_cents: 228, + due_percent_registration_fee: 15, +) +CountryBandDetail.create!( + number: 5, + start_date: '2018-01-01', + due_amount_per_competitor_in_cents: 300, + due_percent_registration_fee: 15, +) diff --git a/lib/database_dumper.rb b/lib/database_dumper.rb index 644cb64f34b..17b59c5961f 100644 --- a/lib/database_dumper.rb +++ b/lib/database_dumper.rb @@ -855,6 +855,20 @@ def self.actions_to_column_sanitizers(columns_by_action) ), ), }.freeze, + "country_band_details" => { + column_sanitizers: actions_to_column_sanitizers( + copy: %w( + id + number + start_date + end_date + due_amount_per_competitor_in_cents + due_percent_registration_fee + created_at + updated_at + ), + ), + }.freeze, "user_roles" => { where_clause: "JOIN user_groups ON user_groups.id=group_id WHERE NOT user_groups.is_hidden", column_sanitizers: actions_to_column_sanitizers( diff --git a/lib/dues_calculator.rb b/lib/dues_calculator.rb index 5d4b381be78..c340a816f21 100644 --- a/lib/dues_calculator.rb +++ b/lib/dues_calculator.rb @@ -25,9 +25,9 @@ def self.dues_per_competitor_in_usd(country_iso2, base_entry_fee_lowest_denomina input_money_us_dollars = Money.new(base_entry_fee_lowest_denomination, currency_code).exchange_to("USD") country_band_detail = CountryBandDetail.find_by(number: country_band) - return nil unless country_band_detail + return 0 unless country_band_detail.present? - registration_fee_dues_us_dollars = input_money_us_dollars * country_band_detail.due_percent_registration_fee.to_f/100 + registration_fee_dues_us_dollars = input_money_us_dollars * country_band_detail.due_percent_registration_fee.to_f / 100 # cent is given directly because Money require lowest currency subunit, which is cents for USD country_band_dues_us_dollars_money = Money.new(country_band_detail.due_amount_per_competitor_in_cents, "USD") diff --git a/spec/models/country_band_spec.rb b/spec/models/country_band_spec.rb index 94507e454d3..882a162874b 100644 --- a/spec/models/country_band_spec.rb +++ b/spec/models/country_band_spec.rb @@ -15,6 +15,6 @@ it "invalidates band with invalid band id" do cb = CountryBand.new(number: 6, iso2: "HELLO") - expect(cb).to be_invalid_with_errors(number: ["is not included in the list"]) + expect(cb).to be_invalid_with_errors(country: ["must exist"]) end end diff --git a/spec/support/test_db_manager.rb b/spec/support/test_db_manager.rb index 924cf1dacff..5bcb895c233 100644 --- a/spec/support/test_db_manager.rb +++ b/spec/support/test_db_manager.rb @@ -16,6 +16,7 @@ class TestDbManager groups_metadata_councils groups_metadata_teams_committees groups_metadata_translators + country_band_details ).freeze def self.fill_tables