on dev help sign in
tests
commitce39e5ddc46975eab3ada5fd7c4622d6b20a7d9e authorEitan Chatav <eitan.chatav@gmail.com> dateSat 22 Apr 2017, 14:19 (10 years ago) parentbc895f9
2 files changed+36−1
squeel-postgresql/squeel-postgresql.cabal+2 squeel-postgresql/test/Squeel/PostgreSQL/QuerySpec.hs+34−1
squeel-postgresql/squeel-postgresql.cabal+2
@@ -51,8 +51,10 @@ test-suite blockapps-data-test
5151 Squeel.PostgreSQL.TypeSpec
5252 Squeel.PostgreSQL.ValueSpec
5353 build-depends: base
54+ , Boolean
5455 , hspec
5556 , squeel-postgresql
57+ , vinyl
5658
5759source-repository head
5860 type: git
squeel-postgresql/test/Squeel/PostgreSQL/QuerySpec.hs+34−1
@@ -1,6 +1,39 @@
1+{-# LANGUAGE
2+ DataKinds
3+ , OverloadedLabels
4+ , OverloadedStrings
5+#-}
6+
17module Squeel.PostgreSQL.QuerySpec where
28
9+import Data.Boolean
10+import Data.Vinyl
311import Test.Hspec
412
13+import Squeel.PostgreSQL.Query
14+import Squeel.PostgreSQL.Type
15+
516spec :: Spec
6−spec = return ()
17+spec = do
18+ it "correctly renders a simple SELECT query" $ do
19+ renderQuery (select (sumAndCol1 `from` (table1 `where_` true)))
20+ `shouldBe`
21+ "SELECT col1+col2 AS sum, col1 AS col1 FROM table1 WHERE TRUE"
22+ it "combines WHEREs using AND" $ do
23+ renderQuery (select (sumAndCol1 `from` (table1 `where_` true `where_` false)))
24+ `shouldBe`
25+ "SELECT col1+col2 AS sum, col1 AS col1 FROM table1 WHERE TRUE AND FALSE"
26+
27+type Columns =
28+ '[ '("col1", 'PGInt4)
29+ , '("col2", 'PGInt4)
30+ ]
31+
32+sumAndCol1 :: Projection '[] Columns
33+ '[ '("sum", 'PGInt4)
34+ , '("col1", 'PGInt4)
35+ ]
36+sumAndCol1 = project ((#col1 + #col2) `As` #sum :& #col1 :& RNil)
37+
38+table1 :: Relation '[] '[ '("table1", Columns)] Columns
39+table1 = #table1