loquor 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Nzc1YzA3OTlhOGVlZWQ1YTMzYzkwNjVjN2QzZjcyOGJjYzExNDFmYw==
5
- data.tar.gz: !binary |-
6
- NWYwNTc3MTRlOTBjZTU5MWMzNzE2YjI0OGMzZTUzZTFlZDViNjc1Yw==
2
+ SHA1:
3
+ metadata.gz: 0207ff4371ea8daf3f959df6bac057d676666e7b
4
+ data.tar.gz: a10652e0df52283f7a0472fddd7002243af6a2a6
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZmQxODJlYTdmZTNkOTU5ZTE0ZDY1YmVhNjA0MDVhMTMyOTFmZTRjOWE1M2I5
10
- ZDQxY2JmNDZlOThkYWExYWZjNzk2ZTBiODZkNGI2YzgxNjNjYjU2OTU5NWU1
11
- NmE0MzI5YmNlMzYwYzgxZjY2NjhiMjFkY2FmMTUxZWVhN2JiMGQ=
12
- data.tar.gz: !binary |-
13
- OGFlZmEwMjY2YmVkZmIxMjIzY2RhYWMwZjYxYzkwNGE0NjNhNTJhOTA0YjFi
14
- Yzg3Yzk1ODU2ZDAzNGUyYmVjZGE1MjU2NTE4ZGVmZjBhZGM1OTFkZjBhN2Yz
15
- NDAzZWRiN2JjMTllNTcyODY5M2Y5ZTVkNDY3N2FhZDAzMTNjM2Y=
6
+ metadata.gz: 3a6e012d933a0a94b5b389958699b895a87e646e4ae73cf9e677b6cbac6111363ab759e0076e016d017195224dd83b6cecd7317cc1a097123604fdcafbb38c64
7
+ data.tar.gz: 4a7cd33b185e61bf519ace8175969171273267d92eefd07aa4e68ce3e17e606bbb4a05b1382c2543b3b2809d32d39ac9e0a5da3cb9f32cf0571e38002e9f98cf
@@ -1,3 +1,6 @@
1
+ # 1.7.0 / 2014-03-13
2
+ * [FEATURE] Add support for per, page and limit
3
+
1
4
  # 1.6.0 / 2014-03-07
2
5
  * [FEATURE] Add support for date, time and datetime in filters.
3
6
  * [FEATURE] Add support deleting entities.
@@ -27,6 +27,22 @@ module Loquor
27
27
  self
28
28
  end
29
29
 
30
+ def order(value)
31
+ @order = value
32
+ self
33
+ end
34
+
35
+ def per(value)
36
+ @per = value
37
+ self
38
+ end
39
+ alias_method :limit, :per
40
+
41
+ def page(value)
42
+ @page = value
43
+ self
44
+ end
45
+
30
46
  # Proxy everything to the results so that this this class
31
47
  # transparently acts as an Array.
32
48
  def method_missing(name, *args, &block)
@@ -64,6 +80,10 @@ module Loquor
64
80
  add_clause(query_string, clause)
65
81
  end
66
82
 
83
+ query_string << "per=#{@per}" if @per
84
+ query_string << "page=#{@page}" if @page
85
+ query_string << "order=#{@order}" if @order
86
+
67
87
  "#{klass.path}?#{query_string.join("&")}"
68
88
  end
69
89
 
@@ -36,16 +36,10 @@ module Loquor
36
36
  ApiCall::Show.new(self, id).execute
37
37
  end
38
38
 
39
- def self.find_each(&block)
40
- ApiCall::Index.new(self).find_each(&block)
41
- end
42
-
43
- def self.select(*args)
44
- ApiCall::Index.new(self).select(*args)
45
- end
46
-
47
- def self.where(*args)
48
- ApiCall::Index.new(self).where(*args)
39
+ %w{where per page order select find_each}.each do |meth|
40
+ self.class.send :define_method, meth do |*args, &block|
41
+ ApiCall::Index.new(self).send(meth, *args, &block)
42
+ end
49
43
  end
50
44
 
51
45
  def self.create(payload)
@@ -1,3 +1,3 @@
1
1
  module Loquor
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  end
@@ -14,6 +14,30 @@ module Loquor
14
14
  assert_equal({fields: fields}, searcher.criteria)
15
15
  end
16
16
 
17
+ def test_order_sets_order
18
+ order = :random
19
+ searcher = ApiCall::Index.new(resource).order(order)
20
+ assert_equal(order, searcher.instance_variable_get("@order"))
21
+ end
22
+
23
+ def test_limit_sets_per
24
+ per = 892
25
+ searcher = ApiCall::Index.new(resource).limit(per)
26
+ assert_equal(per, searcher.instance_variable_get("@per"))
27
+ end
28
+
29
+ def test_per_sets_per
30
+ per = 542
31
+ searcher = ApiCall::Index.new(resource).per(per)
32
+ assert_equal(per, searcher.instance_variable_get("@per"))
33
+ end
34
+
35
+ def test_page_set_page
36
+ page = 542
37
+ searcher = ApiCall::Index.new(resource).page(page)
38
+ assert_equal(page, searcher.instance_variable_get("@page"))
39
+ end
40
+
17
41
  def test_where_sets_clauses
18
42
  clause = "WHERE 1 = 1"
19
43
  searcher = ApiCall::Index.new(resource).where(clause)
@@ -188,5 +212,29 @@ module Loquor
188
212
  assert results[0].is_a?(Resource)
189
213
  assert results[1].is_a?(Resource)
190
214
  end
215
+
216
+ def test_generates_url_correctly_with_order
217
+ order = :random
218
+ searcher = ApiCall::Index.new(resource).order(order)
219
+ searcher.stubs(path: "foobar")
220
+ url = searcher.send(:generate_url)
221
+ assert url.include?("order=#{order}")
222
+ end
223
+
224
+ def test_generates_url_correctly_with_per
225
+ per = 123
226
+ searcher = ApiCall::Index.new(resource).per(per)
227
+ searcher.stubs(path: "foobar")
228
+ url = searcher.send(:generate_url)
229
+ assert url.include?("per=#{per}")
230
+ end
231
+
232
+ def test_generates_url_correctly_with_page
233
+ page = 45
234
+ searcher = ApiCall::Index.new(resource).page(page)
235
+ searcher.stubs(path: "foobar")
236
+ url = searcher.send(:generate_url)
237
+ assert url.include?("page=#{page}")
238
+ end
191
239
  end
192
240
  end
@@ -53,6 +53,14 @@ module Loquor
53
53
  Foobar.where(email: email).to_a
54
54
  end
55
55
 
56
+ %w{where per page order select find_each}.each do |meth|
57
+ define_method "test_#{meth}_should_proxy" do
58
+ args = [mock]
59
+ ApiCall::Index.any_instance.expects(meth).with(*args)
60
+ Foobar.send(meth, *args)
61
+ end
62
+ end
63
+
56
64
  def test_create_should_put_correct_params
57
65
  payload = {bar: 'foo'}
58
66
  Loquor.expects(:post).with("/foobar", payload: payload)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loquor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filum
@@ -84,28 +84,28 @@ dependencies:
84
84
  name: mocha
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: An API dispatcher for Meducation
@@ -168,17 +168,17 @@ require_paths:
168
168
  - lib
169
169
  required_ruby_version: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ! '>='
171
+ - - '>='
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  requirements:
176
- - - ! '>='
176
+ - - '>='
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
180
  rubyforge_project:
181
- rubygems_version: 2.1.9
181
+ rubygems_version: 2.2.1
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: This library dispatches requests to Meducation