Skip to content
Open
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
5 changes: 5 additions & 0 deletions lib/mobility/backends/active_record/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class << self
# @raise [InvalidColumnType] if the type of the container column is not json or jsonb
def configure(options)
options[:column_name] = options[:column_name]&.to_sym || :translations

model_class.define_method(options[:column_name]) do
value = super()
value.is_a?(Hash) ? value.with_indifferent_access : value
end
end
# @!endgroup

Expand Down
6 changes: 6 additions & 0 deletions spec/mobility/backends/active_record/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
.from({ "en" => { "title" => "Title en" }, "de" => { "title" => "Title de" }})
.to({ "de" => { "title" => "Title de" }})
end

it "returns translations as ActiveSupport::HashWithIndifferentAccess" do
post = ContainerPost.create!

expect(post.translations.class).to eq(ActiveSupport::HashWithIndifferentAccess)
end
end

context "with query plugin" do
Expand Down
9 changes: 7 additions & 2 deletions spec/mobility/backends/hash_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
require "spec_helper"
require "mobility/backends/hash"

describe Mobility::Backends::Hash, type: :backend, orm: :none do
describe "Mobility::Backends::Hash", type: :backend, orm: :none do
before(:all) do
require "mobility/backends/hash" # leaks state if defined at top of file (defines Mobility::Backends::Hash, adds :hash to @backends)
end

let(:described_class) { Mobility::Backends::Hash }

describe "#read/#write" do
it "returns value for locale key" do
backend = described_class.new
Expand Down