From 55d6b88de1520c2802646a479d1bd8ce2f478342 Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Sat, 2 Aug 2014 10:38:40 -0700 Subject: [PATCH] mongoid translate spec works --- lib/ransack/adapters/mongoid/ransack/translate.rb | 11 ++++++----- spec/mongoid/translate_spec.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 spec/mongoid/translate_spec.rb diff --git a/lib/ransack/adapters/mongoid/ransack/translate.rb b/lib/ransack/adapters/mongoid/ransack/translate.rb index a6c2730..f321927 100644 --- a/lib/ransack/adapters/mongoid/ransack/translate.rb +++ b/lib/ransack/adapters/mongoid/ransack/translate.rb @@ -2,11 +2,12 @@ module Ransack module Translate def self.i18n_key(klass) - if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0 - klass.model_name.i18n_key.to_s.tr('.', '/') - else - klass.model_name.i18n_key.to_s - end + # if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0 + # klass.model_name.i18n_key.to_s.tr('.', '/') + # else + # klass.model_name.i18n_key.to_s + # end + klass.model_name.i18n_key.to_s end end end diff --git a/spec/mongoid/translate_spec.rb b/spec/mongoid/translate_spec.rb new file mode 100644 index 0000000..2ebfdf4 --- /dev/null +++ b/spec/mongoid/translate_spec.rb @@ -0,0 +1,14 @@ +require 'mongoid_spec_helper' + +module Ransack + describe Translate do + + describe '.attribute' do + it 'translate namespaced attribute like AR does' do + ar_translation = ::Namespace::Article.human_attribute_name(:title) + ransack_translation = Ransack::Translate.attribute(:title, :context => ::Namespace::Article.search.context) + expect(ransack_translation).to eq ar_translation + end + end + end +end