]> git.openstreetmap.org Git - rails.git/commitdiff
Add a way_with_nodes factory, and use it in the way_controller tests.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 26 Apr 2017 06:34:01 +0000 (08:34 +0200)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 26 Apr 2017 06:34:01 +0000 (08:34 +0200)
test/controllers/way_controller_test.rb
test/factories/way.rb

index 7813fb029f772e05fb97f9f416d18c62c8234fc9..c81593249fd84f978dbeca1a9a1c047f6a906600 100644 (file)
@@ -509,9 +509,14 @@ class WayControllerTest < ActionController::TestCase
   ##
   # Try adding a new tag to a way
   def test_add_tags
+    private_user = create(:user, :data_public => false)
+    private_way = create(:way_with_nodes, :nodes_count => 2, :changeset => create(:changeset, :user => private_user))
+    user = create(:user)
+    way = create(:way_with_nodes, :nodes_count => 2, :changeset => create(:changeset, :user => user))
+
     ## Try with the non-public user
     # setup auth
-    basic_authorization(users(:normal_user).email, "test")
+    basic_authorization(private_user.email, "test")
 
     # add an identical tag to the way
     tag_xml = XML::Node.new("tag")
@@ -519,18 +524,18 @@ class WayControllerTest < ActionController::TestCase
     tag_xml["v"] = "yes"
 
     # add the tag into the existing xml
-    way_xml = current_ways(:visible_way).to_xml
+    way_xml = private_way.to_xml
     way_xml.find("//osm/way").first << tag_xml
 
     # try and upload it
     content way_xml
-    put :update, :id => current_ways(:visible_way).id
+    put :update, :id => private_way.id
     assert_response :forbidden,
                     "adding a duplicate tag to a way for a non-public should fail with 'forbidden'"
 
     ## Now try with the public user
     # setup auth
-    basic_authorization(users(:public_user).email, "test")
+    basic_authorization(user.email, "test")
 
     # add an identical tag to the way
     tag_xml = XML::Node.new("tag")
@@ -538,15 +543,15 @@ class WayControllerTest < ActionController::TestCase
     tag_xml["v"] = "yes"
 
     # add the tag into the existing xml
-    way_xml = current_ways(:visible_way).to_xml
+    way_xml = way.to_xml
     way_xml.find("//osm/way").first << tag_xml
 
     # try and upload it
     content way_xml
-    put :update, :id => current_ways(:visible_way).id
+    put :update, :id => way.id
     assert_response :success,
                     "adding a new tag to a way should succeed"
-    assert_equal current_ways(:visible_way).version + 1, @response.body.to_i
+    assert_equal way.version + 1, @response.body.to_i
   end
 
   ##
index 7c35316478b17a0e941e5162292b781859f1343a..89409e807aa0a1088edd3b39ca61c5c3dea903f9 100644 (file)
@@ -9,5 +9,17 @@ FactoryGirl.define do
     trait :deleted do
       visible false
     end
+
+    factory :way_with_nodes do
+      transient do
+        nodes_count 1
+      end
+
+      after(:create) do |way, evaluator|
+        (1..evaluator.nodes_count).each do |n|
+          create(:way_node, :way => way, :sequence_id => n)
+        end
+      end
+    end
   end
 end