working_hours icon indicating copy to clipboard operation
working_hours copied to clipboard

sorts week config hash on setter

Open thomashs-zz opened this issue 11 years ago • 8 comments

Discovered accidentally that, if the working_hours hash config has many "ins" and "outs", the algorithm does not calculate working hours successfully. to avoid failure on the algorithm, working_hours setter sorts the hash. rspec included on this commit.

thomashs-zz avatar Nov 21 '14 16:11 thomashs-zz

Hi ! Thanks !

Several things :

  • You don't seem to need rspec-api-matchers anymore
  • It needs a spec testing behavior, that failed before, for example, set an unsorted config and expect 1.working.hour.ago to work correctly
  • can you use map in the sort method instead of doing it manually ?

Cheers !

Intrepidd avatar Nov 21 '14 16:11 Intrepidd

I'll work on that! But I don't think that testing the behavior after sorting is a nice strategy if the algorithm already expects a sorted hash. Aren't all methods like 1.working.hour.ago covered already?

thomashs-zz avatar Nov 21 '14 16:11 thomashs-zz

It's more of a regression test.

Your current test asserts the config is sorted, but does not ensure that everything still works. If later the code is changed and someone messes up and the precompiled config is not sorted, your test will still pass but the error will still be here.

Intrepidd avatar Nov 21 '14 16:11 Intrepidd

Thanks for your contribution,

You're right about the order issue, but the fix should be in #precompiled IMO: We don't care if the config definition hash is sorted, and sorting in the setter can be dangerous if the hash is modified after calling the setter. The sort needs to be in #precompiled when generating the real hash used for computation.

And as @Intrepidd said, your spec shoud verify the problem, not the solution. It should use a badly ordered hash and verify a computation that fails without the sort.

jarthod avatar Nov 22 '14 11:11 jarthod

@jarthod - you're right. I'll check on #precompiled and try to fix it!

thomashs-zz avatar Nov 22 '14 16:11 thomashs-zz

Hey, happy new year !

Are you still planning on working on this ?

Intrepidd avatar Jan 03 '15 11:01 Intrepidd

YES! But I’m on vacation. I’ll be back on jan 10th!

Thomás Sieczkowski http://www.thomashs.com.br [email protected]

  • 55 51 9182 4581

Em 03/01/2015, à(s) 09:33, Adrien [email protected] escreveu:

Hey, happy new year !

Are you still planning on working on this ?

— Reply to this email directly or view it on GitHub.

thomashs-zz avatar Jan 03 '15 18:01 thomashs-zz

Great :)

On Sat, Jan 3, 2015, 19:21 Thomás Sieczkowski [email protected] wrote:

YES! But I’m on vacation. I’ll be back on jan 10th!

Thomás Sieczkowski http://www.thomashs.com.br [email protected]

  • 55 51 9182 4581

Em 03/01/2015, à(s) 09:33, Adrien [email protected] escreveu:

Hey, happy new year !

Are you still planning on working on this ?

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/Intrepidd/working_hours/pull/14#issuecomment-68604115 .

Intrepidd avatar Jan 03 '15 18:01 Intrepidd

Closing as stale, 10 years later ;)

Intrepidd avatar Jan 24 '24 12:01 Intrepidd