summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-07-23 11:26:04 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-07-23 11:26:04 +0000
commitd74f0bfd5c53962e332c2dd4d30dafaa1105b92b (patch)
treef3eaf66d67c3a87fb34340561bf188d364de623c /lib
parent41bb302594b48152b87c92f196c915f499093bbf (diff)
downloadredmine-d74f0bfd5c53962e332c2dd4d30dafaa1105b92b.tar.gz
redmine-d74f0bfd5c53962e332c2dd4d30dafaa1105b92b.zip
Merged rails-5.1 branch (#23630).
git-svn-id: http://svn.redmine.org/redmine/trunk@16859 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r--lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb6
-rw-r--r--lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb1
-rw-r--r--lib/redmine/acts/positioned.rb19
-rw-r--r--lib/redmine/field_format.rb6
-rw-r--r--lib/redmine/safe_attributes.rb4
-rw-r--r--lib/redmine/sudo_mode.rb2
-rw-r--r--lib/tasks/redmine.rake28
-rw-r--r--lib/tasks/testing.rake30
8 files changed, 49 insertions, 47 deletions
diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
index 36996c950..3cfc49169 100644
--- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -68,6 +68,10 @@ module Redmine
end
def save_attachments(attachments, author=User.current)
+ if attachments.respond_to?(:to_unsafe_hash)
+ attachments = attachments.to_unsafe_hash
+ end
+
if attachments.is_a?(Hash)
attachments = attachments.stringify_keys
attachments = attachments.to_a.sort {|a, b|
@@ -86,7 +90,7 @@ module Redmine
if attachments.is_a?(Array)
@failed_attachment_count = 0
attachments.each do |attachment|
- next unless attachment.is_a?(Hash)
+ next unless attachment.present?
a = nil
if file = attachment['file']
a = Attachment.create(:file => file, :author => author)
diff --git a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
index 2bddd64b7..5c88adb57 100644
--- a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
+++ b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
@@ -17,7 +17,6 @@ module Redmine
joins(:watchers).
where("#{Watcher.table_name}.user_id = ?", user_id)
}
- attr_protected :watcher_ids, :watcher_user_ids
end
send :include, Redmine::Acts::Watchable::InstanceMethods
end
diff --git a/lib/redmine/acts/positioned.rb b/lib/redmine/acts/positioned.rb
index 21cc14a67..00f8332b8 100644
--- a/lib/redmine/acts/positioned.rb
+++ b/lib/redmine/acts/positioned.rb
@@ -54,7 +54,9 @@ module Redmine
end
def position_scope_was
- build_position_scope {|c| send("#{c}_was")}
+ # this can be called in after_update or after_destroy callbacks
+ # with different methods in Rails 5 for retrieving the previous value
+ build_position_scope {|c| send(destroyed? ? "#{c}_was" : "#{c}_before_last_save")}
end
def build_position_scope
@@ -75,8 +77,8 @@ module Redmine
if !new_record? && position_scope_changed?
remove_position
insert_position
- elsif position_changed?
- if position_was.nil?
+ elsif saved_change_to_position?
+ if position_before_last_save.nil?
insert_position
else
shift_positions
@@ -89,16 +91,19 @@ module Redmine
end
def remove_position
- position_scope_was.where("position >= ? AND id <> ?", position_was, id).update_all("position = position - 1")
+ # this can be called in after_update or after_destroy callbacks
+ # with different methods in Rails 5 for retrieving the previous value
+ previous = destroyed? ? position_was : position_before_last_save
+ position_scope_was.where("position >= ? AND id <> ?", previous, id).update_all("position = position - 1")
end
def position_scope_changed?
- (changed & self.class.positioned_options[:scope].map(&:to_s)).any?
+ (saved_changes.keys & self.class.positioned_options[:scope].map(&:to_s)).any?
end
def shift_positions
- offset = position_was <=> position
- min, max = [position, position_was].sort
+ offset = position_before_last_save <=> position
+ min, max = [position, position_before_last_save].sort
r = position_scope.where("id <> ? AND position BETWEEN ? AND ?", id, min, max).update_all("position = position + #{offset}")
if r != max - min
reset_positions_in_list
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb
index fade7c257..b59760674 100644
--- a/lib/redmine/field_format.rb
+++ b/lib/redmine/field_format.rb
@@ -972,7 +972,7 @@ module Redmine
end
def after_save_custom_value(custom_field, custom_value)
- if custom_value.value_changed?
+ if custom_value.saved_change_to_value?
if custom_value.value.present?
attachment = Attachment.where(:id => custom_value.value.to_s).first
if attachment
@@ -980,8 +980,8 @@ module Redmine
attachment.save!
end
end
- if custom_value.value_was.present?
- attachment = Attachment.where(:id => custom_value.value_was.to_s).first
+ if custom_value.value_before_last_save.present?
+ attachment = Attachment.where(:id => custom_value.value_before_last_save.to_s).first
if attachment
attachment.destroy
end
diff --git a/lib/redmine/safe_attributes.rb b/lib/redmine/safe_attributes.rb
index 0bde0f970..a2711cc4b 100644
--- a/lib/redmine/safe_attributes.rb
+++ b/lib/redmine/safe_attributes.rb
@@ -80,6 +80,10 @@ module Redmine
# Sets attributes from attrs that are safe
# attrs is a Hash with string keys
def safe_attributes=(attrs, user=User.current)
+ if attrs.respond_to?(:to_unsafe_hash)
+ attrs = attrs.to_unsafe_hash
+ end
+
return unless attrs.is_a?(Hash)
self.attributes = delete_unsafe_attributes(attrs, user)
end
diff --git a/lib/redmine/sudo_mode.rb b/lib/redmine/sudo_mode.rb
index eddbc04ce..fa491b759 100644
--- a/lib/redmine/sudo_mode.rb
+++ b/lib/redmine/sudo_mode.rb
@@ -31,7 +31,7 @@ module Redmine
#
# taken from https://github.com/brianhempel/hash_to_hidden_fields
def hash_to_hidden_fields(hash)
- cleaned_hash = hash.reject { |k, v| v.nil? }
+ cleaned_hash = hash.to_unsafe_h.reject { |k, v| v.nil? }
pairs = cleaned_hash.to_query.split(Rack::Utils::DEFAULT_SEP)
tags = pairs.map do |pair|
key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) }
diff --git a/lib/tasks/redmine.rake b/lib/tasks/redmine.rake
index fa4b02b33..30d5c4c64 100644
--- a/lib/tasks/redmine.rake
+++ b/lib/tasks/redmine.rake
@@ -160,31 +160,27 @@ DESC
namespace :test do
desc 'Runs the plugins unit tests.'
- Rake::TestTask.new :units => "db:test:prepare" do |t|
- t.libs << "test"
- t.verbose = true
- t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/unit/**/*_test.rb"
+ task :units => "db:test:prepare" do |t|
+ $: << "test"
+ Minitest.rake_run ["plugins/#{ENV['NAME'] || '*'}/test/unit/**/*_test.rb"]
end
desc 'Runs the plugins functional tests.'
- Rake::TestTask.new :functionals => "db:test:prepare" do |t|
- t.libs << "test"
- t.verbose = true
- t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/functional/**/*_test.rb"
+ task :functionals => "db:test:prepare" do |t|
+ $: << "test"
+ Minitest.rake_run ["plugins/#{ENV['NAME'] || '*'}/test/functional/**/*_test.rb"]
end
desc 'Runs the plugins integration tests.'
- Rake::TestTask.new :integration => "db:test:prepare" do |t|
- t.libs << "test"
- t.verbose = true
- t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/integration/**/*_test.rb"
+ task :integration => "db:test:prepare" do |t|
+ $: << "test"
+ Minitest.rake_run ["plugins/#{ENV['NAME'] || '*'}/test/integration/**/*_test.rb"]
end
desc 'Runs the plugins ui tests.'
- Rake::TestTask.new :ui => "db:test:prepare" do |t|
- t.libs << "test"
- t.verbose = true
- t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/ui/**/*_test.rb"
+ task :ui => "db:test:prepare" do |t|
+ $: << "test"
+ Minitest.rake_run ["plugins/#{ENV['NAME'] || '*'}/test/ui/**/*_test.rb"]
end
end
end
diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake
index 831f4d316..47364c82c 100644
--- a/lib/tasks/testing.rake
+++ b/lib/tasks/testing.rake
@@ -79,34 +79,28 @@ namespace :test do
end
end
- Rake::TestTask.new(:units => "db:test:prepare") do |t|
- t.libs << "test"
- t.verbose = true
- t.warning = false
- t.test_files = FileList['test/unit/repository*_test.rb'] + FileList['test/unit/lib/redmine/scm/**/*_test.rb']
+ task(:units => "db:test:prepare") do |t|
+ $: << "test"
+ Minitest.rake_run FileList['test/unit/repository*_test.rb'] + FileList['test/unit/lib/redmine/scm/**/*_test.rb']
end
Rake::Task['test:scm:units'].comment = "Run the scm unit tests"
- Rake::TestTask.new(:functionals => "db:test:prepare") do |t|
- t.libs << "test"
- t.verbose = true
- t.warning = false
- t.test_files = FileList['test/functional/repositories*_test.rb']
+ task(:functionals => "db:test:prepare") do |t|
+ $: << "test"
+ Minitest.rake_run FileList['test/functional/repositories*_test.rb']
end
Rake::Task['test:scm:functionals'].comment = "Run the scm functional tests"
end
- Rake::TestTask.new(:routing) do |t|
- t.libs << "test"
- t.verbose = true
- t.test_files = FileList['test/integration/routing/*_test.rb'] + FileList['test/integration/api_test/*_routing_test.rb']
+ task(:routing) do |t|
+ $: << "test"
+ Minitest.rake_run FileList['test/integration/routing/*_test.rb'] + FileList['test/integration/api_test/*_routing_test.rb']
end
Rake::Task['test:routing'].comment = "Run the routing tests"
- Rake::TestTask.new(:ui => "db:test:prepare") do |t|
- t.libs << "test"
- t.verbose = true
- t.test_files = FileList['test/ui/**/*_test_ui.rb']
+ task(:ui => "db:test:prepare") do |t|
+ $: << "test"
+ Minitest.rake_run FileList['test/ui/**/*_test_ui.rb']
end
Rake::Task['test:ui'].comment = "Run the UI tests with Capybara (PhantomJS listening on port 4444 is required)"
end