@@ -81,6 +81,16 @@ defmodule Ecto.RepoTest do
8181 end
8282 end
8383
84+ defmodule MySchemaWithNonStringPrefix do
85+ use Ecto.Schema
86+
87+ @ schema_prefix % { key: :private }
88+
89+ schema "my_schema" do
90+ field :x , :string
91+ end
92+ end
93+
8494 defmodule MySchemaWithAssoc do
8595 use Ecto.Schema
8696
@@ -318,6 +328,12 @@ defmodule Ecto.RepoTest do
318328 TestRepo . reload ( struct_with_prefix )
319329 assert_received { :all , % { prefix: "another" } }
320330 end
331+
332+ test "supports non-string prefix" do
333+ struct_with_prefix = put_meta ( % MySchema { id: 2 } , prefix: % { key: :another } )
334+ TestRepo . reload ( struct_with_prefix )
335+ assert_received { :all , % { prefix: % { key: :another } } }
336+ end
321337 end
322338
323339 defmodule DefaultOptionRepo do
@@ -1116,6 +1132,12 @@ defmodule Ecto.RepoTest do
11161132
11171133 assert { :ok , schema } = TestRepo . delete ( valid , prefix: "public" )
11181134 assert schema . __meta__ . prefix == "public"
1135+
1136+ assert { :ok , schema } = TestRepo . insert ( valid , prefix: % { key: :public } )
1137+ assert schema . __meta__ . prefix == % { key: :public }
1138+
1139+ assert { :ok , schema } = TestRepo . delete ( valid , prefix: % { key: :public } )
1140+ assert schema . __meta__ . prefix == % { key: :public }
11191141 end
11201142
11211143 test "insert and delete prefix overrides schema_prefix with struct" do
@@ -1128,6 +1150,16 @@ defmodule Ecto.RepoTest do
11281150 assert schema . __meta__ . prefix == "public"
11291151 end
11301152
1153+ test "insert and delete prefix overrides schema_prefix with struct when prefix is not a string" do
1154+ valid = % MySchemaWithNonStringPrefix { id: 1 }
1155+
1156+ assert { :ok , schema } = TestRepo . insert ( valid , prefix: % { key: :public } )
1157+ assert schema . __meta__ . prefix == % { key: :public }
1158+
1159+ assert { :ok , schema } = TestRepo . delete ( valid , prefix: % { key: :public } )
1160+ assert schema . __meta__ . prefix == % { key: :public }
1161+ end
1162+
11311163 test "insert, update, insert_or_update and delete sets schema prefix with changeset" do
11321164 valid = Ecto.Changeset . cast ( % MySchema { id: 1 } , % { x: "foo" } , [ :x ] )
11331165
@@ -1474,6 +1506,18 @@ defmodule Ecto.RepoTest do
14741506
14751507 assert [ schema ] = TestRepo . all ( MySchema , prefix: "public" )
14761508 assert schema . __meta__ . prefix == "public"
1509+
1510+ assert schema = TestRepo . get ( MySchema , 123 , prefix: % { key: :public } )
1511+ assert schema . __meta__ . prefix == % { key: :public }
1512+
1513+ assert schema = TestRepo . get_by ( MySchema , [ id: 123 ] , prefix: % { key: :public } )
1514+ assert schema . __meta__ . prefix == % { key: :public }
1515+
1516+ assert schema = TestRepo . one ( MySchema , prefix: % { key: :public } )
1517+ assert schema . __meta__ . prefix == % { key: :public }
1518+
1519+ assert [ schema ] = TestRepo . all ( MySchema , prefix: % { key: :public } )
1520+ assert schema . __meta__ . prefix == % { key: :public }
14771521 end
14781522
14791523 test "get, get_by, one and all ignores prefix if schema_prefix set" do
@@ -1488,6 +1532,18 @@ defmodule Ecto.RepoTest do
14881532
14891533 assert [ schema ] = TestRepo . all ( MySchemaWithPrefix , prefix: "public" )
14901534 assert schema . __meta__ . prefix == "private"
1535+
1536+ assert schema = TestRepo . get ( MySchemaWithNonStringPrefix , 123 , prefix: % { key: :public } )
1537+ assert schema . __meta__ . prefix == % { key: :private }
1538+
1539+ assert schema = TestRepo . get_by ( MySchemaWithNonStringPrefix , [ id: 123 ] , prefix: % { key: :public } )
1540+ assert schema . __meta__ . prefix == % { key: :private }
1541+
1542+ assert schema = TestRepo . one ( MySchemaWithNonStringPrefix , prefix: % { key: :public } )
1543+ assert schema . __meta__ . prefix == % { key: :private }
1544+
1545+ assert [ schema ] = TestRepo . all ( MySchemaWithNonStringPrefix , prefix: % { key: :public } )
1546+ assert schema . __meta__ . prefix == % { key: :private }
14911547 end
14921548
14931549 describe "changeset prepare" do
0 commit comments