Skip to content

Legacy compatibility#9

Merged
ettomatic merged 6 commits intomasterfrom
legacy-compatibility
Aug 13, 2018
Merged

Legacy compatibility#9
ettomatic merged 6 commits intomasterfrom
legacy-compatibility

Conversation

@ettomatic
Copy link
Contributor

@ettomatic ettomatic commented Aug 8, 2018

Fix issue with different signatures between Ruby 2.1 and 2.4.

For non-String scalar values, the object class name gets injected in the
signature data.

Ruby 2.4 unified Fixnum and Bignum into Integer so a signature
containing numbers in 2.1 will be different from one generated in 2.4.

Ruby 2.1

2.class.ancestors
[Fixnum, Integer, Numeric, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]

Ruby 2.4.2

2.class.ancestors
[Integer, Numeric, Comparable, Object, PP::ObjectMixin, Kernel, BasicObject]

Floats are not showing the same issues, as both 2.1 and 2.4 are returning:

6.6.class.ancestors
[Float, Numeric, Comparable, Object, Kernel, BasicObject]

If you'll use Crimp to generate cache/database ids this can be a
problem.

This commit makes Crimp backwards compatible.

See also PR #8 for more context (thanks @coderkind and @Tarqwyn)

For non Sting scalar values the object class gets injected in the
signature data.

Ruby 2.4 unified Fixnum and Bignum into Integer so a signature
contening numbers in 2.1 will be different from one generated in 2.1.

If you'll use Crimp to generate cache/database ids this can be a
problem.

This commit makes Crimp backward compatible.
Also to cope with TLSv1 issue.
@@ -1,3 +1,3 @@
module Crimp
VERSION = '0.1.2'.freeze
VERSION = '1.0.0'.freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep this change at 0.x and then have the new version at 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed to 1.0.0 with the idea to set the new version as 2.0.0 but probably you're right, the current version is really not a 1.x thing!

@samfrench
Copy link
Contributor

Why do we require the version in the crimp.rb file when it doesn't use it?

https://github.com/BBC-News/crimp/blob/master/lib/crimp.rb#L1

@ettomatic
Copy link
Contributor Author

specify { expect(subject.signature(hash)).to be_a String }

it 'returns MD5 hash of stringified Hash' do
expect(subject.signature(hash)).to eq(Digest::MD5.hexdigest(subject.stringify(hash)))
Copy link
Contributor Author

@ettomatic ettomatic Aug 10, 2018

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

:(

@ettomatic ettomatic force-pushed the legacy-compatibility branch from dffca70 to cdbe0d9 Compare August 10, 2018 10:11
@ettomatic ettomatic requested review from Tarqwyn and coderkind August 10, 2018 10:21
Copy link

@junior451 junior451 left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍
But its there a reason why are all the methods in the Crimp module class methods?

Copy link
Contributor

@samfrench samfrench left a comment

Choose a reason for hiding this comment

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

Looks good to me. 👍

@woodyblah
Copy link

@junior451 The public signature method doesn't need to store any state to work, so there's no need for an instance to be created. A static/class method can't call instance methods though, so all the private methods that signature calls will also need to be class methods in order for it to work (they also don't need state so this is fine)

lib/crimp.rb Outdated
# to debug especially for nested data structures.
#
def self.integer_to_string(obj)
"#{obj}Fixnum"

Choose a reason for hiding this comment

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

Probably an edge case, but would previous invocations always be dealing with Fixnum's (as opposed to Bignum's as well)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes you're right... I'll add another hack to handle this 😞 .

let(:hash_with_numbers) { { a: { b: 1, c: 3.14 }, d: 'd' } }
let(:hash_unordered) { { d: 'd', a: { c: 'c', b: 'b' } } }
let(:array) { [1, 2, 3, [4, [5, 6]]] }
let(:array_unordered) { [3, 2, 1, [[5, 6], 4]] }

Choose a reason for hiding this comment

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

Does this cover the full range of data types you're wanting to test against? No booleans, nil values, non-UTF-8 character strings, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes test coverage is weak, the new version of Crimp i'm working on has better tests tho.

Copy link

@coderkind coderkind left a comment

Choose a reason for hiding this comment

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

👍 looks good; I've added a few questions purely out of ignorance of how it's being/will be used, and having given the Node version some attention.

@ettomatic ettomatic force-pushed the legacy-compatibility branch from 10ec655 to 46f1bb4 Compare August 13, 2018 12:59
@ettomatic ettomatic force-pushed the legacy-compatibility branch from 46f1bb4 to 43bfa4f Compare August 13, 2018 13:01
@ettomatic ettomatic merged commit 9fd971d into master Aug 13, 2018
@ettomatic ettomatic deleted the legacy-compatibility branch August 13, 2018 13:06
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.

7 participants

Comments