Magic number in tests

87 views
Skip to first unread message

artur.b...@internet.ee

unread,
Jan 9, 2018, 4:07:27 AM1/9/18
to Ruby on Rails: Core
Magic number 72 is used many times throughout the tests, which is actually present under ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED constant. I propose to replace that magic number either by the constant or method call.

Kasper Timm Hansen

unread,
Jan 9, 2018, 5:38:05 AM1/9/18
to rubyonra...@googlegroups.com
I’m -1 on changing that. I think the constant 72 is used directly such that tests will fail if anybody changes MAX_PASSWORD_LENGTH_ALLOWED.

With your change in, a later change to MAX_PASSWORD_LENGTH_ALLOWED by some other contributor wouldn’t make any tests fail.

Since that constant isn’t meant to change without us thinking more about it, I’d say we keep the code as is.

Thanks for starting to contribute!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper

Kerri Miller

unread,
Jan 9, 2018, 6:39:49 AM1/9/18
to rubyonra...@googlegroups.com
I could see an argument made for making it a constant in the _test_ (EXPECTED_MAX_PASSWORD_LENGTH), which at least would document /why/ the number is being used.

On Tue, Jan 9, 2018 at 11:37 AM, Kasper Timm Hansen <kas...@gmail.com> wrote:
I’m -1 on changing that. I think the constant 72 is used directly such that tests will fail if anybody changes MAX_PASSWORD_LENGTH_ALLOWED.

With your change in, a later change to MAX_PASSWORD_LENGTH_ALLOWED by some other contributor wouldn’t make any tests fail.

Since that constant isn’t meant to change without us thinking more about it, I’d say we keep the code as is.

Thanks for starting to contribute!
Den 9. jan. 2018 kl. 09.56 skrev artur.b...@internet.ee:

Magic number 72 is used many times throughout the tests, which is actually present under ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED constant. I propose to replace that magic number either by the constant or method call.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.

--
Kasper

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.

Kasper Timm Hansen

unread,
Jan 9, 2018, 3:30:41 PM1/9/18
to rubyonra...@googlegroups.com
Yep, we could do that 👍

To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

--
Kasper

artur.b...@internet.ee

unread,
Jan 10, 2018, 9:19:44 AM1/10/18
to Ruby on Rails: Core
I would be happy to do this!


On Tuesday, January 9, 2018 at 10:30:41 PM UTC+2, Kasper Timm Hansen wrote:
Yep, we could do that 👍
Den 9. jan. 2018 kl. 12.39 skrev Kerri Miller <kerr...@gmail.com>:

I could see an argument made for making it a constant in the _test_ (EXPECTED_MAX_PASSWORD_LENGTH), which at least would document /why/ the number is being used.
On Tue, Jan 9, 2018 at 11:37 AM, Kasper Timm Hansen <kas...@gmail.com> wrote:
I’m -1 on changing that. I think the constant 72 is used directly such that tests will fail if anybody changes MAX_PASSWORD_LENGTH_ALLOWED.

With your change in, a later change to MAX_PASSWORD_LENGTH_ALLOWED by some other contributor wouldn’t make any tests fail.

Since that constant isn’t meant to change without us thinking more about it, I’d say we keep the code as is.

Thanks for starting to contribute!
Den 9. jan. 2018 kl. 09.56 skrev artur.b...@internet.ee:

Magic number 72 is used many times throughout the tests, which is actually present under ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED constant. I propose to replace that magic number either by the constant or method call.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper

artur.b...@internet.ee

unread,
Jan 10, 2018, 9:20:23 AM1/10/18
to Ruby on Rails: Core
Thank you for feedback!

Kerri Miller

unread,
Jan 10, 2018, 9:37:24 AM1/10/18
to rubyonra...@googlegroups.com
Not to "well actually" myself but another option might be to use MAX_PASSWORD_LENGTH_ALLOWED as the OP suggested, but have an explicit test for MAX_PASSWORD_LENGTH_ALLOWED=72.. which might actually be a better approach, since it'll isolate the exact defect case (MAX_PASSWORD_LENGTH_ALLOWED != 72) rather than have it be implied by a well-named-but-oddly-disconnected constant.

// Kerri

To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.

Kasper Hansen

unread,
Jan 20, 2018, 8:28:49 AM1/20/18
to rubyonra...@googlegroups.com
Yep, that sounds good too, Kerri.

Artur, go right ahead!

--
Kasper

Artur Beljajev

unread,
Feb 20, 2018, 7:14:04 PM2/20/18
to Ruby on Rails: Core
Should I create a ticket on Github first?

Kasper Hansen

unread,
Feb 21, 2018, 2:47:06 AM2/21/18
to rubyonra...@googlegroups.com
Artur, send a pull request :)

--
Kasper
Reply all
Reply to author
Forward
Message has been deleted
0 new messages