arel 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/lib/arel.rb +4 -3
  2. data/lib/arel/algebra.rb +1 -1
  3. data/lib/arel/algebra/attributes.rb +7 -0
  4. data/lib/arel/algebra/{attribute.rb → attributes/attribute.rb} +32 -0
  5. data/lib/arel/algebra/attributes/boolean.rb +21 -0
  6. data/lib/arel/algebra/attributes/decimal.rb +9 -0
  7. data/lib/arel/algebra/attributes/float.rb +9 -0
  8. data/lib/arel/algebra/attributes/integer.rb +10 -0
  9. data/lib/arel/algebra/attributes/string.rb +10 -0
  10. data/lib/arel/algebra/attributes/time.rb +6 -0
  11. data/lib/arel/algebra/predicates.rb +1 -0
  12. data/lib/arel/algebra/relations/operations/join.rb +4 -2
  13. data/lib/arel/algebra/relations/operations/order.rb +2 -1
  14. data/lib/arel/algebra/relations/operations/skip.rb +2 -1
  15. data/lib/arel/algebra/relations/operations/take.rb +2 -1
  16. data/lib/arel/algebra/relations/operations/where.rb +7 -6
  17. data/lib/arel/algebra/relations/relation.rb +2 -1
  18. data/lib/arel/algebra/relations/utilities/compound.rb +22 -2
  19. data/lib/arel/algebra/relations/utilities/externalization.rb +1 -1
  20. data/lib/arel/algebra/relations/utilities/nil.rb +2 -2
  21. data/lib/arel/engines/memory/predicates.rb +6 -0
  22. data/lib/arel/engines/memory/relations/array.rb +11 -4
  23. data/lib/arel/engines/memory/relations/compound.rb +1 -1
  24. data/lib/arel/engines/memory/relations/operations.rb +2 -2
  25. data/lib/arel/engines/sql.rb +1 -0
  26. data/lib/arel/engines/sql/attributes.rb +40 -0
  27. data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +0 -14
  28. data/lib/arel/engines/sql/predicates.rb +4 -0
  29. data/lib/arel/engines/sql/primitives.rb +0 -4
  30. data/lib/arel/engines/sql/relations/compiler.rb +5 -5
  31. data/lib/arel/engines/sql/relations/operations/join.rb +1 -1
  32. data/lib/arel/engines/sql/relations/relation.rb +1 -1
  33. data/lib/arel/engines/sql/relations/table.rb +6 -7
  34. data/lib/arel/engines/sql/relations/utilities/compound.rb +1 -1
  35. data/lib/arel/engines/sql/relations/utilities/nil.rb +1 -1
  36. data/lib/arel/session.rb +2 -2
  37. data/lib/arel/version.rb +3 -0
  38. data/spec/{arel/algebra → algebra}/unit/predicates/binary_spec.rb +0 -0
  39. data/spec/{arel/algebra → algebra}/unit/predicates/equality_spec.rb +0 -0
  40. data/spec/{arel/algebra → algebra}/unit/predicates/in_spec.rb +0 -0
  41. data/spec/{arel/algebra → algebra}/unit/primitives/attribute_spec.rb +0 -0
  42. data/spec/{arel/algebra → algebra}/unit/primitives/expression_spec.rb +0 -0
  43. data/spec/{arel/algebra → algebra}/unit/primitives/value_spec.rb +0 -0
  44. data/spec/{arel/algebra → algebra}/unit/relations/alias_spec.rb +0 -0
  45. data/spec/{arel/algebra → algebra}/unit/relations/delete_spec.rb +0 -0
  46. data/spec/{arel/algebra → algebra}/unit/relations/group_spec.rb +0 -0
  47. data/spec/{arel/algebra → algebra}/unit/relations/insert_spec.rb +0 -0
  48. data/spec/{arel/algebra → algebra}/unit/relations/join_spec.rb +0 -0
  49. data/spec/{arel/algebra → algebra}/unit/relations/order_spec.rb +0 -0
  50. data/spec/{arel/algebra → algebra}/unit/relations/project_spec.rb +0 -0
  51. data/spec/{arel/algebra → algebra}/unit/relations/relation_spec.rb +0 -0
  52. data/spec/{arel/algebra → algebra}/unit/relations/skip_spec.rb +0 -0
  53. data/spec/{arel/algebra → algebra}/unit/relations/table_spec.rb +0 -0
  54. data/spec/{arel/algebra → algebra}/unit/relations/take_spec.rb +0 -0
  55. data/spec/{arel/algebra → algebra}/unit/relations/update_spec.rb +0 -0
  56. data/spec/{arel/algebra → algebra}/unit/relations/where_spec.rb +1 -0
  57. data/spec/{arel/algebra → algebra}/unit/session/session_spec.rb +0 -0
  58. data/spec/attributes/boolean_spec.rb +57 -0
  59. data/spec/attributes/float_spec.rb +119 -0
  60. data/spec/attributes/integer_spec.rb +119 -0
  61. data/spec/attributes/string_spec.rb +43 -0
  62. data/spec/attributes/time_spec.rb +22 -0
  63. data/spec/{arel/engines → engines}/memory/integration/joins/cross_engine_spec.rb +1 -1
  64. data/spec/{arel/engines → engines}/memory/unit/relations/array_spec.rb +1 -1
  65. data/spec/{arel/engines → engines}/memory/unit/relations/insert_spec.rb +1 -1
  66. data/spec/{arel/engines → engines}/memory/unit/relations/join_spec.rb +1 -1
  67. data/spec/{arel/engines → engines}/memory/unit/relations/order_spec.rb +1 -1
  68. data/spec/{arel/engines → engines}/memory/unit/relations/project_spec.rb +1 -1
  69. data/spec/{arel/engines → engines}/memory/unit/relations/skip_spec.rb +1 -1
  70. data/spec/{arel/engines → engines}/memory/unit/relations/take_spec.rb +1 -1
  71. data/spec/{arel/engines → engines}/memory/unit/relations/where_spec.rb +1 -1
  72. data/spec/{arel/engines → engines}/sql/integration/joins/with_adjacency_spec.rb +0 -0
  73. data/spec/{arel/engines → engines}/sql/integration/joins/with_aggregations_spec.rb +0 -0
  74. data/spec/{arel/engines → engines}/sql/integration/joins/with_compounds_spec.rb +0 -0
  75. data/spec/{arel/engines → engines}/sql/unit/engine_spec.rb +0 -0
  76. data/spec/{arel/engines → engines}/sql/unit/predicates/binary_spec.rb +0 -0
  77. data/spec/{arel/engines → engines}/sql/unit/predicates/equality_spec.rb +0 -0
  78. data/spec/{arel/engines → engines}/sql/unit/predicates/in_spec.rb +0 -0
  79. data/spec/{arel/engines → engines}/sql/unit/predicates/predicates_spec.rb +0 -0
  80. data/spec/{arel/engines → engines}/sql/unit/primitives/attribute_spec.rb +0 -0
  81. data/spec/{arel/engines → engines}/sql/unit/primitives/expression_spec.rb +0 -0
  82. data/spec/{arel/engines → engines}/sql/unit/primitives/literal_spec.rb +0 -0
  83. data/spec/{arel/engines → engines}/sql/unit/primitives/value_spec.rb +0 -0
  84. data/spec/{arel/engines → engines}/sql/unit/relations/alias_spec.rb +0 -0
  85. data/spec/{arel/engines → engines}/sql/unit/relations/delete_spec.rb +0 -0
  86. data/spec/{arel/engines → engines}/sql/unit/relations/from_spec.rb +0 -0
  87. data/spec/{arel/engines → engines}/sql/unit/relations/group_spec.rb +0 -0
  88. data/spec/{arel/engines → engines}/sql/unit/relations/having_spec.rb +0 -0
  89. data/spec/{arel/engines → engines}/sql/unit/relations/insert_spec.rb +0 -0
  90. data/spec/{arel/engines → engines}/sql/unit/relations/join_spec.rb +0 -0
  91. data/spec/{arel/engines → engines}/sql/unit/relations/lock_spec.rb +0 -0
  92. data/spec/{arel/engines → engines}/sql/unit/relations/order_spec.rb +0 -0
  93. data/spec/{arel/engines → engines}/sql/unit/relations/project_spec.rb +0 -0
  94. data/spec/{arel/engines → engines}/sql/unit/relations/skip_spec.rb +0 -0
  95. data/spec/{arel/engines → engines}/sql/unit/relations/table_spec.rb +0 -0
  96. data/spec/{arel/engines → engines}/sql/unit/relations/take_spec.rb +0 -0
  97. data/spec/{arel/engines → engines}/sql/unit/relations/update_spec.rb +0 -0
  98. data/spec/{arel/engines → engines}/sql/unit/relations/where_spec.rb +0 -0
  99. data/spec/relations/join_spec.rb +40 -0
  100. data/spec/relations/relation_spec.rb +31 -0
  101. data/spec/shared/relation_spec.rb +142 -0
  102. data/spec/spec_helper.rb +17 -45
  103. data/spec/support/check.rb +6 -0
  104. data/spec/{connections → support/connections}/mysql_connection.rb +2 -4
  105. data/spec/{connections → support/connections}/oracle_connection.rb +3 -5
  106. data/spec/{connections → support/connections}/postgresql_connection.rb +2 -4
  107. data/spec/{connections → support/connections}/sqlite3_connection.rb +2 -4
  108. data/spec/support/guards.rb +28 -0
  109. data/spec/support/matchers.rb +4 -0
  110. data/spec/{matchers → support/matchers}/be_like.rb +1 -1
  111. data/spec/{matchers → support/matchers}/disambiguate_attributes.rb +1 -1
  112. data/spec/{matchers → support/matchers}/hash_the_same_as.rb +1 -1
  113. data/spec/support/matchers/have_rows.rb +18 -0
  114. data/spec/support/model.rb +58 -0
  115. data/spec/{schemas → support/schemas}/mysql_schema.rb +0 -0
  116. data/spec/{schemas → support/schemas}/oracle_schema.rb +0 -0
  117. data/spec/{schemas → support/schemas}/postgresql_schema.rb +0 -0
  118. data/spec/{schemas → support/schemas}/sqlite3_schema.rb +0 -0
  119. metadata +107 -163
  120. data/.gitignore +0 -6
  121. data/.gitmodules +0 -3
  122. data/Rakefile +0 -48
  123. data/Thorfile +0 -124
  124. data/arel.gemspec +0 -258
  125. data/doc/CONVENTIONS +0 -17
  126. data/doc/TODO +0 -118
  127. data/spec/doubles/hash.rb +0 -27
  128. data/spec/spec.opts +0 -3
