squeel 0.9.0 → 0.9.1
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.
data/lib/squeel/nodes/literal.rb
CHANGED
data/lib/squeel/version.rb
CHANGED
@@ -220,7 +220,7 @@ module Squeel
|
|
220
220
|
# @param parent The parent object in the context
|
221
221
|
# @return [Arel::Nodes::Or] An ARel Or node, with left and right sides visited
|
222
222
|
def visit_Squeel_Nodes_Or(o, parent)
|
223
|
-
visit(o.left, parent)
|
223
|
+
Arel::Nodes::Grouping.new(Arel::Nodes::Or.new(visit(o.left, parent), (visit(o.right, parent))))
|
224
224
|
end
|
225
225
|
|
226
226
|
def visit_Squeel_Nodes_Not(o, parent)
|
@@ -3,33 +3,39 @@ require 'spec_helper'
|
|
3
3
|
module Squeel
|
4
4
|
module Nodes
|
5
5
|
describe Literal do
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
subject { Literal.new 'string'}
|
7
|
+
|
8
|
+
it { should respond_to :& }
|
9
|
+
it { should respond_to :| }
|
10
|
+
it { should respond_to :-@ }
|
11
|
+
|
12
|
+
specify { (subject & subject).should be_a And }
|
13
|
+
specify { (subject | subject).should be_a Or }
|
14
|
+
specify { (-subject).should be_a Not }
|
9
15
|
|
10
16
|
it 'hashes like its expr' do
|
11
|
-
|
17
|
+
subject.hash.should eq 'string'.hash
|
12
18
|
end
|
13
19
|
|
14
20
|
it 'returns nil when sent to_sym' do
|
15
|
-
|
21
|
+
subject.to_sym.should be_nil
|
16
22
|
end
|
17
23
|
|
18
24
|
it 'returns a string matching its expr when sent to_s' do
|
19
|
-
|
25
|
+
subject.to_s.should eq 'string'
|
20
26
|
end
|
21
27
|
|
22
28
|
Squeel::Constants::PREDICATES.each do |method_name|
|
23
29
|
it "creates #{method_name} predicates with no value" do
|
24
|
-
predicate =
|
25
|
-
predicate.expr.should eq
|
30
|
+
predicate = subject.send(method_name)
|
31
|
+
predicate.expr.should eq subject
|
26
32
|
predicate.method_name.should eq method_name
|
27
33
|
predicate.value?.should be_false
|
28
34
|
end
|
29
35
|
|
30
36
|
it "creates #{method_name} predicates with a value" do
|
31
|
-
predicate =
|
32
|
-
predicate.expr.should eq
|
37
|
+
predicate = subject.send(method_name, 'value')
|
38
|
+
predicate.expr.should eq subject
|
33
39
|
predicate.method_name.should eq method_name
|
34
40
|
predicate.value.should eq 'value'
|
35
41
|
end
|
@@ -39,15 +45,15 @@ module Squeel
|
|
39
45
|
aliases.each do |aliaz|
|
40
46
|
['', '_any', '_all'].each do |suffix|
|
41
47
|
it "creates #{method_name.to_s + suffix} predicates with no value using the alias #{aliaz.to_s + suffix}" do
|
42
|
-
predicate =
|
43
|
-
predicate.expr.should eq
|
48
|
+
predicate = subject.send(aliaz.to_s + suffix)
|
49
|
+
predicate.expr.should eq subject
|
44
50
|
predicate.method_name.should eq "#{method_name}#{suffix}".to_sym
|
45
51
|
predicate.value?.should be_false
|
46
52
|
end
|
47
53
|
|
48
54
|
it "creates #{method_name.to_s + suffix} predicates with a value using the alias #{aliaz.to_s + suffix}" do
|
49
|
-
predicate =
|
50
|
-
predicate.expr.should eq
|
55
|
+
predicate = subject.send((aliaz.to_s + suffix), 'value')
|
56
|
+
predicate.expr.should eq subject
|
51
57
|
predicate.method_name.should eq "#{method_name}#{suffix}".to_sym
|
52
58
|
predicate.value.should eq 'value'
|
53
59
|
end
|
@@ -56,96 +62,96 @@ module Squeel
|
|
56
62
|
end
|
57
63
|
|
58
64
|
it 'creates eq predicates with ==' do
|
59
|
-
predicate =
|
60
|
-
predicate.expr.should eq
|
65
|
+
predicate = subject == 1
|
66
|
+
predicate.expr.should eq subject
|
61
67
|
predicate.method_name.should eq :eq
|
62
68
|
predicate.value.should eq 1
|
63
69
|
end
|
64
70
|
|
65
71
|
it 'creates not_eq predicates with ^' do
|
66
|
-
predicate =
|
67
|
-
predicate.expr.should eq
|
72
|
+
predicate = subject ^ 1
|
73
|
+
predicate.expr.should eq subject
|
68
74
|
predicate.method_name.should eq :not_eq
|
69
75
|
predicate.value.should eq 1
|
70
76
|
end
|
71
77
|
|
72
78
|
it 'creates not_eq predicates with !=' do
|
73
|
-
predicate =
|
74
|
-
predicate.expr.should eq
|
79
|
+
predicate = subject != 1
|
80
|
+
predicate.expr.should eq subject
|
75
81
|
predicate.method_name.should eq :not_eq
|
76
82
|
predicate.value.should eq 1
|
77
83
|
end if respond_to?('!=')
|
78
84
|
|
79
85
|
it 'creates in predicates with >>' do
|
80
|
-
predicate =
|
81
|
-
predicate.expr.should eq
|
86
|
+
predicate = subject >> [1,2,3]
|
87
|
+
predicate.expr.should eq subject
|
82
88
|
predicate.method_name.should eq :in
|
83
89
|
predicate.value.should eq [1,2,3]
|
84
90
|
end
|
85
91
|
|
86
92
|
it 'creates not_in predicates with <<' do
|
87
|
-
predicate =
|
88
|
-
predicate.expr.should eq
|
93
|
+
predicate = subject << [1,2,3]
|
94
|
+
predicate.expr.should eq subject
|
89
95
|
predicate.method_name.should eq :not_in
|
90
96
|
predicate.value.should eq [1,2,3]
|
91
97
|
end
|
92
98
|
|
93
99
|
it 'creates matches predicates with =~' do
|
94
|
-
predicate =
|
95
|
-
predicate.expr.should eq
|
100
|
+
predicate = subject =~ '%bob%'
|
101
|
+
predicate.expr.should eq subject
|
96
102
|
predicate.method_name.should eq :matches
|
97
103
|
predicate.value.should eq '%bob%'
|
98
104
|
end
|
99
105
|
|
100
106
|
it 'creates does_not_match predicates with !~' do
|
101
|
-
predicate =
|
102
|
-
predicate.expr.should eq
|
107
|
+
predicate = subject !~ '%bob%'
|
108
|
+
predicate.expr.should eq subject
|
103
109
|
predicate.method_name.should eq :does_not_match
|
104
110
|
predicate.value.should eq '%bob%'
|
105
111
|
end if respond_to?('!~')
|
106
112
|
|
107
113
|
it 'creates gt predicates with >' do
|
108
|
-
predicate =
|
109
|
-
predicate.expr.should eq
|
114
|
+
predicate = subject > 1
|
115
|
+
predicate.expr.should eq subject
|
110
116
|
predicate.method_name.should eq :gt
|
111
117
|
predicate.value.should eq 1
|
112
118
|
end
|
113
119
|
|
114
120
|
it 'creates gteq predicates with >=' do
|
115
|
-
predicate =
|
116
|
-
predicate.expr.should eq
|
121
|
+
predicate = subject >= 1
|
122
|
+
predicate.expr.should eq subject
|
117
123
|
predicate.method_name.should eq :gteq
|
118
124
|
predicate.value.should eq 1
|
119
125
|
end
|
120
126
|
|
121
127
|
it 'creates lt predicates with <' do
|
122
|
-
predicate =
|
123
|
-
predicate.expr.should eq
|
128
|
+
predicate = subject < 1
|
129
|
+
predicate.expr.should eq subject
|
124
130
|
predicate.method_name.should eq :lt
|
125
131
|
predicate.value.should eq 1
|
126
132
|
end
|
127
133
|
|
128
134
|
it 'creates lteq predicates with <=' do
|
129
|
-
predicate =
|
130
|
-
predicate.expr.should eq
|
135
|
+
predicate = subject <= 1
|
136
|
+
predicate.expr.should eq subject
|
131
137
|
predicate.method_name.should eq :lteq
|
132
138
|
predicate.value.should eq 1
|
133
139
|
end
|
134
140
|
|
135
141
|
it 'creates ascending orders' do
|
136
|
-
order =
|
142
|
+
order = subject.asc
|
137
143
|
order.should be_ascending
|
138
144
|
end
|
139
145
|
|
140
146
|
it 'creates descending orders' do
|
141
|
-
order =
|
147
|
+
order = subject.desc
|
142
148
|
order.should be_descending
|
143
149
|
end
|
144
150
|
|
145
151
|
it 'creates as nodes with #as' do
|
146
|
-
as =
|
152
|
+
as = subject.as('other_name')
|
147
153
|
as.should be_a Squeel::Nodes::As
|
148
|
-
as.left.should eq
|
154
|
+
as.left.should eq subject
|
149
155
|
as.right.should be_a Arel::Nodes::SqlLiteral
|
150
156
|
as.right.should eq 'other_name'
|
151
157
|
end
|
@@ -55,6 +55,12 @@ module Squeel
|
|
55
55
|
predicate.should eq '1=1'
|
56
56
|
end
|
57
57
|
|
58
|
+
it 'creates OR nodes against a Literal' do
|
59
|
+
predicate = @v.accept(dsl{`blah` | `blah`})
|
60
|
+
predicate.should be_a Arel::Nodes::Grouping
|
61
|
+
predicate.to_sql.should eq '(blah OR blah)'
|
62
|
+
end
|
63
|
+
|
58
64
|
it 'generates IS NULL for hash keys with a value of [nil]' do
|
59
65
|
predicate = @v.accept(:id => [nil])
|
60
66
|
predicate.to_sql.should be_like '"people"."id" IS NULL'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squeel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70206840193580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70206840193580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70206840192480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70206840192480
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: polyamorous
|
38
|
-
requirement: &
|
38
|
+
requirement: &70206840191580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.5.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70206840191580
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70206840190960 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.6.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70206840190960
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: machinist
|
60
|
-
requirement: &
|
60
|
+
requirement: &70206840190480 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.6
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70206840190480
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: faker
|
71
|
-
requirement: &
|
71
|
+
requirement: &70206840190000 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.9.5
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70206840190000
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: sqlite3
|
82
|
-
requirement: &
|
82
|
+
requirement: &70206840189500 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: 1.3.3
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70206840189500
|
91
91
|
description: ! "\n Squeel unlocks the power of ARel in your Rails 3 application
|
92
92
|
with\n a handy block-based syntax. You can write subqueries, access named\n
|
93
93
|
\ functions provided by your RDBMS, and more, all without writing\n SQL
|