redmine_plugins_helper 0.6.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc58802ae88b2b9bdacd3f4e197e526b8ebe0143a8e2d6d269030ac8ac6d2541
4
- data.tar.gz: a064c7cfb58df6f7a588c2d9f560896d32236f37c6438fcacb894035f547bc5f
3
+ metadata.gz: e85f357f0bcab7126a87e73c6024417f999db4b657e39371ddc492107a6b6287
4
+ data.tar.gz: 85038fc7bae3559703d6f2a728a74cf8d336831c5c7ede88d4216a6b9ee26183
5
5
  SHA512:
6
- metadata.gz: 2ac7da23d1fc020f8450a374299c4fb9dc079532b122c9ceb5f4a193a3a16895888ee273f72d69c60b2cbbb022da84a8d91006cef15c4216f43309a1a982eaf1
7
- data.tar.gz: 400bf68c4cc3a00452b6bf67aa75f407378fa8670a89c272377ea213f53bd059f5df69aeae7f36c539beb594cd8506f3709fcd82a3669573e0526de0f68dd469
6
+ metadata.gz: e7b9cf889a34e7ef54f69d07175bead407b641972c0d03a7b32394758532a6944940302cafa07e29c810674935293b94a5ff2a84841bfe755f4c26720887f43d
7
+ data.tar.gz: cc69bb1784ad3eaa8e7a21b187dea155aabff4bea75f0611d59bf4d013a58b832a020bf15ea9ca9e8d7710cc2ddc256e87edb09410f6b2e4b7ba0456d6408fee
data/init.rb CHANGED
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'redmine'
4
4
  require 'redmine_plugins_helper/version'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sass-rails'
2
4
 
3
5
  module RedminePluginsHelper
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedminePluginsHelper
2
4
  class FixMigrations
3
5
  def initialize
@@ -17,6 +19,7 @@ module RedminePluginsHelper
17
19
  def check_database_version(dbv)
18
20
  lv = local_version(dbv[:timestamp])
19
21
  return unless lv && lv.count == 1 && dbv[:plugin] != lv.first[:plugin]
22
+
20
23
  fix_plugin_version(dbv, lv.first[:plugin])
21
24
  end
22
25
 
@@ -41,18 +44,19 @@ module RedminePluginsHelper
41
44
  def move_plugin_version(source_version, target_version)
42
45
  Rails.logger.info("Moving #{source_version} to plugin \"#{target_version}\"")
43
46
  ::ActiveRecord::SchemaMigration.find_by(version: source_version)
44
- .update!(version: target_version)
47
+ .update!(version: target_version)
45
48
  end
46
49
 
47
50
  def local_version(timestamp)
48
51
  return [] unless local_versions.key?(timestamp)
52
+
49
53
  local_versions[timestamp]
50
54
  end
51
55
 
52
56
  def local_versions
53
57
  @local_versions = begin
54
58
  r = {}
55
- Redmine::Plugin.registered_plugins.values.each do |p|
59
+ Redmine::Plugin.registered_plugins.each_value do |p|
56
60
  p.migrations.each do |m|
57
61
  r[m] ||= []
58
62
  r[m] << { plugin: p.id, timestamp: m, version: plugin_version(p.id, m) }
@@ -68,15 +72,16 @@ module RedminePluginsHelper
68
72
  ::RedminePluginsHelper::Migrations.db_all_versions.each do |v|
69
73
  pv = parse_plugin_version(v)
70
74
  next unless pv
75
+
71
76
  r << pv
72
77
  end
73
78
  r
74
79
  end
75
80
  end
76
81
 
77
- def parse_plugin_version(v)
78
- h = ::RedminePluginsHelper::Migrations.parse_plugin_version(v)
79
- h[:version] = v if h.is_a?(Hash)
82
+ def parse_plugin_version(version)
83
+ h = ::RedminePluginsHelper::Migrations.parse_plugin_version(version)
84
+ h[:version] = version if h.is_a?(Hash)
80
85
  h