@@ -26,6 +26,10 @@ module Arel
26
26
  end
27
27
  end
28
28
 
29
+ class Not < Binary
30
+ def predicate_sql; '!=' end
31
+ end
32
+
29
33
  class GreaterThanOrEqualTo < Binary
30
34
  def predicate_sql; '>=' end
31
35
  end
@@ -16,10 +16,6 @@ module Arel
16
16
  original_relation.column_for(self)
17
17
  end
18
18
 
19
- def type_cast(value)
20
- root.relation.format(self, value)
21
- end
22
-
23
19
  def format(object)
24
20
  object.to_sql(Sql::Attribute.new(self))
25
21
  end
@@ -8,17 +8,17 @@ module Arel
8
8
  end
9
9
 
10
10
  def select_sql
11
- build_query \
11
+ query = build_query \
12
12
  "SELECT #{select_clauses.join(', ')}",
13
13
  "FROM #{from_clauses}",
14
14
  (joins(self) unless joins(self).blank? ),
15
15
  ("WHERE #{where_clauses.join(" AND ")}" unless wheres.blank? ),
16
16
  ("GROUP BY #{group_clauses.join(', ')}" unless groupings.blank? ),
17
17
  ("HAVING #{having_clauses.join(', ')}" unless havings.blank? ),
