Closed viralpraxis closed 3 months ago
Hey @viralpraxis. What Rails version are you using?
@nashby ruby MRI 3.3.0, rails 7.1.3.2
@viralpraxis I did a quick test with STI and everything seems to work fine. So my guess is that something is fishy with JSONB/jsonb_accessor gem. Will try to reproduce it tonight (unless you want to try to add a failing spec, that would be really helpful)
@nashby I made a repo with reproducible behaviour https://github.com/viralpraxis/enumerize-mre
Running with 2.8.0:
$ bundle exec rails test
Running 1 tests in a single process (parallelization threshold is 50)
Run options: --seed 60429
# Running:
F
Failure:
ThemeSpecificTest#test_creation [test/models/theme/specific_test.rb:11]:
Expected: "border"
Actual: nil
Running with 2.7.0:
(test passes)
(the only non-default files are Gemfile
, app/models/theme.rb
and app/models/theme/specific.rb
)
@viralpraxis thanks! I noticed if you add
jsonb_accessor :data, menu_variant: [:string, default: "default"]
to Specific
model the test passes. So there's something strange with how jsonb_accessor
works with STI. Will keep investigating
@viralpraxis this should be fixed by https://github.com/brainspec/enumerize/commit/47f0dc569a9dd2bc73e2b9fd5773fb37fe65634a. Could you please test master branch of enumerize with your app?
@nashby I can confirm that our tests are green when running against master 👍🏻
Hey @nashby 👋🏻 Thanks for the fix, any plans on releasing new version?
@viralpraxis 2.8.1 has been released! Thanks for reporting this issue and proving a sample app! ❤️
An MRE:
ThemeSpecific
is an STI-subclass ofTheme
.On 2.7.0 we had this behaviour:
On 2.8.0:
I'm not sure if it matters but
variant
is not an ordinary database column, it's a JSONB field (we usejsonb_accessor
gem to make it an AR attribute).Also, it seems like the issue is not STI-specific and happens due to subclassing