Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/RickCarlino/volt into Ric…
Browse files Browse the repository at this point in the history
…kCarlino-master
  • Loading branch information
ryanstout committed Jun 3, 2015
2 parents eefbbf6 + 338161f commit e13adda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/volt/models/array_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ def to_a
array
end

def to_json
to_a.to_json
end


def inspect
Computation.run_without_tracking do
# Track on size
Expand Down
4 changes: 4 additions & 0 deletions lib/volt/models/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ def destroy
end
end

def to_json
to_h.to_json
end

private
def run_initial_setup(initial_setup)
# Save the changes
Expand Down
10 changes: 10 additions & 0 deletions spec/models/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,14 @@ def name=(val)
'Model does not have a parent and cannot be deleted.')
end
end

describe 'serialization' do
it 'supports JSON via to_json' do
model = Volt::Model.new({})
expect(model.to_json).to eq(model.to_h.to_json)
expect(model.to_json).to eq(model.to_h.to_json)
array_model = Volt::ArrayModel.new([model])
expect(array_model.to_json).to eq(array_model.to_a.to_json)
end
end
end

0 comments on commit e13adda

Please sign in to comment.