18
- ("ORDER BY #{order_clauses.join(', ')}" unless orders.blank? ),
19
- ("LIMIT #{taken}" unless taken.blank? ),
20
- ("OFFSET #{skipped}" unless skipped.blank? ),
21
- ("#{locked}" unless locked.blank?)
18
+ ("ORDER BY #{order_clauses.join(', ')}" unless orders.blank? )
19
+ engine.add_limit_offset!(query,{ :limit => taken, :offset => skipped }) if taken || skipped
20
+ query << " #{locked}" unless locked.blank?
21
+ query
22
22
  end
23
23
 
24
24
  def delete_sql
@@ -1,5 +1,5 @@
1
1
  module Arel
2
- class Join < Relation
2
+ class Join
3
3
  def table_sql(formatter = Sql::TableReference.new(self))
4
4
  relation1.externalize.table_sql(formatter)
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Arel
2
- class Relation
2
+ module Relation
3
3
  @@connection_tables_primary_keys = {}
4
4
 
5
5
  def compiler
@@ -1,12 +1,13 @@
1
1
  module Arel
2
- class Table < Relation
3
- include Recursion::BaseCase
2
+ class Table
3
+ include Relation, Recursion::BaseCase
4
4
 
5
5
  cattr_accessor :engine, :tables
6
6
  attr_reader :name, :engine, :table_alias, :options
