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
2013-11-30 20:56:50 +01:00

109 lines
2.6 KiB
Ruby

require 'spec_helper'
require 'active_record'
require 'logger'
require 'i18n'
load_schema
class LocalizerTestModel < ActiveRecord::Base
include AASM
attr_accessor :aasm_state
aasm_initial_state :opened
aasm_state :opened
aasm_state :closed
aasm_event :close
aasm_event :open
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
LocalizerTestModel.aasm.states.detect {|s| s == :opened}.localized_name.should == "It's open now!"
end
it 'should use fallback' do
LocalizerTestModel.aasm.states.detect {|s| s == :closed}.localized_name.should == 'Closed'
end
end
describe AASM::Localizer, "new style" 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
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
foo_opened.aasm.human_state.should == "It's open now!"
end
it 'should return humanized value if not localized' do
foo_closed.aasm.human_state.should == "Closed"
end
end
context 'aasm_human_event_name' do
it 'should return translated event name' do
LocalizerTestModel.aasm_human_event_name(:close).should == "Let's close it!"
end
it 'should return humanized event name' do
LocalizerTestModel.aasm_human_event_name(:open).should == "Open"
end
end
end
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
foo_opened.aasm.human_state.should == "It's open now!"
end
it 'should return humanized value if not localized' do
foo_closed.aasm.human_state.should == "Closed"
end
end
context 'aasm_human_event_name' do
it 'should return translated event name' do
LocalizerTestModel.aasm_human_event_name(:close).should == "Let's close it!"
end
it 'should return humanized event name' do
LocalizerTestModel.aasm_human_event_name(:open).should == "Open"
end
end
end