Skip to content

Commit

Permalink
Switch to use jsex and fix some 0.14.2 compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rcdilorenzo committed Jul 5, 2014
1 parent c6d4c4b commit c9f0848
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/weber.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Weber do

use Application.Behaviour
use Application

require Weber.Templates.ViewsLoader

Expand Down Expand Up @@ -66,4 +66,4 @@ defmodule Weber do
:ok
end

end
end
6 changes: 4 additions & 2 deletions lib/weber/handler/weber_req_handler_default.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ defmodule Handler.WeberReqHandler.Default do
end

def request({:json, data, headers}, _app) do
{:json, 200, ExJSON.generate(data), :lists.append([{"Content-Type", "application/json"}], headers)}
{:ok, json} = JSEX.encode(data)
{:json, 200, json, :lists.append([{"Content-Type", "application/json"}], headers)}
end

def request({:json, status, data, headers}, _app) do
{:json, status, ExJSON.generate(data), :lists.append([{"Content-Type", "application/json"}], headers)}
{:ok, json} = JSEX.encode(data)
{:json, status, json, :lists.append([{"Content-Type", "application/json"}], headers)}
end

def request({:not_found, data, _headers}, _app) do
Expand Down
3 changes: 2 additions & 1 deletion lib/weber/i18n/localization/locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule Weber.Localization.Locale do
end

def init([locale]) do
{ :ok, %Locale{locale: ExJSON.parse locale}}
{:ok, parsed_locale} = JSEX.decode locale
{ :ok, %Locale{locale: parsed_locale}}
end

def handle_call(:get_abbr_day_names, _from, state) do
Expand Down
2 changes: 1 addition & 1 deletion lib/weber/i18n/localization_manager.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Weber.Localization.LocalizationManager do

use GenServer.Behaviour
use GenServer

defmodule LocalizationConfig do
defstruct config: nil,
Expand Down
3 changes: 2 additions & 1 deletion lib/weber/i18n/translation/Translate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ defmodule Weber.Translation.Translate do
end

def init([lang]) do
{ :ok, %Translate{t: ExJSON.parse(lang)}}
{:ok, parsed_lang} = JSEX.decode(lang)
{ :ok, %Translate{t: parsed_lang}}
end

def handle_call({:translate, key}, _from, state) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Weber.Mixfile do
defp deps(:prod) do
[
{:cowboy, github: "extend/cowboy" },
{:exjson, github: "guedes/exjson"},
{:jsex, github: "talentdeficit/jsex"},
{:plug, github: "elixir-lang/plug"},
{:exlager, github: "khia/exlager"},
{:weberContrib, github: "0xAX/weber-contrib"}
Expand Down
4 changes: 2 additions & 2 deletions test/controllers.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule TestTestTest.Main do

use Weber.Controller

layout false
Expand All @@ -14,7 +14,7 @@ defmodule TestTestTest.Main do
end

defmodule TestTestTest.Include do

use Weber.Controller

layout false
Expand Down
6 changes: 3 additions & 3 deletions test/weberTest/response_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule WeberHttpResponseTest do
use ExUnit.Case

test "SimpleResponse test" do
{:ok, status, _, client} = :hackney.request(:get, 'http://localhost:8080/weber', [], <<>>, [])
body = :hackney.body(client)
Expand All @@ -11,10 +11,10 @@ defmodule WeberHttpResponseTest do
test "json response with custom status" do
{:ok, status, _, client} = :hackney.request(:get, 'http://localhost:8080/json/action', [], <<>>, [])
body = :hackney.body(client)
assert(body == {:ok, "{}"})
assert(body == {:ok, "[]"})
assert(status == 201)
end

test "`redirect` in route test" do
{:ok, status, _, _client} = :hackney.request(:get, 'http://localhost:8080/redirect', [], <<>>, [])
assert(status == 302)
Expand Down

0 comments on commit c9f0848

Please sign in to comment.