Skip to content

Commit 10bf495

Browse files
committed
Add specs for non-nullable boolean field
Refs. #3612
1 parent 195ef0b commit 10bf495

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AddNonNullableBooleanField < ActiveRecord::Migration[6.0]
4+
def change
5+
add_column :field_tests, :non_nullable_boolean_field, :boolean, null: false, default: false
6+
end
7+
end

spec/integration/fields/boolean_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,28 @@
9292
expect(field_test.reload.boolean_field).to be false
9393
end
9494
end
95+
96+
context 'if the database column is not nullable', active_record: true do
97+
before do
98+
RailsAdmin.config FieldTest do
99+
field :non_nullable_boolean_field
100+
end
101+
end
102+
103+
it 'shows a checkbox' do
104+
visit new_path(model_name: 'field_test')
105+
is_expected.to have_content 'New Field test'
106+
is_expected.to have_css '[type="checkbox"][name="field_test[non_nullable_boolean_field]"]'
107+
end
108+
109+
it 'can be updated' do
110+
visit edit_path(model_name: 'field_test', id: field_test.id)
111+
find('.boolean_type input').check
112+
click_button 'Save and edit'
113+
expect(field_test.reload.non_nullable_boolean_field).to be true
114+
find('.boolean_type input').uncheck
115+
click_button 'Save and edit'
116+
expect(field_test.reload.non_nullable_boolean_field).to be false
117+
end
118+
end
95119
end

0 commit comments

Comments
 (0)