diff --git a/Gemfile.lock b/Gemfile.lock index 1e176713..b399cd1a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - spina-admin-conferences (1.3.2) + spina-admin-conferences (1.3.3) babel-transpiler (~> 0.7) icalendar (~> 2.5) mobility (~> 0.8.10) @@ -339,23 +339,23 @@ PLATFORMS ruby DEPENDENCIES - capybara - coveralls_reborn - dotenv-rails - image_processing - minitest-rails - minitest-reporters - percy-capybara - puma - reek - rubocop - rubocop-performance - rubocop-rails - selenium-webdriver - simplecov + capybara (~> 3.33) + coveralls_reborn (~> 0.18) + dotenv-rails (~> 2.7) + image_processing (~> 1.12) + minitest-rails (~> 6.0) + minitest-reporters (~> 1.4) + percy-capybara (~> 4.3) + puma (~> 5.0) + reek (~> 6.0) + rubocop (~> 0.93) + rubocop-performance (~> 1.8) + rubocop-rails (~> 2.8) + selenium-webdriver (~> 3.142) + simplecov (~> 0.19) spina-admin-conferences! - web-console - webdrivers + web-console (~> 4.0) + webdrivers (~> 4.4) BUNDLED WITH 2.1.4 diff --git a/db/migrate/20200420104603_create_spina_conferences_dietary_requirement_name_translations_for_mobility_table_backend.rb b/db/migrate/20200420104603_create_spina_conferences_dietary_requirement_name_translations.rb similarity index 84% rename from db/migrate/20200420104603_create_spina_conferences_dietary_requirement_name_translations_for_mobility_table_backend.rb rename to db/migrate/20200420104603_create_spina_conferences_dietary_requirement_name_translations.rb index df32ed4b..009b4056 100644 --- a/db/migrate/20200420104603_create_spina_conferences_dietary_requirement_name_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200420104603_create_spina_conferences_dietary_requirement_name_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesDietaryRequirementNameTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # :nodoc: +class CreateSpinaConferencesDietaryRequirementNameTranslations < ActiveRecord::Migration[6.0] # :nodoc: def change create_table :spina_conferences_dietary_requirement_translations do |t| # Translated attribute(s) diff --git a/db/migrate/20200420104740_create_spina_conferences_institution_name_and_city_translations_for_mobility_table_backend.rb b/db/migrate/20200420104740_create_spina_conferences_institution_name_and_city_translations.rb similarity index 84% rename from db/migrate/20200420104740_create_spina_conferences_institution_name_and_city_translations_for_mobility_table_backend.rb rename to db/migrate/20200420104740_create_spina_conferences_institution_name_and_city_translations.rb index 831f3238..bf3c09a8 100644 --- a/db/migrate/20200420104740_create_spina_conferences_institution_name_and_city_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200420104740_create_spina_conferences_institution_name_and_city_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesInstitutionNameAndCityTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # :nodoc: +class CreateSpinaConferencesInstitutionNameAndCityTranslations < ActiveRecord::Migration[6.0] # :nodoc: def change create_table :spina_conferences_institution_translations do |t| # Translated attribute(s) diff --git a/db/migrate/20200420105057_create_spina_conferences_presentation_title_and_abstract_translations_for_mobility_table_backend.rb b/db/migrate/20200420105057_create_spina_conferences_presentation_title_and_abstract_translations.rb similarity index 91% rename from db/migrate/20200420105057_create_spina_conferences_presentation_title_and_abstract_translations_for_mobility_table_backend.rb rename to db/migrate/20200420105057_create_spina_conferences_presentation_title_and_abstract_translations.rb index 79be298b..b5d56b0b 100644 --- a/db/migrate/20200420105057_create_spina_conferences_presentation_title_and_abstract_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200420105057_create_spina_conferences_presentation_title_and_abstract_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesPresentationTitleAndAbstractTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # :nodoc: +class CreateSpinaConferencesPresentationTitleAndAbstractTranslations < ActiveRecord::Migration[6.0] # :nodoc: def change create_table :spina_conferences_presentation_translations do |t| # Translated attribute(s) diff --git a/db/migrate/20200420105144_create_spina_conferences_presentation_attachment_type_name_translations_for_mobility_table_backend.rb b/db/migrate/20200420105144_create_spina_conferences_presentation_attachment_type_name_translations.rb similarity index 92% rename from db/migrate/20200420105144_create_spina_conferences_presentation_attachment_type_name_translations_for_mobility_table_backend.rb rename to db/migrate/20200420105144_create_spina_conferences_presentation_attachment_type_name_translations.rb index b24504e3..e30f7883 100644 --- a/db/migrate/20200420105144_create_spina_conferences_presentation_attachment_type_name_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200420105144_create_spina_conferences_presentation_attachment_type_name_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesPresentationAttachmentTypeNameTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # :nodoc: +class CreateSpinaConferencesPresentationAttachmentTypeNameTranslations < ActiveRecord::Migration[6.0] # :nodoc: def change create_table :spina_conferences_presentation_attachment_type_translations do |t| # Translated attribute(s) diff --git a/db/migrate/20200420105201_create_spina_conferences_presentation_type_name_translations_for_mobility_table_backend.rb b/db/migrate/20200420105201_create_spina_conferences_presentation_type_name_translations.rb similarity index 84% rename from db/migrate/20200420105201_create_spina_conferences_presentation_type_name_translations_for_mobility_table_backend.rb rename to db/migrate/20200420105201_create_spina_conferences_presentation_type_name_translations.rb index 923ca192..1530b3ac 100644 --- a/db/migrate/20200420105201_create_spina_conferences_presentation_type_name_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200420105201_create_spina_conferences_presentation_type_name_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesPresentationTypeNameTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # :nodoc: +class CreateSpinaConferencesPresentationTypeNameTranslations < ActiveRecord::Migration[6.0] # :nodoc: def change create_table :spina_conferences_presentation_type_translations do |t| # Translated attribute(s) diff --git a/db/migrate/20200420105458_create_spina_conferences_room_building_and_number_translations_for_mobility_table_backend.rb b/db/migrate/20200420105458_create_spina_conferences_room_building_and_number_translations.rb similarity index 84% rename from db/migrate/20200420105458_create_spina_conferences_room_building_and_number_translations_for_mobility_table_backend.rb rename to db/migrate/20200420105458_create_spina_conferences_room_building_and_number_translations.rb index 060893a7..32304f28 100644 --- a/db/migrate/20200420105458_create_spina_conferences_room_building_and_number_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200420105458_create_spina_conferences_room_building_and_number_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesRoomBuildingAndNumberTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # :nodoc: +class CreateSpinaConferencesRoomBuildingAndNumberTranslations < ActiveRecord::Migration[6.0] # :nodoc: def change create_table :spina_conferences_room_translations do |t| # Translated attribute(s) diff --git a/db/migrate/20200502133408_create_spina_conferences_conference_name_translations_for_mobility_table_backend.rb b/db/migrate/20200502133408_create_spina_conferences_conference_name_translations.rb similarity index 84% rename from db/migrate/20200502133408_create_spina_conferences_conference_name_translations_for_mobility_table_backend.rb rename to db/migrate/20200502133408_create_spina_conferences_conference_name_translations.rb index 5a4110cc..8c4a4653 100644 --- a/db/migrate/20200502133408_create_spina_conferences_conference_name_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200502133408_create_spina_conferences_conference_name_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesConferenceNameTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # :nodoc: +class CreateSpinaConferencesConferenceNameTranslations < ActiveRecord::Migration[6.0] # :nodoc: def change create_table :spina_conferences_conference_translations do |t| # Translated attribute(s) diff --git a/db/migrate/20200510125131_create_spina_conferences_session_name_translations_for_mobility_table_backend.rb b/db/migrate/20200510125131_create_spina_conferences_session_name_translations.rb similarity index 84% rename from db/migrate/20200510125131_create_spina_conferences_session_name_translations_for_mobility_table_backend.rb rename to db/migrate/20200510125131_create_spina_conferences_session_name_translations.rb index 444e98c9..e4c61a35 100644 --- a/db/migrate/20200510125131_create_spina_conferences_session_name_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200510125131_create_spina_conferences_session_name_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesSessionNameTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # :nodoc: +class CreateSpinaConferencesSessionNameTranslations < ActiveRecord::Migration[6.0] # :nodoc: def change create_table :spina_conferences_session_translations do |t| # Translated attribute(s) diff --git a/db/migrate/20200802184921_create_spina_conferences_event_name_and_description_and_location_translations_for_mobility_table_backend.rb b/db/migrate/20200802184921_create_spina_conferences_event_name_description_and_location_translations.rb similarity index 81% rename from db/migrate/20200802184921_create_spina_conferences_event_name_and_description_and_location_translations_for_mobility_table_backend.rb rename to db/migrate/20200802184921_create_spina_conferences_event_name_description_and_location_translations.rb index 64922758..6b2e4b45 100644 --- a/db/migrate/20200802184921_create_spina_conferences_event_name_and_description_and_location_translations_for_mobility_table_backend.rb +++ b/db/migrate/20200802184921_create_spina_conferences_event_name_description_and_location_translations.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSpinaConferencesEventNameAndDescriptionAndLocationTranslationsForMobilityTableBackend < ActiveRecord::Migration[6.0] # rubocop:disable Style/Documentation +class CreateSpinaConferencesEventNameDescriptionAndLocationTranslations < ActiveRecord::Migration[6.0] # rubocop:disable Style/Documentation def change # rubocop:disable Metrics/MethodLength create_table :spina_conferences_event_translations do |t| # Translated attribute(s) diff --git a/lib/spina/admin/conferences.rb b/lib/spina/admin/conferences.rb index 8774c2f5..00bb4f0d 100644 --- a/lib/spina/admin/conferences.rb +++ b/lib/spina/admin/conferences.rb @@ -2,6 +2,7 @@ require 'spina' require 'spina/admin/conferences/engine' +require 'spina/admin/conferences/railtie' if defined?(Rails::Railtie) require 'rails-i18n' require 'icalendar' diff --git a/lib/spina/admin/conferences/migration/renaming.rb b/lib/spina/admin/conferences/migration/renaming.rb new file mode 100644 index 00000000..b09977f0 --- /dev/null +++ b/lib/spina/admin/conferences/migration/renaming.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +require 'active_support/concern' + +module Spina + module Admin + module Conferences + module Migration + module Renaming + extend ActiveSupport::Concern + + included do + @stale_migrations ||= [] + @migrations_path ||= nil + end + + class_methods do + def rename_migration(name, to:) + config.after_initialize do + migration = {} + migration[:old] = migration_hash(name) + migration[:new] = migration_hash(to) + if [migration[:old], migration[:new]].pluck(:file).all?(&:present?) + @stale_migrations << migration + end + end + end + + def raise_on_duplicate_migrations! + raise DuplicateMigrationsError.new(@stale_migrations) if @stale_migrations.any? + end + + private + + attr_reader :duplicate_migrations + + class DuplicateMigrationsError < ::StandardError + def initialize(migrations) + messages = migrations.collect { |migration| generate_message(migration) } + super(messages.join("\n")) + end + + private + + MIGRATION_REGEXP = /([0-9]+)_.+\.(spina(_admin)?_conferences).rb$/ + + def generate_message(migration) + old_version, old_scope = parse_filename(migration[:old][:file]) + messages = [] + messages << "#{File.basename(migration[:new][:file])} is a renamed version of #{File.basename(migration[:old][:file])}." + messages << "Rename #{File.basename(migration[:old][:file])} to #{old_version}_#{migration[:new][:name]}.#{old_scope}.rb " \ + "and delete #{File.basename(migration[:new][:file])}." + messages.join("\n") + end + + def parse_filename(filename) + filename.scan(MIGRATION_REGEXP).first + end + end + + def migration_hash(name) + { name: name, file: detect_migration(name) } + end + + def migrations_path + @migrations_path || ActiveRecord::Tasks::DatabaseTasks.migrations_paths.first + end + + def engine_migration_glob(name) + "#{migrations_path}/**/*_#{name}.spina{_admin,}_conferences.rb" + end + + def detect_migration(name) + Dir[engine_migration_glob(name)].first + end + end + end + end + end + end +end diff --git a/lib/spina/admin/conferences/railtie.rb b/lib/spina/admin/conferences/railtie.rb new file mode 100644 index 00000000..5ff02d39 --- /dev/null +++ b/lib/spina/admin/conferences/railtie.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spina/admin/conferences/migration/renaming' + +module Spina + module Admin + module Conferences + class Railtie < Rails::Railtie + include Migration::Renaming + + rename_migration 'create_spina_conferences_dietary_requirement_name_translations_for_mobility_table_backend', + to: 'create_spina_conferences_dietary_requirement_name_translations' + rename_migration 'create_spina_conferences_institution_name_and_city_translations_for_mobility_table_backend', + to: 'create_spina_conferences_institution_name_and_city_translations' + rename_migration 'create_spina_conferences_presentation_attachment_type_name_translations_for_mobility_table_backend', + to: 'create_spina_conferences_presentation_attachment_type_name_translations' + rename_migration 'create_spina_conferences_presentation_type_name_translations_for_mobility_table_backend', + to: 'create_spina_conferences_presentation_type_name_translations' + rename_migration 'create_spina_conferences_room_building_and_number_translations_for_mobility_table_backend', + to: 'create_spina_conferences_room_building_and_number_translations' + rename_migration 'create_spina_conferences_conference_name_translations_for_mobility_table_backend', + to: 'create_spina_conferences_conference_name_translations' + rename_migration 'create_spina_conferences_session_name_translations_for_mobility_table_backend', + to: 'create_spina_conferences_session_name_translations' + rename_migration 'create_spina_conferences_event_name_description_and_location_translations_for_mobility_table_backend', + to: 'create_spina_conferences_event_name_description_and_location_translations' + + config.after_initialize do + raise_on_duplicate_migrations! + end + end + end + end +end diff --git a/lib/spina/admin/conferences/version.rb b/lib/spina/admin/conferences/version.rb index 55534dcd..2210807f 100644 --- a/lib/spina/admin/conferences/version.rb +++ b/lib/spina/admin/conferences/version.rb @@ -4,7 +4,7 @@ module Spina module Admin module Conferences # Version number. - VERSION = '1.3.2' + VERSION = '1.3.3' end end end diff --git a/spina-admin-conferences.gemspec b/spina-admin-conferences.gemspec index 85f23e80..45911bba 100644 --- a/spina-admin-conferences.gemspec +++ b/spina-admin-conferences.gemspec @@ -30,20 +30,20 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength spec.add_dependency 'rails-i18n', '~> 6.0' spec.add_dependency 'spina', '~> 1.1' - spec.add_development_dependency 'capybara' - spec.add_development_dependency 'coveralls_reborn' - spec.add_development_dependency 'dotenv-rails' - spec.add_development_dependency 'image_processing' - spec.add_development_dependency 'minitest-rails' - spec.add_development_dependency 'minitest-reporters' - spec.add_development_dependency 'percy-capybara' - spec.add_development_dependency 'puma' - spec.add_development_dependency 'reek' - spec.add_development_dependency 'rubocop' - spec.add_development_dependency 'rubocop-performance' - spec.add_development_dependency 'rubocop-rails' - spec.add_development_dependency 'selenium-webdriver' - spec.add_development_dependency 'simplecov' - spec.add_development_dependency 'web-console' - spec.add_development_dependency 'webdrivers' + spec.add_development_dependency 'capybara', '~> 3.33' + spec.add_development_dependency 'coveralls_reborn', '~> 0.18' + spec.add_development_dependency 'dotenv-rails', '~> 2.7' + spec.add_development_dependency 'image_processing', '~> 1.12' + spec.add_development_dependency 'minitest-rails', '~> 6.0' + spec.add_development_dependency 'minitest-reporters', '~> 1.4' + spec.add_development_dependency 'percy-capybara', '~> 4.3' + spec.add_development_dependency 'puma', '~> 5.0' + spec.add_development_dependency 'reek', '~> 6.0' + spec.add_development_dependency 'rubocop', '~> 0.93' + spec.add_development_dependency 'rubocop-performance', '~> 1.8' + spec.add_development_dependency 'rubocop-rails', '~> 2.8' + spec.add_development_dependency 'selenium-webdriver', '~> 3.142' + spec.add_development_dependency 'simplecov', '~> 0.19' + spec.add_development_dependency 'web-console', '~> 4.0' + spec.add_development_dependency 'webdrivers', '~> 4.4' end diff --git a/test/fixtures/files/migrations/fresh/00000000000000_old_name.spina_conferences.rb b/test/fixtures/files/migrations/fresh/00000000000000_old_name.spina_conferences.rb new file mode 100644 index 00000000..21b0a2b3 --- /dev/null +++ b/test/fixtures/files/migrations/fresh/00000000000000_old_name.spina_conferences.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Foo < ActiveRecord::Migration[6.0] # :nodoc: + def change; end +end diff --git a/test/fixtures/files/migrations/stale/00000000000000_new_name.spina_admin_conferences.rb b/test/fixtures/files/migrations/stale/00000000000000_new_name.spina_admin_conferences.rb new file mode 100644 index 00000000..21b0a2b3 --- /dev/null +++ b/test/fixtures/files/migrations/stale/00000000000000_new_name.spina_admin_conferences.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Foo < ActiveRecord::Migration[6.0] # :nodoc: + def change; end +end diff --git a/test/fixtures/files/migrations/stale/00000000000000_old_name.spina_conferences.rb b/test/fixtures/files/migrations/stale/00000000000000_old_name.spina_conferences.rb new file mode 100644 index 00000000..21b0a2b3 --- /dev/null +++ b/test/fixtures/files/migrations/stale/00000000000000_old_name.spina_conferences.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Foo < ActiveRecord::Migration[6.0] # :nodoc: + def change; end +end diff --git a/test/spina/admin/conferences/migration/renaming_test.rb b/test/spina/admin/conferences/migration/renaming_test.rb new file mode 100644 index 00000000..0970cf6c --- /dev/null +++ b/test/spina/admin/conferences/migration/renaming_test.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require 'test_helper' + +module Spina + module Admin + module Conferences + module Migration + class RenamingTest < ActiveSupport::TestCase + setup do + @dummy_class = Class.new(Rails::Railtie) do + class << self + attr_accessor :stale_migrations + attr_accessor :migrations_path + end + end + end + + test 'initializes stale migrations array' do + assert_nil @dummy_class.stale_migrations + @dummy_class.include(Renaming) + assert_equal [], @dummy_class.stale_migrations + end + + test 'adds stale migrations when declared' do + @dummy_class.migrations_path = file_fixture('migrations/stale').to_path + @dummy_class.include(Renaming) + assert_empty @dummy_class.stale_migrations + @dummy_class.rename_migration 'old_name', to: 'new_name' + assert_not_empty @dummy_class.stale_migrations + end + + test 'does not add fresh migrations when declared' do + @dummy_class.migrations_path = file_fixture('migrations/fresh').to_path + @dummy_class.include(Renaming) + assert_empty @dummy_class.stale_migrations + @dummy_class.rename_migration 'old_name', to: 'new_name' + assert_empty @dummy_class.stale_migrations + end + + test 'raises on duplicate migrations' do + @dummy_class.include(Renaming) + @dummy_class.stale_migrations = [ + { + old: { name: 'old_name', file: '00000000000000_old_name.spina_conferences.rb' }, + new: { name: 'new_name', file: '00000000000000_new_name.spina_conferences.rb' } + } + ] + assert_raises Renaming::DuplicateMigrationsError do + @dummy_class.raise_on_duplicate_migrations! + end + end + + test 'does not raise on empty migrations' do + @dummy_class.include(Renaming) + @dummy_class.stale_migrations = [] + assert_nothing_raised do + @dummy_class.raise_on_duplicate_migrations! + end + end + end + end + end + end +end