Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
[dm-more] Updated to use :required instead of :nullable for Property …
Browse files Browse the repository at this point in the history
…declarations

[#935]
  • Loading branch information
dkubb committed Nov 11, 2009
1 parent 05d6c8f commit 9ee32e4
Show file tree
Hide file tree
Showing 31 changed files with 73 additions and 74 deletions.
4 changes: 2 additions & 2 deletions dm-aggregates/spec/public/shared/aggregate_shared_spec.rb
Expand Up @@ -19,7 +19,7 @@ class ::Dragon
property :birth_on, Date
property :birth_time, Time

belongs_to :knight, :nullable => true
belongs_to :knight, :required => false
end

# A more complex example, with BigDecimal and Float properties
Expand All @@ -29,7 +29,7 @@ class ::Country
include DataMapper::Resource

property :id, Serial
property :name, String, :nullable => false
property :name, String, :required => true
property :population, Integer
property :birth_rate, Float, :precision => 4, :scale => 2
property :gold_reserve_tonnes, Float, :precision => 6, :scale => 2
Expand Down
16 changes: 8 additions & 8 deletions dm-constraints/spec/integration/constraints_spec.rb
Expand Up @@ -10,7 +10,7 @@ class ::Article
include DataMapper::Resource

property :id, Serial
property :title, String, :nullable => false
property :title, String, :required => true
property :content, Text

has 1, :revision
Expand Down Expand Up @@ -53,12 +53,12 @@ class ::Revision
describe 'create related objects' do
before :all do
class ::Comment
belongs_to :article, :nullable => true
belongs_to :author, :nullable => true
belongs_to :article, :required => false
belongs_to :author, :required => false
end

class ::Revision
belongs_to :article, :nullable => true
belongs_to :article, :required => false
end
end

Expand Down Expand Up @@ -406,12 +406,12 @@ class ::Author
end

class ::Comment
belongs_to :article, :nullable => true
belongs_to :author, :nullable => true
belongs_to :article, :required => false
belongs_to :author, :required => false
end

class ::Revision
belongs_to :article, :nullable => true
belongs_to :article, :required => false
end
end

Expand Down Expand Up @@ -555,7 +555,7 @@ class ::Revision
# M:M relationships results in a join table composed of composite (composed of two parts)
# primary key.
# Setting a portion of this primary key is not possible for two reasons:
# 1. the columns are defined as :nullable => false
# 1. the columns are defined as :required => true
# 2. there could be duplicate rows if more than one of either of the types
# was deleted while being associated to the same type on the other side of the relationshp
# Given
Expand Down
2 changes: 1 addition & 1 deletion dm-is-list/spec/integration/list_spec.rb
Expand Up @@ -988,7 +988,7 @@ class ClientTodo

property :id, Serial
property :title, String
property :position, Integer, :nullable => false, :unique_index => :position
property :position, Integer, :required => true, :unique_index => :position
property :client_id, Integer, :unique_index => :position

belongs_to :client
Expand Down
2 changes: 1 addition & 1 deletion dm-is-nested_set/lib/dm-is-nested_set/is/nested_set.rb
Expand Up @@ -21,7 +21,7 @@ def is_nested_set(options={})
# be cut down to 1 instead of 2 queries. this would be the other way, but seems hackish:
# options[:child_key].each{|pname| property(pname, Integer) unless properties.detect{|p| p.name == pname}}

belongs_to :parent, :model => self, :child_key => options[:child_key], :order => [ :lft ], :nullable => true
belongs_to :parent, :model => self, :child_key => options[:child_key], :order => [ :lft ], :required => false
has n, :children, :model => self, :child_key => options[:child_key], :order => [ :lft ]

before :create do
Expand Down
2 changes: 1 addition & 1 deletion dm-is-remixable/lib/dm-is-remixable/is/remixable.rb
Expand Up @@ -298,7 +298,7 @@ def populate_remixables_mapping(remixable_model, options)
# options <Hash> options hash
def remix_one_to_many(cardinality, model, options)
self.has cardinality, (options[:as] || options[:table_name]).to_sym, :model => model.name
model.property Extlib::Inflection.foreign_key(self.name).intern, Integer, :min => 0, :nullable => false
model.property Extlib::Inflection.foreign_key(self.name).intern, Integer, :min => 0, :required => true
model.belongs_to belongs_to_name(self.name)
end

Expand Down
13 changes: 3 additions & 10 deletions dm-is-remixable/spec/data/bot.rb
Expand Up @@ -6,14 +6,7 @@
class Bot
include DataMapper::Resource

property :id, Serial

property :bot_name, String,
:nullable => false,
:length => 2..50

property :bot_version, String,
:nullable => false,
:length => 2..50

property :id, Serial
property :bot_name, String, :required => true, :length => 2..50
property :bot_version, String, :required => true, :length => 2..50
end
4 changes: 2 additions & 2 deletions dm-is-remixable/spec/data/rating.rb
Expand Up @@ -14,8 +14,8 @@ def self.included(base)
# properties

property :id, Serial
property :user_id, Integer, :nullable => false
property :rating, Integer, :nullable => false, :default => 0
property :user_id, Integer, :required => true
property :rating, Integer, :required => true, :default => 0

module ClassMethods

Expand Down
2 changes: 1 addition & 1 deletion dm-is-remixable/spec/data/tag.rb
Expand Up @@ -2,5 +2,5 @@ class Tag
include DataMapper::Resource

property :id, Serial
property :name, String, :unique => true, :nullable => false
property :name, String, :unique => true, :required => true
end
4 changes: 2 additions & 2 deletions dm-is-remixable/spec/data/user.rb
Expand Up @@ -8,8 +8,8 @@ class User
include DataMapper::Resource

property :id, Serial
property :first_name, String, :nullable => false, :length=> 2..50
property :last_name, String, :nullable => false, :length => 2..50
property :first_name, String, :required => true, :length=> 2..50
property :last_name, String, :required => true, :length => 2..50

remix n, :viewables
remix n, :billables, :model => "Account"
Expand Down
2 changes: 1 addition & 1 deletion dm-migrations/db/migrations/2_add_dob_to_people.rb
@@ -1,7 +1,7 @@
migration 2, :add_dob_to_people do
up do
modify_table :people do
add_column :dob, DateTime, :nullable? => true
add_column :dob, DateTime, :allow_nil => true
end
end

Expand Down
2 changes: 1 addition & 1 deletion dm-migrations/examples/sample_migration.rb
Expand Up @@ -21,7 +21,7 @@
migration 2, :add_dob_to_people do
up do
modify_table :people do
add_column :dob, DateTime, :nullable? => true
add_column :dob, DateTime, :allow_nil => true
end
end

Expand Down
10 changes: 8 additions & 2 deletions dm-migrations/lib/dm-migrations/sql/table_creator.rb
Expand Up @@ -64,8 +64,14 @@ def to_sql
def build_type(type_class)
schema = { :name => @name, :quote_column_name => quoted_name }.merge(@opts)

unless schema.key?(:nullable)
schema[:nullable] = !schema[:not_null]
[ :nullable, :nullable? ].each do |option|
next if (value = schema.delete(option)).nil?
warn "#{option.inspect} is deprecated, use :allow_nil instead"
schema[:allow_nil] = value unless schema.key?(:allow_nil)
end

unless schema.key?(:allow_nil)
schema[:allow_nil] = !schema[:not_null]
end

schema[:length] ||= schema.delete(:size) if schema.key?(:size)
Expand Down
4 changes: 2 additions & 2 deletions dm-migrations/spec/integration/sql_spec.rb
Expand Up @@ -19,7 +19,7 @@ def repository(*args)
before do
@creator = DataMapper::Migration::TableCreator.new(repository(adapter).adapter, :people) do
column :id, DataMapper::Types::Serial
column :name, 'VARCHAR(50)', :nullable => false
column :name, 'VARCHAR(50)', :allow_nil => false
column :long_string, String, :size => 200
end
end
Expand Down Expand Up @@ -58,7 +58,7 @@ def repository(*args)
col.instance_eval("@type").should include("200")
end

it "should generate a NOT NULL column when :nullable is false" do
it "should generate a NOT NULL column when :allow_nil is false" do
@creator.instance_eval("@columns")[1].type.should match(/NOT NULL/)
end

Expand Down
2 changes: 1 addition & 1 deletion dm-serializer/benchmarks/to_json.rb
Expand Up @@ -82,7 +82,7 @@ class Cow
property :breed, String

has n, :baby_cows, :model => 'Cow'
belongs_to :mother_cow, :model => 'Cow', :nullable => true
belongs_to :mother_cow, :model => 'Cow', :required => false
end

DataMapper.auto_migrate!
Expand Down
2 changes: 1 addition & 1 deletion dm-serializer/spec/fixtures/cow.rb
Expand Up @@ -6,6 +6,6 @@ class Cow
property :name, String
property :breed, String

belongs_to :mother_cow, :model => self, :nullable => true
belongs_to :mother_cow, :model => self, :required => false
has n, :baby_cows, :model => self, :child_key => [ :mother_cow_id, :mother_cow_composite ]
end
2 changes: 1 addition & 1 deletion dm-sweatshop/spec/dm-sweatshop/model_spec.rb
Expand Up @@ -9,7 +9,7 @@ class Widget
property :name, String
property :price, Integer

belongs_to :order, :nullable => true
belongs_to :order, :required => false
validates_present :price
end

Expand Down
2 changes: 1 addition & 1 deletion dm-tags/lib/dm-tags/tag.rb
Expand Up @@ -2,7 +2,7 @@ class Tag
include DataMapper::Resource

property :id, Serial
property :name, String, :nullable => false, :unique => true, :unique_index => true
property :name, String, :required => true, :unique => true, :unique_index => true

has n, :taggings

Expand Down
6 changes: 3 additions & 3 deletions dm-tags/lib/dm-tags/tagging.rb
Expand Up @@ -2,9 +2,9 @@ class Tagging
include DataMapper::Resource

property :id, Serial
property :taggable_id, Integer, :nullable => false
property :taggable_type, Class, :nullable => false
property :tag_context, String, :nullable => false
property :taggable_id, Integer, :required => true
property :taggable_type, Class, :required => true
property :tag_context, String, :required => true

belongs_to :tag

Expand Down
2 changes: 1 addition & 1 deletion dm-timestamps/lib/dm-timestamps.rb
Expand Up @@ -41,7 +41,7 @@ def timestamps(*names)
case name
when *TIMESTAMP_PROPERTIES.keys
type = TIMESTAMP_PROPERTIES[name].first
property name, type, :nullable => false, :auto_validation => false
property name, type, :required => true, :auto_validation => false
when :at
timestamps(:created_at, :updated_at)
when :on
Expand Down
8 changes: 4 additions & 4 deletions dm-timestamps/spec/integration/timestamps_spec.rb
Expand Up @@ -115,10 +115,10 @@ class GreenSmoothie

property :id, Serial
property :name, String
property :created_at, DateTime, :nullable => false, :auto_validation => false
property :created_on, Date, :nullable => false, :auto_validation => false
property :updated_at, DateTime, :nullable => false, :auto_validation => false
property :updated_on, Date, :nullable => false, :auto_validation => false
property :created_at, DateTime, :required => true, :auto_validation => false
property :created_on, Date, :required => true, :auto_validation => false
property :updated_at, DateTime, :required => true, :auto_validation => false
property :updated_on, Date, :required => true, :auto_validation => false

auto_migrate!
end
Expand Down
6 changes: 3 additions & 3 deletions dm-validations/lib/dm-validations/auto_validate.rb
Expand Up @@ -39,8 +39,8 @@ def without_auto_validations(&block)
# @details [Triggers]
# Triggers that generate validator creation
#
# :nullable => false
# Setting the option :nullable to false causes a
# :required => true
# Setting the option :required to true causes a
# validates_presence_of validator to be automatically created on
# the property
#
Expand Down Expand Up @@ -194,7 +194,7 @@ def infer_type_validation_for(property, options)
private

def allow_nil?(property)
property.nullable? || property.serial?
property.allow_nil? || property.serial?
end
end # module AutoValidate
end # module Validate
Expand Down
2 changes: 1 addition & 1 deletion dm-validations/spec/fixtures/company.rb
Expand Up @@ -76,7 +76,7 @@ class Product
#

property :id, Serial
property :name, String, :nullable => false
property :name, String, :required => true

#
# Associations
Expand Down
2 changes: 1 addition & 1 deletion dm-validations/spec/fixtures/event.rb
Expand Up @@ -16,7 +16,7 @@ class Event
#

property :id, Serial
property :name, String, :nullable => false
property :name, String, :required => true

property :starts_at, DateTime
property :ends_at, DateTime
Expand Down
4 changes: 2 additions & 2 deletions dm-validations/spec/fixtures/page.rb
Expand Up @@ -17,14 +17,14 @@ class Page
#

property :id, Serial, :key => true
property :body, Text, :nullable => false
property :body, Text, :required => true

#
# Validations
#

# duplicates inferred validation for body (caused by
# :nullable => false)
# :required => true)
validates_present :body
end
end # Fixtures
Expand Down
Expand Up @@ -6,7 +6,7 @@
custom_boat = Class.new do
include DataMapper::Resource
property :id, DataMapper::Types::Serial
property :name, String, :nullable => false, :message => "This boat must have name"
property :name, String, :required => true, :message => "This boat must have name"
end
boat = custom_boat.new
boat.should_not be_valid
Expand All @@ -17,7 +17,7 @@
custom_boat = Class.new do
include DataMapper::Resource
property :id, DataMapper::Types::Serial
property :name, String, :nullable => false, :length => 5..20, :format => /^[a-z]+$/,
property :name, String, :required => true, :length => 5..20, :format => /^[a-z]+$/,
:messages => {
:presence => "This boat must have name",
:length => "Name must have at least 4 and at most 20 chars",
Expand Down
Expand Up @@ -7,8 +7,8 @@
include DataMapper::Resource

property :id, DataMapper::Types::Serial, :auto_validation => false
property :name, String, :nullable => false, :auto_validation => false
property :bool, DataMapper::Types::Boolean, :nullable => false, :auto_validation => false
property :name, String, :required => true, :auto_validation => false
property :bool, DataMapper::Types::Boolean, :required => true, :auto_validation => false
end

@model = @klass.new
Expand All @@ -27,8 +27,8 @@

without_auto_validations do
property :id, DataMapper::Types::Serial
property :name, String, :nullable => false
property :bool, DataMapper::Types::Boolean, :nullable => false
property :name, String, :required => true
property :bool, DataMapper::Types::Boolean, :required => true
end
end

Expand Down
Expand Up @@ -33,7 +33,7 @@



describe "A model with a non-nullable Boolean property" do
describe "A model with a required Boolean property" do
before :all do
@model = HasNotNullableBoolean.new(:id => 1)
end
Expand Down Expand Up @@ -69,7 +69,7 @@



describe "A model with a non-nullable paranoid Boolean property" do
describe "A model with a required paranoid Boolean property" do
before :all do
@model = HasNotNullableParanoidBoolean.new(:id => 1)
end
Expand Down
Expand Up @@ -13,7 +13,7 @@
@model.name = nil
end

# has validates_is_present for name thanks to :nullable => false
# has validates_is_present for name thanks to :required => true
it "is invalid" do
@model.should_not be_valid_for_presence_test
@model.errors.on(:name).should == [ 'Name must not be blank' ]
Expand All @@ -35,7 +35,7 @@
# no op
end

# has validates_is_present for name thanks to :nullable => false
# has validates_is_present for name thanks to :required => true
it_should_behave_like "valid model"
end
end

0 comments on commit 9ee32e4

Please sign in to comment.