Skip to content

Commit

Permalink
Merge pull request #27 from joaomdmoura/fix-machinery-dashboard
Browse files Browse the repository at this point in the history
Better treating the JSON return for the Dashboard
  • Loading branch information
joaomdmoura authored Jan 22, 2018
2 parents 426c922 + 4892767 commit 33b50e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ChangeLog

## WIP Version
- Better treating the JSON return for the Dashboard - [Pull Request](https://github.com/joaomdmoura/machinery/pull/27)

## 0.12.0
- Adding new toogle all btn and auto closing alerts - [Pull Request](https://github.com/joaomdmoura/machinery/pull/24)
Expand Down
5 changes: 4 additions & 1 deletion lib/web/controllers/resource_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ defmodule Machinery.ResourceController do
machinery_module = conn.assigns.module

struct = repo.get!(model, id)
{transition, content} = Machinery.transition_to(struct, machinery_module, state)
{transition, content} = case Machinery.transition_to(struct, machinery_module, state) do
{:ok, struct} -> {:ok, struct.id}
{:error, message} -> {:error, message}
end

json(conn, [transition, content])
end
Expand Down
3 changes: 2 additions & 1 deletion test/web/controllers/resource_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ defmodule MachineryTest.ResourceControllerTest do
@tag :capture_log
test "index/2 api should enable to transition states" do
updated_stuct = %{"state" => "partial", "missing_fields" => true, "id" => "1"}
id = Map.get(updated_stuct, "id")
conn = Machinery.Plug.call(conn(:post, "/machinery/api/resources/#{updated_stuct["id"]}", state: "partial"), [])
assert Poison.decode!(conn.resp_body) == ["ok", updated_stuct]
assert Poison.decode!(conn.resp_body) == ["ok", id]
end

defp stringify_keys(nil), do: nil
Expand Down

0 comments on commit 33b50e6

Please sign in to comment.