Skip to content

Commit

Permalink
Remove the text? predicate from the type objects
Browse files Browse the repository at this point in the history
This was only used for uniqueness validations. The first usage was in
conjunction with `limit`. Types which cast to string, but are not
considered text cannot have a limit. The second case was only with an
explicit `:case_sensitive => true` option given by the user.
  • Loading branch information
sgrif committed Jul 6, 2014
1 parent 2f71669 commit 3559230
Show file tree
Hide file tree
Showing 18 changed files with 4 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ class SpecializedString < Type::String # :nodoc:
def initialize(type)
@type = type
end

def text?
false
end
end
end
end
Expand Down
4 changes: 0 additions & 4 deletions activerecord/lib/active_record/type/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ def type
:string
end

def text?
true
end

def changed_in_place?(raw_old_value, new_value)
if new_value.is_a?(::String)
raw_old_value != new_value
Expand Down
4 changes: 0 additions & 4 deletions activerecord/lib/active_record/type/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ def type_cast_for_schema(value) # :nodoc:

# These predicates are not documented, as I need to look further into
# their use, and see if they can be removed entirely.
def text? # :nodoc:
false
end

def number? # :nodoc:
false
end
Expand Down
6 changes: 4 additions & 2 deletions activerecord/lib/active_record/validations/uniqueness.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ def build_relation(klass, table, attribute, value) #:nodoc:

column = klass.columns_hash[attribute_name]
value = klass.connection.type_cast(value, column)
value = value.to_s[0, column.limit] if value && column.limit && column.text?
if value.is_a?(String) && column.limit
value = value.to_s[0, column.limit]
end

if !options[:case_sensitive] && value && column.text?
if !options[:case_sensitive] && value.is_a?(String)
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
klass.connection.case_insensitive_comparison(table, attribute, column, value)
else
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/array_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_column
assert_equal :string, @column.type
assert_equal "character varying", @column.sql_type
assert @column.array
assert_not @column.text?
assert_not @column.number?
assert_not @column.binary?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_bit_string_column
column = PostgresqlBitString.columns_hash["a_bit"]
assert_equal :bit, column.type
assert_equal "bit(8)", column.sql_type
assert_not column.text?
assert_not column.number?
assert_not column.binary?
assert_not column.array
Expand All @@ -36,7 +35,6 @@ def test_bit_string_varying_column
column = PostgresqlBitString.columns_hash["a_bit_varying"]
assert_equal :bit_varying, column.type
assert_equal "bit varying(4)", column.sql_type
assert_not column.text?
assert_not column.number?
assert_not column.binary?
assert_not column.array
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/citext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_column
column = Citext.columns_hash['cival']
assert_equal :citext, column.type
assert_equal 'citext', column.sql_type
assert_not column.text?
assert_not column.number?
assert_not column.binary?
assert_not column.array
Expand Down
2 changes: 0 additions & 2 deletions activerecord/test/cases/adapters/postgresql/composite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_column
assert_nil column.type
assert_equal "full_address", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down Expand Up @@ -113,7 +112,6 @@ def test_column
assert_equal :full_address, column.type
assert_equal "full_address", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_column
assert_equal :decimal, column.type
assert_equal "custom_money", column.sql_type
assert column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/enum_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def test_column
assert_equal :enum, column.type
assert_equal "mood", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def test_tsvector_column
assert_equal :tsvector, column.type
assert_equal "tsvector", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def test_column
column = PostgresqlPoint.columns_hash["x"]
assert_equal :point, column.type
assert_equal "point", column.sql_type
assert_not column.text?
assert_not column.number?
assert_not column.binary?
assert_not column.array
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/hstore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def test_column
assert_equal :hstore, @column.type
assert_equal "hstore", @column.sql_type
assert_not @column.number?
assert_not @column.text?
assert_not @column.binary?
assert_not @column.array
end
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_column
assert_equal :json, column.type
assert_equal "json", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/ltree_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test_column
assert_equal :ltree, column.type
assert_equal "ltree", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/money_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_column
assert_equal "money", column.sql_type
assert_equal 2, column.scale
assert column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down
3 changes: 0 additions & 3 deletions activerecord/test/cases/adapters/postgresql/network_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def test_cidr_column
assert_equal :cidr, column.type
assert_equal "cidr", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand All @@ -20,7 +19,6 @@ def test_inet_column
assert_equal :inet, column.type
assert_equal "inet", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand All @@ -30,7 +28,6 @@ def test_macaddr_column
assert_equal :macaddr, column.type
assert_equal "macaddr", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down
1 change: 0 additions & 1 deletion activerecord/test/cases/adapters/postgresql/uuid_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_data_type_of_uuid_types
assert_equal :uuid, column.type
assert_equal "uuid", column.sql_type
assert_not column.number?
assert_not column.text?
assert_not column.binary?
assert_not column.array
end
Expand Down

0 comments on commit 3559230

Please sign in to comment.