7
7
 
8
8
  def initialize(name, options = {})
9
9
  @name = name.to_s
10
+ @table_exists = nil
10
11
 
11
12
  if options.is_a?(Hash)
12
13
  @options = options
@@ -41,7 +42,9 @@ module Arel
41
42
  def attributes
42
43
  return @attributes if defined?(@attributes)
43
44
  if table_exists?
44
- @attributes = columns.collect { |column| Attribute.new(self, column.name.to_sym) }
45
+ @attributes = columns.collect do |column|
46
+ Sql::Attributes.for(column).new(column, self, column.name.to_sym)
47
+ end
45
48
  else
46
49
  []
47
50
  end
@@ -55,10 +58,6 @@ module Arel
55
58
  @hash ||= :name.hash
56
59
  end
57
60
 
58
- def format(attribute, value)
59
- attribute.column.type_cast(value)
60
- end
61
-
62
61
  def column_for(attribute)
63
62
  has_attribute?(attribute) and columns.detect { |c| c.name == attribute.name.to_s }
64
63
  end
@@ -1,5 +1,5 @@
1
1
  module Arel
2
- class Compound < Relation
2
+ class Compound
3
3
  delegate :table, :table_sql, :to => :relation
4
4
 
5
5
  def build_query(*parts)
@@ -1,5 +1,5 @@
1
1
  module Arel
2
- class Nil < Relation
2
+ class Nil
3
3
  def table_sql(formatter = nil); '' end
4
4
  def name; '' end
5
5
  end
@@ -11,13 +11,13 @@ module Arel
11
11
  begin
12
12
  @started = true
13
13
  @instance = manufacture
14
- metaclass.class_eval do
14
+ singleton_class.class_eval do
15
15
  undef :new
16
16
  alias_method :new, :instance
17
17
  end
18
18
  yield
19
19
  ensure
20
- metaclass.class_eval do
20
+ singleton_class.class_eval do
21
21
  undef :new
22
22
  alias_method :new, :manufacture
23
23
  end
@@ -0,0 +1,3 @@
1
+ module Arel
2
+ VERSION = "0.3.2" unless defined?(Arel::VERSION)
3
+ end
@@ -9,6 +9,7 @@ module Arel
9
9
 
10
10
  describe '#initialize' do
11
11
  it "manufactures nested where relations if multiple predicates are provided" do
12
+ pending "This is not true anymore"
12
13
  another_predicate = @relation[:name].lt(2)
13
14
  Where.new(@relation, @predicate, another_predicate). \
