Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deleted_in_original_table method #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions lib/acts_as_versioned.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ def next
def versions_count
page.version
end

# Returns true if record was deleted in original table, else
# false.
#
def deleted_in_original_table
not original_class.exists?(self.send original_class.versioned_foreign_key)
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on with this indentation? Do you mind fixing that?

end

versioned_class.cattr_accessor :original_class
Expand Down
9 changes: 8 additions & 1 deletion test/versioned_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,11 @@ def test_without_locking_reverts_optimistic_locking_settings_if_block_raises_exc
end
assert ActiveRecord::Base.lock_optimistically
end
end

def test_deleted_in_original_table
record = Page::Version.find 1
assert !record.deleted_in_original_table
record.page.delete
assert record.deleted_in_original_table
end
end