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

52 lines
1.2 KiB
Ruby
Raw Normal View History

2011-02-12 11:10:39 -05:00
require 'spec_helper'
require 'active_record'
require 'logger'
require 'i18n'
ActiveRecord::Base.logger = Logger.new(STDERR)
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_initial_state :open
aasm_state :opened
aasm_state :closed
aasm_event :close
aasm_event :open
end
2011-11-26 12:33:58 -05:00
describe AASM::SupportingClasses::Localizer do
2011-02-12 11:10:39 -05:00
before(:all) do
I18n.load_path << 'spec/en.yml'
I18n.default_locale = :en
end
2011-07-03 15:09:17 -04:00
2011-02-12 11:10:39 -05:00
after(:all) { I18n.load_path.clear }
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 '.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
LocalizerTestModel.human_event_name(:close).should == "Let's close it!"
2011-02-12 11:10:39 -05:00
end
it 'should return humanized event name' do
LocalizerTestModel.human_event_name(:open).should == "Open"
2011-02-12 11:10:39 -05:00
end
end
end