Skip to content

Commit

Permalink
add tag on test with json column
Browse files Browse the repository at this point in the history
  • Loading branch information
hashijun committed Oct 22, 2017
1 parent 0a88aea commit cb8a783
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
21 changes: 10 additions & 11 deletions test/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -686,20 +686,19 @@ defmodule QueryTest do
assert :ok = query("REPLACE INTO test_replace VALUES (1, 'New', ?);", [timestamp])
end

if System.get_env("JSON_SUPPORT") === "true" do
test "encode and decode json", context do
map = %{"hoge" => "1", "huga" => "2"}
map_string = ~s|{"hoge": "1", "huga": "2"}|
@tag :json
test "encode and decode json", context do
map = %{"hoge" => "1", "huga" => "2"}
map_string = ~s|{"hoge": "1", "huga": "2"}|

table = "test_jsons"
table = "test_jsons"

sql = ~s{CREATE TABLE #{table} (id int, map json)}
:ok = query(sql, [])
sql = ~s{CREATE TABLE #{table} (id int, map json)}
:ok = query(sql, [])

insert = ~s{INSERT INTO #{table} (id, map) VALUES (?, ?)}
:ok = query(insert, [1, map_string])
insert = ~s{INSERT INTO #{table} (id, map) VALUES (?, ?)}
:ok = query(insert, [1, map_string])

assert query("SELECT map FROM #{table} WHERE id = 1", []) == [[map]]
end
assert query("SELECT map FROM #{table} WHERE id = 1", []) == [[map]]
end
end
2 changes: 1 addition & 1 deletion test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ExUnit.configure exclude: [:ssl_tests]
ExUnit.configure exclude: [ssl_tests: :true, json: System.get_env("JSON_SUPPORT") != "true"]
ExUnit.start()

run_cmd = fn cmd ->
Expand Down
11 changes: 5 additions & 6 deletions test/text_query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ defmodule TextQueryTest do
assert(rows == [[{{1,1,1}, {0,0,0,0}}], [{{1,1,1}, {0,0,1,0}}]])
end

if System.get_env("JSON_SUPPORT") === "true" do
test "select json", context do
opts = [json_library: Poison]
@tag :json
test "select json", context do
opts = [json_library: Poison]

rows = execute_text("SELECT map FROM test_text_json_query_table", [], opts)
assert(rows == [[%{"hoge" => "1", "huga" => "2"}], [%{"hoge" => "3", "huga" => "4"}]])
end
rows = execute_text("SELECT map FROM test_text_json_query_table", [], opts)
assert(rows == [[%{"hoge" => "1", "huga" => "2"}], [%{"hoge" => "3", "huga" => "4"}]])
end
end

0 comments on commit cb8a783

Please sign in to comment.