Skip to content

Commit

Permalink
Merge pull request #25 from IoraHealth/ar-fix-bug-with-restful-update…
Browse files Browse the repository at this point in the history
…-supporting-both-patch-and-put

Fix bug with restful update supporting both patch and put
  • Loading branch information
alexrothenberg committed Feb 4, 2016
2 parents 53d8631 + f2e7bc3 commit 39fccb7
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 43 deletions.
Binary file modified bin/braise
Binary file not shown.
4 changes: 0 additions & 4 deletions examples/output/model/v1/calendar-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export default DS.Model.extend({
show: function() {
throw new Error("'show' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
4 changes: 0 additions & 4 deletions examples/output/model/v20150918/emergency-contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ export default DS.Model.extend({
update: function() {
throw new Error("'update' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
4 changes: 0 additions & 4 deletions examples/output/model/v20150918/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export default DS.Model.extend({
update: function() {
throw new Error("'update' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
4 changes: 0 additions & 4 deletions examples/output/model/v20150918/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export default DS.Model.extend({
update: function() {
throw new Error("'update' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
4 changes: 0 additions & 4 deletions examples/output/model/v20150918/practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export default DS.Model.extend({
update: function() {
throw new Error("'update' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
4 changes: 0 additions & 4 deletions examples/output/model/v20150918/staff-member.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export default DS.Model.extend({
update: function() {
throw new Error("'update' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
4 changes: 0 additions & 4 deletions examples/output/model/v20150918/state-of-health.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export default DS.Model.extend({
update: function() {
throw new Error("'update' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
4 changes: 0 additions & 4 deletions examples/output/model/v3/medication-verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export default DS.Model.extend({
update: function() {
throw new Error("'update' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
4 changes: 0 additions & 4 deletions examples/output/model/v3/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export default DS.Model.extend({
update: function() {
throw new Error("'update' is not supported by the api");
}
,
update: function() {
throw new Error("'update' is not supported by the api");
}
,
delete: function() {
throw new Error("'delete' is not supported by the api");
Expand Down
3 changes: 1 addition & 2 deletions lib/braise/link_action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ defmodule Braise.LinkAction do
%Braise.LinkAction{restful: true, name: :show, method: "GET", on_member: true},
%Braise.LinkAction{restful: true, name: :create, method: "POST", on_member: false},
%Braise.LinkAction{restful: true, name: :update, method: "PUT", on_member: true},
%Braise.LinkAction{restful: true, name: :update, method: "PATCH", on_member: true},
%Braise.LinkAction{restful: true, name: :delete, method: "DELETE", on_member: true}
]

Expand All @@ -50,7 +49,7 @@ defmodule Braise.LinkAction do
%Braise.LinkAction{restful: true, name: :update, method: "PUT", on_member: true}
end
defp restful_action("PATCH", _) do
%Braise.LinkAction{restful: true, name: :update, method: "PATCH", on_member: true}
%Braise.LinkAction{restful: true, name: :update, method: "PUT", on_member: true}
end
defp restful_action("DELETE", _) do
%Braise.LinkAction{restful: true, name: :delete, method: "DELETE", on_member: true}
Expand Down
9 changes: 4 additions & 5 deletions test/link_action_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ defmodule LinkActionTest do
assert name("patient", link) == %Braise.LinkAction{method: "PUT", name: :update, on_member: true, restful: true}
end

test "restful update action (patch)" do
test "restful update action (patch - we group with PUT update action to avoid dups)" do
link = %{"method"=>"PATCH", "href"=>"http://blah.com/api/v1/patients/123"}
assert name("patient", link) == %Braise.LinkAction{method: "PATCH", name: :update, on_member: true, restful: true}
assert name("patient", link) == %Braise.LinkAction{method: "PUT", name: :update, on_member: true, restful: true}
end

test "restful delete action" do
Expand All @@ -47,14 +47,13 @@ defmodule LinkActionTest do

test "finding the unsupported-restful actions" do
index = %Braise.LinkAction{method: "GET", name: :index, on_member: false, restful: true}
update = %Braise.LinkAction{method: "PUT", name: :update, on_member: true, restful: true}
cancel = %Braise.LinkAction{method: "PUT", name: "cancel", on_member: true, restful: false}
actions = [index, cancel]
actions = [index, update, cancel]

expected = [
%Braise.LinkAction{method: "GET", name: :show, on_member: true, restful: true},
%Braise.LinkAction{method: "POST", name: :create, on_member: false, restful: true},
%Braise.LinkAction{method: "PUT", name: :update, on_member: true, restful: true},
%Braise.LinkAction{method: "PATCH", name: :update, on_member: true, restful: true},
%Braise.LinkAction{method: "DELETE", name: :delete, on_member: true, restful: true}
]
assert unsupported_restful_actions(actions) == expected
Expand Down

0 comments on commit 39fccb7

Please sign in to comment.