arel 5.0.0 → 5.0.1.20140414130214
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -1
- data/Gemfile +1 -1
- data/History.txt +14 -0
- data/README.markdown +0 -6
- data/arel.gemspec +11 -11
- data/lib/arel.rb +1 -1
- data/lib/arel/select_manager.rb +4 -2
- data/lib/arel/tree_manager.rb +3 -0
- data/lib/arel/visitors/mssql.rb +2 -2
- data/lib/arel/visitors/postgresql.rb +2 -0
- data/lib/arel/visitors/to_sql.rb +4 -0
- data/test/nodes/test_ascending.rb +1 -1
- data/test/nodes/test_bin.rb +1 -1
- data/test/nodes/test_descending.rb +1 -1
- data/test/nodes/test_infix_operation.rb +1 -1
- data/test/nodes/test_named_function.rb +1 -1
- data/test/nodes/test_node.rb +1 -1
- data/test/nodes/test_select_core.rb +1 -1
- data/test/test_crud.rb +1 -1
- data/test/test_factory_methods.rb +1 -1
- data/test/test_select_manager.rb +23 -78
- data/test/visitors/test_bind_visitor.rb +1 -1
- data/test/visitors/test_depth_first.rb +1 -1
- data/test/visitors/test_dot.rb +1 -1
- data/test/visitors/test_postgres.rb +36 -0
- data/test/visitors/test_to_sql.rb +59 -10
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86a3156add2973e4e2cd8b3a852e82c26c073601
|
4
|
+
data.tar.gz: 06fc106d1ef5fdc41de327a78a8e0b467096202b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba39500686768a6865b688ce693dd6bc69e2e7ea1a7acb52ab0ad1f0d00fefb85b537f4c5405e865abe67016c166f06503ded328c3b79c2a34156c8ed75e6293
|
7
|
+
data.tar.gz: 1d916874f785a6fc85a2df91633edbc4b607612c876160e6fce14d03ebc17694fd87be197b793ec44f89a68a9815dba07161717333fb15575e36419efae16508
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
source "https://rubygems.org/"
|
6
6
|
|
7
7
|
|
8
|
-
gem "minitest", "~>
|
8
|
+
gem "minitest", "~>5.1", :group => [:development, :test]
|
9
9
|
gem "rdoc", "~>4.0", :group => [:development, :test]
|
10
10
|
gem "hoe", "~>3.5", :group => [:development, :test]
|
11
11
|
|
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 5.0.1 / 2014-04-14
|
2
|
+
|
3
|
+
* Bug Fixes
|
4
|
+
|
5
|
+
* Fix `SqlLiteral` YAML serialization
|
6
|
+
* PostgreSQL bugfix for invalid SQL in subqueries
|
7
|
+
|
1
8
|
== 5.0.0 / 2013-12-04
|
2
9
|
|
3
10
|
* Enhancements
|
@@ -8,6 +15,13 @@
|
|
8
15
|
|
9
16
|
* Fix serializing a relation when calling `to_yaml`
|
10
17
|
|
18
|
+
=== 4.0.2 / 2014-02-05
|
19
|
+
|
20
|
+
* Bug Fixes
|
21
|
+
|
22
|
+
* Fix `SqlLiteral` YAML serialization
|
23
|
+
* PostgreSQL bugfix for invalid SQL in subqueries
|
24
|
+
|
11
25
|
== 4.0.1 / 2013-10-22
|
12
26
|
|
13
27
|
* Enhancements
|
data/README.markdown
CHANGED
@@ -87,12 +87,6 @@ All operators are chainable in this way, and they are chainable any number of ti
|
|
87
87
|
users.where(users[:name].eq('bob')).where(users[:age].lt(25))
|
88
88
|
```
|
89
89
|
|
90
|
-
Of course, many of the operators take multiple arguments, so the last example can be written more tersely:
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
users.where(users[:name].eq('bob'), users[:age].lt(25))
|
94
|
-
```
|
95
|
-
|
96
90
|
The `OR` operator works like this:
|
97
91
|
|
98
92
|
```ruby
|
data/arel.gemspec
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: arel 5.0.
|
2
|
+
# stub: arel 5.0.1.20140414130214 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "arel"
|
6
|
-
s.version = "5.0.
|
6
|
+
s.version = "5.0.1.20140414130214"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib"]
|
9
10
|
s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
|
10
|
-
s.date = "
|
11
|
+
s.date = "2014-04-14"
|
11
12
|
s.description = "Arel is a SQL AST manager for Ruby. It\n\n1. Simplifies the generation of complex SQL queries\n2. Adapts to various RDBMSes\n\nIt is intended to be a framework framework; that is, you can build your own ORM\nwith it, focusing on innovative object and collection modeling as opposed to\ndatabase compatibility and query generation."
|
12
13
|
s.email = ["aaron@tenderlovemaking.com", "bryan@brynary.com", "miloops@gmail.com", "nick@example.org"]
|
13
14
|
s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown"]
|
@@ -15,9 +16,8 @@ Gem::Specification.new do |s|
|
|
15
16
|
s.homepage = "http://github.com/rails/arel"
|
16
17
|
s.licenses = ["MIT"]
|
17
18
|
s.rdoc_options = ["--main", "README.markdown"]
|
18
|
-
s.require_paths = ["lib"]
|
19
19
|
s.rubyforge_project = "arel"
|
20
|
-
s.rubygems_version = "2.
|
20
|
+
s.rubygems_version = "2.2.2"
|
21
21
|
s.summary = "Arel is a SQL AST manager for Ruby"
|
22
22
|
s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_and.rb", "test/nodes/test_as.rb", "test/nodes/test_ascending.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_descending.rb", "test/nodes/test_distinct.rb", "test/nodes/test_equality.rb", "test/nodes/test_extract.rb", "test/nodes/test_false.rb", "test/nodes/test_grouping.rb", "test/nodes/test_infix_operation.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_over.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_table_alias.rb", "test/nodes/test_true.rb", "test/nodes/test_update_statement.rb", "test/nodes/test_window.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_bind_visitor.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dispatch_contamination.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_informix.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"]
|
23
23
|
|
@@ -25,17 +25,17 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.specification_version = 4
|
26
26
|
|
27
27
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
-
s.add_development_dependency(%q<minitest>, ["~> 5.
|
28
|
+
s.add_development_dependency(%q<minitest>, ["~> 5.3"])
|
29
29
|
s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
|
30
|
-
s.add_development_dependency(%q<hoe>, ["~> 3.
|
30
|
+
s.add_development_dependency(%q<hoe>, ["~> 3.6"])
|
31
31
|
else
|
32
|
-
s.add_dependency(%q<minitest>, ["~> 5.
|
32
|
+
s.add_dependency(%q<minitest>, ["~> 5.3"])
|
33
33
|
s.add_dependency(%q<rdoc>, ["~> 4.0"])
|
34
|
-
s.add_dependency(%q<hoe>, ["~> 3.
|
34
|
+
s.add_dependency(%q<hoe>, ["~> 3.6"])
|
35
35
|
end
|
36
36
|
else
|
37
|
-
s.add_dependency(%q<minitest>, ["~> 5.
|
37
|
+
s.add_dependency(%q<minitest>, ["~> 5.3"])
|
38
38
|
s.add_dependency(%q<rdoc>, ["~> 4.0"])
|
39
|
-
s.add_dependency(%q<hoe>, ["~> 3.
|
39
|
+
s.add_dependency(%q<hoe>, ["~> 3.6"])
|
40
40
|
end
|
41
41
|
end
|
data/lib/arel.rb
CHANGED
data/lib/arel/select_manager.rb
CHANGED
@@ -2,6 +2,8 @@ module Arel
|
|
2
2
|
class SelectManager < Arel::TreeManager
|
3
3
|
include Arel::Crud
|
4
4
|
|
5
|
+
STRING_OR_SYMBOL_CLASS = [Symbol, String]
|
6
|
+
|
5
7
|
def initialize engine, table = nil
|
6
8
|
super(engine)
|
7
9
|
@ast = Nodes::SelectStatement.new
|
@@ -128,7 +130,7 @@ module Arel
|
|
128
130
|
# FIXME: converting these to SQLLiterals is probably not good, but
|
129
131
|
# rails tests require it.
|
130
132
|
@ctx.projections.concat projections.map { |x|
|
131
|
-
|
133
|
+
STRING_OR_SYMBOL_CLASS.include?(x.class) ? SqlLiteral.new(x.to_s) : x
|
132
134
|
}
|
133
135
|
self
|
134
136
|
end
|
@@ -152,7 +154,7 @@ module Arel
|
|
152
154
|
def order *expr
|
153
155
|
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
|
154
156
|
@ast.orders.concat expr.map { |x|
|
155
|
-
|
157
|
+
STRING_OR_SYMBOL_CLASS.include?(x.class) ? Nodes::SqlLiteral.new(x.to_s) : x
|
156
158
|
}
|
157
159
|
self
|
158
160
|
end
|
data/lib/arel/tree_manager.rb
CHANGED
data/lib/arel/visitors/mssql.rb
CHANGED
@@ -62,8 +62,8 @@ module Arel
|
|
62
62
|
x.projections.length == 1 && Arel::Nodes::Count === x.projections.first
|
63
63
|
end
|
64
64
|
|
65
|
-
#
|
66
|
-
#
|
65
|
+
# FIXME raise exception of there is no pk?
|
66
|
+
# FIXME!! Table.primary_key will be deprecated. What is the replacement??
|
67
67
|
def find_left_table_pk o, a
|
68
68
|
return visit o.primary_key, a if o.instance_of? Arel::Table
|
69
69
|
find_left_table_pk o.left, a if o.kind_of? Arel::Nodes::Join
|
@@ -4,10 +4,12 @@ module Arel
|
|
4
4
|
private
|
5
5
|
|
6
6
|
def visit_Arel_Nodes_Matches o, a
|
7
|
+
a = o.left if Arel::Attributes::Attribute === o.left
|
7
8
|
"#{visit o.left, a} ILIKE #{visit o.right, a}"
|
8
9
|
end
|
9
10
|
|
10
11
|
def visit_Arel_Nodes_DoesNotMatch o, a
|
12
|
+
a = o.left if Arel::Attributes::Attribute === o.left
|
11
13
|
"#{visit o.left, a} NOT ILIKE #{visit o.right, a}"
|
12
14
|
end
|
13
15
|
|
data/lib/arel/visitors/to_sql.rb
CHANGED
@@ -42,6 +42,10 @@ module Arel
|
|
42
42
|
# `getconstant` should be a hash lookup, and no object is duped when the
|
43
43
|
# value of the constant is pushed on the stack. Hence the crazy
|
44
44
|
# constants below.
|
45
|
+
#
|
46
|
+
# `matches` and `doesNotMatch` operate case-insensitively via Visitor subclasses
|
47
|
+
# specialized for specific databases when necessary.
|
48
|
+
#
|
45
49
|
|
46
50
|
WHERE = ' WHERE ' # :nodoc:
|
47
51
|
SPACE = ' ' # :nodoc:
|
data/test/nodes/test_bin.rb
CHANGED
data/test/nodes/test_node.rb
CHANGED
data/test/test_crud.rb
CHANGED
@@ -45,7 +45,7 @@ module Arel
|
|
45
45
|
table = Table.new :users
|
46
46
|
fc = FakeCrudder.new
|
47
47
|
fc.from table
|
48
|
-
stmt = fc.compile_update [[table[:id], 'foo']], table
|
48
|
+
stmt = fc.compile_update [[table[:id], 'foo']], Arel::Attributes::Attribute.new(table, 'id')
|
49
49
|
assert_instance_of Arel::UpdateManager, stmt
|
50
50
|
end
|
51
51
|
end
|
data/test/test_select_manager.rb
CHANGED
@@ -1,58 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
module Arel
|
4
|
-
class EngineProxy
|
5
|
-
attr_reader :executed
|
6
|
-
attr_reader :connection_pool
|
7
|
-
attr_reader :spec
|
8
|
-
attr_reader :config
|
9
|
-
|
10
|
-
def initialize engine
|
11
|
-
@engine = engine
|
12
|
-
@executed = []
|
13
|
-
@connection_pool = self
|
14
|
-
@spec = self
|
15
|
-
@config = { :adapter => 'sqlite3' }
|
16
|
-
end
|
17
|
-
|
18
|
-
def with_connection
|
19
|
-
yield self
|
20
|
-
end
|
21
|
-
|
22
|
-
def connection
|
23
|
-
self
|
24
|
-
end
|
25
|
-
|
26
|
-
def quote_table_name thing; @engine.connection.quote_table_name thing end
|
27
|
-
def quote_column_name thing; @engine.connection.quote_column_name thing end
|
28
|
-
def quote thing, column; @engine.connection.quote thing, column end
|
29
|
-
def columns table, message = nil
|
30
|
-
@engine.connection.columns table, message
|
31
|
-
end
|
32
|
-
|
33
|
-
def columns_hash
|
34
|
-
@engine.connection.columns_hash
|
35
|
-
end
|
36
|
-
|
37
|
-
def table_exists? name
|
38
|
-
@engine.connection.table_exists? name
|
39
|
-
end
|
40
|
-
|
41
|
-
def tables
|
42
|
-
@engine.connection.tables
|
43
|
-
end
|
44
|
-
|
45
|
-
def visitor
|
46
|
-
@engine.connection.visitor
|
47
|
-
end
|
48
|
-
|
49
|
-
def execute sql, name = nil, *args
|
50
|
-
@executed << sql
|
51
|
-
end
|
52
|
-
alias :update :execute
|
53
|
-
alias :delete :execute
|
54
|
-
alias :insert :execute
|
55
|
-
end
|
56
4
|
|
57
5
|
describe 'select manager' do
|
58
6
|
def test_join_sources
|
@@ -61,6 +9,13 @@ module Arel
|
|
61
9
|
assert_equal "SELECT FROM 'foo'", manager.to_sql
|
62
10
|
end
|
63
11
|
|
12
|
+
def test_manager_stores_bind_values
|
13
|
+
manager = Arel::SelectManager.new Table.engine
|
14
|
+
assert_equal [], manager.bind_values
|
15
|
+
manager.bind_values = [1]
|
16
|
+
assert_equal [1], manager.bind_values
|
17
|
+
end
|
18
|
+
|
64
19
|
describe 'backwards compatibility' do
|
65
20
|
describe 'project' do
|
66
21
|
it 'accepts symbols as sql literals' do
|
@@ -874,9 +829,8 @@ module Arel
|
|
874
829
|
|
875
830
|
describe 'delete' do
|
876
831
|
it "copies from" do
|
877
|
-
engine = EngineProxy.new Table.engine
|
878
832
|
table = Table.new :users
|
879
|
-
manager = Arel::SelectManager.new engine
|
833
|
+
manager = Arel::SelectManager.new Table.engine
|
880
834
|
manager.from table
|
881
835
|
stmt = manager.compile_delete
|
882
836
|
|
@@ -884,9 +838,8 @@ module Arel
|
|
884
838
|
end
|
885
839
|
|
886
840
|
it "copies where" do
|
887
|
-
engine = EngineProxy.new Table.engine
|
888
841
|
table = Table.new :users
|
889
|
-
manager = Arel::SelectManager.new engine
|
842
|
+
manager = Arel::SelectManager.new Table.engine
|
890
843
|
manager.from table
|
891
844
|
manager.where table[:id].eq 10
|
892
845
|
stmt = manager.compile_delete
|
@@ -916,12 +869,11 @@ module Arel
|
|
916
869
|
|
917
870
|
describe 'update' do
|
918
871
|
it 'copies limits' do
|
919
|
-
engine = EngineProxy.new Table.engine
|
920
872
|
table = Table.new :users
|
921
|
-
manager = Arel::SelectManager.new engine
|
873
|
+
manager = Arel::SelectManager.new Table.engine
|
922
874
|
manager.from table
|
923
875
|
manager.take 1
|
924
|
-
stmt = manager.compile_update(SqlLiteral.new('foo = bar'), table
|
876
|
+
stmt = manager.compile_update(SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id'))
|
925
877
|
stmt.key = table['id']
|
926
878
|
|
927
879
|
stmt.to_sql.must_be_like %{
|
@@ -931,12 +883,11 @@ module Arel
|
|
931
883
|
end
|
932
884
|
|
933
885
|
it 'copies order' do
|
934
|
-
engine = EngineProxy.new Table.engine
|
935
886
|
table = Table.new :users
|
936
|
-
manager = Arel::SelectManager.new engine
|
887
|
+
manager = Arel::SelectManager.new Table.engine
|
937
888
|
manager.from table
|
938
889
|
manager.order :foo
|
939
|
-
stmt = manager.compile_update(SqlLiteral.new('foo = bar'), table
|
890
|
+
stmt = manager.compile_update(SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id'))
|
940
891
|
stmt.key = table['id']
|
941
892
|
|
942
893
|
stmt.to_sql.must_be_like %{
|
@@ -946,22 +897,20 @@ module Arel
|
|
946
897
|
end
|
947
898
|
|
948
899
|
it 'takes a string' do
|
949
|
-
engine = EngineProxy.new Table.engine
|
950
900
|
table = Table.new :users
|
951
|
-
manager = Arel::SelectManager.new engine
|
901
|
+
manager = Arel::SelectManager.new Table.engine
|
952
902
|
manager.from table
|
953
|
-
stmt = manager.compile_update(SqlLiteral.new('foo = bar'), table
|
903
|
+
stmt = manager.compile_update(SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id'))
|
954
904
|
|
955
905
|
stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar }
|
956
906
|
end
|
957
907
|
|
958
908
|
it 'copies where clauses' do
|
959
|
-
engine = EngineProxy.new Table.engine
|
960
909
|
table = Table.new :users
|
961
|
-
manager = Arel::SelectManager.new engine
|
910
|
+
manager = Arel::SelectManager.new Table.engine
|
962
911
|
manager.where table[:id].eq 10
|
963
912
|
manager.from table
|
964
|
-
stmt = manager.compile_update({table[:id] => 1}, table
|
913
|
+
stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id'))
|
965
914
|
|
966
915
|
stmt.to_sql.must_be_like %{
|
967
916
|
UPDATE "users" SET "id" = 1 WHERE "users"."id" = 10
|
@@ -969,13 +918,12 @@ module Arel
|
|
969
918
|
end
|
970
919
|
|
971
920
|
it 'copies where clauses when nesting is triggered' do
|
972
|
-
engine = EngineProxy.new Table.engine
|
973
921
|
table = Table.new :users
|
974
|
-
manager = Arel::SelectManager.new engine
|
922
|
+
manager = Arel::SelectManager.new Table.engine
|
975
923
|
manager.where table[:foo].eq 10
|
976
924
|
manager.take 42
|
977
925
|
manager.from table
|
978
|
-
stmt = manager.compile_update({table[:id] => 1}, table
|
926
|
+
stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id'))
|
979
927
|
|
980
928
|
stmt.to_sql.must_be_like %{
|
981
929
|
UPDATE "users" SET "id" = 1 WHERE "users"."id" IN (SELECT "users"."id" FROM "users" WHERE "users"."foo" = 10 LIMIT 42)
|
@@ -983,11 +931,10 @@ module Arel
|
|
983
931
|
end
|
984
932
|
|
985
933
|
it 'executes an update statement' do
|
986
|
-
engine = EngineProxy.new Table.engine
|
987
934
|
table = Table.new :users
|
988
|
-
manager = Arel::SelectManager.new engine
|
935
|
+
manager = Arel::SelectManager.new Table.engine
|
989
936
|
manager.from table
|
990
|
-
stmt = manager.compile_update({table[:id] => 1}, table
|
937
|
+
stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id'))
|
991
938
|
|
992
939
|
stmt.to_sql.must_be_like %{
|
993
940
|
UPDATE "users" SET "id" = 1
|
@@ -1005,16 +952,14 @@ module Arel
|
|
1005
952
|
|
1006
953
|
it 'takes strings' do
|
1007
954
|
manager = Arel::SelectManager.new Table.engine
|
1008
|
-
manager.project
|
955
|
+
manager.project '*'
|
1009
956
|
manager.to_sql.must_be_like %{ SELECT * }
|
1010
957
|
end
|
1011
958
|
|
1012
959
|
it "takes sql literals" do
|
1013
960
|
manager = Arel::SelectManager.new Table.engine
|
1014
961
|
manager.project Nodes::SqlLiteral.new '*'
|
1015
|
-
manager.to_sql.must_be_like %{
|
1016
|
-
SELECT *
|
1017
|
-
}
|
962
|
+
manager.to_sql.must_be_like %{ SELECT * }
|
1018
963
|
end
|
1019
964
|
end
|
1020
965
|
|
data/test/visitors/test_dot.rb
CHANGED
@@ -5,6 +5,8 @@ module Arel
|
|
5
5
|
describe 'the postgres visitor' do
|
6
6
|
before do
|
7
7
|
@visitor = PostgreSQL.new Table.engine.connection
|
8
|
+
@table = Table.new(:users)
|
9
|
+
@attr = @table[:id]
|
8
10
|
end
|
9
11
|
|
10
12
|
describe 'locking' do
|
@@ -43,6 +45,40 @@ module Arel
|
|
43
45
|
core.set_quantifier = Arel::Nodes::Distinct.new
|
44
46
|
assert_equal 'SELECT DISTINCT', @visitor.accept(core)
|
45
47
|
end
|
48
|
+
|
49
|
+
describe "Nodes::Matches" do
|
50
|
+
it "should know how to visit" do
|
51
|
+
node = @table[:name].matches('foo%')
|
52
|
+
@visitor.accept(node).must_be_like %{
|
53
|
+
"users"."name" ILIKE 'foo%'
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can handle subqueries' do
|
58
|
+
subquery = @table.project(:id).where(@table[:name].matches('foo%'))
|
59
|
+
node = @attr.in subquery
|
60
|
+
@visitor.accept(node).must_be_like %{
|
61
|
+
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%')
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "Nodes::DoesNotMatch" do
|
67
|
+
it "should know how to visit" do
|
68
|
+
node = @table[:name].does_not_match('foo%')
|
69
|
+
@visitor.accept(node).must_be_like %{
|
70
|
+
"users"."name" NOT ILIKE 'foo%'
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can handle subqueries' do
|
75
|
+
subquery = @table.project(:id).where(@table[:name].does_not_match('foo%'))
|
76
|
+
node = @attr.in subquery
|
77
|
+
@visitor.accept(node).must_be_like %{
|
78
|
+
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT ILIKE 'foo%')
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
46
82
|
end
|
47
83
|
end
|
48
84
|
end
|
@@ -92,7 +92,14 @@ module Arel
|
|
92
92
|
assert_equal 'omg(*, *)', @visitor.accept(function)
|
93
93
|
end
|
94
94
|
|
95
|
-
describe '
|
95
|
+
describe 'Nodes::Equality' do
|
96
|
+
it "should escape strings" do
|
97
|
+
test = Table.new(:users)[:name].eq 'Aaron Patterson'
|
98
|
+
@visitor.accept(test).must_be_like %{
|
99
|
+
"users"."name" = 'Aaron Patterson'
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
96
103
|
it 'should handle false' do
|
97
104
|
sql = @visitor.accept Nodes::Equality.new(false, false)
|
98
105
|
sql.must_be_like %{ 'f' = 'f' }
|
@@ -103,6 +110,23 @@ module Arel
|
|
103
110
|
sql = @visitor.accept Nodes::Equality.new(table[:id], '1-fooo')
|
104
111
|
sql.must_be_like %{ "users"."id" = 1 }
|
105
112
|
end
|
113
|
+
|
114
|
+
it 'should handle nil' do
|
115
|
+
sql = @visitor.accept Nodes::Equality.new(@table[:name], nil)
|
116
|
+
sql.must_be_like %{ "users"."name" IS NULL }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'Nodes::NotEqual' do
|
121
|
+
it 'should handle false' do
|
122
|
+
sql = @visitor.accept Nodes::NotEqual.new(@table[:active], false)
|
123
|
+
sql.must_be_like %{ "users"."active" != 'f' }
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should handle nil' do
|
127
|
+
sql = @visitor.accept Nodes::NotEqual.new(@table[:name], nil)
|
128
|
+
sql.must_be_like %{ "users"."name" IS NOT NULL }
|
129
|
+
end
|
106
130
|
end
|
107
131
|
|
108
132
|
it "should visit string subclass" do
|
@@ -194,6 +218,40 @@ module Arel
|
|
194
218
|
@visitor.accept(test).must_be_like %{ "users"."bool" = 't' }
|
195
219
|
end
|
196
220
|
|
221
|
+
describe "Nodes::Matches" do
|
222
|
+
it "should know how to visit" do
|
223
|
+
node = @table[:name].matches('foo%')
|
224
|
+
@visitor.accept(node).must_be_like %{
|
225
|
+
"users"."name" LIKE 'foo%'
|
226
|
+
}
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'can handle subqueries' do
|
230
|
+
subquery = @table.project(:id).where(@table[:name].matches('foo%'))
|
231
|
+
node = @attr.in subquery
|
232
|
+
@visitor.accept(node).must_be_like %{
|
233
|
+
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" LIKE 'foo%')
|
234
|
+
}
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "Nodes::DoesNotMatch" do
|
239
|
+
it "should know how to visit" do
|
240
|
+
node = @table[:name].does_not_match('foo%')
|
241
|
+
@visitor.accept(node).must_be_like %{
|
242
|
+
"users"."name" NOT LIKE 'foo%'
|
243
|
+
}
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'can handle subqueries' do
|
247
|
+
subquery = @table.project(:id).where(@table[:name].does_not_match('foo%'))
|
248
|
+
node = @attr.in subquery
|
249
|
+
@visitor.accept(node).must_be_like %{
|
250
|
+
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT LIKE 'foo%')
|
251
|
+
}
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
197
255
|
describe "Nodes::Ordering" do
|
198
256
|
it "should know how to visit" do
|
199
257
|
node = @attr.desc
|
@@ -378,15 +436,6 @@ module Arel
|
|
378
436
|
end
|
379
437
|
end
|
380
438
|
|
381
|
-
describe 'Equality' do
|
382
|
-
it "should escape strings" do
|
383
|
-
test = Table.new(:users)[:name].eq 'Aaron Patterson'
|
384
|
-
@visitor.accept(test).must_be_like %{
|
385
|
-
"users"."name" = 'Aaron Patterson'
|
386
|
-
}
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
439
|
describe 'Constants' do
|
391
440
|
it "should handle true" do
|
392
441
|
test = Table.new(:users).create_true
|
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: 5.0.
|
4
|
+
version: 5.0.1.20140414130214
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
@@ -11,50 +11,50 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: minitest
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- - ~>
|
20
|
+
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '5.
|
22
|
+
version: '5.3'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '5.
|
29
|
+
version: '5.3'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rdoc
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- - ~>
|
34
|
+
- - "~>"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '4.0'
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '4.0'
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: hoe
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- - ~>
|
48
|
+
- - "~>"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: '3.
|
50
|
+
version: '3.6'
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- - ~>
|
55
|
+
- - "~>"
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: '3.
|
57
|
+
version: '3.6'
|
58
58
|
description: |-
|
59
59
|
Arel is a SQL AST manager for Ruby. It
|
60
60
|
|
@@ -77,9 +77,9 @@ extra_rdoc_files:
|
|
77
77
|
- Manifest.txt
|
78
78
|
- README.markdown
|
79
79
|
files:
|
80
|
-
- .autotest
|
81
|
-
- .gemtest
|
82
|
-
- .travis.yml
|
80
|
+
- ".autotest"
|
81
|
+
- ".gemtest"
|
82
|
+
- ".travis.yml"
|
83
83
|
- Gemfile
|
84
84
|
- History.txt
|
85
85
|
- MIT-LICENSE.txt
|
@@ -216,23 +216,23 @@ licenses:
|
|
216
216
|
metadata: {}
|
217
217
|
post_install_message:
|
218
218
|
rdoc_options:
|
219
|
-
- --main
|
219
|
+
- "--main"
|
220
220
|
- README.markdown
|
221
221
|
require_paths:
|
222
222
|
- lib
|
223
223
|
required_ruby_version: !ruby/object:Gem::Requirement
|
224
224
|
requirements:
|
225
|
-
- -
|
225
|
+
- - ">="
|
226
226
|
- !ruby/object:Gem::Version
|
227
227
|
version: '0'
|
228
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
229
|
requirements:
|
230
|
-
- -
|
230
|
+
- - ">="
|
231
231
|
- !ruby/object:Gem::Version
|
232
232
|
version: '0'
|
233
233
|
requirements: []
|
234
234
|
rubyforge_project: arel
|
235
|
-
rubygems_version: 2.
|
235
|
+
rubygems_version: 2.2.2
|
236
236
|
signing_key:
|
237
237
|
specification_version: 4
|
238
238
|
summary: Arel is a SQL AST manager for Ruby
|