81
86
  end
82
87
 
@@ -30,10 +30,10 @@ module RedminePluginsHelper
30
30
  ::Redmine::Plugin.migrate(plugin_name, migration_version)
31
31
  end
32
32
 
33
- def migrate_plugin_version(v)
34
- return if migrated?(v)
33
+ def migrate_plugin_version(version)
34
+ return if migrated?(version)
35
35
 
36
- ::Redmine::Plugin.registered_plugins[v[:plugin]].migrate(v[:timestamp])
36
+ ::Redmine::Plugin.registered_plugins[version[:plugin]].migrate(version[:timestamp])
37
37
  end
38
38
 
39
39
  def versions_sorted
@@ -48,9 +48,10 @@ module RedminePluginsHelper
48
48
  r
49
49
  end
50
50
 
51
- def migrated?(v)
52
- return false unless db_versions.key?(v[:plugin])
53
- db_versions[v[:plugin]].include?(v[:timestamp])
51
+ def migrated?(version)
52
+ return false unless db_versions.key?(version[:plugin])
53
+
54
+ db_versions[version[:plugin]].include?(version[:timestamp])
54
55
  end
55
56
 
56
57
  def db_versions
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedminePluginsHelper
2
4
  class Migrations
3
5
  class << self
4
6
  def local_versions
5
7
  r = {}
6
- Redmine::Plugin.registered_plugins.values.each do |p|
8
+ Redmine::Plugin.registered_plugins.each_value do |p|
7
9
  p.migrations.each do |ts|
8
10
  r[p.id] ||= []
9
11
  r[p.id] << ts
@@ -17,6 +19,7 @@ module RedminePluginsHelper
17
19
  db_all_versions.each do |v|
18
20
  pv = parse_plugin_version(v)
19
21
  next unless pv
22
+
20
23
  r[pv[:plugin]] ||= []
21
24
  r[pv[:plugin]] << pv[:timestamp]
22
25
  end
@@ -28,9 +31,10 @@ module RedminePluginsHelper
28
31
  ::ActiveRecord::SchemaMigration.all.pluck(:version)
29
32
  end
30
33
 
31
- def parse_plugin_version(v)
32
- m = v.match(/^(\d+)\-(\S+)$/)
34
+ def parse_plugin_version(version)
35
+ m = version.match(/^(\d+)\-(\S+)$/)
33
36
  return nil unless m
37
+
34
38
  { plugin: m[2].to_sym, timestamp: m[1].to_i }
35
39
  end
36
40
  end
@@ -8,7 +8,7 @@ module RedminePluginsHelper
8
8
  module PluginMigrationContextPatch
9
9
  extend ActiveSupport::Concern
10
10
 
11
- def get_all_versions
11
+ def get_all_versions # rubocop:disable Naming/AccessorMethodName
12
12
  plugin.present? ? plugin.migrations : super
13
13
  end
14
14
 
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
1
5
  module RedminePluginsHelper
2
6
  module Patches
3
7
  module Redmine
@@ -12,6 +16,22 @@ module RedminePluginsHelper
12
16
  ASSETS_SUBDIRS = %w[stylesheets javascripts images].freeze
13
17
 
14
18
  module ClassMethods
19
+ def by_path(path)
20
+ plugin_id_from_path(path).if_present do |v|
21
+ registered_plugins[v]
22
+ end
23
+ end
24
+
25
+ def plugin_id_from_path(path)
26
+ path = path.to_pathname.expand_path
27
+ return nil unless path.to_path.start_with?(::Rails.root.to_path)
28
+
29
+ parts = path.relative_path_from(::Rails.root).each_filename.to_a
30
+ return nil unless parts.first == 'plugins' && parts.count >= 2
31
+
32
+ parts[1].to_sym
33
+ end
34
+
15
35
  def post_register(plugin_name, &block)
