Skip to content

Commit f747e90

Browse files
authored
Merge pull request #817 from cerebris/update_relationship_nil
Test for update_relationship to nil.
2 parents 3c06c3c + 7d68db6 commit f747e90

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

test/controllers/controller_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,19 @@ def test_update_relationship_to_one
10751075
assert_equal ruby.id, post_object.section_id
10761076
end
10771077

1078+
def test_update_relationship_to_one_nil
1079+
set_content_type_header!
1080+
ruby = Section.find_by(name: 'ruby')
1081+
post_object = Post.find(4)
1082+
assert_not_equal ruby.id, post_object.section_id
1083+
1084+
put :update_relationship, params: {post_id: 4, relationship: 'section', data: nil}
1085+
1086+
assert_response :no_content
1087+
post_object = Post.find(4)
1088+
assert_equal nil, post_object.section_id
1089+
end
1090+
10781091
def test_update_relationship_to_one_invalid_links_hash_keys_ids
10791092
set_content_type_header!
10801093
put :update_relationship, params: {post_id: 3, relationship: 'section', data: {type: 'sections', ids: 'foo'}}

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class TestApp < Rails::Application
5656
if Rails::VERSION::MAJOR >= 5
5757
config.active_support.halt_callback_chains_on_return_false = false
5858
config.active_record.time_zone_aware_types = [:time, :datetime]
59+
config.active_record.belongs_to_required_by_default = false
5960
end
6061
end
6162

0 commit comments

Comments
 (0)