ardb 0.19.0 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ardb/relation_spy.rb +9 -1
- data/lib/ardb/version.rb +1 -1
- data/test/unit/relation_spy_tests.rb +27 -0
- metadata +4 -4
data/lib/ardb/relation_spy.rb
CHANGED
@@ -21,6 +21,10 @@ module Ardb
|
|
21
21
|
other.kind_of?(self.class) ? @applied == other.applied : super
|
22
22
|
end
|
23
23
|
|
24
|
+
def to_sql
|
25
|
+
@applied.map(&:to_sql).join(", ")
|
26
|
+
end
|
27
|
+
|
24
28
|
# ActiveRecord::QueryMethods
|
25
29
|
|
26
30
|
[ :select,
|
@@ -114,7 +118,11 @@ module Ardb
|
|
114
118
|
all.size
|
115
119
|
end
|
116
120
|
|
117
|
-
AppliedExpression
|
121
|
+
class AppliedExpression < Struct.new(:type, :args)
|
122
|
+
def to_sql
|
123
|
+
"#{self.type}: #{self.args.inspect}"
|
124
|
+
end
|
125
|
+
end
|
118
126
|
|
119
127
|
NotFoundError = Class.new(RuntimeError)
|
120
128
|
|
data/lib/ardb/version.rb
CHANGED
@@ -13,6 +13,7 @@ class Ardb::RelationSpy
|
|
13
13
|
should have_readers :applied
|
14
14
|
should have_accessors :results
|
15
15
|
should have_accessors :limit_value, :offset_value
|
16
|
+
should have_imeths :to_sql
|
16
17
|
should have_imeths :select
|
17
18
|
should have_imeths :from
|
18
19
|
should have_imeths :includes, :joins
|
@@ -47,6 +48,15 @@ class Ardb::RelationSpy
|
|
47
48
|
assert_equal other_relation, subject
|
48
49
|
end
|
49
50
|
|
51
|
+
should "build a fake sql string for its applied expressions using `to_sql`" do
|
52
|
+
subject.select 'column'
|
53
|
+
subject.from 'table'
|
54
|
+
subject.joins 'my_table.my_column ON my_table.my_column = table.column'
|
55
|
+
|
56
|
+
expected = subject.applied.map(&:to_sql).join(', ')
|
57
|
+
assert_equal expected, subject.to_sql
|
58
|
+
end
|
59
|
+
|
50
60
|
end
|
51
61
|
|
52
62
|
class SelectTests < UnitTests
|
@@ -448,6 +458,23 @@ class Ardb::RelationSpy
|
|
448
458
|
|
449
459
|
end
|
450
460
|
|
461
|
+
class AppliedExpressionTests < UnitTests
|
462
|
+
desc "AppliedExpression"
|
463
|
+
setup do
|
464
|
+
@applied_expression = AppliedExpression.new(:select, 'column')
|
465
|
+
end
|
466
|
+
subject{ @applied_expression }
|
467
|
+
|
468
|
+
should have_readers :type, :args
|
469
|
+
should have_imeths :to_sql
|
470
|
+
|
471
|
+
should "return a string representing the expression using `to_sql`" do
|
472
|
+
expected = "#{subject.type}: #{subject.args.inspect}"
|
473
|
+
assert_equal expected, subject.to_sql
|
474
|
+
end
|
475
|
+
|
476
|
+
end
|
477
|
+
|
451
478
|
Result = Struct.new(:id)
|
452
479
|
|
453
480
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ardb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 79
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 20
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.20.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2014-
|
19
|
+
date: 2014-05-07 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|