Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use the property class methods instead of the DEFAULT_* constants

* When the Property::String.length is overridden the constant value will not
  update, and will be (incorrectly) used in the migration.
* Stop memoizing the type_map to allow overridden property options to be
  used.
  • Loading branch information...
commit c6078d775bd6e9480dbae0006098ddfdff0caa87 1 parent 9735517
@dkubb dkubb authored
View
8 lib/dm-migrations/adapters/dm-do-adapter.rb
@@ -269,11 +269,11 @@ module ClassMethods
#
# @api private
def type_map
- length = Property::String::DEFAULT_LENGTH
- precision = Property::Numeric::DEFAULT_PRECISION
- scale = Property::Decimal::DEFAULT_SCALE
+ length = Property::String.length
+ precision = Property::Numeric.precision
+ scale = Property::Decimal.scale
- @type_map ||= {
+ {
Property::Binary => { :primitive => 'BLOB' },
Object => { :primitive => 'TEXT' },
Integer => { :primitive => 'INTEGER' },
View
2  lib/dm-migrations/adapters/dm-mysql-adapter.rb
@@ -271,7 +271,7 @@ module ClassMethods
#
# @api private
def type_map
- @type_map ||= super.merge(
+ super.merge(
DateTime => { :primitive => 'DATETIME' },
Time => { :primitive => 'DATETIME' }
).freeze
View
8 lib/dm-migrations/adapters/dm-oracle-adapter.rb
@@ -278,11 +278,11 @@ module ClassMethods
#
# @api private
def type_map
- length = Property::String::DEFAULT_LENGTH
- precision = Property::Numeric::DEFAULT_PRECISION
- scale = Property::Decimal::DEFAULT_SCALE
+ length = Property::String.length
+ precision = Property::Numeric.precision
+ scale = Property::Decimal.scale
- @type_map ||= {
+ {
Integer => { :primitive => 'NUMBER', :precision => precision, :scale => 0 },
String => { :primitive => 'VARCHAR2', :length => length },
Class => { :primitive => 'VARCHAR2', :length => length },
View
6 lib/dm-migrations/adapters/dm-postgres-adapter.rb
@@ -143,10 +143,10 @@ module ClassMethods
#
# @api private
def type_map
- precision = Property::Numeric::DEFAULT_PRECISION
- scale = Property::Decimal::DEFAULT_SCALE
+ precision = Property::Numeric.precision
+ scale = Property::Decimal.scale
- @type_map ||= super.merge(
+ super.merge(
Property::Binary => { :primitive => 'BYTEA' },
BigDecimal => { :primitive => 'NUMERIC', :precision => precision, :scale => scale },
Float => { :primitive => 'DOUBLE PRECISION' }
View
2  lib/dm-migrations/adapters/dm-sqlite-adapter.rb
@@ -87,7 +87,7 @@ module ClassMethods
#
# @api private
def type_map
- @type_map ||= super.merge(Class => { :primitive => 'VARCHAR' }).freeze
+ super.merge(Class => { :primitive => 'VARCHAR' }).freeze
end
end
View
8 lib/dm-migrations/adapters/dm-sqlserver-adapter.rb
@@ -158,11 +158,11 @@ module ClassMethods
#
# @api private
def type_map
- length = Property::String::DEFAULT_LENGTH
- precision = Property::Numeric::DEFAULT_PRECISION
- scale = Property::Decimal::DEFAULT_SCALE
+ length = Property::String.length
+ precision = Property::Numeric.precision
+ scale = Property::Decimal.scale
- @type_map ||= super.merge(
+ super.merge(
DateTime => { :primitive => 'DATETIME' },
Date => { :primitive => 'SMALLDATETIME' },
Time => { :primitive => 'SMALLDATETIME' },
View
19 spec/integration/sql_spec.rb
@@ -79,6 +79,25 @@
@creator.to_sql.should == %q{CREATE TABLE "people" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
end
end
+
+ context 'when the default string length is modified' do
+ before do
+ @original = DataMapper::Property::String.length
+ DataMapper::Property::String.length(255)
+
+ @creator = DataMapper::Migration::TableCreator.new(@adapter, :people) do
+ column :string, String
+ end
+ end
+
+ after do
+ DataMapper::Property::String.length(@original)
+ end
+
+ it 'uses the new length for the character column' do
+ @creator.to_sql.should match(/CHAR\(255\)/)
+ end
+ end
end
describe DataMapper::Migration, "#modify_table helper" do
Please sign in to comment.
Something went wrong with that request. Please try again.