fix issue about sorting by a localized field with the Memory adapter (#44)
did
committed Nov 27, 2015
commit 941ebf6416d595aed10ddc4427fec1d1fe2538fb
Showing 2
changed files with
14 additions
and 0 deletions
locomotive/steam/adapters/memory/order.rb b/lib/locomotive/steam/adapters/memory/order.rb
+5
-0
| @@ | @@ -25,6 +25,11 @@ module Locomotive::Steam |
| def apply_to(entry, locale) | |
| @list.collect do |(name, direction)| | |
| value = entry.send(name) | |
| + | |
| + | if value.respond_to?(:translations) # localized |
| + | value = value[locale] |
| + | end |
| + | |
| asc?(direction) ? Asc.new(value) : Desc.new(value) | |
| end | |
| end | |
spec/unit/adapters/memory/order_spec.rb
+9
-0
| @@ | @@ -44,6 +44,15 @@ describe Locomotive::Steam::Adapters::Memory::Order do |
| let(:entry) { instance_double('Entry', title: 'foo', date: Time.zone.now) } | |
| it { expect(subject.map(&:class)).to eq([Locomotive::Steam::Adapters::Memory::Order::Asc, Locomotive::Steam::Adapters::Memory::Order::Desc]) } | |
| + | context 'localized field' do |
| + | |
| + | let(:now) { Time.zone.now } |
| + | let(:field) { instance_double('TitleI18nField', :[] => 'Hello world', translations: true) } |
| + | let(:entry) { instance_double('Entry', title: field, date: now) } |
| + | it { expect(subject.map(&:obj)).to eq(['Hello world', now]) } |
| + | |
| + | end |
| + | |
| end | |
| describe 'sort' do | |