ardb 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,12 @@ module Ardb
11
11
  @offset_value, @limit_value = nil, nil
12
12
  end
13
13
 
14
+ def initialize_copy(copied_from)
15
+ super
16
+ @applied = copied_from.applied.dup
17
+ @results = copied_from.results.dup
18
+ end
19
+
14
20
  def ==(other)
15
21
  other.kind_of?(self.class) ? @applied == other.applied : super
16
22
  end
@@ -18,6 +24,7 @@ module Ardb
18
24
  # ActiveRecord::QueryMethods
19
25
 
20
26
  [ :select,
27
+ :from,
21
28
  :includes, :joins,
22
29
  :where,
23
30
  :group, :having,
@@ -58,18 +65,20 @@ module Ardb
58
65
 
59
66
  def except(*skips)
60
67
  skips = skips.map(&:to_sym)
61
- @applied.reject!{ |a| skips.include?(a.type) }
62
- @limit_value = nil if skips.include?(:limit)
63
- @offset_value = nil if skips.include?(:offset)
64
- self
68
+ self.dup.tap do |r|
69
+ r.applied.reject!{ |a| skips.include?(a.type) }
70
+ r.limit_value = nil if skips.include?(:limit)
71
+ r.offset_value = nil if skips.include?(:offset)
72
+ end
65
73
  end
66
74
 
67
75
  def only(*onlies)
68
76
  onlies = onlies.map(&:to_sym)
69
- @applied.reject!{ |a| !onlies.include?(a.type) }
70
- @limit_value = nil unless onlies.include?(:limit)
71
- @offset_value = nil unless onlies.include?(:offset)
72
- self
77
+ self.dup.tap do |r|
78
+ r.applied.reject!{ |a| !onlies.include?(a.type) }
79
+ r.limit_value = nil unless onlies.include?(:limit)
80
+ r.offset_value = nil unless onlies.include?(:offset)
81
+ end
73
82
  end
74
83
 
75
84
  # ActiveRecord::FinderMethods
data/lib/ardb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ardb
2
- VERSION = "0.18.0"
2
+ VERSION = "0.19.0"
3
3
  end
@@ -14,6 +14,7 @@ class Ardb::RelationSpy
14
14
  should have_accessors :results
15
15
  should have_accessors :limit_value, :offset_value
16
16
  should have_imeths :select
17
+ should have_imeths :from
17
18
  should have_imeths :includes, :joins
18
19
  should have_imeths :where
19
20
  should have_imeths :order, :reverse_order
@@ -31,6 +32,12 @@ class Ardb::RelationSpy
31
32
  assert_equal nil, subject.offset_value
32
33
  end
33
34
 
35
+ should "dup its applied and results arrays when copied" do
36
+ new_relation_spy = subject.dup
37
+ assert_not_same subject.applied, new_relation_spy.applied
38
+ assert_not_same subject.results, new_relation_spy.results
39
+ end
40
+
34
41
  should "be comparable using there applied collections" do
35
42
  other_relation = Ardb::RelationSpy.new
36
43
  other_relation.select :column_a
@@ -57,6 +64,21 @@ class Ardb::RelationSpy
57
64
 
58
65
  end
59
66
 
67
+ class FromTests < UnitTests
68
+ desc "from"
69
+ setup do
70
+ @relation_spy.from "some SQL"
71
+ @applied = subject.applied.first
72
+ end
73
+
74
+ should "have added a from applied expression with the passed args" do
75
+ assert_instance_of AppliedExpression, @applied
76
+ assert_equal :from, @applied.type
77
+ assert_equal [ "some SQL" ], @applied.args
78
+ end
79
+
80
+ end
81
+
60
82
  class IncludesTests < UnitTests
61
83
  desc "includes"
62
84
  setup do
@@ -270,9 +292,14 @@ class Ardb::RelationSpy
270
292
  class ExceptTests < WithExpressionsTests
271
293
  desc "except"
272
294
 
295
+ should "return a new relation spy" do
296
+ new_relation_spy = subject.except(:select)
297
+ assert_not_same subject, new_relation_spy
298
+ end
299
+
273
300
  should "remove any applied expressions in the passed types" do
274
- subject.except(:includes, :where, :group, :offset)
275
- applied_types = subject.applied.map(&:type)
301
+ relation_spy = subject.except(:includes, :where, :group, :offset)
302
+ applied_types = relation_spy.applied.map(&:type)
276
303
  [ :select, :joins, :order, :having, :limit ].each do |type|
277
304
  assert_includes type, applied_types
278
305
  end
@@ -282,17 +309,17 @@ class Ardb::RelationSpy
282
309
  end
283
310
 
284
311
  should "unset the limit value if limit is included in the passed types" do
285
- subject.except(:select)
286
- assert_not_nil subject.limit_value
287
- subject.except(:limit)
288
- assert_nil subject.limit_value
312
+ relation_spy = subject.except(:select)
313
+ assert_not_nil relation_spy.limit_value
314
+ relation_spy = subject.except(:limit)
315
+ assert_nil relation_spy.limit_value
289
316
  end
290
317
 
291
318
  should "unset the offset value if offset is included in the passed types" do
292
- subject.except(:select)
293
- assert_not_nil subject.offset_value
294
- subject.except(:offset)
295
- assert_nil subject.offset_value
319
+ relation_spy = subject.except(:select)
320
+ assert_not_nil relation_spy.offset_value
321
+ relation_spy = subject.except(:offset)
322
+ assert_nil relation_spy.offset_value
296
323
  end
297
324
 
298
325
  end
@@ -300,9 +327,14 @@ class Ardb::RelationSpy
300
327
  class OnlyTests < WithExpressionsTests
301
328
  desc "only"
302
329
 
330
+ should "return a new relation spy" do
331
+ new_relation_spy = subject.only(:select)
332
+ assert_not_same subject, new_relation_spy
333
+ end
334
+
303
335
  should "remove any applied expressions not in the passed types" do
304
- subject.only(:includes, :where, :group, :offset)
305
- applied_types = subject.applied.map(&:type)
336
+ relation_spy = subject.only(:includes, :where, :group, :offset)
337
+ applied_types = relation_spy.applied.map(&:type)
306
338
  [ :includes, :where, :group, :offset ].each do |type|
307
339
  assert_includes type, applied_types
308
340
  end
@@ -312,17 +344,17 @@ class Ardb::RelationSpy
312
344
  end
313
345
 
314
346
  should "unset the limit value if limit is not included in the passed types" do
315
- subject.only(:limit)
316
- assert_not_nil subject.limit_value
317
- subject.only(:select)
318
- assert_nil subject.limit_value
347
+ relation_spy = subject.only(:limit)
348
+ assert_not_nil relation_spy.limit_value
349
+ relation_spy = subject.only(:select)
350
+ assert_nil relation_spy.limit_value
319
351
  end
320
352
 
321
353
  should "unset the offset value if offset is not included in the passed types" do
322
- subject.only(:offset)
323
- assert_not_nil subject.offset_value
324
- subject.only(:select)
325
- assert_nil subject.offset_value
354
+ relation_spy = subject.only(:offset)
355
+ assert_not_nil relation_spy.offset_value
356
+ relation_spy = subject.only(:select)
357
+ assert_nil relation_spy.offset_value
326
358
  end
327
359
 
328
360
  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: 87
4
+ hash: 83
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 18
8
+ - 19
9
9
  - 0
10
- version: 0.18.0
10
+ version: 0.19.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-02-18 00:00:00 Z
19
+ date: 2014-03-17 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement