Sha256: 1b9bfa3bab07512cfd5299cef75d904c3b4b5ff4322b04b8637887f28ac5d521

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'minitest/autorun'
require 'active_record'
require 'i18n'
require 'acts_as_localized'

ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"

class MiniTest::Test
  def capture_stdout(&block)
    real_stdout = $stdout
    $stdout = StringIO.new
    yield
    $stdout.string
  ensure
    $stdout = real_stdout
  end

  def setup_db
    capture_stdout do
      ActiveRecord::Schema.define(:version => 1) do
        create_table :test_models do |t|
          t.string :attr_en
          t.string :attr_fr
        end
      end
    end
  end

  def teardown_db
    ActiveRecord::Base.connection.tables.each do |table|
      ActiveRecord::Base.connection.drop_table(table)
    end
  end
end

class TestModel < ActiveRecord::Base
  include ActsAsLocalized
  acts_as_localized :attr
end

class ActsAsLocalizedTest < MiniTest::Test

  def setup
    setup_db
    I18n.enforce_available_locales = false
    I18n.locale = :en
  end

  def teardown
    teardown_db
  end

  def test_localization
    model = TestModel.create!(
      :attr_en  => 'content EN',
      :attr_fr  => 'content FR'
    )
    assert_equal 'content EN', model.attr
    I18n.locale = :fr
    assert_equal 'content FR', model.attr
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acts_as_localized-0.0.1 test/acts_as_localized_test.rb