Skip to content

Commit

Permalink
cleanup test output. improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
slogsdon committed Dec 22, 2014
1 parent 44b5801 commit 16fc410
Show file tree
Hide file tree
Showing 23 changed files with 145 additions and 126 deletions.
50 changes: 0 additions & 50 deletions lib/mix/tasks/sugar/gen/config.ex

This file was deleted.

3 changes: 2 additions & 1 deletion lib/mix/tasks/sugar/gen/controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ defmodule Mix.Tasks.Sugar.Gen.Controller do
defp do_create_file(name, opts) do
module = camelize String.Chars.to_string(Mix.Project.config[:app])
name = camelize name
path = "lib/#{underscore name}"

assigns = [
app: Mix.Project.config[:app],
module: module,
name: name,
path: "lib/#{underscore module}"
path: path
] |> Keyword.merge opts
assigns = assigns |> Keyword.merge([name: camelize(assigns[:name])])

Expand Down
3 changes: 2 additions & 1 deletion lib/mix/tasks/sugar/gen/model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ defmodule Mix.Tasks.Sugar.Gen.Model do

defp do_create_files(name, opts) do
module = camelize String.Chars.to_string(Mix.Project.config[:app])
path = "lib/#{underscore name}"

assigns = [
app: Mix.Project.config[:app],
module: module,
name: camelize(name),
table_name: name,
path: "lib/#{underscore module}"
path: path
] |> Keyword.merge opts

Mix.Tasks.Ecto.Gen.Migration.run ["#{assigns[:module]}.Repos.Main", "create_#{name}"]
Expand Down
3 changes: 2 additions & 1 deletion lib/mix/tasks/sugar/gen/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ defmodule Mix.Tasks.Sugar.Gen.Router do

defp do_create_file(opts) do
module = camelize String.Chars.to_string(Mix.Project.config[:app])
path = "lib/#{underscore module}"

assigns = [
app: Mix.Project.config[:app],
module: module,
path: "lib/#{underscore module}"
path: path
] |> Keyword.merge opts

create_file "#{assigns[:path]}/router.ex", router_template(assigns)
Expand Down
3 changes: 2 additions & 1 deletion lib/mix/tasks/sugar/gen/view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ defmodule Mix.Tasks.Sugar.Gen.View do
defp do_create_file(name, opts) do
module = camelize String.Chars.to_string(Mix.Project.config[:app])
name = camelize name
path = "lib/#{underscore name}"

assigns = [
app: Mix.Project.config[:app],
module: module,
name: name,
path: "lib/#{underscore module}"
path: path
] |> Keyword.merge opts

case opts[:type] do
Expand Down
4 changes: 2 additions & 2 deletions lib/mix/tasks/sugar/init.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ defmodule Mix.Tasks.Sugar.Init do

defp do_init(opts) do
name = camelize String.Chars.to_string(Mix.Project.config[:app])
path = "lib/#{underscore name}"

assigns = [
app: Mix.Project.config[:app],
module: name,
path: "lib/#{underscore name}",
path: path,
priv_path: "priv"
] |> Keyword.merge opts

Expand All @@ -37,7 +38,6 @@ defmodule Mix.Tasks.Sugar.Init do
create_directory "#{assigns[:priv_path]}/static"

# Support files
Mix.Tasks.Sugar.Gen.Config.run_detached assigns
Mix.Tasks.Sugar.Gen.Router.run_detached assigns

# Controllers
Expand Down
3 changes: 2 additions & 1 deletion lib/mix/tasks/sugar/scaffold.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ defmodule Mix.Tasks.Sugar.Scaffold do
end

defp do_scaffold(name, opts) do
path = "lib/#{underscore name}"
assigns = [
app: Mix.Project.config[:app],
module: name,
path: "lib/#{underscore name}",
path: path,
priv_path: "priv"
] |> Keyword.merge opts

