Skip to content

Confusion with string/symbol keys #17

@glennfu

Description

@glennfu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions