Skip to content

Commit a5ed925

Browse files
authored
Merge pull request #2980 from Kaligo/bugfix/display_empty_json
Fixed displaying empty json in edit form
2 parents a345c3c + ae8fe16 commit a5ed925

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/rails_admin/config/fields/types/json.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Json < RailsAdmin::Config::Fields::Types::Text
1010
RailsAdmin::Config::Fields::Types.register(:jsonb, self)
1111

1212
register_instance_option :formatted_value do
13-
value.present? ? JSON.pretty_generate(value) : nil
13+
value ? JSON.pretty_generate(value) : nil
1414
end
1515

1616
register_instance_option :pretty_value do

spec/rails_admin/config/fields/types/json_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
end
2020
end
2121

22+
it 'returns correct value for empty json' do
23+
allow(object).to receive(:json_field) { {} }
24+
actual = field.with(bindings).formatted_value
25+
expect(actual).to eq("{\n}")
26+
end
27+
2228
it 'retuns correct value' do
2329
allow(object).to receive(:json_field) { {sample_key: "sample_value"} }
2430
actual = field.with(bindings).formatted_value

0 commit comments

Comments
 (0)