Skip to content

Commit

Permalink
Merge branch 'release/1.3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalcic committed Oct 24, 2020
2 parents 7434be5 + 6702802 commit 4aa3481
Show file tree
Hide file tree
Showing 19 changed files with 239 additions and 43 deletions.
34 changes: 17 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/spina/admin/conferences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
81 changes: 81 additions & 0 deletions lib/spina/admin/conferences/migration/renaming.rb
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions lib/spina/admin/conferences/railtie.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/spina/admin/conferences/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Spina
module Admin
module Conferences
# Version number.
VERSION = '1.3.2'
VERSION = '1.3.3'
end
end
end
32 changes: 16 additions & 16 deletions spina-admin-conferences.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Foo < ActiveRecord::Migration[6.0] # :nodoc:
def change; end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Foo < ActiveRecord::Migration[6.0] # :nodoc:
def change; end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Foo < ActiveRecord::Migration[6.0] # :nodoc:
def change; end
end
65 changes: 65 additions & 0 deletions test/spina/admin/conferences/migration/renaming_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4aa3481

Please sign in to comment.