16
36
  plugin = registered_plugins[plugin_name]
17
37
  raise "Plugin not registered: #{plugin_name}" unless plugin
@@ -22,7 +42,7 @@ module RedminePluginsHelper
22
42
 
23
43
  module InstanceMethods
24
44
  def load_initializers
25
- Dir["#{initializers_directory}/*.rb"].each { |f| require f }
45
+ Dir["#{initializers_directory}/*.rb"].sort.each { |f| require f }
26
46
  end
27
47
 
28
48
  ASSETS_SUBDIRS.each do |assert_subdir|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support'
2
4
 
3
5
  module RedminePluginsHelper
@@ -6,37 +8,15 @@ module RedminePluginsHelper
6
8
  extend ActiveSupport::Concern
7
9
 
8
10
  included do
9
- extend ClassMethods
11
+ extend ::RedminePluginsHelper::TestHelper
10
12
  include InstanceMethods
11
- setup { mailer_setup }
12
- teardown { mailer_teadown }
13
- end
14
-
15
- module ClassMethods
16
- def plugin_fixtures(plugin_name, *files)
17
- fixtures_dir = File.expand_path(
18
- 'test/fixtures',
19
- ::Redmine::Plugin.registered_plugins[plugin_name].directory
20
- )
21
- ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, files)
22
- fixtures(*files)
23
- end
13
+ setup { the_test_config.before_each }
14
+ teardown { the_test_config.after_each }
24
15
  end
25
16
 
26
17
  module InstanceMethods
27
- def mailer_setup
28
- unless @mailer_perform_deliveries_changed
29
- @mailer_perform_deliveries_changed = true
30
- @mailer_perform_deliveries_was_enabled = ::ActionMailer::Base.perform_deliveries
31
- end
32
- ::ActionMailer::Base.perform_deliveries = false
33
- end
34
-
35
- def mailer_teadown
36
- return unless @mailer_perform_deliveries_changed
37
-
38
- ::ActionMailer::Base.perform_deliveries = @mailer_perform_deliveries_was_enabled
39
- @mailer_perform_deliveries_changed = false
18
+ def the_test_config
19
+ @the_test_config ||= ::RedminePluginsHelper::TestConfig.new
40
20
  end
41
21
  end
42
22
  end
@@ -46,5 +26,5 @@ end
46
26
  unless ActiveSupport::TestCase.included_modules.include?(
47
27
  RedminePluginsHelper::Patches::TestCasePatch
48
28
  )
49
- ActiveSupport::TestCase.send(:include, RedminePluginsHelper::Patches::TestCasePatch)
29
+ ActiveSupport::TestCase.include RedminePluginsHelper::Patches::TestCasePatch
50
30
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'rspec/core/rake_task'
5
+ require 'shellwords'
6
+
7
+ module RedminePluginsHelper
8
+ class PluginRakeTask
9
+ DEFAULT_TASK_NAME_LAST_PART = 'rspec'
10
+
11
+ class << self
12
+ def register(plugin_id, task_name_last_part = DEFAULT_TASK_NAME_LAST_PART)
13
+ new(plugin_id, task_name_last_part).register
14
+ end
15
+ end
16
+
17
+ common_constructor :plugin_id, :task_name_last_part
18
+
19
+ def register
20
+ ::RSpec::Core::RakeTask.new(task_full_name) do |t|
21
+ t.rspec_opts = ::Shellwords.join(rspec_opts)
22
+ end
23
+ Rake::Task[task_full_name].enhance ['db:test:prepare']
24
+ end
25
+
26
+ def task_full_name
27
+ "#{plugin_id}:#{task_name_last_part}"
28
+ end
29
+
30
+ def rspec_opts
31
+ ['--pattern', "plugins/#{plugin_id}/spec/**/*_spec.rb",
32
+ '--default-path', 'plugins/redmine_plugins_helper/spec',
33
+ '--require', 'spec_helper']
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_dependency 'redmine_plugins_helper'
2
4
 
