Skip to content

Commit

Permalink
Add specs for non-nullable boolean field
Browse files Browse the repository at this point in the history
Refs. #3612
  • Loading branch information
mshibuya committed Sep 22, 2024
1 parent 195ef0b commit 10bf495
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions spec/integration/fields/boolean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 10bf495

Please sign in to comment.