arel 2.0.8 → 2.0.9.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -1,3 +1,14 @@
1
+ == 2.0.9 / unreleased
2
+
3
+ * Bug Fixes
4
+
5
+ * Custom LOCK strings are allowed. Fixes LH # 6399
6
+ https://rails.lighthouseapp.com/projects/8994/tickets/6399-allow-database-specific-locking-clauses-to-be-used
7
+
8
+ * Strings passed to StringManager#on will be automatically tagged as SQL
9
+ literals. Fixes Rails LH #6384
10
+ https://rails.lighthouseapp.com/projects/8994/tickets/6384-activerecord-303-and-3-0-stable-generate-invalid-sql-for-has_many-through-association-with-conditions
11
+
1
12
  == 2.0.8 / 2010/02/08
2
13
 
3
14
  * Bug Fixes
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{arel}
5
- s.version = "2.0.8.beta.20110131120940"
5
+ s.version = "2.0.9.20110222133018"
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 = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
9
- s.date = %q{2011-01-31}
9
+ s.date = %q{2011-02-22}
10
10
  s.description = %q{Arel is a Relational Algebra for Ruby. It 1) simplifies the generation complex of SQL queries and it 2) adapts to various RDBMS systems. It is intended to be a framework framework; that is, you can build your own ORM with it, focusing on innovative object and collection modeling as opposed to database compatibility and query generation.}
11
11
  s.email = ["aaron@tenderlovemaking.com", "bryan@brynary.com", "miloops@gmail.com", "nick@example.org"]
12
12
  s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown"]
@@ -15,12 +15,11 @@ Gem::Specification.new do |s|
15
15
  s.rdoc_options = ["--main", "README.markdown"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{arel}
18
- s.rubygems_version = %q{1.3.7}
18
+ s.rubygems_version = %q{1.5.0}
19
19
  s.summary = %q{Arel is a Relational Algebra for Ruby}
20
20
  s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_as.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_equality.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_update_statement.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
23
  s.specification_version = 3
25
24
 
26
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -29,7 +29,7 @@ require 'arel/sql_literal'
29
29
  ####
30
30
 
31
31
  module Arel
32
- VERSION = '2.0.8'
32
+ VERSION = '2.0.9'
33
33
 
34
34
  def self.sql raw_sql
35
35
  Arel::Nodes::SqlLiteral.new raw_sql
@@ -1,6 +1,6 @@
1
1
  module Arel
2
2
  module Nodes
3
- class Lock < Arel::Nodes::Node
3
+ class Lock < Arel::Nodes::Unary
4
4
  end
5
5
  end
6
6
  end
@@ -34,10 +34,16 @@ module Arel
34
34
  @ctx.wheres.map { |c| to_sql.accept c }
35
35
  end
36
36
 
37
- def lock locking = true
38
- # FIXME: do we even need to store this? If locking is +false+ shouldn't
39
- # we just remove the node from the AST?
40
- @ast.lock = Nodes::Lock.new
37
+ def lock locking = Arel.sql('FOR UPDATE')
38
+ case locking
39
+ when true
40
+ locking = Arel.sql('FOR UPDATE')
41
+ when Arel::Nodes::SqlLiteral
42
+ when String
43
+ locking = Arel.sql locking
44
+ end
45
+
46
+ @ast.lock = Nodes::Lock.new(locking)
41
47
  self
42
48
  end
43
49
 
@@ -213,6 +219,8 @@ module Arel
213
219
 
214
220
  private
215
221
  def collapse exprs
222
+ exprs.map! { |x| x.class == ::String ? Arel.sql(x) : x }
223
+
216
224
  return exprs.first if exprs.length == 1
217
225
 
218
226
  right = exprs.pop
@@ -3,7 +3,7 @@ module Arel
3
3
  class MySQL < Arel::Visitors::ToSql
4
4
  private
5
5
  def visit_Arel_Nodes_Lock o
6
- "FOR UPDATE"
6
+ visit o.expr
7
7
  end
8
8
 
9
9
  ###
@@ -3,7 +3,7 @@ module Arel
3
3
  class PostgreSQL < Arel::Visitors::ToSql
4
4
  private
5
5
  def visit_Arel_Nodes_Lock o
6
- "FOR UPDATE"
6
+ visit o.expr
7
7
  end
8
8
 
9
9
  def visit_Arel_Nodes_SelectStatement o
@@ -90,6 +90,24 @@ module Arel
90
90
  mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo }
91
91
  end
