test_attributes.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require 'helper'
  2. module Arel
  3. describe 'Attributes' do
  4. it 'responds to lower' do
  5. relation = Table.new(:users)
  6. attribute = relation[:foo]
  7. node = attribute.lower
  8. assert_equal 'LOWER', node.name
  9. assert_equal [attribute], node.expressions
  10. end
  11. describe 'for' do
  12. it 'deals with unknown column types' do
  13. column = Struct.new(:type).new :crazy
  14. Attributes.for(column).must_equal Attributes::Undefined
  15. end
  16. it 'returns the correct constant for strings' do
  17. [:string, :text, :binary].each do |type|
  18. column = Struct.new(:type).new type
  19. Attributes.for(column).must_equal Attributes::String
  20. end
  21. end
  22. it 'returns the correct constant for ints' do
  23. column = Struct.new(:type).new :integer
  24. Attributes.for(column).must_equal Attributes::Integer
  25. end
  26. it 'returns the correct constant for floats' do
  27. column = Struct.new(:type).new :float
  28. Attributes.for(column).must_equal Attributes::Float
  29. end
  30. it 'returns the correct constant for decimals' do
  31. column = Struct.new(:type).new :decimal
  32. Attributes.for(column).must_equal Attributes::Decimal
  33. end
  34. it 'returns the correct constant for boolean' do
  35. column = Struct.new(:type).new :boolean
  36. Attributes.for(column).must_equal Attributes::Boolean
  37. end
  38. it 'returns the correct constant for time' do
  39. [:date, :datetime, :timestamp, :time].each do |type|
  40. column = Struct.new(:type).new type
  41. Attributes.for(column).must_equal Attributes::Time
  42. end
  43. end
  44. end
  45. end
  46. end