From a5120116d0c54357ea6ad9c16e059599b1b23995 Mon Sep 17 00:00:00 2001 From: Andreas Reischuck Date: Fri, 22 Feb 2019 17:40:28 +0100 Subject: [PATCH 01/14] first support for Rails 5 --- config/initializers/redmine_integration.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/initializers/redmine_integration.rb b/config/initializers/redmine_integration.rb index 5033cefc..3bd29dcd 100644 --- a/config/initializers/redmine_integration.rb +++ b/config/initializers/redmine_integration.rb @@ -3,7 +3,11 @@ def add_patch(module_to_patch, method: :include) module_to_patch.send method, patch unless module_to_patch.ancestors.include? patch end -ActionDispatch::Callbacks.to_prepare do +if Rails::VERSION::MAJOR >= 5 + ActiveSupport::Reloader +else + ActionDispatch::Callbacks +end.to_prepare do [Project, TimeEntry, User, ProjectsHelper, SettingsController, UserPreference, TimeEntryActivity].each { |module_to_patch| add_patch module_to_patch } [Query].each { |module_to_patch| add_patch module_to_patch, method: :prepend } From 4e0f18f65d7899cb35d381c791f9b9160e40ddc3 Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Fri, 8 Mar 2019 10:23:09 +0100 Subject: [PATCH 02/14] * Fixed some rails 5 code issues. --- app/controllers/concerns/boolean_parsing.rb | 6 ++++- app/models/hourglass/global_settings.rb | 15 ++---------- app/models/hourglass/project_settings.rb | 20 ++++------------ .../redmine_patches/projects_helper_patch.rb | 3 ++- .../settings_controller_patch.rb | 3 ++- lib/hourglass/type_parsing.rb | 23 +++++++++++++++++++ 6 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 lib/hourglass/type_parsing.rb diff --git a/app/controllers/concerns/boolean_parsing.rb b/app/controllers/concerns/boolean_parsing.rb index bbd02d31..d15e4513 100644 --- a/app/controllers/concerns/boolean_parsing.rb +++ b/app/controllers/concerns/boolean_parsing.rb @@ -4,7 +4,11 @@ module BooleanParsing def parse_boolean(keys, params) keys = [keys] if keys.is_a? Symbol keys.each do |key| - params[key] = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[key]) + if Rails::VERSION::MAJOR <= 4 + params[key] = ActiveRecord::Type::Boolean.new.type_cast_from_user(params[key]) + else + params[key] = ActiveRecord::Type::Boolean.new.cast(params[key]) + end end params end diff --git a/app/models/hourglass/global_settings.rb b/app/models/hourglass/global_settings.rb index e9072b6e..6bf5bfe4 100644 --- a/app/models/hourglass/global_settings.rb +++ b/app/models/hourglass/global_settings.rb @@ -1,5 +1,6 @@ module Hourglass class GlobalSettings + include TypeParsing include ActiveModel::Model attr_accessor :round_sums_only, @@ -14,8 +15,7 @@ class GlobalSettings validates :round_sums_only, inclusion: { in: ['true', 'false', '1', '0', true, false] } validates :round_minimum, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 24 } - validates :round_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0, - less_than_or_equal_to: 100 } + validates :round_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 100 } validates :round_default, inclusion: { in: ['true', 'false', '1', '0', true, false] } validates :round_carry_over_due, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 24 } validates :report_title, length: { maximum: 23 }, presence: true @@ -68,16 +68,5 @@ def resolve_types self.report_logo_width = parse_type :integer, @report_logo_width self.global_tracker = parse_type :boolean, @global_tracker end - - def parse_type(type, attribute) - case type - when :boolean - ActiveRecord::Type::Boolean.new.type_cast_from_user(attribute) - when :integer - ActiveRecord::Type::Integer.new.type_cast_from_user(attribute) - when :float - ActiveRecord::Type::Float.new.type_cast_from_user(attribute) - end - end end end diff --git a/app/models/hourglass/project_settings.rb b/app/models/hourglass/project_settings.rb index f0934b58..bc59180a 100644 --- a/app/models/hourglass/project_settings.rb +++ b/app/models/hourglass/project_settings.rb @@ -1,5 +1,6 @@ module Hourglass class ProjectSettings + include TypeParsing include ActiveModel::Model attr_accessor :round_sums_only, @@ -9,13 +10,12 @@ class ProjectSettings :round_carry_over_due validates :round_sums_only, inclusion: { in: ['true', 'false', true, false] }, allow_blank: true - validates :round_minimum, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 24 }, - allow_blank: true + validates :round_minimum, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 24 }, allow_blank: true validates :round_limit, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }, allow_blank: true validates :round_default, inclusion: { in: ['true', 'false', true, false] }, allow_blank: true - validates :round_carry_over_due, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 24 }, - allow_blank: true + validates :round_carry_over_due, numericality: { greater_than_or_equal_to: 0, + less_than_or_equal_to: 24 }, allow_blank: true def initialize(project = nil) @project = project @@ -36,6 +36,7 @@ def update(attributes) end private + def from_hash(attributes) self.round_sums_only = attributes[:round_sums_only] self.round_minimum = attributes[:round_minimum] @@ -61,16 +62,5 @@ def resolve_types self.round_default = parse_type :boolean, @round_default self.round_carry_over_due = parse_type :float, @round_carry_over_due end - - def parse_type(type, attribute) - case type - when :boolean - ActiveRecord::Type::Boolean.new.type_cast_from_user(attribute) - when :integer - ActiveRecord::Type::Integer.new.type_cast_from_user(attribute) - when :float - ActiveRecord::Type::Float.new.type_cast_from_user(attribute) - end - end end end diff --git a/lib/hourglass/redmine_patches/projects_helper_patch.rb b/lib/hourglass/redmine_patches/projects_helper_patch.rb index 75c8dbb8..7b12b579 100644 --- a/lib/hourglass/redmine_patches/projects_helper_patch.rb +++ b/lib/hourglass/redmine_patches/projects_helper_patch.rb @@ -4,7 +4,8 @@ module ProjectsHelperPatch extend ActiveSupport::Concern included do - alias_method_chain :project_settings_tabs, :hourglass + alias_method :project_settings_tabs_without_hourglass, :project_settings_tabs + alias_method :project_settings_tabs, :project_settings_tabs_with_hourglass end def project_settings_tabs_with_hourglass diff --git a/lib/hourglass/redmine_patches/settings_controller_patch.rb b/lib/hourglass/redmine_patches/settings_controller_patch.rb index e38da7e6..7495fec0 100644 --- a/lib/hourglass/redmine_patches/settings_controller_patch.rb +++ b/lib/hourglass/redmine_patches/settings_controller_patch.rb @@ -4,7 +4,8 @@ module SettingsControllerPatch extend ActiveSupport::Concern included do - alias_method_chain :plugin, :hourglass + alias_method :plugin_without_hourglass, :plugin + alias_method :plugin, :plugin_with_hourglass end def plugin_with_hourglass diff --git a/lib/hourglass/type_parsing.rb b/lib/hourglass/type_parsing.rb new file mode 100644 index 00000000..85fc988e --- /dev/null +++ b/lib/hourglass/type_parsing.rb @@ -0,0 +1,23 @@ +module TypeParsing + def parse_type(type, attribute) + if Rails::VERSION::MAJOR <= 4 + case type + when :boolean + ActiveRecord::Type::Boolean.new.type_cast_from_user(attribute) + when :integer + ActiveRecord::Type::Integer.new.type_cast_from_user(attribute) + when :float + ActiveRecord::Type::Float.new.type_cast_from_user(attribute) + end + else + case type + when :boolean + ActiveRecord::Type::Boolean.new.cast(attribute) + when :integer + ActiveRecord::Type::Integer.new.cast(attribute) + when :float + ActiveRecord::Type::Float.new.cast(attribute) + end + end + end +end \ No newline at end of file From 094d9bc4e0711737110bbfd5e016f79b5316a89c Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Fri, 8 Mar 2019 10:55:28 +0100 Subject: [PATCH 03/14] * Fix travis database migration failure for redmine 4.0.x versions. --- .travis.yml | 11 ++--------- .travis/clone_redmine.sh | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5d89ea6f..98c181b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,12 +18,10 @@ matrix: rvm: 2.0.0 env: - REDMINE_VERSION=3.2.9 - - DATABASE=SQLITE3 - name: Ruby 2.0 / Redmine 3.3 rvm: 2.0.0 env: - REDMINE_VERSION=3.3.9 - - DATABASE=SQLITE3 - name: Ruby 2.1 / Redmine 3.3 rvm: 2.1.10 @@ -51,31 +49,26 @@ matrix: rvm: 2.3.8 env: - REDMINE_VERSION=3.4.1 - - DATABASE=SQLITE3 - name: Ruby 2.3 / Redmine 3.4.9 rvm: 2.3.8 env: - REDMINE_VERSION=3.4.9 - - DATABASE=SQLITE3 - name: Ruby 2.5 / Redmine 4 rvm: 2.5.3 env: - REDMINE_VERSION=4.0.2 - - DATABASE=SQLITE3 - name: Ruby 2.6 / Redmine 4 rvm: 2.6.1 env: - REDMINE_VERSION=4.0.2 - - DATABASE=SQLITE3 allow_failures: - env: - REDMINE_VERSION=4.0.2 - - DATABASE=SQLITE3 - + before_install: - source .travis/clone_redmine.sh - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true @@ -90,7 +83,7 @@ install: - cd $PATH_TO_REDMINE - bundle install --without rmagick --jobs=3 --retry=3 --path=$PATH_TO_PLUGIN/vendor/bundle - bundle exec rake $TRACE db:create - - bundle exec rake $TRACE db:migrate + - bundle exec rake $TRACE db:migrate RAILS_ENV=test - bundle exec rake $TRACE redmine:load_default_data REDMINE_LANG=en - bundle exec rake $TRACE $GENERATE_SECRET - bundle exec rake $TRACE $MIGRATE_PLUGINS diff --git a/.travis/clone_redmine.sh b/.travis/clone_redmine.sh index a58aa9f8..6b9b78da 100644 --- a/.travis/clone_redmine.sh +++ b/.travis/clone_redmine.sh @@ -48,11 +48,11 @@ fi ln -s "$PATH_TO_PLUGIN" "$PATH_TO_PLUGINS/$PLUGIN" case $DATABASE in - SQLITE3) cp $PATH_TO_PLUGINS/$PLUGIN/.travis/sqlite3_database.yml config/database.yml - ;; MYSQL) cp $PATH_TO_PLUGINS/$PLUGIN/.travis/mysql_database.yml config/database.yml ;; POSTGRESQL) cp $PATH_TO_PLUGINS/$PLUGIN/.travis/postgresql_database.yml config/database.yml ;; + *) cp $PATH_TO_PLUGINS/$PLUGIN/.travis/sqlite3_database.yml config/database.yml + ;; esac From 477bd9afa0582cb2421dcaf299df5c34b4a84cac Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Fri, 8 Mar 2019 11:06:34 +0100 Subject: [PATCH 04/14] * Fix travis redmine plugins migration. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 98c181b5..6230037c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,7 +86,7 @@ install: - bundle exec rake $TRACE db:migrate RAILS_ENV=test - bundle exec rake $TRACE redmine:load_default_data REDMINE_LANG=en - bundle exec rake $TRACE $GENERATE_SECRET - - bundle exec rake $TRACE $MIGRATE_PLUGINS + - bundle exec rake $TRACE $MIGRATE_PLUGINS RAILS_ENV=test script: - cd $PATH_TO_REDMINE From cac89774aec768e68b33dfb9fedc835940c7c72d Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Fri, 8 Mar 2019 11:29:57 +0100 Subject: [PATCH 05/14] * Fixed database migration failure. --- .../1418311263_create_hourglass_time_logs.rb | 39 +++++++++---- ...18311331_create_hourglass_time_bookings.rb | 42 +++++++++----- ...18914331_create_hourglass_time_trackers.rb | 57 +++++++++++++------ ...hange_hourglass_time_log_comments_limit.rb | 28 ++++++--- 4 files changed, 115 insertions(+), 51 deletions(-) diff --git a/db/migrate/1418311263_create_hourglass_time_logs.rb b/db/migrate/1418311263_create_hourglass_time_logs.rb index 870ae6ab..1cefd967 100644 --- a/db/migrate/1418311263_create_hourglass_time_logs.rb +++ b/db/migrate/1418311263_create_hourglass_time_logs.rb @@ -1,12 +1,27 @@ -class CreateHourglassTimeLogs < ActiveRecord::Migration - def change - create_table :hourglass_time_logs do |t| - t.datetime :start, null: false - t.datetime :stop, null: false - t.string :comments - t.belongs_to :user, null: false - t.timestamps null: true - end - add_index :hourglass_time_logs, :user_id - end -end +CreateHourglassTimeLogs = if Rails::VERSION::MAJOR <= 4 + Class.new(ActiveRecord::Migration) do + def change + create_table :hourglass_time_logs do |t| + t.datetime :start, null: false + t.datetime :stop, null: false + t.string :comments + t.belongs_to :user, null: false + t.timestamps null: true + end + add_index :hourglass_time_logs, :user_id + end + end + else + Class.new(ActiveRecord::Migration[4.2]) do + def change + create_table :hourglass_time_logs do |t| + t.datetime :start, null: false + t.datetime :stop, null: false + t.string :comments + t.belongs_to :user, null: false + t.timestamps null: true + end + add_index :hourglass_time_logs, :user_id + end + end + end diff --git a/db/migrate/1418311331_create_hourglass_time_bookings.rb b/db/migrate/1418311331_create_hourglass_time_bookings.rb index dd57d69d..5025a6c0 100644 --- a/db/migrate/1418311331_create_hourglass_time_bookings.rb +++ b/db/migrate/1418311331_create_hourglass_time_bookings.rb @@ -1,13 +1,29 @@ -class CreateHourglassTimeBookings < ActiveRecord::Migration - def change - create_table :hourglass_time_bookings do |t| - t.datetime :start, null: false - t.datetime :stop, null: false - t.belongs_to :time_log, null: false - t.belongs_to :time_entry, null: false - t.timestamps null: true - end - add_index :hourglass_time_bookings, :time_log_id - add_index :hourglass_time_bookings, :time_entry_id, unique: true - end -end +CreateHourglassTimeBookings = if Rails::VERSION::MAJOR <= 4 + Class.new(ActiveRecord::Migration) do + def change + create_table :hourglass_time_bookings do |t| + t.datetime :start, null: false + t.datetime :stop, null: false + t.belongs_to :time_log, null: false + t.belongs_to :time_entry, null: false + t.timestamps null: true + end + add_index :hourglass_time_bookings, :time_log_id + add_index :hourglass_time_bookings, :time_entry_id, unique: true + end + end + else + Class.new(ActiveRecord::Migration[4.2]) do + def change + create_table :hourglass_time_bookings do |t| + t.datetime :start, null: false + t.datetime :stop, null: false + t.belongs_to :time_log, null: false + t.belongs_to :time_entry, null: false + t.timestamps null: true + end + add_index :hourglass_time_bookings, :time_log_id + add_index :hourglass_time_bookings, :time_entry_id, unique: true + end + end + end diff --git a/db/migrate/1418914331_create_hourglass_time_trackers.rb b/db/migrate/1418914331_create_hourglass_time_trackers.rb index a81b3326..65643067 100644 --- a/db/migrate/1418914331_create_hourglass_time_trackers.rb +++ b/db/migrate/1418914331_create_hourglass_time_trackers.rb @@ -1,18 +1,39 @@ -class CreateHourglassTimeTrackers < ActiveRecord::Migration - def change - create_table :hourglass_time_trackers do |t| - t.datetime :start, null: false - t.string :comments - t.boolean :round - t.belongs_to :user, null: false - t.belongs_to :project - t.belongs_to :issue - t.belongs_to :activity - t.timestamps null: true - end - add_index :hourglass_time_trackers, :user_id, unique: true - add_index :hourglass_time_trackers, :project_id - add_index :hourglass_time_trackers, :issue_id - add_index :hourglass_time_trackers, :activity_id - end -end +CreateHourglassTimeTrackers = if Rails::VERSION::MAJOR <= 4 + Class.new(ActiveRecord::Migration) do + def change + create_table :hourglass_time_trackers do |t| + t.datetime :start, null: false + t.string :comments + t.boolean :round + t.belongs_to :user, null: false + t.belongs_to :project + t.belongs_to :issue + t.belongs_to :activity + t.timestamps null: true + end + add_index :hourglass_time_trackers, :user_id, unique: true + add_index :hourglass_time_trackers, :project_id + add_index :hourglass_time_trackers, :issue_id + add_index :hourglass_time_trackers, :activity_id + end + end + else + Class.new(ActiveRecord::Migration[4.2]) do + def change + create_table :hourglass_time_trackers do |t| + t.datetime :start, null: false + t.string :comments + t.boolean :round + t.belongs_to :user, null: false + t.belongs_to :project + t.belongs_to :issue + t.belongs_to :activity + t.timestamps null: true + end + add_index :hourglass_time_trackers, :user_id, unique: true + add_index :hourglass_time_trackers, :project_id + add_index :hourglass_time_trackers, :issue_id + add_index :hourglass_time_trackers, :activity_id + end + end + end diff --git a/db/migrate/20190307074023_change_hourglass_time_log_comments_limit.rb b/db/migrate/20190307074023_change_hourglass_time_log_comments_limit.rb index dfe65687..27d22614 100644 --- a/db/migrate/20190307074023_change_hourglass_time_log_comments_limit.rb +++ b/db/migrate/20190307074023_change_hourglass_time_log_comments_limit.rb @@ -1,9 +1,21 @@ -class ChangeHourglassTimeLogCommentsLimit < ActiveRecord::Migration - def up - change_column :hourglass_time_logs, :comments, :string, limit: 1024 - end +ChangeHourglassTimeLogCommentsLimit = if Rails::VERSION::MAJOR <= 4 + Class.new(ActiveRecord::Migration) do + def up + change_column :hourglass_time_logs, :comments, :string, limit: 1024 + end - def down - change_column :hourglass_time_logs, :comments, :string - end -end + def down + change_column :hourglass_time_logs, :comments, :string + end + end + else + Class.new(ActiveRecord::Migration[4.2]) do + def up + change_column :hourglass_time_logs, :comments, :string, limit: 1024 + end + + def down + change_column :hourglass_time_logs, :comments, :string + end + end + end From cb10b144eb0ef66601043db1fcb60449289f2fec Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Mon, 11 Mar 2019 09:28:48 +0100 Subject: [PATCH 06/14] * Always set travis environment to test. --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6230037c..429d0712 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ env: - PLUGIN=redmine_hourglass - REDMINE=test_redmine - TRACE=--trace + - RAILS_ENV=test matrix: include: @@ -83,10 +84,10 @@ install: - cd $PATH_TO_REDMINE - bundle install --without rmagick --jobs=3 --retry=3 --path=$PATH_TO_PLUGIN/vendor/bundle - bundle exec rake $TRACE db:create - - bundle exec rake $TRACE db:migrate RAILS_ENV=test + - bundle exec rake $TRACE db:migrate - bundle exec rake $TRACE redmine:load_default_data REDMINE_LANG=en - bundle exec rake $TRACE $GENERATE_SECRET - - bundle exec rake $TRACE $MIGRATE_PLUGINS RAILS_ENV=test + - bundle exec rake $TRACE $MIGRATE_PLUGINS script: - cd $PATH_TO_REDMINE From b4f4b95d492c7024f3d1466c45aa21ce28d282bc Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Mon, 11 Mar 2019 11:18:58 +0100 Subject: [PATCH 07/14] * Remove duplicated migration class definition. --- config/initializers/autoload.rb | 9 +-- .../1418311263_create_hourglass_time_logs.rb | 41 +++++-------- ...18311331_create_hourglass_time_bookings.rb | 44 +++++--------- ...18914331_create_hourglass_time_trackers.rb | 59 +++++++------------ ...hange_hourglass_time_log_comments_limit.rb | 28 +++------ lib/hourglass/hourglass_migration.rb | 2 + 6 files changed, 65 insertions(+), 118 deletions(-) create mode 100644 lib/hourglass/hourglass_migration.rb diff --git a/config/initializers/autoload.rb b/config/initializers/autoload.rb index 6911ff2f..9166ea89 100644 --- a/config/initializers/autoload.rb +++ b/config/initializers/autoload.rb @@ -1,8 +1,9 @@ [ - %w(app models concerns), - %w(app controllers concerns), - %w(app policies), - %w(app policies concerns) + %w(app models concerns), + %w(app controllers concerns), + %w(app policies), + %w(app policies concerns), + %w(lib hourglass) ].each do |path| ActiveSupport::Dependencies.autoload_paths << File.join(Hourglass::PLUGIN_ROOT, *path) end diff --git a/db/migrate/1418311263_create_hourglass_time_logs.rb b/db/migrate/1418311263_create_hourglass_time_logs.rb index 1cefd967..39882bca 100644 --- a/db/migrate/1418311263_create_hourglass_time_logs.rb +++ b/db/migrate/1418311263_create_hourglass_time_logs.rb @@ -1,27 +1,14 @@ -CreateHourglassTimeLogs = if Rails::VERSION::MAJOR <= 4 - Class.new(ActiveRecord::Migration) do - def change - create_table :hourglass_time_logs do |t| - t.datetime :start, null: false - t.datetime :stop, null: false - t.string :comments - t.belongs_to :user, null: false - t.timestamps null: true - end - add_index :hourglass_time_logs, :user_id - end - end - else - Class.new(ActiveRecord::Migration[4.2]) do - def change - create_table :hourglass_time_logs do |t| - t.datetime :start, null: false - t.datetime :stop, null: false - t.string :comments - t.belongs_to :user, null: false - t.timestamps null: true - end - add_index :hourglass_time_logs, :user_id - end - end - end +require 'hourglass/hourglass_migration' + +class CreateHourglassTimeLogs < HourglassMigration + def change + create_table :hourglass_time_logs do |t| + t.datetime :start, null: false + t.datetime :stop, null: false + t.string :comments + t.belongs_to :user, null: false + t.timestamps null: true + end + add_index :hourglass_time_logs, :user_id + end +end diff --git a/db/migrate/1418311331_create_hourglass_time_bookings.rb b/db/migrate/1418311331_create_hourglass_time_bookings.rb index 5025a6c0..ba7a5d58 100644 --- a/db/migrate/1418311331_create_hourglass_time_bookings.rb +++ b/db/migrate/1418311331_create_hourglass_time_bookings.rb @@ -1,29 +1,15 @@ -CreateHourglassTimeBookings = if Rails::VERSION::MAJOR <= 4 - Class.new(ActiveRecord::Migration) do - def change - create_table :hourglass_time_bookings do |t| - t.datetime :start, null: false - t.datetime :stop, null: false - t.belongs_to :time_log, null: false - t.belongs_to :time_entry, null: false - t.timestamps null: true - end - add_index :hourglass_time_bookings, :time_log_id - add_index :hourglass_time_bookings, :time_entry_id, unique: true - end - end - else - Class.new(ActiveRecord::Migration[4.2]) do - def change - create_table :hourglass_time_bookings do |t| - t.datetime :start, null: false - t.datetime :stop, null: false - t.belongs_to :time_log, null: false - t.belongs_to :time_entry, null: false - t.timestamps null: true - end - add_index :hourglass_time_bookings, :time_log_id - add_index :hourglass_time_bookings, :time_entry_id, unique: true - end - end - end +require 'hourglass/hourglass_migration' + +class CreateHourglassTimeBookings < HourglassMigration + def change + create_table :hourglass_time_bookings do |t| + t.datetime :start, null: false + t.datetime :stop, null: false + t.belongs_to :time_log, null: false + t.belongs_to :time_entry, null: false + t.timestamps null: true + end + add_index :hourglass_time_bookings, :time_log_id + add_index :hourglass_time_bookings, :time_entry_id, unique: true + end +end diff --git a/db/migrate/1418914331_create_hourglass_time_trackers.rb b/db/migrate/1418914331_create_hourglass_time_trackers.rb index 65643067..522a9d4d 100644 --- a/db/migrate/1418914331_create_hourglass_time_trackers.rb +++ b/db/migrate/1418914331_create_hourglass_time_trackers.rb @@ -1,39 +1,20 @@ -CreateHourglassTimeTrackers = if Rails::VERSION::MAJOR <= 4 - Class.new(ActiveRecord::Migration) do - def change - create_table :hourglass_time_trackers do |t| - t.datetime :start, null: false - t.string :comments - t.boolean :round - t.belongs_to :user, null: false - t.belongs_to :project - t.belongs_to :issue - t.belongs_to :activity - t.timestamps null: true - end - add_index :hourglass_time_trackers, :user_id, unique: true - add_index :hourglass_time_trackers, :project_id - add_index :hourglass_time_trackers, :issue_id - add_index :hourglass_time_trackers, :activity_id - end - end - else - Class.new(ActiveRecord::Migration[4.2]) do - def change - create_table :hourglass_time_trackers do |t| - t.datetime :start, null: false - t.string :comments - t.boolean :round - t.belongs_to :user, null: false - t.belongs_to :project - t.belongs_to :issue - t.belongs_to :activity - t.timestamps null: true - end - add_index :hourglass_time_trackers, :user_id, unique: true - add_index :hourglass_time_trackers, :project_id - add_index :hourglass_time_trackers, :issue_id - add_index :hourglass_time_trackers, :activity_id - end - end - end +require 'hourglass/hourglass_migration' + +class CreateHourglassTimeTrackers < HourglassMigration + def change + create_table :hourglass_time_trackers do |t| + t.datetime :start, null: false + t.string :comments + t.boolean :round + t.belongs_to :user, null: false + t.belongs_to :project + t.belongs_to :issue + t.belongs_to :activity + t.timestamps null: true + end + add_index :hourglass_time_trackers, :user_id, unique: true + add_index :hourglass_time_trackers, :project_id + add_index :hourglass_time_trackers, :issue_id + add_index :hourglass_time_trackers, :activity_id + end +end diff --git a/db/migrate/20190307074023_change_hourglass_time_log_comments_limit.rb b/db/migrate/20190307074023_change_hourglass_time_log_comments_limit.rb index 27d22614..e61427b9 100644 --- a/db/migrate/20190307074023_change_hourglass_time_log_comments_limit.rb +++ b/db/migrate/20190307074023_change_hourglass_time_log_comments_limit.rb @@ -1,21 +1,11 @@ -ChangeHourglassTimeLogCommentsLimit = if Rails::VERSION::MAJOR <= 4 - Class.new(ActiveRecord::Migration) do - def up - change_column :hourglass_time_logs, :comments, :string, limit: 1024 - end +require 'hourglass/hourglass_migration' - def down - change_column :hourglass_time_logs, :comments, :string - end - end - else - Class.new(ActiveRecord::Migration[4.2]) do - def up - change_column :hourglass_time_logs, :comments, :string, limit: 1024 - end +class ChangeHourglassTimeLogCommentsLimit < HourglassMigration + def up + change_column :hourglass_time_logs, :comments, :string, limit: 1024 + end - def down - change_column :hourglass_time_logs, :comments, :string - end - end - end + def down + change_column :hourglass_time_logs, :comments, :string + end +end diff --git a/lib/hourglass/hourglass_migration.rb b/lib/hourglass/hourglass_migration.rb new file mode 100644 index 00000000..6d6d0ba1 --- /dev/null +++ b/lib/hourglass/hourglass_migration.rb @@ -0,0 +1,2 @@ +class HourglassMigration < (Rails::VERSION::MAJOR <= 4 ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]) +end From d3d31e585e1738d88d25384b9f91220aa4445c64 Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Wed, 13 Mar 2019 09:58:04 +0100 Subject: [PATCH 08/14] * Fixed bulk generation. * Minor cleanups. --- .../hourglass/api_base_controller.rb | 26 +++++--- .../hourglass/time_logs_controller.rb | 13 ++-- spec/integration/time_bookings_spec.rb | 46 ++++++------- spec/integration/time_logs_spec.rb | 64 +++++++++---------- 4 files changed, 79 insertions(+), 70 deletions(-) diff --git a/app/controllers/hourglass/api_base_controller.rb b/app/controllers/hourglass/api_base_controller.rb index c37de604..0f7802da 100644 --- a/app/controllers/hourglass/api_base_controller.rb +++ b/app/controllers/hourglass/api_base_controller.rb @@ -14,6 +14,7 @@ class ApiBaseController < ApplicationController include ::AuthorizationConcern private + # use only these codes: # :ok (200) # :not_modified (304) @@ -24,8 +25,8 @@ class ApiBaseController < ApplicationController # :internal_server_error (500) def respond_with_error(status, message, **options) render json: { - message: message.is_a?(Array) && options[:array_mode] == :sentence ? message.to_sentence : message, - status: Rack::Utils.status_code(status) + message: message.is_a?(Array) && options[:array_mode] == :sentence ? message.to_sentence : message, + status: Rack::Utils.status_code(status) }, status: status throw :halt unless options[:no_halt] @@ -71,18 +72,25 @@ def list_records(klass) scope = @query.results_scope order: sort_clause offset, limit = api_offset_and_limit respond_with_success( - count: scope.count, - offset: offset, - limit: limit, - records: scope.offset(offset).limit(limit).to_a + count: scope.count, + offset: offset, + limit: limit, + records: scope.offset(offset).limit(limit).to_a ) end def bulk(params_key = controller_name, &block) @bulk_success = [] @bulk_errors = [] - params[params_key].each_with_index do |(id, params), index| - id, params = "new#{index}", id if id.is_a?(Hash) + entries = params[params_key] + entries = entries.to_unsafe_h if entries.instance_of?(ActionController::Parameters) + entries.each_with_index do |(id, params), index| + if Rails::VERSION::MAJOR <= 4 + id, params = "new#{index}", id if id.is_a?(Hash) + else + id, params = "new#{index}", id if id.instance_of?(ActionController::Parameters) + params = ActionController::Parameters.new(params) if params.is_a?(Hash) + end error_preface = id.start_with?('new') ? bulk_error_preface(index, mode: :create) : bulk_error_preface(id) evaluate_entry bulk_entry(id, params, &block), error_preface end @@ -132,7 +140,7 @@ def internal_server_error(e) end def flash_array(type, messages) - flash[type] = render_to_string partial: 'hourglass_ui/flash_array', locals: {messages: messages} + flash[type] = render_to_string partial: 'hourglass_ui/flash_array', locals: { messages: messages } end def custom_field_keys(params_hash) diff --git a/app/controllers/hourglass/time_logs_controller.rb b/app/controllers/hourglass/time_logs_controller.rb index 329f12d0..c2ec9eef 100644 --- a/app/controllers/hourglass/time_logs_controller.rb +++ b/app/controllers/hourglass/time_logs_controller.rb @@ -107,6 +107,7 @@ def bulk_destroy end private + def time_log_params(params_hash = params.require(:time_log)) parse_boolean :round, params_hash.permit(:start, :stop, :comments, :round, :user_id) end @@ -117,16 +118,16 @@ def create_time_log_params(params_hash = params.require(:time_log)) def split_params parse_boolean [:round, :insert_new_before], - { - split_at: Time.parse(params[:split_at]), - insert_new_before: params[:insert_new_before], - round: params[:round] - } + { + split_at: Time.parse(params[:split_at]), + insert_new_before: params[:insert_new_before], + round: params[:round] + } end def time_booking_params(params_hash = params.require(:time_booking)) parse_boolean :round, params_hash.permit(:comments, :project_id, :issue_id, :activity_id, :round, - custom_field_values: custom_field_keys(params_hash)) + custom_field_values: custom_field_keys(params_hash)) end def time_log_from_id(id = params[:id]) diff --git a/spec/integration/time_bookings_spec.rb b/spec/integration/time_bookings_spec.rb index 8d7cc855..c773d2a2 100644 --- a/spec/integration/time_bookings_spec.rb +++ b/spec/integration/time_bookings_spec.rb @@ -90,7 +90,7 @@ tags 'Time bookings' parameter name: :id, in: :path, type: :string parameter name: :time_booking, in: :body, schema: { - '$ref' => '#/definitions/time_booking_params' + '$ref' => '#/definitions/time_booking_params' } let(:user) { create :user, :as_member, permissions: [:hourglass_edit_booked_time, :hourglass_view_booked_time] } @@ -98,7 +98,7 @@ time_booking = create :time_booking, project: user.projects.first, user: user time_booking.id end - let(:time_booking) { {time_booking: {comments: 'test2'}} } + let(:time_booking) { { time_booking: { comments: 'test2' } } } include_examples 'access rights', :hourglass_book_time, :hourglass_book_own_time, :hourglass_edit_booked_time, :hourglass_edit_own_booked_time, success_code: '204' @@ -107,7 +107,7 @@ let(:time_booking) do project = create :project create :member, project: project, user: user, permissions: [:hourglass_edit_booked_time, :hourglass_view_booked_time] - {time_booking: {project_id: project.id}} + { time_booking: { project_id: project.id } } end response '204', 'time booking found' do run_test! @@ -123,7 +123,7 @@ path '/time_bookings/bulk_destroy.json' do delete 'Deletes multiple time bookings at once' do tags 'Time bookings' - parameter name: :'time_bookings[]', in: :query, type: :array, items: {type: :string}, collectionFormat: :multi + parameter name: :'time_bookings[]', in: :query, type: :array, items: { type: :string }, collectionFormat: :multi let(:user) { create :user, :as_member, permissions: [:hourglass_edit_booked_time, :hourglass_view_booked_time] } let(:time_booking_ids) do @@ -147,7 +147,7 @@ consumes 'application/json' produces 'application/json' tags 'Time bookings' - parameter name: :time_bookings, in: :body, schema: {type: :object, additionalProperties: {'$ref' => '#/definitions/time_booking'}}, description: 'takes an object of time bookings' + parameter name: :time_bookings, in: :body, schema: { type: :object, additionalProperties: { '$ref' => '#/definitions/time_booking' } }, description: 'takes an object of time bookings' let(:user) { create :user, :as_member, permissions: [:hourglass_edit_booked_time, :hourglass_view_booked_time] } let(:time_booking_ids) do @@ -156,7 +156,7 @@ [tt1.id, tt2.id] end - let(:time_bookings) { {time_bookings: {time_booking_ids[0] => {comments: 'test3'}, time_booking_ids[1] => {comments: 'test4'}}} } + let(:time_bookings) { { time_bookings: { time_booking_ids[0] => { comments: 'test3' }, time_booking_ids[1] => { comments: 'test4' } } } } include_examples 'access rights', :hourglass_book_time, :hourglass_book_own_time, :hourglass_edit_booked_time, :hourglass_edit_own_booked_time @@ -176,17 +176,17 @@ consumes 'application/json' produces 'application/json' tags 'Time bookings' - parameter name: :time_bookings, in: :body, schema: {type: :array, items: {'$ref' => '#/definitions/time_booking'}}, description: 'takes an array of time bookings' + parameter name: :time_bookings, in: :body, schema: { type: :array, items: { '$ref' => '#/definitions/time_booking' } }, description: 'takes an array of time bookings' let(:user) { create :user, :as_member, permissions: [:hourglass_edit_booked_time] } let(:time_bookings) do { - time_bookings: [ - {user_id: user.id, project_id: user.projects.first.id, activity_id: create(:time_entry_activity).id, - start: Faker::Time.between(Date.today, Date.today, :morning), - stop: Faker::Time.between(Date.today, Date.today, :afternoon)} - ] + time_bookings: [ + { user_id: user.id, project_id: user.projects.first.id, activity_id: create(:time_entry_activity).id, + start: Faker::Time.between(Date.today, Date.today, :morning), + stop: Faker::Time.between(Date.today, Date.today, :afternoon) } + ] } end @@ -197,17 +197,17 @@ activity = create :time_entry_activity project = user.projects.first { - time_bookings: [ - {user_id: user.id, project_id: project.id, activity_id: activity.id, - start: Faker::Time.between(Date.today, Date.today, :morning), - stop: Faker::Time.between(Date.today, Date.today, :afternoon)}, - {user_id: create(:user).id, project_id: project.id, activity_id: activity.id, - start: Faker::Time.between(Date.today, Date.today, :morning), - stop: Faker::Time.between(Date.today, Date.today, :afternoon)}, - {user_id: create(:user).id, project_id: project.id, activity_id: activity.id, - start: Faker::Time.between(Date.today, Date.today, :morning), - stop: Faker::Time.between(Date.today, Date.today, :afternoon)} - ] + time_bookings: [ + { user_id: user.id, project_id: project.id, activity_id: activity.id, + start: Faker::Time.between(Date.today, Date.today, :morning), + stop: Faker::Time.between(Date.today, Date.today, :afternoon) }, + { user_id: create(:user).id, project_id: project.id, activity_id: activity.id, + start: Faker::Time.between(Date.today, Date.today, :morning), + stop: Faker::Time.between(Date.today, Date.today, :afternoon) }, + { user_id: create(:user).id, project_id: project.id, activity_id: activity.id, + start: Faker::Time.between(Date.today, Date.today, :morning), + stop: Faker::Time.between(Date.today, Date.today, :afternoon) } + ] } end run_test! diff --git a/spec/integration/time_logs_spec.rb b/spec/integration/time_logs_spec.rb index ed14dfe8..ebb66ed3 100644 --- a/spec/integration/time_logs_spec.rb +++ b/spec/integration/time_logs_spec.rb @@ -89,19 +89,19 @@ tags 'Time logs' parameter name: :id, in: :path, type: :string parameter name: :time_log, in: :body, schema: { - '$ref' => '#/definitions/time_log_update' + '$ref' => '#/definitions/time_log_update' } let(:user) { create :user, :as_member, permissions: [:hourglass_edit_tracked_time] } let(:existing_time_log) { create :time_log, user: user } let(:id) { existing_time_log.id } - let(:time_log) { {time_log: {comments: 'test2'}} } + let(:time_log) { { time_log: { comments: 'test2' } } } include_examples 'access rights', :hourglass_track_time, :hourglass_edit_tracked_time, :hourglass_edit_own_tracked_time, success_code: '204' include_examples 'not found' context do - let(:time_log) { {time_log: {stop: existing_time_log.stop + 1.hour}} } + let(:time_log) { { time_log: { stop: existing_time_log.stop + 1.hour } } } response '204', 'time log found' do run_test! @@ -120,15 +120,15 @@ tags 'Time logs' parameter name: :id, in: :path, type: :string parameter name: :time_booking, in: :body, schema: { - '$ref' => '#/definitions/time_booking_params' + '$ref' => '#/definitions/time_booking_params' } let(:user) { create :user, :as_member, permissions: [:hourglass_book_time] } let(:time_log) { create :time_log, user: user } let(:id) { time_log.id } - let(:time_booking) { {time_booking: { - project_id: user.projects.first.id, activity_id: create(:time_entry_activity).id - }} } + let(:time_booking) { { time_booking: { + project_id: user.projects.first.id, activity_id: create(:time_entry_activity).id + } } } include_examples 'access rights', :hourglass_book_time, :hourglass_book_own_time include_examples 'not found' @@ -169,14 +169,14 @@ response '200', 'time log found' do schema type: 'object', properties: { - time_log: { - '$ref' => '#/definitions/time_log', - required: %w(id start stop user_id created_at updated_at) - }, - new_time_log: { - '$ref' => '#/definitions/time_log', - required: %w(id start stop user_id created_at updated_at) - } + time_log: { + '$ref' => '#/definitions/time_log', + required: %w(id start stop user_id created_at updated_at) + }, + new_time_log: { + '$ref' => '#/definitions/time_log', + required: %w(id start stop user_id created_at updated_at) + } } include_examples 'has a valid response' @@ -195,7 +195,7 @@ post 'Joins multiple time logs' do produces 'application/json' tags 'Time logs' - parameter name: :'ids[]', in: :query, type: :array, items: {type: :integer}, collectionFormat: :multi + parameter name: :'ids[]', in: :query, type: :array, items: { type: :integer }, collectionFormat: :multi let(:user) { create :user, :as_member, permissions: [:hourglass_track_time] } let(:time_log) { create :time_log, user: user } @@ -211,10 +211,10 @@ response '200', 'time logs found' do schema type: 'object', properties: { - time_log: { - '$ref' => '#/definitions/time_log', - required: %w(id start stop user_id created_at updated_at) - } + time_log: { + '$ref' => '#/definitions/time_log', + required: %w(id start stop user_id created_at updated_at) + } } include_examples 'has a valid response' @@ -236,7 +236,7 @@ path '/time_logs/bulk_destroy.json' do delete 'Deletes multiple time logs at once' do tags 'Time logs' - parameter name: :'time_logs[]', in: :query, type: :array, items: {type: :string}, collectionFormat: :multi + parameter name: :'time_logs[]', in: :query, type: :array, items: { type: :string }, collectionFormat: :multi let(:user) { create :user, :as_member, permissions: [:hourglass_edit_tracked_time] } let(:time_log_ids) do @@ -260,7 +260,7 @@ consumes 'application/json' produces 'application/json' tags 'Time logs' - parameter name: :time_logs, in: :body, schema: {type: :object, additionalProperties: {'$ref' => '#/definitions/time_log'}}, description: 'takes an object of time logs' + parameter name: :time_logs, in: :body, schema: { type: :object, additionalProperties: { '$ref' => '#/definitions/time_log' } }, description: 'takes an object of time logs' let(:user) { create :user, :as_member, permissions: [:hourglass_edit_tracked_time, :hourglass_view_tracked_time] } let(:time_log_ids) do @@ -269,7 +269,7 @@ [tt1.id, tt2.id] end - let(:time_logs) { {time_logs: {time_log_ids[0] => {comments: 'test3'}, time_log_ids[1] => {comments: 'test4'}}} } + let(:time_logs) { { time_logs: { time_log_ids[0] => { comments: 'test3' }, time_log_ids[1] => { comments: 'test4' } } } } include_examples 'access rights', :hourglass_track_time, :hourglass_edit_tracked_time, :hourglass_edit_own_tracked_time @@ -289,7 +289,7 @@ consumes 'application/json' produces 'application/json' tags 'Time logs' - parameter name: :time_bookings, in: :body, schema: {type: :object, additionalProperties: {'$ref' => '#/definitions/time_booking'}}, description: 'takes an object of time bookings' + parameter name: :time_bookings, in: :body, schema: { type: :object, additionalProperties: { '$ref' => '#/definitions/time_booking' } }, description: 'takes an object of time bookings' let(:user) { create :user, :as_member, permissions: [:hourglass_book_time, :hourglass_view_tracked_time] } let(:time_logs) do @@ -300,9 +300,9 @@ let(:time_bookings) do tl1, tl2 = time_logs - {time_bookings: { - tl1.id => {project_id: tl1.user.projects.first.id, activity_id: create(:time_entry_activity).id}, - tl2.id => {} + { time_bookings: { + tl1.id => { project_id: tl1.user.projects.first.id, activity_id: create(:time_entry_activity).id }, + tl2.id => {} } } end @@ -324,15 +324,15 @@ consumes 'application/json' produces 'application/json' tags 'Time logs' - parameter name: :time_logs, in: :body, schema: {type: :array, items: {'$ref' => '#/definitions/time_log'}}, description: 'takes an array of time logs' + parameter name: :time_logs, in: :body, schema: { type: :array, items: { '$ref' => '#/definitions/time_log' } }, description: 'takes an array of time logs' let(:user) { create :user, :as_member, permissions: [:hourglass_edit_tracked_time] } let(:time_logs) do - {time_logs: [ - build(:time_log, user: user), - build(:time_log), - build(:time_log) + { time_logs: [ + build(:time_log, user: user), + build(:time_log), + build(:time_log) ] } end From b803986ba2316a94d8ac66750990def766ee2e84 Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Wed, 13 Mar 2019 10:56:10 +0100 Subject: [PATCH 09/14] * Fixed some pathing issues. * Fixed crashing bulk generation for previous versions. --- app/controllers/hourglass/api_base_controller.rb | 2 +- {lib => app/models/concerns}/hourglass/type_parsing.rb | 0 config/initializers/autoload.rb | 3 +-- 3 files changed, 2 insertions(+), 3 deletions(-) rename {lib => app/models/concerns}/hourglass/type_parsing.rb (100%) diff --git a/app/controllers/hourglass/api_base_controller.rb b/app/controllers/hourglass/api_base_controller.rb index 0f7802da..a30740d5 100644 --- a/app/controllers/hourglass/api_base_controller.rb +++ b/app/controllers/hourglass/api_base_controller.rb @@ -83,7 +83,7 @@ def bulk(params_key = controller_name, &block) @bulk_success = [] @bulk_errors = [] entries = params[params_key] - entries = entries.to_unsafe_h if entries.instance_of?(ActionController::Parameters) + entries = entries.to_unsafe_h if Rails::VERSION::MAJOR >= 5 && entries.instance_of?(ActionController::Parameters) entries.each_with_index do |(id, params), index| if Rails::VERSION::MAJOR <= 4 id, params = "new#{index}", id if id.is_a?(Hash) diff --git a/lib/hourglass/type_parsing.rb b/app/models/concerns/hourglass/type_parsing.rb similarity index 100% rename from lib/hourglass/type_parsing.rb rename to app/models/concerns/hourglass/type_parsing.rb diff --git a/config/initializers/autoload.rb b/config/initializers/autoload.rb index 9166ea89..e73ebf10 100644 --- a/config/initializers/autoload.rb +++ b/config/initializers/autoload.rb @@ -2,8 +2,7 @@ %w(app models concerns), %w(app controllers concerns), %w(app policies), - %w(app policies concerns), - %w(lib hourglass) + %w(app policies concerns) ].each do |path| ActiveSupport::Dependencies.autoload_paths << File.join(Hourglass::PLUGIN_ROOT, *path) end From 6b088d42aded7ad926152c82a9f48ccfbd685d22 Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Wed, 13 Mar 2019 11:47:36 +0100 Subject: [PATCH 10/14] * Fixed TypeParsing concern. --- app/models/concerns/hourglass/type_parsing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/hourglass/type_parsing.rb b/app/models/concerns/hourglass/type_parsing.rb index 85fc988e..1d8b09d1 100644 --- a/app/models/concerns/hourglass/type_parsing.rb +++ b/app/models/concerns/hourglass/type_parsing.rb @@ -1,4 +1,4 @@ -module TypeParsing +module Hourglass::TypeParsing def parse_type(type, attribute) if Rails::VERSION::MAJOR <= 4 case type From 12cd4f957c0fa9f93ad7dea7630daf4fce5060ef Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Wed, 13 Mar 2019 12:35:03 +0100 Subject: [PATCH 11/14] * Added ruby 2.3 with redmine 4 to travis automated testing. * Set allowed failures to only ruby v2.6.1. --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 909e85b5..24c38467 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,6 +55,10 @@ matrix: env: - REDMINE_VERSION=3.4.9 + - name: Ruby 2.3 / Redmine 4 + rvm: 2.3.8 + env: + - REDMINE_VERSION=4.0.2 - name: Ruby 2.5 / Redmine 4 rvm: 2.5.3 @@ -68,8 +72,7 @@ matrix: fast_finish: true allow_failures: - - env: - - REDMINE_VERSION=4.0.2 + - rvm: 2.6.1 before_install: - source .travis/clone_redmine.sh From 777fab73515b025850c6625d4e7af6883e4331d4 Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Wed, 13 Mar 2019 14:58:48 +0100 Subject: [PATCH 12/14] * Fixed required form select generation including a blank value. --- app/views/hourglass_ui/forms/fields/_activity.slim | 2 +- app/views/hourglass_ui/forms/fields/_project.slim | 2 +- app/views/hourglass_ui/forms/fields/_user_id.slim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/hourglass_ui/forms/fields/_activity.slim b/app/views/hourglass_ui/forms/fields/_activity.slim index bffcc788..b731bb77 100644 --- a/app/views/hourglass_ui/forms/fields/_activity.slim +++ b/app/views/hourglass_ui/forms/fields/_activity.slim @@ -2,4 +2,4 @@ .label = form.label :activity_id .input - = form.collection_select :activity_id, TimeEntryActivity.applicable(entry.project), :id, :name, {include_blank: !local_assigns[:required]}, disabled: local_assigns[:disabled], required: local_assigns[:required] + = form.collection_select :activity_id, TimeEntryActivity.applicable(entry.project), :id, :name, { include_blank: true }, disabled: local_assigns[:disabled], required: local_assigns[:required] diff --git a/app/views/hourglass_ui/forms/fields/_project.slim b/app/views/hourglass_ui/forms/fields/_project.slim index 6af5e777..3da40bd2 100644 --- a/app/views/hourglass_ui/forms/fields/_project.slim +++ b/app/views/hourglass_ui/forms/fields/_project.slim @@ -4,4 +4,4 @@ - if local_assigns[:with_link] = link_to '', project_path(id: entry.project_id || ''), class: css_classes('icon icon-link', ('hidden' unless entry.project)) .input - = form.select :project_id, projects_for_project_select(entry.project), {include_blank: !local_assigns[:required]}, disabled: local_assigns[:disabled], required: local_assigns[:required] + = form.select :project_id, projects_for_project_select(entry.project), { include_blank: true }, disabled: local_assigns[:disabled], required: local_assigns[:required] diff --git a/app/views/hourglass_ui/forms/fields/_user_id.slim b/app/views/hourglass_ui/forms/fields/_user_id.slim index 27fadb1c..569b1cbc 100644 --- a/app/views/hourglass_ui/forms/fields/_user_id.slim +++ b/app/views/hourglass_ui/forms/fields/_user_id.slim @@ -3,4 +3,4 @@ = form.label :user_id .input - project = entry && entry.respond_to?(:project) && entry.project || nil - = form.select :user_id, options_from_collection_for_select(user_collection(project), :id, :name, entry.user_id || User.current.id), {include_blank: !local_assigns[:required]}, disabled: local_assigns[:disabled], required: local_assigns[:required] + = form.select :user_id, options_from_collection_for_select(user_collection(project), :id, :name, entry.user_id || User.current.id), { include_blank: true }, disabled: local_assigns[:disabled], required: local_assigns[:required] From 21c0a6d7799adbc0ef4037ff700f8ea88304778a Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Thu, 14 Mar 2019 09:22:22 +0100 Subject: [PATCH 13/14] * Added auto generated .ruby-version to gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f71b3c03..85098ddc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ Gemfile.lock tmp/rubycritic/ /.bundle +.ruby-version From 4fb5e5c9f8085bbfd4a1d14e5d2991fcbd98c955 Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Thu, 14 Mar 2019 12:38:07 +0100 Subject: [PATCH 14/14] * Fixed icons of context menus. --- app/views/hourglass_ui/time_bookings/context_menu.slim | 4 ++-- app/views/hourglass_ui/time_logs/context_menu.slim | 10 +++++----- app/views/hourglass_ui/time_trackers/context_menu.slim | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/views/hourglass_ui/time_bookings/context_menu.slim b/app/views/hourglass_ui/time_bookings/context_menu.slim index bbc8be85..f7074692 100644 --- a/app/views/hourglass_ui/time_bookings/context_menu.slim +++ b/app/views/hourglass_ui/time_bookings/context_menu.slim @@ -1,6 +1,6 @@ - ids = @records.map(&:id) ul - li = context_menu_link t(:button_edit), hourglass_ui_bulk_edit_time_bookings_path(ids: ids), class: 'icon-edit js-show-inline-form-multi', title: t(:button_edit), remote: true, data: {type: 'html'}, disabled: !@records.all? { |time_booking| policy(time_booking).change? } - li = context_menu_link t(:button_delete), @records.length == 1 ? hourglass_time_booking_path(@records.first) : bulk_destroy_hourglass_time_bookings_path(time_bookings: ids), class: 'icon-del js-hourglass-remote', title: t(:button_delete), remote: true, method: :delete, data: {confirm: t(:text_are_you_sure)}, disabled: !@records.all? { |time_booking| policy(time_booking).destroy? } + li = context_menu_link t(:button_edit), hourglass_ui_bulk_edit_time_bookings_path(ids: ids), class: 'icon icon-edit js-show-inline-form-multi', title: t(:button_edit), remote: true, data: {type: 'html'}, disabled: !@records.all? { |time_booking| policy(time_booking).change? } + li = context_menu_link t(:button_delete), @records.length == 1 ? hourglass_time_booking_path(@records.first) : bulk_destroy_hourglass_time_bookings_path(time_bookings: ids), class: 'icon icon-del js-hourglass-remote', title: t(:button_delete), remote: true, method: :delete, data: {confirm: t(:text_are_you_sure)}, disabled: !@records.all? { |time_booking| policy(time_booking).destroy? } diff --git a/app/views/hourglass_ui/time_logs/context_menu.slim b/app/views/hourglass_ui/time_logs/context_menu.slim index a23ab536..0a7d3188 100644 --- a/app/views/hourglass_ui/time_logs/context_menu.slim +++ b/app/views/hourglass_ui/time_logs/context_menu.slim @@ -1,8 +1,8 @@ - ids = @records.map(&:id) ul - li = context_menu_link t('hourglass.ui.lists.button_book'), hourglass_ui_bulk_book_time_logs_path(ids: ids), class: 'icon-time js-show-inline-form-multi', title: t('hourglass.ui.lists.button_book'), remote: true, data: {type: 'html'}, disabled: !@records.all? { |time_log| policy(time_log).book? } - li = context_menu_link t(:button_edit), hourglass_ui_bulk_edit_time_logs_path(ids: ids), class: 'icon-edit js-show-inline-form-multi', title: t(:button_edit), remote: true, data: {type: 'html'}, disabled: !@records.all? { |time_log| policy(time_log).change? } - li = context_menu_link t(:button_delete), @records.length == 1 ? hourglass_time_log_path(@records.first) : bulk_destroy_hourglass_time_logs_path(time_logs: ids), class: 'icon-del js-hourglass-remote', title: t(:button_delete), remote: true, method: :delete, data: {confirm: t(:text_are_you_sure)}, disabled: !@records.all? { |time_log| policy(time_log).destroy? } - li = context_menu_link t('hourglass.ui.time_logs.button_join'), join_hourglass_time_logs_path(ids: ids), class: 'icon-hourglass-join js-hourglass-remote', title: t('hourglass.ui.time_logs.button_join'), remote: true, data: {method: 'post'}, disabled: ids.length == 1 || !@records.all? { |time_log| policy(time_log).join? } && Hourglass::TimeLog.joinable?(*ids) + li = context_menu_link t('hourglass.ui.lists.button_book'), hourglass_ui_bulk_book_time_logs_path(ids: ids), class: 'icon icon-time js-show-inline-form-multi', title: t('hourglass.ui.lists.button_book'), remote: true, data: {type: 'html'}, disabled: !@records.all? { |time_log| policy(time_log).book? } + li = context_menu_link t(:button_edit), hourglass_ui_bulk_edit_time_logs_path(ids: ids), class: 'icon icon-edit js-show-inline-form-multi', title: t(:button_edit), remote: true, data: {type: 'html'}, disabled: !@records.all? { |time_log| policy(time_log).change? } + li = context_menu_link t(:button_delete), @records.length == 1 ? hourglass_time_log_path(@records.first) : bulk_destroy_hourglass_time_logs_path(time_logs: ids), class: 'icon icon-del js-hourglass-remote', title: t(:button_delete), remote: true, method: :delete, data: {confirm: t(:text_are_you_sure)}, disabled: !@records.all? { |time_log| policy(time_log).destroy? } + li = context_menu_link t('hourglass.ui.time_logs.button_join'), join_hourglass_time_logs_path(ids: ids), class: 'icon icon-hourglass-join js-hourglass-remote', title: t('hourglass.ui.time_logs.button_join'), remote: true, data: {method: 'post'}, disabled: ids.length == 1 || !@records.all? { |time_log| policy(time_log).join? } && Hourglass::TimeLog.joinable?(*ids) - time_bookings = @records.map(&:time_booking).compact - li = context_menu_link t('hourglass.ui.lists.button_delete_booking'), time_bookings.length == 1 ? hourglass_time_booking_path(time_bookings.first) : bulk_destroy_hourglass_time_bookings_path(time_bookings: time_bookings.map(&:id)), class: 'icon-del js-hourglass-remote', title: t('hourglass.ui.lists.button_delete_booking'), remote: true, method: :delete, data: {confirm: t(:text_are_you_sure)}, disabled: !time_bookings.present? || !time_bookings.all? { |time_booking| policy(time_booking).destroy? } + li = context_menu_link t('hourglass.ui.lists.button_delete_booking'), time_bookings.length == 1 ? hourglass_time_booking_path(time_bookings.first) : bulk_destroy_hourglass_time_bookings_path(time_bookings: time_bookings.map(&:id)), class: 'icon icon-del js-hourglass-remote', title: t('hourglass.ui.lists.button_delete_booking'), remote: true, method: :delete, data: {confirm: t(:text_are_you_sure)}, disabled: !time_bookings.present? || !time_bookings.all? { |time_booking| policy(time_booking).destroy? } diff --git a/app/views/hourglass_ui/time_trackers/context_menu.slim b/app/views/hourglass_ui/time_trackers/context_menu.slim index 1bc9fe30..9db28d6f 100644 --- a/app/views/hourglass_ui/time_trackers/context_menu.slim +++ b/app/views/hourglass_ui/time_trackers/context_menu.slim @@ -1,4 +1,4 @@ - ids = @records.map(&:id) ul - li = context_menu_link t(:button_edit), hourglass_ui_bulk_edit_time_trackers_path(ids: ids), class: 'icon-edit js-show-inline-form-multi', title: t(:button_edit), remote: true, data: {type: 'html'}, disabled: !@records.all? { |time_tracker| policy(time_tracker).change? } - li = context_menu_link t(:button_delete), @records.length == 1 ? hourglass_time_tracker_path(@records.first) : bulk_destroy_hourglass_time_trackers_path(time_trackers: ids), class: 'icon-del js-hourglass-remote', title: t(:button_delete), remote: true, method: :delete, data: {confirm: t(:text_are_you_sure)}, disabled: !@records.all? { |time_tracker| policy(time_tracker).destroy? } + li = context_menu_link t(:button_edit), hourglass_ui_bulk_edit_time_trackers_path(ids: ids), class: 'icon icon-edit js-show-inline-form-multi', title: t(:button_edit), remote: true, data: {type: 'html'}, disabled: !@records.all? { |time_tracker| policy(time_tracker).change? } + li = context_menu_link t(:button_delete), @records.length == 1 ? hourglass_time_tracker_path(@records.first) : bulk_destroy_hourglass_time_trackers_path(time_trackers: ids), class: 'icon icon-del js-hourglass-remote', title: t(:button_delete), remote: true, method: :delete, data: {confirm: t(:text_are_you_sure)}, disabled: !@records.all? { |time_tracker| policy(time_tracker).destroy? }