14
15
  should == Where.new(Where.new(@relation, another_predicate), @predicate)
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ module Arel
4
+ describe "Attributes::Boolean" do
5
+
6
+ before :all do
7
+ @relation = Model.build do |r|
8
+ r.engine Testing::Engine.new
9
+ r.attribute :awesome, Attributes::Boolean
10
+ end
11
+ end
12
+
13
+ def type_cast(val)
14
+ @relation[:awesome].type_cast(val)
15
+ end
16
+
17
+ describe "#type_cast" do
18
+ it "returns same value if passed a boolean" do
19
+ val = true
20
+ type_cast(val).should eql(val)
21
+ end
22
+
23
+ it "returns boolean representation (false) of nil" do
24
+ type_cast(nil).should eql(false)
25
+ end
26
+
27
+ it "returns boolean representation of 'true', 'false'" do
28
+ type_cast('true').should eql(true)
29
+ type_cast('false').should eql(false)
30
+ end
31
+
32
+ it "returns boolean representation of :true, :false" do
33
+ type_cast(:true).should eql(true)
34
+ type_cast(:false).should eql(false)
35
+ end
36
+
37
+ it "returns boolean representation of 0, 1" do
38
+ type_cast(1).should == true
39
+ type_cast(0).should == false
40
+ end
41
+
42
+ it "calls #to_s on arbitrary objects" do
43
+ obj = Object.new
44
+ obj.extend Module.new { def to_s ; 'true' ; end }
45
+ type_cast(obj).should == true
46
+ end
47
+
48
+ [ Object.new, 'string', '00.0', 5 ].each do |value|
49
+ it "raises exception when attempting type_cast of non-boolean value #{value.inspect}" do
50
+ lambda do
51
+ type_cast(value)
52
+ end.should raise_error(TypecastError, /could not typecast/)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+ require 'bigdecimal'
3
+
4
+ module Arel
5
+ describe "Attributes::Float" do
6
+
7
+ before :all do
8
+ @relation = Model.build do |r|
9
+ r.engine Testing::Engine.new
10
+ r.attribute :percentage, Attributes::Float
11
+ end
12
+ end
13
+
14
+ def type_cast(val)
15
+ @relation[:percentage].type_cast(val)
16
+ end
17
+
18
+ describe "#type_cast" do
19
+ it "returns same value if an float" do
20
+ type_cast(24.01).should eql(24.01)
21
+ end
22
+
23
+ it "returns nil if passed nil" do
24
+ type_cast(nil).should be_nil
25
+ end
26
+
27
+ it "returns nil if passed empty string" do
28
+ type_cast('').should be_nil
29
+ end
30
+
31
+ it "returns float representation of a zero string float" do
32
+ type_cast('0').should eql(0.0)
33
+ end
34
+
35
+ it "returns float representation of a positive string integer" do
36
+ type_cast('24').should eql(24.0)
37
+ end
38
+
39
+ it "returns float representation of a positive string integer with spaces" do
40
+ type_cast(' 24').should eql(24.0)
41
+ type_cast('24 ').should eql(24.0)
42
+ end
43
+
44
+ it "returns float representation of a negative string float" do
45
+ type_cast('-24.23').should eql(-24.23)
46
+ end
47
+
48
+ it "returns float representation of a negative string integer with spaces" do
49
+ type_cast('-24 ').should eql(-24.0)
50
+ type_cast(' -24').should eql(-24.0)
51
+ end
52
+
53
+ it "returns integer representation of a zero string float" do
54
+ type_cast('0.0').should eql(0.0)
55
+ end
56
+
57
+ it "returns integer representation of a positive string float" do
58
+ type_cast('24.35').should eql(24.35)
59
+ end
60
+
61
+ it "returns integer representation of a positive string float with spaces" do
62
+ type_cast(' 24.35').should eql(24.35)
63
+ type_cast('24.35 ').should eql(24.35)
64
+ end
65
+
66
+ it "returns integer representation of a negative string float" do
67
+ type_cast('-24.35').should eql(-24.35)
68
+ end
69
+
70
+ it "returns integer representation of a negative string float with spaces" do
71
+ type_cast(' -24.35 ').should eql(-24.35)
72
+ end
73
+
74
+ it "returns integer representation of a zero string float, with no leading digits" do
75
+ type_cast('.0').should eql(0.0)
76
+ end
77
+
78
+ it "returns integer representation of a zero string float, with no leading digits with spaces" do
79
+ type_cast(' .0').should eql(0.0)
80
+ end
81
+
82
+ it "returns integer representation of a positive string float, with no leading digits" do
83
+ type_cast('.41').should eql(0.41)
84
+ end
85
+
86
+ it "returns integer representation of a zero float" do
87
+ type_cast(0.0).should eql(0.0)
88
+ end
89
+
90
+ it "returns integer representation of a positive float" do
91
+ type_cast(24.35).should eql(24.35)
92
+ end
93
+
94
+ it "returns integer representation of a negative float" do
95
+ type_cast(-24.35).should eql(-24.35)
96
+ end
97
+
98
+ it "returns integer representation of a zero decimal" do
99
+ type_cast(BigDecimal('0.0')).should eql(0.0)
100
+ end
101
+
102
+ it "returns integer representation of a positive decimal" do
103
+ type_cast(BigDecimal('24.35')).should eql(24.35)
104
+ end
105
+
106
+ it "returns integer representation of a negative decimal" do
107
+ type_cast(BigDecimal('-24.35')).should eql(-24.35)
108
+ end
109
+
110
+ [ Object.new, true, '00.0', '0.', 'string' ].each do |value|
111
+ it "raises exception when attempting type_cast of non-numeric value #{value.inspect}" do
112
+ lambda do
113
+ type_cast(value)
114
+ end.should raise_error(TypecastError, /could not typecast/)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+ require 'bigdecimal'
3
+
4
+ module Arel
5
+ describe "Attributes::Integer" do
6
+
7
+ before :all do
8
+ @relation = Model.build do |r|
9
+ r.engine Testing::Engine.new
10
+ r.attribute :age, Attributes::Integer
11
+ end
12
+ end
13
+
14
+ def type_cast(val)
15
+ @relation[:age].type_cast(val)
16
+ end
17
+
18
+ describe "#type_cast" do
19
+ it "returns same value if an integer" do
20
+ type_cast(24).should eql(24)
21
+ end
22
+
23
+ it "returns nil if passed nil" do
24
+ type_cast(nil).should be_nil
25
+ end
26
+
27
+ it "returns nil if passed empty string" do
28
+ type_cast('').should be_nil
29
+ end
30
+
31
+ it "returns integer representation of a zero string integer" do
32
+ type_cast('0').should eql(0)
33
+ end
34
+
35
+ it "returns integer representation of a positive string integer" do
36
+ type_cast('24').should eql(24)
37
+ end
38
+
39
+ it "returns integer representation of a positive string integer with spaces" do
40
+ type_cast(' 24').should eql(24)
41
+ type_cast('24 ').should eql(24)
42
+ end
43
+
44
+ it "returns integer representation of a negative string integer" do
45
+ type_cast('-24').should eql(-24)
46
+ end
47
+
48
+ it "returns integer representation of a negative string integer with spaces" do
49
+ type_cast('-24 ').should eql(-24)
50
+ type_cast(' -24').should eql(-24)
51
+ end
52
+
53
+ it "returns integer representation of a zero string float" do
54
+ type_cast('0.0').should eql(0)
55
+ end
56
+
57
+ it "returns integer representation of a positive string float" do
58
+ type_cast('24.35').should eql(24)
59
+ end
60
+
61
+ it "returns integer representation of a positive string float with spaces" do
62
+ type_cast(' 24.35').should eql(24)
63
+ type_cast('24.35 ').should eql(24)
64
+ end
65
+
66
+ it "returns integer representation of a negative string float" do
67
+ type_cast('-24.35').should eql(-24)
68
+ end
69
+
70
+ it "returns integer representation of a negative string float with spaces" do
71
+ type_cast(' -24.35 ').should eql(-24)
72
+ end
73
+
74
+ it "returns integer representation of a zero string float, with no leading digits" do
75
+ type_cast('.0').should eql(0)
76
+ end
77
+
78
+ it "returns integer representation of a zero string float, with no leading digits with spaces" do
79
+ type_cast(' .0').should eql(0)
80
+ end
81
+
82
+ it "returns integer representation of a positive string float, with no leading digits" do
83
+ type_cast('.41').should eql(0)
84
+ end
85
+
86
+ it "returns integer representation of a zero float" do
87
+ type_cast(0.0).should eql(0)
88
+ end
89
+
90
+ it "returns integer representation of a positive float" do
91
+ type_cast(24.35).should eql(24)
92
+ end
93
+
94
+ it "returns integer representation of a negative float" do
95
+ type_cast(-24.35).should eql(-24)
96
+ end
97
+
98
+ it "returns integer representation of a zero decimal" do
99
+ type_cast(BigDecimal('0.0')).should eql(0)
100
+ end
101
+
102
+ it "returns integer representation of a positive decimal" do
103
+ type_cast(BigDecimal('24.35')).should eql(24)
104
+ end
105
+
106
+ it "returns integer representation of a negative decimal" do
107
+ type_cast(BigDecimal('-24.35')).should eql(-24)
108
+ end
109
+
110
+ [ Object.new, true, '00.0', '0.', 'string' ].each do |value|
111
+ it "raises exception when attempting type_cast of non-numeric value #{value.inspect}" do
112
+ lambda do
113
+ type_cast(value)
114
+ end.should raise_error(TypecastError, /could not typecast/)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end