Create RemoteTranslation model

- Each RemoteTranslation is associated with a resource (through polymorphic)
  and has the locale to we want translate.
- After create a RemoteTranslation we create a enqueue_remote_translation
  method that will be send remote translation instance to remote translation
  client
This commit is contained in:
taitus
2019-01-25 15:00:52 +01:00
committed by voodoorai2000
parent 25e9c358ad
commit 04810f5080
5 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
class RemoteTranslation < ApplicationRecord
belongs_to :remote_translatable, polymorphic: true
validates :remote_translatable_id, presence: true
validates :remote_translatable_type, presence: true
validates :locale, presence: true
after_create :enqueue_remote_translation
def enqueue_remote_translation
end
end

View File

@@ -0,0 +1,12 @@
class CreateRemoteTranslations < ActiveRecord::Migration[4.2]
def change
create_table :remote_translations do |t|
t.string :locale
t.integer :remote_translatable_id
t.string :remote_translatable_type
t.text :error_message
t.timestamps null: false
end
end
end

View File

@@ -1400,6 +1400,15 @@ ActiveRecord::Schema.define(version: 20190607160900) do
t.index ["related_content_id"], name: "opposite_related_content", using: :btree
end
create_table "remote_translations", force: :cascade do |t|
t.string "locale"
t.integer "remote_translatable_id"
t.string "remote_translatable_type"
t.text "error_message"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "reports", force: :cascade do |t|
t.boolean "stats"
t.boolean "results"

View File

@@ -0,0 +1,5 @@
FactoryBot.define do
factory :remote_translation do
association :remote_translatable, factory: :debate
end
end

View File

@@ -0,0 +1,32 @@
require "rails_helper"
describe RemoteTranslation do
let(:remote_translation) { build(:remote_translation, locale: :es) }
it "is valid" do
expect(remote_translation).to be_valid
end
it "is valid without error_message" do
remote_translation.error_message = nil
expect(remote_translation).to be_valid
end
it "is not valid without to" do
remote_translation.locale = nil
expect(remote_translation).not_to be_valid
end
it "is not valid without a remote_translatable_id" do
remote_translation.remote_translatable_id = nil
expect(remote_translation).not_to be_valid
end
it "is not valid without a remote_translatable_type" do
remote_translation.remote_translatable_type = nil
expect(remote_translation).not_to be_valid
end
end
end