X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f50ca826aad559c77f948ccca61cbdc0bbddf3d1..70cb93a101638596ecae5782575ada2d4d08c8dd:/test/models/way_test.rb diff --git a/test/models/way_test.rb b/test/models/way_test.rb index 558984e35..36debfac0 100644 --- a/test/models/way_test.rb +++ b/test/models/way_test.rb @@ -243,4 +243,60 @@ class WayTest < ActiveSupport::TestCase way.create_with_history(user) end end + + test "raises id precondition exception when updating" do + user = create(:user) + way = Way.new(:id => 23) + new_way = Way.new(:id => 42) + assert_raises OSM::APIPreconditionFailedError do + way.update_from(new_way, user) + end + end + + test "raises version mismatch exception when updating" do + user = create(:user) + way = Way.new(:id => 42, :version => 7) + new_way = Way.new(:id => 42, :version => 12) + assert_raises OSM::APIVersionMismatchError do + way.update_from(new_way, user) + end + end + + test "raises missing changeset exception when updating" do + user = create(:user) + way = Way.new(:id => 42, :version => 12) + new_way = Way.new(:id => 42, :version => 12) + assert_raises OSM::APIChangesetMissingError do + way.update_from(new_way, user) + end + end + + test "raises user-changeset mismatch exception when updating" do + user = create(:user) + changeset = create(:changeset) + way = Way.new(:id => 42, :version => 12) + new_way = Way.new(:id => 42, :version => 12, :changeset => changeset) + assert_raises OSM::APIUserChangesetMismatchError do + way.update_from(new_way, user) + end + end + + test "raises already closed changeset exception when updating" do + user = create(:user) + changeset = create(:changeset, :closed, :user => user) + way = Way.new(:id => 42, :version => 12) + new_way = Way.new(:id => 42, :version => 12, :changeset => changeset) + assert_raises OSM::APIChangesetAlreadyClosedError do + way.update_from(new_way, user) + end + end + + test "raises id precondition exception when deleting" do + user = create(:user) + way = Way.new(:id => 23, :visible => true) + new_way = Way.new(:id => 42, :visible => false) + assert_raises OSM::APIPreconditionFailedError do + way.delete_with_history!(new_way, user) + end + end end