Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ActiveModel I18n integration #77

Merged
merged 1 commit into from
Dec 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/sequel_rails/railtie.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def configure_sequel(app)
end

def setup_i18n_support
::Sequel::Model.send :include, ::SequelRails::I18nSupport
::Sequel::Model.send :extend, ::ActiveModel::Translation
::Sequel::Model.send :extend, ::SequelRails::I18nSupport
end

def setup_controller_runtime
Expand Down
6 changes: 6 additions & 0 deletions lib/sequel_rails/railties/i18n_support.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ module I18nSupport
def i18n_scope #:nodoc:
:sequel
end

def lookup_ancestors
# ActiveModel uses the name of ancestors. Exclude unnamed classes, like
# those returned by Sequel::Model(...).
super.reject { |x| x.name.nil? }
end
end
end
4 changes: 3 additions & 1 deletion spec/lib/sequel_rails/railtie_spec.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
end

it 'configures Sequel::Model instances for i18n' do
expect(User.new.i18n_scope).to be(:sequel)
expect(User.i18n_scope).to be(:sequel)
expect(User).to respond_to(:lookup_ancestors)
expect(User.model_name.human).to eq('translated user')
end

it 'adds Sequel runtime to controller for logging' do
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@

RSpec.configure do |config|
config.filter_run_excluding rspec_exclusions

config.before(:all) do
I18n.backend.store_translations(
:en,
'sequel' => {
'models' => {
'user' => 'translated user' }
})
end

config.around :each do |example|
if example.metadata[:no_transaction]
example.run
Expand Down