arel 0.2.pre → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,8 @@
1
- == Git
2
-
3
- * 1 major enhancement
1
+ == 0.2.0 / 2010-01-31
4
2
 
5
3
  * Ruby 1.9 compatibility
4
+ * Many improvements to support the Arel integration into ActiveRecord (see `git log v0.1.0..v0.2.0`)
5
+ * Thanks to Emilio Tagua and Pratik Naik for many significant contributions!
6
6
 
7
7
  == 0.1.0 / 2009-08-06
8
8
 
data/Thorfile CHANGED
@@ -1,4 +1,4 @@
1
- require "activerecord"
1
+ require "active_support"
2
2
 
3
3
  module GemHelpers
4
4
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{arel}
5
- s.version = "0.2.pre"
5
+ s.version = "0.2.0"
6
6
 
7
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Bryan Helmkamp", "Nick Kallen"]
9
- s.date = %q{2010-01-08}
9
+ s.date = %q{2010-01-31}
10
10
  s.description = %q{Arel is a Relational Algebra for Ruby. It 1) simplifies the generation complex
11
11
  of SQL queries and it 2) adapts to various RDBMS systems. It is intended to be
12
12
  a framework framework; that is, you can build your own ORM with it, focusing on
@@ -7,5 +7,5 @@ module Arel
7
7
  require 'arel/engines'
8
8
  autoload :Session, 'arel/session'
9
9
 
10
- VERSION = "0.2.pre"
10
+ VERSION = "0.2.0"
11
11
  end
@@ -47,6 +47,10 @@ module Arel
47
47
  class InnerJoin < Join; end
48
48
  class OuterJoin < Join; end
49
49
  class StringJoin < Join
50
+ def externalizable?
51
+ relation1.externalizable?
52
+ end
53
+
50
54
  def attributes
51
55
  relation1.externalize.attributes
52
56
  end
@@ -2,7 +2,11 @@ module Arel
2
2
  module Sql
3
3
  module ArrayExtensions
4
4
  def to_sql(formatter = nil)
5
- "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")"
5
+ if any?
6
+ "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")"
7
+ else
8
+ "(NULL)"
9
+ end
6
10
  end
7
11
 
8
12
  def inclusion_predicate_sql
@@ -9,6 +9,10 @@ module Arel
9
9
  @ar.connection
10
10
  end
11
11
 
12
+ def adapter_name
13
+ @adapter_name ||= connection.adapter_name
14
+ end
15
+
12
16
  def method_missing(method, *args, &block)
13
17
  @ar.connection.send(method, *args, &block)
14
18
  end
@@ -11,7 +11,7 @@ module Arel
11
11
  if options.is_a?(Hash)
12
12
  @options = options
13
13
  @engine = options[:engine] || Table.engine
14
- @table_alias = options[:as].to_s if options[:as].present?
14
+ @table_alias = options[:as].to_s if options[:as].present? && options[:as].to_s != @name
15
15
  else
16
16
  @engine = options # Table.new('foo', engine)
17
17
  end
@@ -52,8 +52,9 @@ module Arel
52
52
  end
53
53
 
54
54
  def ==(other)
55
- Table === other and
56
- name == other.name
55
+ Table === other and
56
+ name == other.name and
57
+ table_alias == other.table_alias
57
58
  end
58
59
  end
59
60
  end
@@ -45,6 +45,25 @@ module Arel
45
45
  end
46
46
  end
47
47
  end
48
+
49
+ describe 'when the array is empty' do
50
+ before do
51
+ @array = []
52
+ end
53
+
54
+ it 'manufactures sql with a comma separated list' do
55
+ sql = In.new(@attribute, @array).to_sql
56
+
57
+ adapter_is :mysql do
58
+ sql.should be_like(%Q{`users`.`id` IN (NULL)})
59
+ end
60
+
61
+ adapter_is_not :mysql do
62
+ sql.should be_like(%Q{"users"."id" IN (NULL)})
63
+ end
64
+ end
65
+ end
66
+
48
67
  end
49
68
 
50
69
  describe 'when relating to a range' do
@@ -103,7 +103,36 @@ module Arel
103
103
  })
104
104
  end
105
105
  end
106
- end
106
+
107
+ it "passes the string when there are multiple string joins" do
108
+ relation = StringJoin.new(@relation1, "INNER JOIN asdf ON fdsa")
109
+ relation = StringJoin.new(relation, "INNER JOIN lifo ON fifo")
110
+ sql = StringJoin.new(relation, "INNER JOIN hatful ON hallow").to_sql
111
+
112
+ adapter_is :mysql do
113
+ sql.should be_like(%Q{
114
+ SELECT `users`.`id`, `users`.`name`
115
+ FROM `users`
116
+ INNER JOIN asdf ON fdsa
117
+ INNER JOIN lifo ON fifo
118
+ INNER JOIN hatful ON hallow
119
+ })
120
+ end
121
+
122
+ adapter_is_not :mysql do
123
+ sql.should be_like(%Q{
124
+ SELECT "users"."id", "users"."name"
125
+ FROM "users"
126
+ INNER JOIN asdf ON fdsa
127
+ INNER JOIN lifo ON fifo
128
+ INNER JOIN hatful ON hallow
129
+ })
130
+ end
131
+ end
132
+
133
+ end
134
+
135
+
107
136
  end
108
137
  end
109
138
  end
@@ -44,6 +44,25 @@ module Arel
44
44
  })
45
45
  end
46
46
  end
47
+
48
+ it "does not apply alias if it's same as the table name" do
49
+ sql = @relation.as(:users).to_sql
50
+
51
+ adapter_is :mysql do
52
+ sql.should be_like(%Q{
53
+ SELECT `users`.`id`, `users`.`name`
54
+ FROM `users`
55
+ })
56
+ end
57
+
58
+ adapter_is_not :mysql do
59
+ sql.should be_like(%Q{
60
+ SELECT "users"."id", "users"."name"
61
+ FROM "users"
62
+ })
63
+ end
64
+ end
65
+
47
66
  end
48
67
 
49
68
  describe '#column_for' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.pre
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-08 00:00:00 -05:00
13
+ date: 2010-01-31 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -194,9 +194,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
194
  version:
195
195
  required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  requirements:
197
- - - ">"
197
+ - - ">="
198
198
  - !ruby/object:Gem::Version
199
- version: 1.3.1
199
+ version: "0"
200
200
  version:
201
201
  requirements: []
202
202