ardb 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,17 +3,20 @@ module Ardb
3
3
  class RelationSpy
4
4
 
5
5
  attr_reader :applied
6
+ attr_accessor :order_values, :reverse_order_value
7
+ attr_accessor :limit_value, :offset_value
6
8
  attr_accessor :results
7
9
 
8
10
  def initialize
9
11
  @applied, @results = [], []
10
- @offset, @limit = 0, nil
12
+ @order_values = []
13
+ @reverse_order_value = nil
14
+ @offset_value, @limit_value = nil, nil
11
15
  end
12
16
 
13
17
  [ :select,
14
18
  :joins,
15
19
  :where,
16
- :order,
17
20
  :group, :having,
18
21
  :merge
19
22
  ].each do |type|
@@ -25,34 +28,32 @@ module Ardb
25
28
 
26
29
  end
27
30
 
31
+ def order(*args)
32
+ @order_values += args
33
+ @applied << AppliedExpression.new(:order, args)
34
+ self
35
+ end
36
+
28
37
  def limit(value)
29
- @limit = value ? value.to_i : nil
38
+ @limit_value = value ? value.to_i : nil
30
39
  @applied << AppliedExpression.new(:limit, [ value ])
31
40
  self
32
41
  end
33
42
 
34
43
  def offset(value)
35
- @offset = value ? value.to_i : 0
44
+ @offset_value = value ? value.to_i : 0
36
45
  @applied << AppliedExpression.new(:offset, [ value ])
37
46
  self
38
47
  end
39
48
 
40
49
  def all
41
- @results[@offset, (@limit || @results.size)] || []
50
+ @results[(@offset_value || 0), (@limit_value || @results.size)] || []
42
51
  end
43
52
 
44
53
  def count
45
54
  all.size
46
55
  end
47
56
 
48
- def limit_value
49
- @limit
50
- end
51
-
52
- def offset_value
53
- @offset
54
- end
55
-
56
57
  def ==(other)
57
58
  @applied == other.applied
58
59
  end
@@ -1,3 +1,3 @@
1
1
  module Ardb
2
- VERSION = "0.15.0"
2
+ VERSION = "0.16.0"
3
3
  end
@@ -12,16 +12,19 @@ class Ardb::RelationSpy
12
12
 
13
13
  should have_readers :applied
14
14
  should have_accessors :results
15
+ should have_accessors :order_values, :reverse_order_value
16
+ should have_accessors :limit_value, :offset_value
15
17
  should have_imeths :select, :joins, :where, :order, :group, :having, :merge
16
18
  should have_imeths :limit, :offset
17
19
  should have_imeths :all, :count
18
- should have_imeths :limit_value, :offset_value
19
20
 
20
21
  should "default it's attributes" do
21
22
  assert_equal [], subject.applied
22
23
  assert_equal [], subject.results
24
+ assert_equal [], subject.order_values
25
+ assert_equal nil, subject.reverse_order_value
23
26
  assert_equal nil, subject.limit_value
24
- assert_equal 0, subject.offset_value
27
+ assert_equal nil, subject.offset_value
25
28
  end
26
29
 
27
30
  should "add an applied expression using `select`" do
@@ -60,6 +63,12 @@ class Ardb::RelationSpy
60
63
  assert_equal [ :column_a, :column_b ], applied_expression.args
61
64
  end
62
65
 
66
+ should "add args to it's `order_values` using `order" do
67
+ subject.order :column_a, :column_b
68
+ assert_includes :column_a, subject.order_values
69
+ assert_includes :column_b, subject.order_values
70
+ end
71
+
63
72
  should "add an applied expression using `group`" do
64
73
  subject.group :column_a, :column_b
65
74
  assert_equal 1, subject.applied.size
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: 35
4
+ hash: 95
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 15
8
+ - 16
9
9
  - 0
10
- version: 0.15.0
10
+ version: 0.16.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: 2013-11-18 00:00:00 Z
19
+ date: 2014-01-06 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  version_requirements: &id001 !ruby/object:Gem::Requirement