Sha256: b28555a4f9fe4f7eed53abab4ebf3d94d2d029250a516d9678e6e866b40c6620

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# -*- coding: utf-8 -*-
require 'rails_helper'

describe User do
  describe 'factory' do
    it { expect(build(:user)).to be_valid }
  end

  describe 'nested_attributes_for' do
    let(:user) do
      User.create(
        first_names_attributes: [{ locale: 'ja', value: 'ジョン' }, { locale: 'en', value: 'John' }],
        last_names_attributes: [{ locale: 'ja', value: 'レノン' }, { locale: 'en', value: 'Lennon' }]
        )
    end
    it { expect(user.first_names.count).to eq 2 }
    it { expect(user.last_names.count).to eq 2 }
  end

  describe 'translatable' do
    before { I18n.available_locales = [:en, :ja] }
    let(:user) { create :user }
    before do
      create :translated_word, :en, translatable: user
      create :translated_word, :ja, translatable: user
    end
    it { expect(user.first_name(:en)).to eq 'John' }
    it { expect(user.first_name(:ja)).to eq 'ジョン' }
    it { expect(user.first_name(:fr)).to eq 'John' }

    context 'default locale = :en' do
      before { I18n.default_locale = :en }
      after  { I18n.default_locale = :en }
      it { expect(user.first_name).to eq 'John' }
    end

    context 'default locale = :ja' do
      before { I18n.default_locale = :ja }
      after  { I18n.default_locale = :en }
      it { expect(user.first_name).to eq 'ジョン' }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar-translatable-0.2.0 spec/models/user_spec.rb