Skip to content

Commit

Permalink
Merge pull request #2 from lguardiola/master
Browse files Browse the repository at this point in the history
Apply deletion filters when retrieving data
  • Loading branch information
fsaravia committed Jul 5, 2019
2 parents 64c3183 + 2b6cc0b commit a5065dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/sequel/plugins/soft_destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ module ClassMethods
Sequel::Plugins.def_dataset_methods(self, :filter_deleted)

def [](*args)
model = super
args = args.first if args.size <= 1

return filter_deleted.first(args) if args.is_a?(Hash)

return if args.nil?

model = primary_key_lookup(args)

return if model.nil? || model.deleted?

Expand Down
12 changes: 11 additions & 1 deletion test/sequel/plugins/soft_destroy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ def test_filter_deleted
assert_equal [foo_1, foo_2], Foo.filter_deleted.where(Sequel.ilike(:name, "foo%")).all
end

def test_fetch
def test_fetch_by_id
foo = Foo.create(name: "foo 1").soft_destroy

assert_nil Foo[foo.id]
end

def test_fetch_by_key
foo_1 = Foo.create(name: "foo").soft_destroy

assert_nil Foo[name: "foo"]

foo_2 = Foo.create(name: "foo")

assert_equal foo_2, Foo[name: "foo"]
end
end

0 comments on commit a5065dd

Please sign in to comment.