diff --git a/postgrest.cabal b/postgrest.cabal index b65b35d50..6ea5b913c 100644 --- a/postgrest.cabal +++ b/postgrest.cabal @@ -146,6 +146,7 @@ Test-Suite spec , Feature.QueryLimitedSpec , Feature.RangeSpec , Feature.StructureSpec + , Feature.UnicodeSpec , Paths_postgrest , PostgREST.App , PostgREST.Auth diff --git a/test/Feature/UnicodeSpec.hs b/test/Feature/UnicodeSpec.hs new file mode 100644 index 000000000..99f93a20f --- /dev/null +++ b/test/Feature/UnicodeSpec.hs @@ -0,0 +1,20 @@ +module Feature.UnicodeSpec where + +import Test.Hspec +import Test.Hspec.Wai +import Test.Hspec.Wai.JSON +import Network.Wai (Application) +import Control.Monad (void) + +spec :: SpecWith Application +spec = + describe "Reading and writing to unicode schema and table names" $ + it "Can read and write values" $ do + get "/%D9%85%D9%88%D8%A7%D8%B1%D8%AF" + `shouldRespondWith` "[]" + + void $ post "/%D9%85%D9%88%D8%A7%D8%B1%D8%AF" + [json| { "هویت": 1 } |] + + get "/%D9%85%D9%88%D8%A7%D8%B1%D8%AF" + `shouldRespondWith` [json| [{ "هویت": 1 }] |] diff --git a/test/Main.hs b/test/Main.hs index 98cdd3c54..a8758aacf 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -18,6 +18,7 @@ import qualified Feature.QueryLimitedSpec import qualified Feature.QuerySpec import qualified Feature.RangeSpec import qualified Feature.StructureSpec +import qualified Feature.UnicodeSpec main :: IO () main = do @@ -29,6 +30,7 @@ main = do let dbStructure = either (error.show) id result withApp = return $ postgrest testCfg dbStructure pool ltdApp = return $ postgrest testLtdRowsCfg dbStructure pool + unicodeApp = return $ postgrest testUnicodeCfg dbStructure pool hspec $ do mapM_ (beforeAll_ resetDb . before withApp) specs @@ -37,6 +39,10 @@ main = do beforeAll_ resetDb . before ltdApp $ describe "Feature.QueryLimitedSpec" Feature.QueryLimitedSpec.spec + -- this test runs with a different schema + beforeAll_ resetDb . before unicodeApp $ + describe "Feature.UnicodeSpec" Feature.UnicodeSpec.spec + where specs = map (uncurry describe) [ ("Feature.AuthSpec" , Feature.AuthSpec.spec) diff --git a/test/SpecHelper.hs b/test/SpecHelper.hs index 87abae532..498e2f847 100644 --- a/test/SpecHelper.hs +++ b/test/SpecHelper.hs @@ -21,6 +21,10 @@ testCfg :: AppConfig testCfg = AppConfig testDbConn "postgrest_test_anonymous" "test" 3000 (secret "safe") 10 Nothing True +testUnicodeCfg :: AppConfig +testUnicodeCfg = + AppConfig testDbConn "postgrest_test_anonymous" "تست" 3000 (secret "safe") 10 Nothing True + testLtdRowsCfg :: AppConfig testLtdRowsCfg = AppConfig testDbConn "postgrest_test_anonymous" "test" 3000 (secret "safe") 10 (Just 3) True diff --git a/test/fixtures/privileges.sql b/test/fixtures/privileges.sql index 884d2de00..e759c711e 100644 --- a/test/fixtures/privileges.sql +++ b/test/fixtures/privileges.sql @@ -2,10 +2,11 @@ GRANT USAGE ON SCHEMA postgrest , test + , "تست" TO postgrest_test_anonymous; -- Schema test objects -SET search_path = test, pg_catalog; +SET search_path = test, "تست", pg_catalog; GRANT ALL ON TABLE items @@ -36,6 +37,7 @@ GRANT ALL ON TABLE , "Escap3e;" , "ghostBusters" , "withUnique" + , "موارد" TO postgrest_test_anonymous; GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous; diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index af949d004..b627759dd 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -33,6 +33,13 @@ CREATE SCHEMA private; CREATE SCHEMA test; +-- +-- Name: تست; Type: SCHEMA; Schema: -; Owner: - +-- + +CREATE SCHEMA تست; + + -- -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - -- @@ -162,6 +169,14 @@ CREATE FUNCTION anti_id(test.items) RETURNS bigint AS $_$ SELECT $1.id * -1 $_$; + +SET search_path = تست, pg_catalog; + +CREATE TABLE موارد ( + هویت bigint NOT NULL +); + + SET search_path = test, pg_catalog; -- @@ -985,7 +1000,6 @@ ALTER TABLE ONLY users_tasks ALTER TABLE ONLY users_tasks ADD CONSTRAINT users_tasks_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); - -- -- PostgreSQL database dump complete --