3 class WayVersionsTest < ActionDispatch::IntegrationTest
 
   5   # check that we can retrieve versions of a way
 
   7     way = create(:way, :with_history)
 
   8     used_way = create(:way, :with_history)
 
   9     create(:relation_member, :member => used_way)
 
  10     way_with_versions = create(:way, :with_history, :version => 4)
 
  12     create(:way_tag, :way => way)
 
  13     create(:way_tag, :way => used_way)
 
  14     create(:way_tag, :way => way_with_versions)
 
  15     propagate_tags(way, way.old_ways.last)
 
  16     propagate_tags(used_way, used_way.old_ways.last)
 
  17     propagate_tags(way_with_versions, way_with_versions.old_ways.last)
 
  19     check_current_version(way.id)
 
  20     check_current_version(used_way.id)
 
  21     check_current_version(way_with_versions.id)
 
  27   # check that the current version of a way is equivalent to the
 
  28   # version which we're getting from the versions call.
 
  29   def check_current_version(way_id)
 
  30     # get the current version
 
  31     current_way = with_controller(WaysController.new) do
 
  32       get api_way_path(way_id)
 
  33       assert_response :success, "can't get current way #{way_id}"
 
  34       Way.from_xml(@response.body)
 
  36     assert_not_nil current_way, "getting way #{way_id} returned nil"
 
  38     # get the "old" version of the way from the version method
 
  39     get api_way_version_path(way_id, current_way.version)
 
  40     assert_response :success, "can't get old way #{way_id}, v#{current_way.version}"
 
  41     old_way = Way.from_xml(@response.body)
 
  43     # check that the ways are identical
 
  44     assert_ways_are_equal current_way, old_way
 
  47   def propagate_tags(way, old_way)
 
  48     way.tags.each do |k, v|
 
  49       create(:old_way_tag, :old_way => old_way, :k => k, :v => v)