3
5
  module RedminePluginsHelper
@@ -5,6 +7,7 @@ module RedminePluginsHelper
5
7
  class << self
6
8
  def default(plugin, default)
7
9
  return unless ::RedminePluginsHelper.settings_table_exist?
10
+
8
11
  p = plugin_current_setting_value(plugin)
9
12
  default.each do |k, v|
10
13
  p[k.to_s] = v unless p.key?(k)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedminePluginsHelper
2
4
  class StatusMigrations
3
5
  def initialize
@@ -10,7 +12,7 @@ module RedminePluginsHelper
10
12
  local_versions.each do |plugin, timestamps|
11
13
  timestamps.each do |timestamp|
12
14
  m = migrated_version?(plugin, timestamp) ? 'up' : 'down'
13
- puts "#{m}\t#{plugin}\t#{timestamp}"
15
+ puts "#{m}\t#{plugin}\t#{timestamp}" # rubocop:disable Rails/Output
14
16
  end
15
17
  end
16
18
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedminePluginsHelper
4
+ class TestConfig
5
+ def before_each
6
+ mailer_setup
7
+ end
8
+
9
+ def after_each
10
+ mailer_teadown
11
+ end
12
+
13
+ def mailer_setup
14
+ unless @mailer_perform_deliveries_changed
15
+ @mailer_perform_deliveries_changed = true
16
+ @mailer_perform_deliveries_was_enabled = ::ActionMailer::Base.perform_deliveries
17
+ end
18
+ ::ActionMailer::Base.perform_deliveries = false
19
+ end
20
+
21
+ def mailer_teadown
22
+ return unless @mailer_perform_deliveries_changed
23
+
24
+ ::ActionMailer::Base.perform_deliveries = @mailer_perform_deliveries_was_enabled
25
+ @mailer_perform_deliveries_changed = false
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedminePluginsHelper
4
+ module TestHelper
5
+ def plugin_fixtures(plugin_name, *files)
6
+ fixtures_dir = File.expand_path(
7
+ 'test/fixtures',
8
+ ::Redmine::Plugin.registered_plugins[plugin_name].directory
9
+ )
10
+ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, files)
11
+ fixtures(*files)
12
+ end
13
+ end
14
+ end
@@ -3,5 +3,5 @@
3
3
  module RedminePluginsHelper
4
4
  AUTHOR = 'Eduardo Henrique Bogoni'
5
5
  SUMMARY = 'Helper for Redmine plugins'
6
- VERSION = '0.6.4'
6
+ VERSION = '0.9.0'
7
7
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rake::Task['redmine:plugins:migrate'].clear
4
+
5
+ namespace :redmine do
6
+ desc 'Run migrations of core Redmine and installed plugins.'
7
+ task migrate: ['db:migrate', 'redmine:plugins:migrate:fix', 'redmine:plugins:migrate'] do
8
+ end
9
+
10
+ namespace :version do
11
+ desc 'Shows Redmine\'s version.'
12
+ task show: :environment do
13
+ puts ::Redmine::VERSION::STRING
14
+ end
15
+ end
16
+
17
+ task version: 'version:show'
18
+
19
+ namespace :plugins do
20
+ desc 'Migrates installed plugins.'
21
+ task migrate: :environment do
22
+ name = ENV['NAME']
23
+ version = nil
24
+ version_string = ENV['VERSION']
25
+ if version_string
26
+ if version_string =~ /^\d+$/
27
+ version = version_string.to_i
28
+ abort 'The VERSION argument requires a plugin NAME.' if name.nil?
29
+ else
30
+ abort "Invalid VERSION #{version_string} given."
31
+ end
32
+ end
33
+
34
+ begin
35
+ RedminePluginsHelper::Migrate.new(name, version)
36
+ Rake::Task['db:schema:dump'].invoke
37
+ rescue Redmine::PluginNotFound
38
+ abort "Plugin #{name} was not found."
39
+ end
40
+ end
41
+
42
+ namespace :migrate do
43
+ desc 'Fix migrations moved from a plugin to another'
44
+ task fix: :environment do
45
+ RedminePluginsHelper::FixMigrations.new
46
+ end
47
+
48
+ desc 'Show migrations status of all plugins'
49
+ task status: :environment do
50
+ RedminePluginsHelper::StatusMigrations.new
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,52 +1,4 @@
1
- Rake::Task['redmine:plugins:migrate'].clear
1
+ # frozen_string_literal: true
2
2
 
