Permalink
Browse files

Support Null

  • Loading branch information...
1 parent 844b46f commit 661bd3d3df3d6aeef1c8c292df9a83228071ac29 @mnoack mnoack committed Dec 23, 2016
Showing with 23 additions and 7 deletions.
  1. +14 −6 lib/active_record/connection_adapters/nulldb_adapter/core.rb
  2. +9 −1 spec/nulldb_spec.rb
@@ -295,12 +295,20 @@ def meta_with_limit!(meta, col_def)
end
def default_column_arguments(col_def)
- [
- col_def.name.to_s,
- col_def.default,
- col_def.type,
- col_def.null
- ]
+ if ActiveRecord::VERSION::MAJOR == 5
+ [
+ col_def.name.to_s,
+ col_def.default,
+ col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
+ ]
+ else
+ [
+ col_def.name.to_s,
+ col_def.default,
+ col_def.type,
+ col_def.null.nil? || col_def.null # cast [false, nil, true] => [false, true, true], other adapters default to null=true
+ ]
+ end
end
def initialize_column_with_cast_type?
View
@@ -71,7 +71,7 @@ class TablelessModel < ActiveRecord::Base
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table(:employees) do |t|
- t.string :name, limit: 50
+ t.string :name, null: false, limit: 50
t.date :hire_date
t.integer :employee_number
t.decimal :salary
@@ -117,6 +117,14 @@ class TablelessModel < ActiveRecord::Base
expect(Employee.columns_hash['name'].limit).to eq 50
end
+ it "should return true on nullable field" do
+ expect(Employee.columns_hash['salary'].null).to be true
+ end
+
+ it "should return false on non-nullable field" do
+ expect(Employee.columns_hash['name'].null).to be false
+ end
+
it "should return the appropriate primary key" do
expect( ActiveRecord::Base.connection.primary_key('employees') ).to eq 'id'
end

0 comments on commit 661bd3d

Please sign in to comment.