File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ def previewable_attachable?
64
64
end
65
65
66
66
def as_json ( *)
67
- super . merge ( attachable_sgid : attachable_sgid )
67
+ super . merge ( " attachable_sgid" => persisted? ? attachable_sgid : nil )
68
68
end
69
69
70
70
def to_trix_content_attachment_partial_path
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ActionText ::AttachableTest < ActiveSupport ::TestCase
6
+ test "as_json is a hash when the attachable is persisted" do
7
+ freeze_time do
8
+ attachable = ActiveStorage ::Blob . create_after_unfurling! ( io : StringIO . new ( "test" ) , filename : "test.txt" , key : 123 )
9
+ attributes = {
10
+ id : attachable . id ,
11
+ key : "123" ,
12
+ filename : "test.txt" ,
13
+ content_type : "text/plain" ,
14
+ metadata : { identified : true } ,
15
+ service_name : "test" ,
16
+ byte_size : 4 ,
17
+ checksum : "CY9rzUYh03PK3k6DJie09g==" ,
18
+ created_at : Time . zone . now . as_json ,
19
+ attachable_sgid : attachable . attachable_sgid
20
+ } . deep_stringify_keys
21
+
22
+ assert_equal attributes , attachable . as_json
23
+ end
24
+ end
25
+
26
+ test "as_json is a hash when the attachable is a new record" do
27
+ attachable = ActiveStorage ::Blob . build_after_unfurling ( io : StringIO . new ( "test" ) , filename : "test.txt" , key : 123 )
28
+ attributes = {
29
+ id : nil ,
30
+ key : "123" ,
31
+ filename : "test.txt" ,
32
+ content_type : "text/plain" ,
33
+ metadata : { identified : true } ,
34
+ service_name : "test" ,
35
+ byte_size : 4 ,
36
+ checksum : "CY9rzUYh03PK3k6DJie09g==" ,
37
+ created_at : nil ,
38
+ attachable_sgid : nil
39
+ } . deep_stringify_keys
40
+
41
+ assert_equal attributes , attachable . as_json
42
+ end
43
+ end
You can’t perform that action at this time.
0 commit comments