Skip to content

Commit

Permalink
add spec about removing empty locale hash after last attribute is del…
Browse files Browse the repository at this point in the history
…eted
  • Loading branch information
doits committed Dec 2, 2021
1 parent c21ee94 commit b47131f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mobility/backends/active_record/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_column_type

# @!macro backend_iterator
def each_locale
model[column_name].each do |l, v|
model[column_name].each_key do |l|
yield l.to_sym
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ postgres:
host: localhost
port: 5432
database: mobility_test
username: markus
username: postgres
encoding: utf8

sqlite3:
Expand Down
12 changes: 12 additions & 0 deletions spec/mobility/backends/active_record/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
.and not_change { post.changed? }.from(false)
end
end

it 'deletes locale hash if last attribute is removed' do
post = ContainerPost.create!

::Mobility.with_locale(:en) { post.title = 'Title en' }
::Mobility.with_locale(:de) { post.title = 'Title de' }

expect { post.title = nil }
.to change { post.translations }
.from({ "en" => { "title" => "Title en" }, "de" => { "title" => "Title de" }})
.to({ "de" => { "title" => "Title de" }})
end
end

context "with query plugin" do
Expand Down

0 comments on commit b47131f

Please sign in to comment.