-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
218 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
defmodule CassandraEctoHelperSpec do | ||
use ESpec, async: true | ||
|
||
alias Cassandra.Ecto.Helper | ||
describe "Cassandra.Ecto.Helper" do | ||
describe "quote_name/1" do | ||
it "wraps field name with quotes" do | ||
expect(Helper.quote_name("test")) |> to(eq "\"test\"") | ||
end | ||
it "fails with bad field name" do | ||
expect(fn -> Helper.quote_name("wro\"ng") end) | ||
|> to(raise_exception()) | ||
end | ||
end | ||
describe "quote_table/1" do | ||
it "wraps table name with quotes" do | ||
expect(Helper.quote_table("test")) |> to(eq "\"test\"") | ||
end | ||
it "fails with bad table name" do | ||
expect(fn -> Helper.quote_table("wro\"ng") end) | ||
|> to(raise_exception()) | ||
end | ||
end | ||
describe "db_value" do | ||
it "saves integers as is" do | ||
expect(Helper.db_value(1, :integer)) |> to(eq "1") | ||
end | ||
it "escapes strings with dollars" do | ||
expect(Helper.db_value("test", :string)) |> to(eq "$$test$$") | ||
end | ||
it "wraps :set with curly brackets" do | ||
expect(Helper.db_value([1, 2, 3], {:set, :int})) |> to(eq "{1, 2, 3}") | ||
end | ||
it "wraps :list with square brackets" do | ||
expect(Helper.db_value([1, 2, 3], {:list, :int})) |> to(eq "[1, 2, 3]") | ||
end | ||
it "saves map" do | ||
expect(Helper.db_value(%{"abra" => 1, "cadabra" => 2}, {:map, :string, :int})) | ||
|> to(eq "{$$abra$$: 1, $$cadabra$$: 2}") | ||
end | ||
it "saves map with skipped key type" do | ||
expect(Helper.db_value(%{"abra" => 1, "cadabra" => 2}, {:map, :int})) | ||
|> to(eq "{$$abra$$: 1, $$cadabra$$: 2}") | ||
end | ||
it "saves tuple" do | ||
expect(Helper.db_value({1, "abra"}, {:tuple, {:int, :string}})) | ||
|> to(eq "(1, $$abra$$)") | ||
end | ||
it "deals with nesting" do | ||
expect(Helper.db_value([{1, 2}, {3, 4}], {:list, {:tuple, {:int, :int}}})) | ||
|> to(eq "[(1, 2), (3, 4)]") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters