Skip to content

Allow new hash syntax in Representation and Interpreter #62

Description

@jpserra

Hi there,

I stumbled upon this issue while developing some specs for my project. I wanted to mock a HalClient::Representation by providing the parsed_json option to the constructor.

If the parsed_json hash keys are symbols instead of strings, things don't work quite like they should.

I'll leave a sample interaction for you to validate if this is something you'd like to see patched or not. Let me know !

[6] pry(main)> json = {
                        :plan => {
                          :id => "fake_plan_id", 
                          :name =>"Awesome Name", 
                          :amount => 0
                        },
                        :counter => 250
                      }
=> {:plan=>{:id=>"fake_plan_id", :name=>"Awesome Name", :amount=>0}, :counter=>250}
[7] pry(main)> resp = HalClient::Representation.new(parsed_json: json)
=> #<HalClient::Representation:0x75d402d4 @hal_client=nil, @href=nil, @raw={:plan=>{:id=>"fake_plan_id", :name=>"Awesome Name", :amount=>0}, :counter=>250}>
[8] pry(main)> resp.property(:plan)
KeyError: key not found: :plan
[9] pry(main)> resp.property('plan')
KeyError: key not found: :plan
[10] pry(main)> json = {
                          'plan' => {
                            'id' => "fake_plan_id", 
                            'name' => "Awesome Name", 
                            'amount' => 0
                          }, 
                          'counter' => 250
                        }
=> {"plan"=>{"id"=>"fake_plan_id", "name"=>"Awesome Name", "amount"=>0}, "counter"=>250}
[11] pry(main)> resp = HalClient::Representation.new(parsed_json: json)
=> #<HalClient::Representation:0x3d42b756 @hal_client=nil, @href=nil, @raw={"plan"=>{"id"=>"fake_plan_id", "name"=>"Awesome Name", "amount"=>0}, "counter"=>250}>
[12] pry(main)> resp.property('plan')
=> {"id"=>"fake_plan_id", "name"=>"Awesome Name", "amount"=>0}
[13] pry(main)> resp.property(:plan)
=> {"id"=>"fake_plan_id", "name"=>"Awesome Name", "amount"=>0}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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