##
# test searching ways
def test_search_ways
+ [:visible_way, :invisible_way, :used_way].each do |way|
+ create(:way_tag, :way => current_ways(way), :k => "test", :v => "yes")
+ end
+ create(:way_tag, :way => current_ways(:used_way), :k => "name", :v => "Test Way")
+
get :search_ways, :type => "test"
assert_response :service_unavailable
assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
# setup auth
basic_authorization(users(:normal_user).email, "test")
+ existing = create(:way_tag, :way => current_ways(:visible_way))
+
# add an identical tag to the way
tag_xml = XML::Node.new("tag")
- tag_xml["k"] = current_way_tags(:t1).k
- tag_xml["v"] = current_way_tags(:t1).v
+ tag_xml["k"] = existing.k
+ tag_xml["v"] = existing.v
# add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml
# add an identical tag to the way
tag_xml = XML::Node.new("tag")
- tag_xml["k"] = current_way_tags(:t1).k
- tag_xml["v"] = current_way_tags(:t1).v
+ tag_xml["k"] = existing.k
+ tag_xml["v"] = existing.v
# add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml
put :update, :id => current_ways(:visible_way).id
assert_response :bad_request,
"adding a duplicate tag to a way should fail with 'bad request'"
- assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{current_way_tags(:t1).k}", @response.body
+ assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{existing.k}", @response.body
end
##
--- /dev/null
+FactoryGirl.define do
+ factory :way_tag do
+ sequence(:k) { |n| "Key #{n}" }
+ sequence(:v) { |n| "Value #{n}" }
+
+ # Fixme requires way factory
+ way_id 1
+ end
+end
+++ /dev/null
-t1:
- way_id: 1
- k: 'test'
- v: 'yes'
-
-t2:
- way_id: 2
- k: 'test'
- v: 'yes'
-
-t3:
- way_id: 3
- k: 'test'
- v: 'yes'
-
-t3_t2:
- way_id: 3
- k: 'name'
- v: 'Test Way'
-
-wv_t1:
- way_id: 4
- k: 'testing'
- v: 'added in way version 3'
-
-wv_t2:
- way_id: 4
- k: 'testing two'
- v: 'modified in way version 4'
require "test_helper"
class WayTagTest < ActiveSupport::TestCase
- api_fixtures
-
- def test_way_tag_count
- assert_equal 6, WayTag.count
- end
-
def test_length_key_valid
- key = "k"
+ tag = create(:way_tag)
(0..255).each do |i|
- tag = WayTag.new
- tag.way_id = current_way_tags(:t1).way_id
- tag.k = key * i
- tag.v = current_way_tags(:t1).v
+ tag.k = "k" * i
assert tag.valid?
end
end
def test_length_value_valid
- val = "v"
+ tag = create(:way_tag)
(0..255).each do |i|
- tag = WayTag.new
- tag.way_id = current_way_tags(:t1).way_id
- tag.k = "k"
- tag.v = val * i
+ tag.v = "v" * i
assert tag.valid?
end
end
def test_length_key_invalid
- ["k" * 256].each do |i|
- tag = WayTag.new
- tag.way_id = current_way_tags(:t1).way_id
- tag.k = i
- tag.v = "v"
- assert !tag.valid?, "Key #{i} should be too long"
- assert tag.errors[:k].any?
- end
+ tag = create(:way_tag)
+ tag.k = "k" * 256
+ assert !tag.valid?, "Key should be too long"
+ assert tag.errors[:k].any?
end
def test_length_value_invalid
- ["v" * 256].each do |i|
- tag = WayTag.new
- tag.way_id = current_way_tags(:t1).way_id
- tag.k = "k"
- tag.v = i
- assert !tag.valid?, "Value #{i} should be too long"
- assert tag.errors[:v].any?
- end
+ tag = create(:way_tag)
+ tag.v = "v" * 256
+ assert !tag.valid?, "Value should be too long"
+ assert tag.errors[:v].any?
end
def test_empty_tag_invalid
end
def test_uniqueness
+ existing = create(:way_tag)
tag = WayTag.new
- tag.way_id = current_way_tags(:t1).way_id
- tag.k = current_way_tags(:t1).k
- tag.v = current_way_tags(:t1).v
+ tag.way_id = existing.way_id
+ tag.k = existing.k
+ tag.v = existing.v
assert tag.new_record?
assert !tag.valid?
assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
def test_way_tags
way = current_ways(:way_with_versions)
+ taglist = create_list(:way_tag, 2, :way => way)
tags = Way.find(way.id).way_tags.order(:k)
assert_equal 2, tags.count
- assert_equal "testing", tags[0].k
- assert_equal "added in way version 3", tags[0].v
- assert_equal "testing two", tags[1].k
- assert_equal "modified in way version 4", tags[1].v
+ taglist.sort_by!(&:k).each_index do |i|
+ assert_equal taglist[i].k, tags[i].k
+ assert_equal taglist[i].v, tags[i].v
+ end
end
def test_tags
way = current_ways(:way_with_versions)
+ taglist = create_list(:way_tag, 2, :way => way)
tags = Way.find(way.id).tags
assert_equal 2, tags.size
- assert_equal "added in way version 3", tags["testing"]
- assert_equal "modified in way version 4", tags["testing two"]
+ taglist.each do |tag|
+ assert_equal tag.v, tags[tag.k]
+ end
end
def test_containing_relation_members
fixtures :current_ways
set_fixture_class :current_ways => Way
- fixtures :current_way_nodes, :current_way_tags
+ fixtures :current_way_nodes
set_fixture_class :current_way_nodes => WayNode
- set_fixture_class :current_way_tags => WayTag
fixtures :ways
set_fixture_class :ways => OldWay