Skip to content

Commit

Permalink
OpenStructWithHashAccess should delegate #to_json and #as_json to the…
Browse files Browse the repository at this point in the history
… internal hash
  • Loading branch information
cbeer committed Feb 21, 2014
1 parent 693886f commit 5915451
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/blacklight/utils.rb
@@ -1,7 +1,7 @@
require 'ostruct'
module Blacklight
class OpenStructWithHashAccess < OpenStruct
delegate :keys, :each, :map, :has_key?, :empty?, :delete, :length, :reject!, :select!, :include, :fetch, :to => :to_h
delegate :keys, :each, :map, :has_key?, :empty?, :delete, :length, :reject!, :select!, :include, :fetch, :to_json, :as_json, :to => :to_h

def []=(key, value)
send "#{key}=", value
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/utils_spec.rb
Expand Up @@ -84,5 +84,13 @@
expect(@h[:a]).to eq 'a'
end
end

describe "#to_json" do
subject { Blacklight::OpenStructWithHashAccess.new a: 1, b: 2}

it "should serialize as json" do
expect(subject.to_json).to eq ({a: 1, b:2}).to_json
end
end
end
end

0 comments on commit 5915451

Please sign in to comment.