3
- namespace :redmine do
4
- desc 'Run migrations of core Redmine and installed plugins.'
5
- task migrate: ['db:migrate', 'redmine:plugins:migrate:fix', 'redmine:plugins:migrate'] do
6
- end
7
-
8
- namespace :version do
9
- desc 'Shows Redmine\'s version.'
10
- task show: :environment do
11
- puts ::Redmine::VERSION::STRING
12
- end
13
- end
14
-
15
- task version: 'version:show'
16
-
17
- namespace :plugins do
18
- desc 'Migrates installed plugins.'
19
- task migrate: :environment do
20
- name = ENV['NAME']
21
- version = nil
22
- version_string = ENV['VERSION']
23
- if version_string
24
- if version_string =~ /^\d+$/
25
- version = version_string.to_i
26
- abort 'The VERSION argument requires a plugin NAME.' if name.nil?
27
- else
28
- abort "Invalid VERSION #{version_string} given."
29
- end
30
- end
31
-
32
- begin
33
- RedminePluginsHelper::Migrate.new(name, version)
34
- Rake::Task['db:schema:dump'].invoke
35
- rescue Redmine::PluginNotFound
36
- abort "Plugin #{name} was not found."
37
- end
38
- end
39
-
40
- namespace :migrate do
41
- desc 'Fix migrations moved from a plugin to another'
42
- task fix: :environment do
43
- RedminePluginsHelper::FixMigrations.new
44
- end
45
-
46
- desc 'Show migrations status of all plugins'
47
- task status: :environment do
48
- RedminePluginsHelper::StatusMigrations.new
49
- end
50
- end
51
- end
52
- end
3
+ require 'redmine_plugins_helper/plugin_rake_task'
4
+ ::RedminePluginsHelper::PluginRakeTask.register(:redmine_plugins_helper, :test)
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_plugins_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
- - 0.6.4
7
+ - 0.9.0
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-01 00:00:00.000000000 Z
11
+ date: 2020-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eac_ruby_utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.43'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.43'
27
+ - !ruby/object:Gem::Dependency
28
+ name: launchy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: sass-rails
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +66,26 @@ dependencies:
24
66
  - - "~>"
25
67
  - !ruby/object:Gem::Version
26
68
  version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: eac_ruby_gem_support
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 0.1.2
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '0.1'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 0.1.2
27
89
  description:
28
90
  email:
29
91
  executables: []
@@ -43,9 +105,13 @@ files:
43
105
  - lib/redmine_plugins_helper/patches/redmine/plugin_migration_context.rb
44
106
  - lib/redmine_plugins_helper/patches/redmine/plugin_patch.rb
45
107
  - lib/redmine_plugins_helper/patches/test_case_patch.rb
108
+ - lib/redmine_plugins_helper/plugin_rake_task.rb
46
109
  - lib/redmine_plugins_helper/settings.rb
47
110
  - lib/redmine_plugins_helper/status_migrations.rb
111
+ - lib/redmine_plugins_helper/test_config.rb
112
+ - lib/redmine_plugins_helper/test_helper.rb
48
113
  - lib/redmine_plugins_helper/version.rb
114
+ - lib/tasks/redmine.rake
49
115
  - lib/tasks/redmine_plugins_helper.rake
50
116
  homepage:
51
117
  licenses: []