From 10bf495f2e69c7dcbccb360026ee875461d1f22f Mon Sep 17 00:00:00 2001 From: Mitsuhiro Shibuya Date: Sat, 21 Sep 2024 17:50:05 +0900 Subject: [PATCH] Add specs for non-nullable boolean field Refs. #3612 --- ...21171953_add_non_nullable_boolean_field.rb | 7 ++++++ spec/integration/fields/boolean_spec.rb | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 spec/dummy_app/db/migrate/20240921171953_add_non_nullable_boolean_field.rb diff --git a/spec/dummy_app/db/migrate/20240921171953_add_non_nullable_boolean_field.rb b/spec/dummy_app/db/migrate/20240921171953_add_non_nullable_boolean_field.rb new file mode 100644 index 0000000000..c7f729d5a0 --- /dev/null +++ b/spec/dummy_app/db/migrate/20240921171953_add_non_nullable_boolean_field.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddNonNullableBooleanField < ActiveRecord::Migration[6.0] + def change + add_column :field_tests, :non_nullable_boolean_field, :boolean, null: false, default: false + end +end diff --git a/spec/integration/fields/boolean_spec.rb b/spec/integration/fields/boolean_spec.rb index ed32f8f6d3..3370a78466 100644 --- a/spec/integration/fields/boolean_spec.rb +++ b/spec/integration/fields/boolean_spec.rb @@ -92,4 +92,28 @@ expect(field_test.reload.boolean_field).to be false end end + + context 'if the database column is not nullable', active_record: true do + before do + RailsAdmin.config FieldTest do + field :non_nullable_boolean_field + end + end + + it 'shows a checkbox' do + visit new_path(model_name: 'field_test') + is_expected.to have_content 'New Field test' + is_expected.to have_css '[type="checkbox"][name="field_test[non_nullable_boolean_field]"]' + end + + it 'can be updated' do + visit edit_path(model_name: 'field_test', id: field_test.id) + find('.boolean_type input').check + click_button 'Save and edit' + expect(field_test.reload.non_nullable_boolean_field).to be true + find('.boolean_type input').uncheck + click_button 'Save and edit' + expect(field_test.reload.non_nullable_boolean_field).to be false + end + end end