-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Description
Following up on this deranged sequence of comments I clone the repo and added a test to prove the point (at least as I see it)
# spec/mobility/backends/active_record/container_spec.rb
context "with cache plugin" do
plugins :active_record, :reader, :writer, :cache
before { translates ContainerPost, :title, :content, backend: :container }
let(:backend) { post.mobility_backends[:title] }
include_accessor_examples 'ContainerPost'
include_dup_examples 'ContainerPost'
include_cache_key_examples 'ContainerPost'
it 'correctly updates the cache when translations are changed' do
post = ContainerPost.new
post.title = "foo"
expect(post.title).to eq("foo")
post.title = "bar"
expect(post.title).to eq("bar")
post.save
end
endwhich fails
ORM=active_record DB=postgres rspec spec/mobility/backends/active_record/container_spec.rb:55 ✔ 6s
Skipping AllocationStats.
Run options:
include {:focus=>true, :locations=>{"./spec/mobility/backends/active_record/container_spec.rb"=>[55]}}
exclude {:orm=>#<Proc: ./spec/spec_helper.rb:95>, :db=>#<Proc: ./spec/spec_helper.rb:95>}
Randomized with seed 25927
Mobility::Backends::ActiveRecord::Container
with cache plugin
correctly updates the cache when translations are changed (FAILED - 1)
behaves like model with translated attribute accessors
sets translations in multiple locales when creating and saving model
gets and sets translations in multiple locales
sets translations in multiple locales when updating model
gets and sets translations in one locale
behaves like dupable model
dups new record
dups persisted model
behaves like cache key
changes cache key when translation updated
Failures:
1) Mobility::Backends::ActiveRecord::Container with cache plugin correctly updates the cache when translations are changed
Failure/Error: expect(post.title).to eq("bar")
expected: "bar"
got: "foo"
(compared using ==)
# ./spec/mobility/backends/active_record/container_spec.rb:72:in `block (3 levels) in <top (required)>'
Finished in 0.31598 seconds (files took 2.19 seconds to load)
8 examples, 1 failure
Failed examples:
rspec ./spec/mobility/backends/active_record/container_spec.rb:65 # Mobility::Backends::ActiveRecord::Container with cache plugin correctly updates the cache when translations are changedThe fix is - naively - easy
diff --git a/lib/mobility/backends/active_record/container.rb b/lib/mobility/backends/active_record/container.rb
index 5f14540..1fce61a 100644
--- a/lib/mobility/backends/active_record/container.rb
+++ b/lib/mobility/backends/active_record/container.rb
@@ -37,7 +37,8 @@ Implements the {Mobility::Backends::Container} backend for ActiveRecord models.
# @return [String,Integer,Boolean] Updated value
def write(locale, value, _ = nil)
set_attribute_translation(locale, value)
- read(locale)
+
+ value
end
# @!endgroupThe tests (for container) pass and I'm happy to open a PR with these two changes, but I wanted to run by you first :)
shioyama
Metadata
Metadata
Assignees
Labels
No labels