arel 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arel.rb +4 -3
- data/lib/arel/algebra.rb +1 -1
- data/lib/arel/algebra/attributes.rb +7 -0
- data/lib/arel/algebra/{attribute.rb → attributes/attribute.rb} +32 -0
- data/lib/arel/algebra/attributes/boolean.rb +21 -0
- data/lib/arel/algebra/attributes/decimal.rb +9 -0
- data/lib/arel/algebra/attributes/float.rb +9 -0
- data/lib/arel/algebra/attributes/integer.rb +10 -0
- data/lib/arel/algebra/attributes/string.rb +10 -0
- data/lib/arel/algebra/attributes/time.rb +6 -0
- data/lib/arel/algebra/predicates.rb +1 -0
- data/lib/arel/algebra/relations/operations/join.rb +4 -2
- data/lib/arel/algebra/relations/operations/order.rb +2 -1
- data/lib/arel/algebra/relations/operations/skip.rb +2 -1
- data/lib/arel/algebra/relations/operations/take.rb +2 -1
- data/lib/arel/algebra/relations/operations/where.rb +7 -6
- data/lib/arel/algebra/relations/relation.rb +2 -1
- data/lib/arel/algebra/relations/utilities/compound.rb +22 -2
- data/lib/arel/algebra/relations/utilities/externalization.rb +1 -1
- data/lib/arel/algebra/relations/utilities/nil.rb +2 -2
- data/lib/arel/engines/memory/predicates.rb +6 -0
- data/lib/arel/engines/memory/relations/array.rb +11 -4
- data/lib/arel/engines/memory/relations/compound.rb +1 -1
- data/lib/arel/engines/memory/relations/operations.rb +2 -2
- data/lib/arel/engines/sql.rb +1 -0
- data/lib/arel/engines/sql/attributes.rb +40 -0
- data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +0 -14
- data/lib/arel/engines/sql/predicates.rb +4 -0
- data/lib/arel/engines/sql/primitives.rb +0 -4
- data/lib/arel/engines/sql/relations/compiler.rb +5 -5
- data/lib/arel/engines/sql/relations/operations/join.rb +1 -1
- data/lib/arel/engines/sql/relations/relation.rb +1 -1
- data/lib/arel/engines/sql/relations/table.rb +6 -7
- data/lib/arel/engines/sql/relations/utilities/compound.rb +1 -1
- data/lib/arel/engines/sql/relations/utilities/nil.rb +1 -1
- data/lib/arel/session.rb +2 -2
- data/lib/arel/version.rb +3 -0
- data/spec/{arel/algebra → algebra}/unit/predicates/binary_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/predicates/equality_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/predicates/in_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/primitives/attribute_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/primitives/expression_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/primitives/value_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/alias_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/delete_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/group_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/insert_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/join_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/order_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/project_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/relation_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/skip_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/table_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/take_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/update_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/where_spec.rb +1 -0
- data/spec/{arel/algebra → algebra}/unit/session/session_spec.rb +0 -0
- data/spec/attributes/boolean_spec.rb +57 -0
- data/spec/attributes/float_spec.rb +119 -0
- data/spec/attributes/integer_spec.rb +119 -0
- data/spec/attributes/string_spec.rb +43 -0
- data/spec/attributes/time_spec.rb +22 -0
- data/spec/{arel/engines → engines}/memory/integration/joins/cross_engine_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/array_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/insert_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/join_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/order_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/project_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/skip_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/take_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/where_spec.rb +1 -1
- data/spec/{arel/engines → engines}/sql/integration/joins/with_adjacency_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/integration/joins/with_aggregations_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/integration/joins/with_compounds_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/engine_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/predicates/binary_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/predicates/equality_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/predicates/in_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/predicates/predicates_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/primitives/attribute_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/primitives/expression_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/primitives/literal_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/primitives/value_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/alias_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/delete_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/from_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/group_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/having_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/insert_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/join_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/lock_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/order_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/project_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/skip_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/table_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/take_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/update_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/where_spec.rb +0 -0
- data/spec/relations/join_spec.rb +40 -0
- data/spec/relations/relation_spec.rb +31 -0
- data/spec/shared/relation_spec.rb +142 -0
- data/spec/spec_helper.rb +17 -45
- data/spec/support/check.rb +6 -0
- data/spec/{connections → support/connections}/mysql_connection.rb +2 -4
- data/spec/{connections → support/connections}/oracle_connection.rb +3 -5
- data/spec/{connections → support/connections}/postgresql_connection.rb +2 -4
- data/spec/{connections → support/connections}/sqlite3_connection.rb +2 -4
- data/spec/support/guards.rb +28 -0
- data/spec/support/matchers.rb +4 -0
- data/spec/{matchers → support/matchers}/be_like.rb +1 -1
- data/spec/{matchers → support/matchers}/disambiguate_attributes.rb +1 -1
- data/spec/{matchers → support/matchers}/hash_the_same_as.rb +1 -1
- data/spec/support/matchers/have_rows.rb +18 -0
- data/spec/support/model.rb +58 -0
- data/spec/{schemas → support/schemas}/mysql_schema.rb +0 -0
- data/spec/{schemas → support/schemas}/oracle_schema.rb +0 -0
- data/spec/{schemas → support/schemas}/postgresql_schema.rb +0 -0
- data/spec/{schemas → support/schemas}/sqlite3_schema.rb +0 -0
- metadata +107 -163
- data/.gitignore +0 -6
- data/.gitmodules +0 -3
- data/Rakefile +0 -48
- data/Thorfile +0 -124
- data/arel.gemspec +0 -258
- data/doc/CONVENTIONS +0 -17
- data/doc/TODO +0 -118
- data/spec/doubles/hash.rb +0 -27
- data/spec/spec.opts +0 -3
@@ -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
|
-
(
|
20
|
-
|
21
|
-
|
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,12 +1,13 @@
|
|
1
1
|
module Arel
|
2
|
-
class Table
|
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
|
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
|
data/lib/arel/session.rb
CHANGED
@@ -11,13 +11,13 @@ module Arel
|
|
11
11
|
begin
|
12
12
|
@started = true
|
13
13
|
@instance = manufacture
|
14
|
-
|
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
|
-
|
20
|
+
singleton_class.class_eval do
|
21
21
|
undef :new
|
22
22
|
alias_method :new, :manufacture
|
23
23
|
end
|
data/lib/arel/version.rb
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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)
|
File without changes
|
@@ -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
|