mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
added spec for i18n
This commit is contained in:
parent
d43889d7ce
commit
b7852e29f8
2 changed files with 69 additions and 0 deletions
10
spec/en.yml
Normal file
10
spec/en.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
en:
|
||||||
|
activerecord:
|
||||||
|
events:
|
||||||
|
i18n_test_model:
|
||||||
|
close: "Let's close it!"
|
||||||
|
|
||||||
|
attributes:
|
||||||
|
i18n_test_model:
|
||||||
|
aasm_state:
|
||||||
|
open: "It's opened now!"
|
59
spec/unit/i18n_spec.rb
Normal file
59
spec/unit/i18n_spec.rb
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
require 'active_record'
|
||||||
|
require 'logger'
|
||||||
|
require 'i18n'
|
||||||
|
|
||||||
|
ActiveRecord::Base.logger = Logger.new(STDERR)
|
||||||
|
|
||||||
|
class Connection
|
||||||
|
end
|
||||||
|
|
||||||
|
class I18nTestModel < ActiveRecord::Base
|
||||||
|
include AASM
|
||||||
|
|
||||||
|
attr_accessor :aasm_state
|
||||||
|
|
||||||
|
aasm_initial_state :open
|
||||||
|
aasm_state :opened
|
||||||
|
aasm_state :closed
|
||||||
|
|
||||||
|
aasm_event :close
|
||||||
|
aasm_event :open
|
||||||
|
end
|
||||||
|
|
||||||
|
describe AASM::I18n do
|
||||||
|
before(:all) do
|
||||||
|
I18n.load_path << 'spec/en.yml'
|
||||||
|
I18n.default_locale = :en
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:all) { I18n.load_path.clear }
|
||||||
|
|
||||||
|
before do
|
||||||
|
connection = mock(Connection, :columns => [])
|
||||||
|
I18nTestModel.stub!(:connection).and_return(connection)
|
||||||
|
end
|
||||||
|
|
||||||
|
let (:foo_opened) { I18nTestModel.new }
|
||||||
|
let (:foo_closed) { I18nTestModel.new.tap {|x| x.aasm_state = :closed } }
|
||||||
|
|
||||||
|
context '.human_state' do
|
||||||
|
it 'should return translated state value' do
|
||||||
|
foo_opened.human_state.should == "It's opened now!"
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return humanized value if not localized' do
|
||||||
|
foo_closed.human_state.should == "Closed"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context '.human_event_name' do
|
||||||
|
it 'should return translated event name' do
|
||||||
|
I18nTestModel.human_event_name(:close).should == "Let's close it!"
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return humanized event name' do
|
||||||
|
I18nTestModel.human_event_name(:open).should == "Open"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue