summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-07-23 11:40:14 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-07-23 11:40:14 +0000
commitb99c3caae8b40df163612e5d1461705a9d16fdb2 (patch)
tree8de5b9441746ff67e5a342eb12cf72fd4a468c3c
parentd74f0bfd5c53962e332c2dd4d30dafaa1105b92b (diff)
downloadredmine-b99c3caae8b40df163612e5d1461705a9d16fdb2.tar.gz
redmine-b99c3caae8b40df163612e5d1461705a9d16fdb2.zip
Renames column comments.comments to comments.content to please Rails 5.1 (#23630).
git-svn-id: http://svn.redmine.org/redmine/trunk@16860 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/comment.rb10
-rw-r--r--config/initializers/10-patches.rb24
-rw-r--r--db/migrate/20170723112801_rename_comments_to_content.rb5
-rw-r--r--test/fixtures/comments.yml4
4 files changed, 16 insertions, 27 deletions
diff --git a/app/models/comment.rb b/app/models/comment.rb
index e29b574c1..3b2044123 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -20,12 +20,20 @@ class Comment < ActiveRecord::Base
belongs_to :commented, :polymorphic => true, :counter_cache => true
belongs_to :author, :class_name => 'User'
- validates_presence_of :commented, :author, :comments
+ validates_presence_of :commented, :author, :content
after_create :send_notification
safe_attributes 'comments'
+ def comments=(arg)
+ self.content = arg
+ end
+
+ def comments
+ content
+ end
+
private
def send_notification
diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb
index 13efe0cb5..e98fa9cf3 100644
--- a/config/initializers/10-patches.rb
+++ b/config/initializers/10-patches.rb
@@ -27,30 +27,6 @@ module ActiveRecord
end
end
class Relation ; undef open ; end
-
- # Workaround for a Rails 5.1 regression that breaks queries with a condition
- # on a table that has a column with the same name as the table
- # (eg. comments.comments). It breaks has_many associations to these tables as well.
- # https://github.com/rails/rails/commit/c6a62dc327c54baec87306f5c381e13cacc00a19
- #
- # Examples (without the following workaround applied):
- # Comment.where(:comments => {:id => 1})
- # TypeError: can't cast Hash
- #
- # News.first.comments.count
- # TypeError: can't cast Hash
- class PredicateBuilder
-
- protected
- alias :create_binds_for_hash_without_comments_fix :create_binds_for_hash
- def create_binds_for_hash(attributes)
- if attributes["comments"].is_a?(Hash)
- return create_binds_for_hash_without_comments_fix attributes["comments"]
- else
- create_binds_for_hash_without_comments_fix attributes
- end
- end
- end
end
module ActionView
diff --git a/db/migrate/20170723112801_rename_comments_to_content.rb b/db/migrate/20170723112801_rename_comments_to_content.rb
new file mode 100644
index 000000000..6c014286d
--- /dev/null
+++ b/db/migrate/20170723112801_rename_comments_to_content.rb
@@ -0,0 +1,5 @@
+class RenameCommentsToContent < ActiveRecord::Migration[5.1]
+ def change
+ rename_column :comments, :comments, :content
+ end
+end
diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml
index 8b87d5b62..3e97b6d94 100644
--- a/test/fixtures/comments.yml
+++ b/test/fixtures/comments.yml
@@ -4,7 +4,7 @@ comments_001:
commented_id: 1
id: 1
author_id: 1
- comments: my first comment
+ content: my first comment
created_on: 2006-12-10 18:10:10 +01:00
updated_on: 2006-12-10 18:10:10 +01:00
comments_002:
@@ -12,6 +12,6 @@ comments_002:
commented_id: 1
id: 2
author_id: 2
- comments: This is an other comment
+ content: This is an other comment
created_on: 2006-12-10 18:12:10 +01:00
updated_on: 2006-12-10 18:12:10 +01:00