Expand Down
26 changes: 9 additions & 17 deletions lib/sugar/controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,11 @@ defmodule Sugar.Controller do
end

@doc """
Sends a normal response. Automatically renders a template based on
the current controller and action names.
Sends a normal response.
## Arguments
* `conn` - `Plug.Conn`
## Returns
`Plug.Conn`
"""
def render(conn) do
template = build_template_key(conn)
render_view(conn, template, [], [])
end

@doc """
Sends a normal response.
Automatically renders a template based on the
current controller and action names when no
template is passed.
## Arguments
Expand All @@ -184,12 +172,16 @@ defmodule Sugar.Controller do
`Plug.Conn`
"""
def render(conn, template, assigns \\ [], opts \\ [])
def render(conn, template \\ nil, assigns \\ [], opts \\ [])
def render(conn, template, assigns, opts) when is_atom(template)
or is_binary(template) do
template = build_template_key(conn, template)
render_view(conn, template, assigns, opts)
end
def render(conn, assigns, opts, _) when is_list(assigns) do
template = build_template_key(conn)
render_view(conn, template, assigns, opts)
end

defp render_view(conn, template_key, assigns, opts) do
opts = [status: 200] |> Keyword.merge opts
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/templates/index.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= @title %>
1 change: 1 addition & 0 deletions test/fixtures/view_finder/index.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= @title %>
9 changes: 7 additions & 2 deletions test/mix/tasks/server_test.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
defmodule Mix.Tasks.ServerTest do
use ExUnit.Case
import ExUnit.CaptureIO

test "run/1 with port" do
args = ["--port=8080"]
Mix.Tasks.Server.run(args)
capture_io(fn ->
Mix.Tasks.Server.run(args)
end)
end

test "run/1 without port" do
args = []
Mix.Tasks.Server.run(args)
capture_io(fn ->
Mix.Tasks.Server.run(args)
end)
end
end
25 changes: 0 additions & 25 deletions test/mix/tasks/sugar/gen/config_test.exs

This file was deleted.

9 changes: 7 additions & 2 deletions test/mix/tasks/sugar/gen/controller_test.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
defmodule Mix.Tasks.Sugar.Gen.ControllerTest do
use ExUnit.Case, async: true
import ExUnit.CaptureIO

test "run_detached/1" do
assigns = [
app: :test_app,
module: "TestApp",
path: "test/fixtures"
]
Mix.Tasks.Sugar.Gen.Controller.run_detached(assigns ++ [name: "main"])
capture_io(fn ->
Mix.Tasks.Sugar.Gen.Controller.run_detached(assigns ++ [name: "main"])
end)

assert File.exists?("test/fixtures/controllers/main.ex") === true
File.rm_rf! "test/fixtures/controllers"
end

test "run/1 with proper name" do
args = ["main", "--path=test/fixtures"]
Mix.Tasks.Sugar.Gen.Controller.run(args)
capture_io(fn ->
Mix.Tasks.Sugar.Gen.Controller.run(args)
end)

assert File.exists?("test/fixtures/controllers/main.ex") === true
File.rm_rf! "test/fixtures/controllers"
Expand Down
9 changes: 7 additions & 2 deletions test/mix/tasks/sugar/gen/model_test.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
defmodule Mix.Tasks.Sugar.Gen.ModelTest do
use ExUnit.Case, async: true
import ExUnit.CaptureIO

test "run_detached/1" do
assigns = [
app: :test_app,
module: "Mix.Tasks.Sugar.Gen.ModelTest",
path: "test/fixtures"
]
Mix.Tasks.Sugar.Gen.Model.run_detached(assigns ++ [name: "main"])
capture_io(fn ->
Mix.Tasks.Sugar.Gen.Model.run_detached(assigns ++ [name: "main"])
end)

assert File.exists?("test/fixtures/models/main.ex") === true
assert File.exists?("test/fixtures/queries/main.ex") === true
Expand All @@ -16,7 +19,9 @@ defmodule Mix.Tasks.Sugar.Gen.ModelTest do

