Convert the duplicate_tags node controller test to use factories.

This commit is contained in:
Andy Allan 2017-04-24 20:41:43 +02:00
parent b375050e6c
commit d595577a49
2 changed files with 9 additions and 9 deletions

View file

@ -460,25 +460,26 @@ class NodeControllerTest < ActionController::TestCase
## ##
# test adding tags to a node # test adding tags to a node
def test_duplicate_tags def test_duplicate_tags
existing = create(:node_tag, :node => current_nodes(:public_visible_node)) existing_tag = create(:node_tag)
assert_equal true, existing_tag.node.changeset.user.data_public
# setup auth # setup auth
basic_authorization(users(:public_user).email, "test") basic_authorization(existing_tag.node.changeset.user.email, "test")
# add an identical tag to the node # add an identical tag to the node
tag_xml = XML::Node.new("tag") tag_xml = XML::Node.new("tag")
tag_xml["k"] = existing.k tag_xml["k"] = existing_tag.k
tag_xml["v"] = existing.v tag_xml["v"] = existing_tag.v
# add the tag into the existing xml # add the tag into the existing xml
node_xml = current_nodes(:public_visible_node).to_xml node_xml = existing_tag.node.to_xml
node_xml.find("//osm/node").first << tag_xml node_xml.find("//osm/node").first << tag_xml
# try and upload it # try and upload it
content node_xml content node_xml
put :update, :id => current_nodes(:public_visible_node).id put :update, :id => existing_tag.node.id
assert_response :bad_request, assert_response :bad_request,
"adding duplicate tags to a node should fail with 'bad request'" "adding duplicate tags to a node should fail with 'bad request'"
assert_equal "Element node/#{current_nodes(:public_visible_node).id} has duplicate tags with key #{existing.k}", @response.body assert_equal "Element node/#{existing_tag.node.id} has duplicate tags with key #{existing_tag.k}", @response.body
end end
# test whether string injection is possible # test whether string injection is possible

View file

@ -3,7 +3,6 @@ FactoryGirl.define do
sequence(:k) { |n| "Key #{n}" } sequence(:k) { |n| "Key #{n}" }
sequence(:v) { |n| "Value #{n}" } sequence(:v) { |n| "Value #{n}" }
# Fixme requires node factory node
node_id 1
end end
end end