mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
avoiding naming conflict with using I18n module in AASM'ified class
This commit is contained in:
parent
192fc96ffa
commit
55fbd65fa9
6 changed files with 13 additions and 13 deletions
|
@ -7,4 +7,4 @@ require File.join(File.dirname(__FILE__), 'aasm', 'supporting_classes')
|
|||
require File.join(File.dirname(__FILE__), 'aasm', 'state_machine')
|
||||
require File.join(File.dirname(__FILE__), 'aasm', 'persistence')
|
||||
require File.join(File.dirname(__FILE__), 'aasm', 'aasm')
|
||||
require File.join(File.dirname(__FILE__), 'aasm', 'i18n')
|
||||
require File.join(File.dirname(__FILE__), 'aasm', 'localizer')
|
||||
|
|
|
@ -79,7 +79,7 @@ module AASM
|
|||
end
|
||||
|
||||
def human_event_name(event)
|
||||
AASM::I18n.new.human_event_name(self, event)
|
||||
AASM::Localizer.new.human_event_name(self, event)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -123,7 +123,7 @@ module AASM
|
|||
end
|
||||
|
||||
def human_state
|
||||
AASM::I18n.new.human_state(self)
|
||||
AASM::Localizer.new.human_state(self)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class AASM::I18n
|
||||
class AASM::Localizer
|
||||
def human_event_name(klass, event)
|
||||
defaults = ancestors_list(klass).map do |ancestor|
|
||||
:"#{i18n_scope(klass)}.events.#{i18n_klass(ancestor)}.#{event}"
|
|
@ -1,10 +1,10 @@
|
|||
en:
|
||||
activerecord:
|
||||
events:
|
||||
i18n_test_model:
|
||||
localizer_test_model:
|
||||
close: "Let's close it!"
|
||||
|
||||
attributes:
|
||||
i18n_test_model:
|
||||
localizer_test_model:
|
||||
aasm_state:
|
||||
open: "It's opened now!"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
ActiveRecord::Schema.define(:version => 0) do
|
||||
|
||||
%w{gates readers writers transients simples thieves i18n_test_models}.each do |table_name|
|
||||
%w{gates readers writers transients simples thieves localizer_test_models}.each do |table_name|
|
||||
create_table table_name, :force => true
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'i18n'
|
|||
|
||||
ActiveRecord::Base.logger = Logger.new(STDERR)
|
||||
|
||||
class I18nTestModel < ActiveRecord::Base
|
||||
class LocalizerTestModel < ActiveRecord::Base
|
||||
include AASM
|
||||
|
||||
attr_accessor :aasm_state
|
||||
|
@ -18,7 +18,7 @@ class I18nTestModel < ActiveRecord::Base
|
|||
aasm_event :open
|
||||
end
|
||||
|
||||
describe AASM::I18n do
|
||||
describe AASM::Localizer do
|
||||
before(:all) do
|
||||
I18n.load_path << 'spec/en.yml'
|
||||
I18n.default_locale = :en
|
||||
|
@ -26,8 +26,8 @@ describe AASM::I18n do
|
|||
|
||||
after(:all) { I18n.load_path.clear }
|
||||
|
||||
let (:foo_opened) { I18nTestModel.new }
|
||||
let (:foo_closed) { I18nTestModel.new.tap { |x| x.aasm_state = :closed } }
|
||||
let (:foo_opened) { LocalizerTestModel.new }
|
||||
let (:foo_closed) { LocalizerTestModel.new.tap { |x| x.aasm_state = :closed } }
|
||||
|
||||
context '.human_state' do
|
||||
it 'should return translated state value' do
|
||||
|
@ -41,11 +41,11 @@ describe AASM::I18n do
|
|||
|
||||
context '.human_event_name' do
|
||||
it 'should return translated event name' do
|
||||
I18nTestModel.human_event_name(:close).should == "Let's close it!"
|
||||
LocalizerTestModel.human_event_name(:close).should == "Let's close it!"
|
||||
end
|
||||
|
||||
it 'should return humanized event name' do
|
||||
I18nTestModel.human_event_name(:open).should == "Open"
|
||||
LocalizerTestModel.human_event_name(:open).should == "Open"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue