Skip to content

Instantly share code, notes, and snippets.

@santuxus
Created February 8, 2013 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santuxus/4739569 to your computer and use it in GitHub Desktop.
Save santuxus/4739569 to your computer and use it in GitHub Desktop.
rspec matcher for paper_trail 1.6.5 (the latest version working with rails 2.3.x)
Spec::Matchers.define :have_paper_trail do
match do |object|
has_class_methods?(object) && has_instance_methods?(object)
end
failure_message_for_should do |object|
"Expected #{object.class} to have a has_paper_trail"
end
failure_message_for_should_not do |object|
"Not expected #{object.class} to have a has_paper_trail"
end
description do
"have paper_trail"
end
end
### WARNING! this should be updated when paper_trail version is changed
def has_class_methods?(object)
[
:paper_trail_off,
:paper_trail_on,
:has_paper_trail
].inject(true) do |result, method|
result && object.class.respond_to?(method)
end
end
def has_instance_methods?(object)
[
:previous_version,
:next_version,
:version_ids,
:version_ids=,
:paper_trail_active,
:paper_trail_active=,
:autosave_associated_records_for_versions,
:version,
:validate_associated_records_for_versions,
:version=,
:versions,
:versions=,
:meta,
:meta=,
:ignore,
:ignore=,
:live?,
:originator,
:version_at
].inject(true) do |result, method|
result && object.respond_to?(method)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment