Last active
March 20, 2017 18:56
-
-
Save kstevens715/61aac85e65a90c330c0ae7b248552f65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecordComparer | |
def initialize(original, new) | |
@original = original | |
@new = new | |
end | |
def method_missing(m, *arg) | |
puts arg | |
@original = @original.send(m, *arg) | |
@new = @new.send(m, *arg) | |
if @original.class != @new.class | |
fail "classes don't match" | |
end | |
if @original.class != ActiveRecord::Relation | |
if @original != @new | |
fail "results don't match. Original: #{@original.inspect}, New: #{@new.inspect}" | |
end | |
return @original | |
end | |
self | |
end | |
end | |
# Use: | |
# | |
# In Organization user identity class: | |
# def applicants | |
# ActiveRecordComparer(self.old_applicants_method, self.new_applicants_method) | |
# end | |
# | |
# In client code: | |
# applicants.application_status_of("In Progress") | |
# | |
# I think it would raise a failure because they don't match. Which would make regression testing more likely to catch problems. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.