Skip to content

Commit

Permalink
raise on nested new objects instead of silently just not saving them …
Browse files Browse the repository at this point in the history
…since REST api doesn't support it, circular saves are impossible
  • Loading branch information
ericcj committed May 22, 2013
1 parent 735ac0b commit 653145a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 135 deletions.
121 changes: 0 additions & 121 deletions fixtures/vcr_cassettes/test_circular_save.yml

This file was deleted.

62 changes: 62 additions & 0 deletions fixtures/vcr_cassettes/test_saving_nested_objects.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/parse/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def Parse.parse_datatype(obj)

def Parse.pointerize_value(obj)
if obj.kind_of?(Parse::Object)
obj.pointer
p = obj.pointer
raise ArgumentError.new("new object used in context requiring pointer #{obj}") unless p
p
elsif obj.is_a?(Array)
obj.map do |v|
Parse.pointerize_value(v)
Expand Down
21 changes: 8 additions & 13 deletions test/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ def test_nils_delete_keys
end
end

def test_saving_nested_objects
VCR.use_cassette('test_saving_nested_objects', :record => :new_episodes) do
post = Parse::Object.new "Post"
post["comment"] = Parse::Object.new("Comment", "text" => "testing")
assert_raise{post.save}
end
end

def test_boolean_values_as_json
post = Parse::Object.new "Post"
post["read"] = false
Expand Down Expand Up @@ -269,17 +277,4 @@ def test_save_with_sub_objects
assert_equal 'baz', bar['baz']
end
end

def test_circular_save
VCR.use_cassette('test_circular_save', :record => :new_episodes) do
bar = Parse::Object.new("CircularBar", "text" => "bar")
bar_2 = Parse::Object.new("CircularBar", "bar" => bar, "text" => "bar_2")
bar_2.save
bar['bar'] = bar_2
assert bar.save

assert_equal "bar_2", bar["bar"]["text"]
assert_equal "bar", bar["bar"]["bar"]["text"]
end
end
end

0 comments on commit 653145a

Please sign in to comment.