From 55fbd65fa90296d1b8d9b50db1c513a0ef363517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Bo=CC=88ttger?= Date: Sat, 10 Sep 2011 18:41:48 +0200 Subject: [PATCH] avoiding naming conflict with using I18n module in AASM'ified class --- lib/aasm.rb | 2 +- lib/aasm/aasm.rb | 4 ++-- lib/aasm/{i18n.rb => localizer.rb} | 2 +- spec/en.yml | 4 ++-- spec/schema.rb | 2 +- spec/unit/{i18n_spec.rb => localizer_spec.rb} | 12 ++++++------ 6 files changed, 13 insertions(+), 13 deletions(-) rename lib/aasm/{i18n.rb => localizer.rb} (98%) rename spec/unit/{i18n_spec.rb => localizer_spec.rb} (70%) diff --git a/lib/aasm.rb b/lib/aasm.rb index ebc0cd3..8e12b73 100644 --- a/lib/aasm.rb +++ b/lib/aasm.rb @@ -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') diff --git a/lib/aasm/aasm.rb b/lib/aasm/aasm.rb index 0f02b48..4e02ba8 100644 --- a/lib/aasm/aasm.rb +++ b/lib/aasm/aasm.rb @@ -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 diff --git a/lib/aasm/i18n.rb b/lib/aasm/localizer.rb similarity index 98% rename from lib/aasm/i18n.rb rename to lib/aasm/localizer.rb index 0776d38..2e16372 100644 --- a/lib/aasm/i18n.rb +++ b/lib/aasm/localizer.rb @@ -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}" diff --git a/spec/en.yml b/spec/en.yml index 5a1a6e5..38ab0bb 100644 --- a/spec/en.yml +++ b/spec/en.yml @@ -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!" diff --git a/spec/schema.rb b/spec/schema.rb index 5522bb1..298c0b5 100644 --- a/spec/schema.rb +++ b/spec/schema.rb @@ -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 diff --git a/spec/unit/i18n_spec.rb b/spec/unit/localizer_spec.rb similarity index 70% rename from spec/unit/i18n_spec.rb rename to spec/unit/localizer_spec.rb index 3ac91d2..fe3b07c 100644 --- a/spec/unit/i18n_spec.rb +++ b/spec/unit/localizer_spec.rb @@ -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