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:
14
app/models/remote_translation.rb
Normal file
14
app/models/remote_translation.rb
Normal 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
|
||||||
12
db/migrate/20181205191300_create_remote_translations.rb
Normal file
12
db/migrate/20181205191300_create_remote_translations.rb
Normal 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
|
||||||
@@ -1400,6 +1400,15 @@ ActiveRecord::Schema.define(version: 20190607160900) do
|
|||||||
t.index ["related_content_id"], name: "opposite_related_content", using: :btree
|
t.index ["related_content_id"], name: "opposite_related_content", using: :btree
|
||||||
end
|
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|
|
create_table "reports", force: :cascade do |t|
|
||||||
t.boolean "stats"
|
t.boolean "stats"
|
||||||
t.boolean "results"
|
t.boolean "results"
|
||||||
|
|||||||
5
spec/factories/remote_translations.rb
Normal file
5
spec/factories/remote_translations.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
FactoryBot.define do
|
||||||
|
factory :remote_translation do
|
||||||
|
association :remote_translatable, factory: :debate
|
||||||
|
end
|
||||||
|
end
|
||||||
32
spec/models/remote_translation_spec.rb
Normal file
32
spec/models/remote_translation_spec.rb
Normal 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
|
||||||
Reference in New Issue
Block a user