92
92
  end
93
+
94
+ describe 'on' do
95
+ it 'converts to sqlliterals' do
96
+ table = Table.new :users
97
+ right = table.alias
98
+ mgr = table.from table
99
+ mgr.join(right).on("omg")
100
+ mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg }
101
+ end
102
+
103
+ it 'converts to sqlliterals' do
104
+ table = Table.new :users
105
+ right = table.alias
106
+ mgr = table.from table
107
+ mgr.join(right).on("omg", "123")
108
+ mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg AND 123 }
109
+ end
110
+ end
93
111
  end
94
112
 
95
113
  describe 'clone' do
@@ -56,7 +56,7 @@ module Arel
56
56
  end
57
57
 
58
58
  def test_lock
59
- lock = Nodes::Lock.new
59
+ lock = Nodes::Lock.new true
60
60
  @visitor.accept lock
61
61
  assert_equal [lock], @collector.calls
62
62
  end
@@ -29,11 +29,16 @@ module Arel
29
29
  sql.must_be_like "SELECT FROM DUAL"
30
30
  end
31
31
 
32
- it 'uses FOR UPDATE when locking' do
33
- stmt = Nodes::SelectStatement.new
34
- stmt.lock = Nodes::Lock.new
35
- sql = @visitor.accept(stmt)
36
- sql.must_be_like "SELECT FROM DUAL FOR UPDATE"
32
+ describe 'locking' do
33
+ it 'defaults to FOR UPDATE when locking' do
34
+ node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
35
+ @visitor.accept(node).must_be_like "FOR UPDATE"
36
+ end
37
+
38
+ it 'allows a custom string to be used as a lock' do
39
+ node = Nodes::Lock.new(Arel.sql('LOCK IN SHARE MODE'))
40
+ @visitor.accept(node).must_be_like "LOCK IN SHARE MODE"
41
+ end
37
42
  end
38
43
  end
39
44
  end
@@ -7,10 +7,19 @@ module Arel
7
7
  @visitor = PostgreSQL.new Table.engine
8
8
  end
9
9
 
10
- it 'should produce a lock value' do
11
- @visitor.accept(Nodes::Lock.new).must_be_like %{
12
- FOR UPDATE
13
- }
10
+ describe 'locking' do
11
+ it 'defaults to FOR UPDATE' do
12
+ @visitor.accept(Nodes::Lock.new(Arel.sql('FOR UPDATE'))).must_be_like %{
13
+ FOR UPDATE
14
+ }
15
+ end
16
+
17
+ it 'allows a custom string to be used as a lock' do
18
+ node = Nodes::Lock.new(Arel.sql('FOR SHARE'))
19
+ @visitor.accept(node).must_be_like %{
20
+ FOR SHARE
21
+ }
22
+ end
14
23
  end
15
24
 
16
25
  it "should escape LIMIT" do
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 15424031
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 8
10
- version: 2.0.8
9
+ - 9
10
+ - rc
11
+ - 1
12
+ version: 2.0.9.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - Aaron Patterson
@@ -18,7 +20,7 @@ autorequire:
18
20
  bindir: bin
19
21
  cert_chain: []
20
22
 
21
- date: 2011-02-08 00:00:00 -08:00
23
+ date: 2011-02-22 00:00:00 -08:00
22
24
  default_executable:
23
25
  dependencies:
24
26
  - !ruby/object:Gem::Dependency
@@ -77,12 +79,12 @@ dependencies:
77
79
  requirements:
78
80
  - - ">="
79
81
  - !ruby/object:Gem::Version
80
- hash: 47
82
+ hash: 41
81
83
  segments:
82
84
  - 2
83
- - 8
84
- - 0
85
- version: 2.8.0
85
+ - 9
86
+ - 1
87
+ version: 2.9.1
86
88
  type: :development
87
89
  version_requirements: *id004
88
90
  description: Arel is a Relational Algebra for Ruby. It 1) simplifies the generation complex of SQL queries and it 2) adapts to various RDBMS systems. It is intended to be a framework framework; that is, you can build your own ORM with it, focusing on innovative object and collection modeling as opposed to database compatibility and query generation.
@@ -225,6 +227,7 @@ files:
225
227
  - test/visitors/test_postgres.rb
226
228
  - test/visitors/test_sqlite.rb
227
229
  - test/visitors/test_to_sql.rb
230
+ - .gemtest
228
231
  has_rdoc: true
229
232
  homepage: http://github.com/rails/arel
230
233
  licenses: []