@@ -50,6 +50,30 @@ defmodule EctoWatchTest do
50
50
end
51
51
end
52
52
53
+ defmodule ModuleWithAReallyLongName do
54
+ use Ecto.Schema
55
+
56
+ @ moduledoc """
57
+ A module that *just* barely fits when creating function/trigger names
58
+ """
59
+
60
+ schema "a_module_with_a_really_long_name" do
61
+ field ( :the_string , :string )
62
+ end
63
+ end
64
+
65
+ defmodule ModuleWithJustTooLongAName do
66
+ use Ecto.Schema
67
+
68
+ @ moduledoc """
69
+ A module that *just* barely fits when creating function/trigger names
70
+ """
71
+
72
+ schema "a_module_with_just_too_long_a_name" do
73
+ field ( :the_string , :string )
74
+ end
75
+ end
76
+
53
77
setup do
54
78
start_supervised! ( TestRepo )
55
79
@@ -91,6 +115,28 @@ defmodule EctoWatchTest do
91
115
[ ]
92
116
)
93
117
118
+ Ecto.Adapters.SQL . query! (
119
+ TestRepo ,
120
+ """
121
+ CREATE TABLE a_module_with_a_really_long_name (
122
+ id SERIAL PRIMARY KEY,
123
+ the_string TEXT
124
+ )
125
+ """ ,
126
+ [ ]
127
+ )
128
+
129
+ Ecto.Adapters.SQL . query! (
130
+ TestRepo ,
131
+ """
132
+ CREATE TABLE a_module_with_just_too_long_a_name (
133
+ id SERIAL PRIMARY KEY,
134
+ the_string TEXT
135
+ )
136
+ """ ,
137
+ [ ]
138
+ )
139
+
94
140
% Postgrex.Result {
95
141
rows: [ [ already_existing_id1 ] ]
96
142
} =
@@ -486,6 +532,78 @@ defmodule EctoWatchTest do
486
532
start_supervised! ( { EctoWatch , repo: TestRepo , pub_sub: TestPubSub , watchers: [ ] } )
487
533
end
488
534
535
+ test "Errors should be given if the schema module is too long for creating the trigger name" do
536
+ assert_raise RuntimeError ,
537
+ ~r/ Schema module name is 1 character\( s\) too long for the auto-generated Postgres trigger/ ,
538
+ fn ->
539
+ start_supervised! (
540
+ { EctoWatch ,
541
+ repo: TestRepo ,
542
+ pub_sub: TestPubSub ,
543
+ watchers: [
544
+ { ModuleWithJustTooLongAName , :inserted }
545
+ ] }
546
+ )
547
+ end
548
+
549
+ # Everything works fine if you're just at the limit
550
+ start_supervised! (
551
+ { EctoWatch ,
552
+ repo: TestRepo ,
553
+ pub_sub: TestPubSub ,
554
+ watchers: [
555
+ { ModuleWithAReallyLongName , :inserted }
556
+ ] }
557
+ )
558
+
559
+ EctoWatch . subscribe ( { ModuleWithAReallyLongName , :inserted } )
560
+
561
+ Ecto.Adapters.SQL . query! (
562
+ TestRepo ,
563
+ "INSERT INTO a_module_with_a_really_long_name (the_string) VALUES ('the value')" ,
564
+ [ ]
565
+ )
566
+
567
+ assert_receive { { ModuleWithAReallyLongName , :inserted } , % { id: _ } }
568
+ end
569
+
570
+ test "Errors should be given if the label is too long" do
571
+ assert_raise RuntimeError ,
572
+ ~r/ Label is 1 character\( s\) too long for the auto-generated Postgres trigger name/ ,
573
+ fn ->
574
+ start_supervised! (
575
+ { EctoWatch ,
576
+ repo: TestRepo ,
577
+ pub_sub: TestPubSub ,
578
+ watchers: [
579
+ { ModuleWithJustTooLongAName , :inserted ,
580
+ label: :the_label_is_also_just_much_too_long_such_a_shame }
581
+ ] }
582
+ )
583
+ end
584
+
585
+ # Everything works fine if you're just at the limit
586
+ start_supervised! (
587
+ { EctoWatch ,
588
+ repo: TestRepo ,
589
+ pub_sub: TestPubSub ,
590
+ watchers: [
591
+ { ModuleWithJustTooLongAName , :inserted ,
592
+ label: :the_label_is_also_just_much_too_long_such_a_sham }
593
+ ] }
594
+ )
595
+
596
+ EctoWatch . subscribe ( :the_label_is_also_just_much_too_long_such_a_sham )
597
+
598
+ Ecto.Adapters.SQL . query! (
599
+ TestRepo ,
600
+ "INSERT INTO a_module_with_just_too_long_a_name (the_string) VALUES ('the value')" ,
601
+ [ ]
602
+ )
603
+
604
+ assert_receive { :the_label_is_also_just_much_too_long_such_a_sham , % { id: _ } }
605
+ end
606
+
489
607
test "subscribe requires proper Ecto schema" , % {
490
608
already_existing_id1: already_existing_id1
491
609
} do
0 commit comments