diff --git a/app/models/comment.rb b/app/models/comment.rb index e5b83e818..e80a5e048 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -18,7 +18,10 @@ class Comment < ApplicationRecord attr_accessor :as_moderator, :as_administrator - validates :body, presence: true + translates :body, touch: true + include Globalizable + + validates_translation :body, presence: true validates :user, presence: true validates :commentable_type, inclusion: { in: COMMENTABLE_TYPES } diff --git a/db/migrate/20181205102153_add_comments_translations.rb b/db/migrate/20181205102153_add_comments_translations.rb new file mode 100644 index 000000000..a7ea1b64c --- /dev/null +++ b/db/migrate/20181205102153_add_comments_translations.rb @@ -0,0 +1,14 @@ +class AddCommentsTranslations < ActiveRecord::Migration[4.2] + def self.up + Comment.create_translation_table!( + { + body: :text + }, + { migrate_data: true } + ) + end + + def self.down + Comment.drop_translation_table! + end +end diff --git a/db/schema.rb b/db/schema.rb index 90b287745..c2e6c60af 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -415,6 +415,16 @@ ActiveRecord::Schema.define(version: 20190607160900) do t.index ["type"], name: "index_ckeditor_assets_on_type", using: :btree end + create_table "comment_translations", force: :cascade do |t| + t.integer "comment_id", null: false + t.string "locale", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "body" + t.index ["comment_id"], name: "index_comment_translations_on_comment_id", using: :btree + t.index ["locale"], name: "index_comment_translations_on_locale", using: :btree + end + create_table "comments", force: :cascade do |t| t.integer "commentable_id" t.string "commentable_type" diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 59b016e13..fac612404 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -5,6 +5,7 @@ describe Comment do let(:comment) { build(:comment) } it_behaves_like "has_public_author" + it_behaves_like "globalizable", :comment it "is valid" do expect(comment).to be_valid