summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb11
-rw-r--r--lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb15
2 files changed, 13 insertions, 13 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 bc4242564..2e5fc841c 100644
--- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -34,6 +34,7 @@ module Redmine
options.merge(:as => :container, :dependent => :destroy, :inverse_of => :container)
send :include, Redmine::Acts::Attachable::InstanceMethods
before_save :attach_saved_attachments
+ after_rollback :detach_saved_attachments
validate :warn_about_failed_attachments
end
end
@@ -90,7 +91,7 @@ module Redmine
if file = attachment['file']
next unless file.size > 0
a = Attachment.create(:file => file, :author => author)
- elsif token = attachment['token']
+ elsif token = attachment['token'].presence
a = Attachment.find_by_token(token)
unless a
@failed_attachment_count += 1
@@ -117,6 +118,14 @@ module Redmine
end
end
+ def detach_saved_attachments
+ saved_attachments.each do |attachment|
+ # TODO: use #reload instead, after upgrading to Rails 5
+ # (after_rollback is called when running transactional tests in Rails 4)
+ attachment.container = nil
+ end
+ end
+
def warn_about_failed_attachments
if @failed_attachment_count && @failed_attachment_count > 0
errors.add :base, ::I18n.t('warning_attachments_not_saved', count: @failed_attachment_count)
diff --git a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index f9da79c22..fb5edf0fc 100644
--- a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -68,16 +68,7 @@ module Redmine
custom_field_values.each do |custom_field_value|
key = custom_field_value.custom_field_id.to_s
if values.has_key?(key)
- value = values[key]
- if value.is_a?(Array)
- value = value.reject(&:blank?).map(&:to_s).uniq
- if value.empty?
- value << ''
- end
- else
- value = value.to_s
- end
- custom_field_value.value = value
+ custom_field_value.value = values[key]
end
end
@custom_field_values_changed = true
@@ -93,11 +84,11 @@ module Redmine
if values.empty?
values << custom_values.build(:customized => self, :custom_field => field)
end
- x.value = values.map(&:value)
+ x.instance_variable_set("@value", values.map(&:value))
else
cv = custom_values.detect { |v| v.custom_field == field }
cv ||= custom_values.build(:customized => self, :custom_field => field)
- x.value = cv.value
+ x.instance_variable_set("@value", cv.value)
end
x.value_was = x.value.dup if x.value
x