raise OSM::APIPreconditionFailedError, "New and old IDs don't match on #{new.class}. #{new.id} != #{old.id}."
elsif new.version != old.version
raise OSM::APIVersionMismatchError.new(new.id, new.class.to_s, new.version, old.version)
- elsif new.changeset.nil?
- raise OSM::APIChangesetMissingError
- elsif new.changeset.user_id != user.id
- raise OSM::APIUserChangesetMismatchError
- elsif !new.changeset.open?
- raise OSM::APIChangesetAlreadyClosedError, new.changeset
end
+
+ check_changeset_consistency(new.changeset, user)
end
# This is similar to above, just some validations don't apply
node.create_with_history(user)
end
end
+
+ test "raises id precondition exception when updating" do
+ user = create(:user)
+ node = Node.new(:id => 23)
+ new_node = Node.new(:id => 42)
+ assert_raises OSM::APIPreconditionFailedError do
+ node.update_from(new_node, user)
+ end
+ end
+
+ test "raises version mismatch exception when updating" do
+ user = create(:user)
+ node = Node.new(:id => 42, :version => 7)
+ new_node = Node.new(:id => 42, :version => 12)
+ assert_raises OSM::APIVersionMismatchError do
+ node.update_from(new_node, user)
+ end
+ end
+
+ test "raises missing changeset exception when updating" do
+ user = create(:user)
+ node = Node.new(:id => 42, :version => 12)
+ new_node = Node.new(:id => 42, :version => 12)
+ assert_raises OSM::APIChangesetMissingError do
+ node.update_from(new_node, user)
+ end
+ end
+
+ test "raises user-changeset mismatch exception when updating" do
+ user = create(:user)
+ changeset = create(:changeset)
+ node = Node.new(:id => 42, :version => 12)
+ new_node = Node.new(:id => 42, :version => 12, :changeset => changeset)
+ assert_raises OSM::APIUserChangesetMismatchError do
+ node.update_from(new_node, user)
+ end
+ end
+
+ test "raises already closed changeset exception when updating" do
+ user = create(:user)
+ changeset = create(:changeset, :closed, :user => user)
+ node = Node.new(:id => 42, :version => 12)
+ new_node = Node.new(:id => 42, :version => 12, :changeset => changeset)
+ assert_raises OSM::APIChangesetAlreadyClosedError do
+ node.update_from(new_node, user)
+ end
+ end
end
relation.create_with_history(user)
end
end
+
+ test "raises id precondition exception when updating" do
+ user = create(:user)
+ relation = Relation.new(:id => 23)
+ new_relation = Relation.new(:id => 42)
+ assert_raises OSM::APIPreconditionFailedError do
+ relation.update_from(new_relation, user)
+ end
+ end
+
+ test "raises version mismatch exception when updating" do
+ user = create(:user)
+ relation = Relation.new(:id => 42, :version => 7)
+ new_relation = Relation.new(:id => 42, :version => 12)
+ assert_raises OSM::APIVersionMismatchError do
+ relation.update_from(new_relation, user)
+ end
+ end
+
+ test "raises missing changeset exception when updating" do
+ user = create(:user)
+ relation = Relation.new(:id => 42, :version => 12)
+ new_relation = Relation.new(:id => 42, :version => 12)
+ assert_raises OSM::APIChangesetMissingError do
+ relation.update_from(new_relation, user)
+ end
+ end
+
+ test "raises user-changeset mismatch exception when updating" do
+ user = create(:user)
+ changeset = create(:changeset)
+ relation = Relation.new(:id => 42, :version => 12)
+ new_relation = Relation.new(:id => 42, :version => 12, :changeset => changeset)
+ assert_raises OSM::APIUserChangesetMismatchError do
+ relation.update_from(new_relation, user)
+ end
+ end
+
+ test "raises already closed changeset exception when updating" do
+ user = create(:user)
+ changeset = create(:changeset, :closed, :user => user)
+ relation = Relation.new(:id => 42, :version => 12)
+ new_relation = Relation.new(:id => 42, :version => 12, :changeset => changeset)
+ assert_raises OSM::APIChangesetAlreadyClosedError do
+ relation.update_from(new_relation, user)
+ end
+ end
end
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
end