Sha256: afeeaf6908ccb467affe3b6c5bddfc9b53b8eb74203e92e8c5258ea821e15a13

Contents?: true

Size: 1.47 KB

Versions: 13

Compression:

Stored size: 1.47 KB

Contents

require File.expand_path("../spec_helper", File.dirname(__FILE__))

FastGettext.silence_errors

ActiveRecord::Base.establish_connection({
  :adapter => "sqlite3",
  :database => ":memory:",
})

ActiveRecord::Schema.define(:version => 1) do
  create_table :car_seats, :force=>true do |t|
    t.string :seat_color
  end
end

class CarSeat < ActiveRecord::Base
  validates_presence_of :seat_color, :message=>"translate me"
end

describe ActiveRecord::Base do
  before do
    FastGettext.current_cache = {}
  end

  it "has a human name that is translated through FastGettext" do
    CarSeat.expects(:_).with('car seat').returns('Autositz')
    CarSeat.human_name.should == 'Autositz'
  end

  it "translates attributes through FastGettext" do
    CarSeat.expects(:s_).with('CarSeat|Seat color').returns('Sitz farbe')
    CarSeat.human_attribute_name(:seat_color).should == 'Sitz farbe'
  end

  it "translates error messages" do
    FastGettext.stubs(:current_repository).returns('translate me'=>"Übersetz mich!")
    FastGettext._('translate me').should == "Übersetz mich!"
    c = CarSeat.new
    c.valid?
    c.errors.on(:seat_color).should == "Übersetz mich!"
  end

  it "translates scoped error messages" do
    FastGettext.stubs(:current_repository).returns('activerecord.errors.translate me'=>"Übersetz mich!")
    FastGettext._('activerecord.errors.translate me').should == "Übersetz mich!"
    c = CarSeat.new
    c.valid?
    c.errors.on(:seat_color).should == "Übersetz mich!"
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
zena-0.16.9 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.8 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.7 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.6 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.5 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.4 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.3 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.2 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.1 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.16.0 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.15.2 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.15.1 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb
zena-0.15.0 vendor/plugins/gettext_i18n_rails/spec/gettext_i18n_rails/active_record_spec.rb