Skip to content

Commit

Permalink
fixed broken validation, added server tests (rethinkdb#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tryneus authored Aug 18, 2016
1 parent ade8288 commit d598791
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/src/endpoint/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const run = (raw_request, context, ruleset, metadata, send, done) => {
r.expr(rows.map((row) => row.id))
.map((id) => collection.table.get(id))
.run(conn, reql_options),
(row, info) => writes.validate_old_row_required(row, info, null, ruleset),
(row, info) => writes.validate_old_row_required(context, row, info, null, ruleset),
(rows) => // write to database, all valid rows
r.expr(rows).do((row_data) =>
row_data.forEach((info) =>
Expand Down
2 changes: 1 addition & 1 deletion server/src/endpoint/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const run = (raw_request, context, ruleset, metadata, send, done) => {
r.expr(rows.map((row) => row.id))
.map((id) => collection.table.get(id))
.run(conn, reql_options),
(row, info) => writes.validate_old_row_required(row, info, row, ruleset),
(row, info) => writes.validate_old_row_required(context, row, info, row, ruleset),
(rows) => // write to database, all valid rows
r.expr(rows)
.forEach((new_row) =>
Expand Down
2 changes: 1 addition & 1 deletion server/src/endpoint/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const run = (raw_request, context, ruleset, metadata, send, done) => {
r.expr(rows.map((row) => (row.id === undefined ? null : row.id)))
.map((id) => r.branch(id.eq(null), null, collection.table.get(id)))
.run(conn, reql_options),
(row, info) => writes.validate_old_row_optional(row, info, row, ruleset),
(row, info) => writes.validate_old_row_optional(context, row, info, row, ruleset),
(rows) => // write to database, all valid rows
r.expr(rows)
.forEach((new_row) =>
Expand Down
2 changes: 1 addition & 1 deletion server/src/endpoint/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const run = (raw_request, context, ruleset, metadata, send, done) => {
null,
[ old_row, old_row.merge(new_row) ])))
.run(conn, reql_options),
(row, info) => writes.validate_old_row_required(row, info[0], info[1], ruleset),
(row, info) => writes.validate_old_row_required(context, row, info[0], info[1], ruleset),
(rows) => // write to database, all valid rows
r.expr(rows)
.forEach((new_row) =>
Expand Down
2 changes: 1 addition & 1 deletion server/src/endpoint/upsert.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const run = (raw_request, context, ruleset, metadata, send, done) => {
[ old_row, old_row.merge(new_row) ])),
[ null, new_row ]))
.run(conn, reql_options),
(row, info) => writes.validate_old_row_optional(row, info[0], info[1], ruleset),
(row, info) => writes.validate_old_row_optional(context, row, info[0], info[1], ruleset),
(rows) => // write to database, all valid rows
r.expr(rows)
.forEach((new_row) =>
Expand Down
4 changes: 2 additions & 2 deletions server/src/endpoint/writes.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const retry_loop = (original_rows, ruleset, timeout, pre_validate, validate_row,
null).then(make_write_response);
};

const validate_old_row_optional = (original, old_row, new_row, ruleset) => {
const validate_old_row_optional = (context, original, old_row, new_row, ruleset) => {
const expected_version = original[hz_v];
if (expected_version !== undefined &&
(!old_row || expected_version !== old_row[hz_v])) {
Expand All @@ -148,7 +148,7 @@ const validate_old_row_optional = (original, old_row, new_row, ruleset) => {
}
};

const validate_old_row_required = (original, old_row, new_row, ruleset) => {
const validate_old_row_required = (context, original, old_row, new_row, ruleset) => {
if (old_row === null) {
return new Error(missing_msg);
}
Expand Down
Loading

0 comments on commit d598791

Please sign in to comment.