File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,22 @@ def self.[](input)
187
187
} . to raise_error ( ROM ::SQL ::NotNullConstraintError )
188
188
end
189
189
190
+ context 'with json notes' do
191
+ include_context 'json_notes'
192
+
193
+ before do
194
+ conf . commands ( :json_notes ) do
195
+ define ( :create )
196
+ end
197
+ end
198
+
199
+ it 'writes and reads back custom type' do
200
+ json_notes = commands [ :json_notes ]
201
+
202
+ expect ( json_notes [ :create ] . call ( note : 'this is my note' ) ) . to eq ( [ { id : 1 , note : 'this is my note' } ] )
203
+ end
204
+ end
205
+
190
206
# Because Oracle doesn't have boolean in SQL
191
207
unless metadata [ :oracle ]
192
208
context 'with puppies' do
Original file line number Diff line number Diff line change @@ -110,6 +110,25 @@ def by_name(name)
110
110
{ id : 2 , name : 'Josie' }
111
111
] )
112
112
end
113
+
114
+ context "with json notes" do
115
+ include_context "json_notes"
116
+
117
+ before do
118
+ conf . commands ( :json_notes ) do
119
+ define ( :update )
120
+ end
121
+ end
122
+
123
+ let ( :json_notes ) { container . relations [ :json_notes ] }
124
+
125
+ it "writes and reads back custom type" do
126
+ note_id = conn [ :json_notes ] . insert ( note : "note version 1" )
127
+ result = json_notes . by_pk ( note_id ) . command ( :update ) . call ( note : "note version 2" )
128
+
129
+ expect ( result ) . to eq ( [ { id : 1 , note : "note version 2" } ] )
130
+ end
131
+ end
113
132
end
114
133
end
115
134
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ RSpec . shared_context "json_notes" do
4
+ before do
5
+ inferrable_relations . concat %i[ json_notes ]
6
+ end
7
+
8
+ before do |_example |
9
+ conn . create_table :json_notes do
10
+ primary_key :id
11
+ String :note
12
+ end
13
+
14
+ write_type = Dry . Types . Constructor ( String ) { |value | JSON . dump ( { content : value } ) }
15
+ read_type = Dry . Types . Constructor ( String ) { |value | JSON . parse ( value ) [ "content" ] }
16
+
17
+ conf . relation ( :json_notes ) do
18
+ schema ( infer : true ) do
19
+ attribute :note , write_type , read : read_type
20
+ end
21
+ end
22
+ end
23
+ end
You can’t perform that action at this time.
0 commit comments