1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00
aasm/spec/unit/localizer_spec.rb

115 lines
2.8 KiB
Ruby
Raw Normal View History

2011-02-12 11:10:39 -05:00
require 'spec_helper'
require 'active_record'
require 'logger'
require 'i18n'
I18n.enforce_available_locales = false
2012-12-26 15:51:01 -05:00
load_schema
class LocalizerTestModel < ActiveRecord::Base
2011-02-12 11:10:39 -05:00
include AASM
2011-07-03 15:09:17 -04:00
2011-02-12 11:10:39 -05:00
attr_accessor :aasm_state
aasm do
2013-11-30 18:23:34 -05:00
state :opened, :initial => true
state :closed
event :close
event :open
end
2011-02-12 11:10:39 -05:00
end
describe 'localized state names' do
before(:all) do
I18n.load_path << 'spec/en.yml'
I18n.default_locale = :en
I18n.reload!
end
after(:all) do
I18n.load_path.clear
end
it 'should localize' do
state = LocalizerTestModel.aasm.states.detect {|s| s == :opened}
expect(state.localized_name).to eq("It's open now!")
expect(state.human_name).to eq("It's open now!")
end
it 'should use fallback' do
state = LocalizerTestModel.aasm.states.detect {|s| s == :closed}
expect(state.localized_name).to eq('Closed')
expect(state.human_name).to eq('Closed')
end
end
2013-02-21 22:02:40 -05:00
describe AASM::Localizer, "new style" do
2011-02-12 11:10:39 -05:00
before(:all) do
I18n.load_path << 'spec/en.yml'
I18n.default_locale = :en
I18n.reload!
2011-02-12 11:10:39 -05:00
end
2011-07-03 15:09:17 -04:00
after(:all) do
I18n.load_path.clear
end
2011-02-12 11:10:39 -05:00
let (:foo_opened) { LocalizerTestModel.new }
let (:foo_closed) { LocalizerTestModel.new.tap { |x| x.aasm_state = :closed } }
2011-02-12 11:10:39 -05:00
context 'aasm.human_state' do
2011-02-12 11:10:39 -05:00
it 'should return translated state value' do
expect(foo_opened.aasm.human_state).to eq("It's open now!")
2011-02-12 11:10:39 -05:00
end
it 'should return humanized value if not localized' do
expect(foo_closed.aasm.human_state).to eq("Closed")
2011-02-12 11:10:39 -05:00
end
end
context 'aasm_human_event_name' do
2011-02-12 11:10:39 -05:00
it 'should return translated event name' do
expect(LocalizerTestModel.aasm_human_event_name(:close)).to eq("Let's close it!")
2011-02-12 11:10:39 -05:00
end
it 'should return humanized event name' do
expect(LocalizerTestModel.aasm_human_event_name(:open)).to eq("Open")
2011-02-12 11:10:39 -05:00
end
end
end
2013-02-21 22:02:40 -05:00
describe AASM::Localizer, "deprecated style" do
before(:all) do
I18n.load_path << 'spec/en_deprecated_style.yml'
I18n.default_locale = :en
I18n.reload!
end
after(:all) do
I18n.load_path.clear
end
let (:foo_opened) { LocalizerTestModel.new }
let (:foo_closed) { LocalizerTestModel.new.tap { |x| x.aasm_state = :closed } }
context 'aasm.human_state' do
it 'should return translated state value' do
expect(foo_opened.aasm.human_state).to eq("It's open now!")
end
it 'should return humanized value if not localized' do
expect(foo_closed.aasm.human_state).to eq("Closed")
end
end
context 'aasm_human_event_name' do
it 'should return translated event name' do
expect(LocalizerTestModel.aasm_human_event_name(:close)).to eq("Let's close it!")
end
it 'should return humanized event name' do
expect(LocalizerTestModel.aasm_human_event_name(:open)).to eq("Open")
end
end
end