stex / setting_accessors

Global key-value-store and database-persisted attribute accessors

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails 5.2

rubydesign opened this issue · comments

Hi,
hear the talk at unconf and wanted to try.
Unfortunately i have rails 5.2 , so i was wondering what the plan is ?
T.

Hey!

Did you run into a specific problem when using Rails 5.2?
Generally, the gem should be working fine with it as the version as it's part of the CI testing

Ok, sorry. Yes bundler says
setting_accessors was resolved to 1.1.0, which depends on
activemodel (<= 5.2, >= 4.2)

since that was the only thing i added i assume that was the error. I mean bundler does say other things, but without setting_accessors all is good.

Haven't looked at the gemspec, but maybe you are restricting to 5.2 (.0 ?)

From my understanding, the gemspec should be ok, but I'll look into it with a fresh 5.2.x application :)

spec.add_dependency 'activemodel', ['>= 4.2', '<= 5.2']
spec.add_dependency 'activerecord', ['>= 4.2', '<= 5.2']
spec.add_dependency 'activesupport', ['>= 4.2', '<= 5.2']

Thanks for checking. I can never remember how those arrows go, it's not like they are well documented.
< 5.3 would seem intuitive

Ok, that bundles. I'll try out.
Thanks

The migration that is created by the generator does not work anymore
class CreateSettings < ActiveRecord::Migration
now needs to be
class CreateSettings < ActiveRecord::Migration[5.2]
but the 5.2 can be a 4.2 and it would still work (for all your supported versions, me thinks)

Still no luck, basic meaning of life example returns nil. I'll wait

Sorry about that, I'll try to get it working as soon as possible!

The applications I'm working were upgraded to Rails 5 with the gem already in place, I'm guessing this is why the problem never occurred.

A short update:

It looks like the with_model gem behaves slightly different from the actual AR implementation when it comes to belongs_to associations. These are by default required in Rails 5 and have to be explicitly marked with optional: true otherwise.

The "model" used in the tests does not exhibit this behaviour, might be a bug in with_model itself.


Otherwise, the gem is now working in a fresh 5.2.3 application, I'll test it in the other supported versions as well though.

For the future, I'll have to find a better way to test the actual integration including the migration itself and don't rely purely on dynamically generated tables in the tests.

Took a bit more effort, but I think I found a good way to ensure the migration is future proof from now on. The model was a bit more tricky as a "framework default" flag was missing in the testing environment, but should be ok now as well.

@rubydesign Could you give it another try in #17? And I'm really sorry about this, that's what happens when your stuff is used in projects that started on older versions :)

Don't be sorry, i think it's great your trying to fix this so quickly. Even it is trick with rails chainging under you.

I tried this out and the basic meaning_of_life is now indeed 42. So far so good.

The bad news is that some of my tests now fail :-( It looks like pages that use vue, specifically serialize data into the page with to_json

 Failure/Error: @products = #{@products.to_json(only: [:id , :price , :cost , :tax]).html_safe}
  
  ActionView::Template::Error:
    SettingAccessors::NestedHashKeyNotFoundError

That off course worked before, so my guess there is some patching in there that causes this ?
(PS sure understand if you want to stop here)

Did you do anything else except for including the gem in your application's Gemfile?

#to_json and #as_json should be covered by the tests, so I'll have to investigate a bit here.

That off course worked before, so my guess there is some patching in there that causes this ?

The gem adds setting attributes to the return value of #as_json as it would otherwise only include actual attributes. There might be an edge case here, probably if the gem was only included without specifying a single setting_accessor... I'll check it.

(PS sure understand if you want to stop here)

Not at all, it's great to get feedback from someone starting fresh with the Gem and pointing out problems I didn't see before. The Gem can only get better through this :)

I just included the gem, nothing else. The meaning_of_life i tested in the console.
I guess if you do a test case with to_json it should go bang, at least in a template. If not i will have to dig into my code.

Lets keep at it then. ps, day job may sometimes mean i'm slow responding

Lets keep at it then. ps, day job may sometimes mean i'm slow responding

Same :)

I just included the gem, nothing else. The meaning_of_life i tested in the console.

That's exactly the problem, as soon as a setting_accessor is defined, everything works as expected. I'll write a test for it and get it fixed.

@rubydesign Could you try again now?

@stex no more boom ! All tests are green.
Look like you can close this.
Will you put out a patch version for this ?

Glad to hear this :)

I'll release a new version with the fixes, thanks again for opening the issue and helping me with finding the various problems!

With the changes to the gem's tests, I'm pretty confident that problems like this shouldn't occur in the future again.

@rubydesign I released a new version with the fixes. If you come across anything else that seems off, please let me know :)