counter_culture icon indicating copy to clipboard operation
counter_culture copied to clipboard

Fix passing a proc to `column_names`

Open KevinCarterDev opened this issue 2 years ago • 4 comments

The documentation states

You can specify a scope instead of a where condition string for column_names. We recommend providing a Proc that returns a hash instead of directly providing a hash: If you were to directly provide a scope this would load your schema cache on startup which will break things like rake db:migrate.

This doesn't work tho as the proc is immediately call-ed in the counter_culture method to check it's return value. To fix this I've moved the ArgumentError from the setup side to the runtime side.

KevinCarterDev avatar Apr 25 '22 23:04 KevinCarterDev

options[:column_names] could still be checked as a Hash or a Proc on startup, as it was before this commit : https://github.com/magnusvk/counter_culture/commit/2a86dd82daefdc75744d08b42e50a5681239ebb2#diff-34fcb2d6df6a065b09e89f5e0980d73d3bd56f9e91c1bd71ded2ff36610df30aL48-R60

But yes, the proc should not be called on startup.

AntoineBecquet avatar May 25 '22 13:05 AntoineBecquet

This fixes issue https://github.com/magnusvk/counter_culture/issues/347.

AntoineBecquet avatar May 25 '22 13:05 AntoineBecquet

I've updated it to add back in the check for a hash or proc and raise an error if it's not one of those.

KevinCarterDev avatar May 25 '22 17:05 KevinCarterDev

I'm running into this issue as well, any chance of getting this merged into the gem...? @magnusvk

nzifnab avatar Sep 12 '22 22:09 nzifnab

Released in gem version 3.3.0. Sorry for the delay and thanks for the contribution.

magnusvk avatar Oct 12 '22 03:10 magnusvk