2011-02-12 11:10:39 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'active_record'
|
|
|
|
require 'i18n'
|
|
|
|
|
2014-10-12 11:20:32 -04:00
|
|
|
I18n.enforce_available_locales = false
|
2012-12-26 15:51:01 -05:00
|
|
|
load_schema
|
|
|
|
|
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
|
2012-01-16 11:04:03 -05:00
|
|
|
I18n.reload!
|
2011-02-12 11:10:39 -05:00
|
|
|
end
|
2011-07-03 15:09:17 -04:00
|
|
|
|
2012-01-16 11:04:03 -05:00
|
|
|
after(:all) do
|
|
|
|
I18n.load_path.clear
|
|
|
|
end
|
2011-02-12 11:10:39 -05:00
|
|
|
|
2011-09-10 12:41:48 -04: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
|
|
|
|
2013-11-30 14:56:50 -05:00
|
|
|
context 'aasm.human_state' do
|
2011-02-12 11:10:39 -05:00
|
|
|
it 'should return translated state value' do
|
2014-01-07 13:35:51 -05:00
|
|
|
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
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(foo_closed.aasm.human_state).to eq("Closed")
|
2011-02-12 11:10:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-16 16:59:35 -05:00
|
|
|
context 'aasm.human_event_name' do
|
2011-02-12 11:10:39 -05:00
|
|
|
it 'should return translated event name' do
|
2014-11-16 16:59:35 -05:00
|
|
|
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
|
2014-11-16 16:59:35 -05:00
|
|
|
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
|
2011-02-12 11:10:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-06 06:32:52 -04:00
|
|
|
|
2013-02-21 22:02:40 -05:00
|
|
|
describe AASM::Localizer, "deprecated style" do
|
2012-06-06 06:32:52 -04:00
|
|
|
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 } }
|
|
|
|
|
2013-11-30 14:56:50 -05:00
|
|
|
context 'aasm.human_state' do
|
2012-06-06 06:32:52 -04:00
|
|
|
it 'should return translated state value' do
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(foo_opened.aasm.human_state).to eq("It's open now!")
|
2012-06-06 06:32:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return humanized value if not localized' do
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(foo_closed.aasm.human_state).to eq("Closed")
|
2012-06-06 06:32:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-16 16:59:35 -05:00
|
|
|
context 'aasm.human_event_name' do
|
2012-06-06 06:32:52 -04:00
|
|
|
it 'should return translated event name' do
|
2014-11-16 16:59:35 -05:00
|
|
|
expect(LocalizerTestModel.aasm.human_event_name(:close)).to eq("Let's close it!")
|
2012-06-06 06:32:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return humanized event name' do
|
2014-11-16 16:59:35 -05:00
|
|
|
expect(LocalizerTestModel.aasm.human_event_name(:open)).to eq("Open")
|
2012-06-06 06:32:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|