test "run/1 with proper name" do
args = ["main", "--path=test/fixtures", "--module=Mix.Tasks.Sugar.Gen.ModelTest"]
Mix.Tasks.Sugar.Gen.Model.run(args)
capture_io(fn ->
Mix.Tasks.Sugar.Gen.Model.run(args)
end)

assert File.exists?("test/fixtures/models/main.ex") === true
assert File.exists?("test/fixtures/queries/main.ex") === true
Expand Down
9 changes: 7 additions & 2 deletions test/mix/tasks/sugar/gen/router_test.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
defmodule Mix.Tasks.Sugar.Gen.RouterTest do
use ExUnit.Case, async: true
import ExUnit.CaptureIO

test "run_detached/1" do
assigns = [
app: :test_app,
module: "TestApp",
path: "test/fixtures"
]
Mix.Tasks.Sugar.Gen.Router.run_detached(assigns)
capture_io(fn ->
Mix.Tasks.Sugar.Gen.Router.run_detached(assigns)
end)
expected_path = "test/fixtures/router.ex"

assert File.exists?(expected_path) === true
Expand All @@ -16,7 +19,9 @@ defmodule Mix.Tasks.Sugar.Gen.RouterTest do

test "run/1" do
args = ["--path=test/fixtures"]
Mix.Tasks.Sugar.Gen.Router.run(args)
capture_io(fn ->
Mix.Tasks.Sugar.Gen.Router.run(args)
end)
expected_path = "test/fixtures/router.ex"

assert File.exists?(expected_path) === true
Expand Down
21 changes: 16 additions & 5 deletions test/mix/tasks/sugar/gen/view_test.exs
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
defmodule Mix.Tasks.Sugar.Gen.ViewTest do
use ExUnit.Case, async: true
import ExUnit.CaptureIO

test "run_detached/1" do
assigns = [
app: :test_app,
module: "TestApp",
path: "test/fixtures"
]
Mix.Tasks.Sugar.Gen.View.run_detached(assigns ++ [name: "main"])
capture_io(fn ->
Mix.Tasks.Sugar.Gen.View.run_detached(assigns ++ [name: "main"])
end)

assert File.exists?("test/fixtures/views/main.html.eex") === true
File.rm_rf! "test/fixtures/views"
end

test "run/1 with proper name and default type" do
args = ["main", "--path=test/fixtures"]
Mix.Tasks.Sugar.Gen.View.run(args)
capture_io(fn ->
Mix.Tasks.Sugar.Gen.View.run(args)
end)

assert File.exists?("test/fixtures/views/main.html.eex") === true
File.rm_rf! "test/fixtures/views"
end

test "run/1 with proper name and eex type" do
args = ["main", "--path=test/fixtures"]
Mix.Tasks.Sugar.Gen.View.run(args)
capture_io(fn ->
Mix.Tasks.Sugar.Gen.View.run(args)
end)

assert File.exists?("test/fixtures/views/main.html.eex") === true
File.rm_rf! "test/fixtures/views"
end

test "run/1 with proper name and dtl type" do
args = ["main", "--path=test/fixtures", "--type=dtl"]
Mix.Tasks.Sugar.Gen.View.run(args)
capture_io(fn ->
Mix.Tasks.Sugar.Gen.View.run(args)
end)

assert File.exists?("test/fixtures/views/main.html.dtl") === true
File.rm_rf! "test/fixtures/views"
end

test "run/1 with proper name and haml type" do
args = ["main", "--path=test/fixtures", "--type=haml"]
Mix.Tasks.Sugar.Gen.View.run(args)
capture_io(fn ->
Mix.Tasks.Sugar.Gen.View.run(args)
end)

assert File.exists?("test/fixtures/views/main.html.haml") === true
File.rm_rf! "test/fixtures/views"
Expand Down
Loading

0 comments on commit 16fc410

Please sign in to comment.