Skip to content

compare scrubbed attribute values rather than attribute hashes#6

Open
davebenvenuti wants to merge 1 commit intomasterfrom
test_helper_fix
Open

compare scrubbed attribute values rather than attribute hashes#6
davebenvenuti wants to merge 1 commit intomasterfrom
test_helper_fix

Conversation

@davebenvenuti
Copy link
Copy Markdown
Contributor

Cleans up output and attribute comparisons in assert_data_equal and related methods

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why use Date instead of DateTime here (like above)? I believe cassandra_datum uses DateTime to be compatible with ActiveAttr. You could easily convert to a date and take the integer if that is the desired comparison.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll make it a DateTime

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't believe Date has a "to_i" method. Perhaps the end of this method should be:

try_to_i = lambda {|v| v.respond_to?(:to_i) && v.to_i || v}
assert_equal try_to_i.call(value1), try_to_i.call(value2), full_explanation


Alternatively, you could still remove the assert_hashes_equal method and change this:

assert_attributes_equal datum1, datum2, explanation

to something like (this could certainly be cleaned up to make it more DRY):

try_to_i = lambda {|v| v.respond_to?(:to_i) && v.to_i || v}
assert_equal Hash[datum1.attributes.map {|k, v| [k, try_to_i.call(v)]}], Hash[datum2.attributes.map {|k, v| [k, try_to_i.call(v)]}], explanation

Otherwise, LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants