Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion with string/symbol keys #17

Open
glennfu opened this issue May 26, 2015 · 0 comments · May be fixed by #20
Open

Confusion with string/symbol keys #17

glennfu opened this issue May 26, 2015 · 0 comments · May be fixed by #20

Comments

@glennfu
Copy link

glennfu commented May 26, 2015

I just upgraded to 0.0.5 to 0.1.2, and noticed some specs failing. With my Story model like:

class Story < ActiveRecord::Base

    serialize :data, ActiveRecord::Coders::NestedHstore` I had a spec like:

    def twitter_title
      data && data["twitterDescription"] ? data["twitterDescription"] : title
    end

end

Then my spec like:

story = create(:story, title: "This is the title", data: {twitterDescription: "Title"})
story.twitter_title.should == "Title"

This was passing before. Now it doesn't pass because story.data["twitterDescription"] == nil and story.data[:twitterDescription] == "Title".

To fix my spec, I need to change it to:

story = create(:story, title: "This is the title", data: {twitterDescription: "Title"})
story.reload
story.twitter_title.should == "Title"

Is this a bug or intended behavior? I'd prefer the previous behavior, where the output was consistent before and after the model had been reloaded. The keys were always strings and I could code for that.

To clarify: if you set a hash with string keys, they stay string keys before and after a model reload. If you set a hash with symbol keys, they'll be symbols until you reload the model and then they'll be strings.

@amasses amasses linked a pull request Feb 7, 2017 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant