Skip to content

Commit

Permalink
add failing spec for query plugin not respecting default_scope on Tra…
Browse files Browse the repository at this point in the history
…nslation class
  • Loading branch information
mrbrdo committed May 3, 2022
1 parent f70acbc commit a6e28f3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/mobility/plugins/active_record/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@
expect { Article.i18n { author([]).eq("foo") } }.to raise_error(Mobility::InvalidLocale)
end
end

it "uses Translation's default_scope if it was set" do
# apply default_scope to Translation class, like paranoia gem would
Article::Translation.send(:default_scope) { where.not(title: "DELETED") }

Mobility.locale = :en
article = Article.create!(title: "New Article")
association_name = article.mobility_backends[:title].association_name
expect(Article.i18n { title(:en).eq("New Article") }).to eq([article])

article.translations.first.update title: "DELETED"
article.reload

# default_scope filters translations on model instance
expect(article.translations).to be_empty
expect(article.mobility_backends[:title].read(:en)).to be_nil

# default_scope filters translations when querying
expect(Article.i18n { title(:en).eq("DELETED") }).to be_empty
end
end

# TODO: Test more thoroughly
Expand Down

0 comments on commit a6e28f3

Please sign in to comment.