query-interface-client 0.0.3 → 0.1.0
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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +8 -0
- data/lib/query-interface-client/lazy_query.rb +83 -42
- data/lib/query-interface-client/version.rb +1 -1
- data/lib/query-interface-client.rb +2 -0
- data/query-interface-client.gemspec +1 -0
- data/spec/lib/lazy_query_spec.rb +194 -62
- data/spec/spec_helper.rb +5 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c18cd4dae2c81dd2e352d5509607cc1905c0e01e
|
4
|
+
data.tar.gz: 1b68f3bb6b2d722861b111d4237590840f0ec041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ab5f0827c2b0f95f2adf47ac32b5300cd37ba75930551fdc6fa0d73dcbf7f2c83d81a21aaf4a818e73f89eb74fd34c22ca728910d81d6b13637f3b03c6149e4
|
7
|
+
data.tar.gz: c5f347f8779355906031dbf25aa546d992c53750f3090c061a15ce204118cab9a19d835f7a8a65f3ec3a1deba3215ef02f0a8e492bc00a2e0fc12264cb749415
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -11,6 +11,7 @@ GEM
|
|
11
11
|
thread_safe (~> 0.1)
|
12
12
|
tzinfo (~> 0.3.37)
|
13
13
|
atomic (1.1.10)
|
14
|
+
autotest-standalone (4.5.11)
|
14
15
|
builder (3.1.4)
|
15
16
|
diff-lcs (1.2.4)
|
16
17
|
faraday (0.8.7)
|
@@ -33,6 +34,10 @@ GEM
|
|
33
34
|
rspec-expectations (2.14.0)
|
34
35
|
diff-lcs (>= 1.1.3, < 2.0)
|
35
36
|
rspec-mocks (2.14.1)
|
37
|
+
simplecov (0.7.1)
|
38
|
+
multi_json (~> 1.0)
|
39
|
+
simplecov-html (~> 0.7.1)
|
40
|
+
simplecov-html (0.7.1)
|
36
41
|
thread_safe (0.1.0)
|
37
42
|
atomic
|
38
43
|
tzinfo (0.3.37)
|
@@ -42,7 +47,10 @@ PLATFORMS
|
|
42
47
|
ruby
|
43
48
|
|
44
49
|
DEPENDENCIES
|
50
|
+
activesupport
|
51
|
+
autotest-standalone
|
45
52
|
her
|
46
53
|
rake
|
47
54
|
rspec
|
55
|
+
simplecov
|
48
56
|
will_paginate
|
@@ -2,88 +2,130 @@ module QueryInterface
|
|
2
2
|
module Client
|
3
3
|
class LazyQuery
|
4
4
|
|
5
|
-
attr_accessor :model, :
|
5
|
+
attr_accessor :model, :result, :result_model, :transformations
|
6
6
|
|
7
|
-
def initialize(model,
|
7
|
+
def initialize(model, transformations=nil, result_model=nil)
|
8
8
|
self.model = model
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
if transformations
|
10
|
+
self.transformations = transformations.map {|item| item.dup}
|
11
|
+
else
|
12
|
+
self.transformations = []
|
13
|
+
end
|
14
14
|
self.result = nil
|
15
|
+
self.result_model = result_model
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
-
self.
|
19
|
-
dataset.api_params[:conditions].merge!(conditions)
|
20
|
-
end
|
18
|
+
def parse(data)
|
19
|
+
(self.result_model ? self.result_model.parse(data) : self.model.parse(data))
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
self.
|
25
|
-
dataset.api_params[:with] += fields
|
26
|
-
end
|
22
|
+
def instantiate(data)
|
23
|
+
(self.result_model ? self.result_model.new(data) : self.model.new(data))
|
27
24
|
end
|
28
25
|
|
29
|
-
def
|
30
|
-
self.
|
31
|
-
dataset.api_params[:order] = fields
|
32
|
-
end
|
26
|
+
def instantiate_collection(parsed_data)
|
27
|
+
(self.result_model ? self.result_model.new_collection(parsed_data) : self.model.new_collection(parsed_data))
|
33
28
|
end
|
34
29
|
|
35
30
|
def copy(options = {})
|
36
|
-
self.class.new(self.model, self.
|
31
|
+
self.class.new(self.model, self.transformations, self.result_model)
|
37
32
|
end
|
38
33
|
|
39
|
-
def
|
40
|
-
self.
|
34
|
+
def add_transformation(type, parameter=nil)
|
35
|
+
self.transformations << {transformation: type, parameter: parameter}
|
41
36
|
end
|
42
37
|
|
43
|
-
def
|
44
|
-
self.
|
38
|
+
def filter(conditions={})
|
39
|
+
self.copy.tap do |query|
|
40
|
+
conditions.each do |key, value|
|
41
|
+
query.add_transformation(:filter, {field: key, value: value})
|
42
|
+
end
|
43
|
+
end
|
45
44
|
end
|
46
45
|
|
47
|
-
def
|
48
|
-
self.
|
46
|
+
def instance(id)
|
47
|
+
self.copy.tap do |query|
|
48
|
+
query.add_transformation(:instance, id)
|
49
|
+
end
|
49
50
|
end
|
50
51
|
|
51
|
-
def
|
52
|
-
|
52
|
+
def context(association, model=nil)
|
53
|
+
self.copy.tap do |query|
|
54
|
+
query.result_model = (model ? model : association.to_s.singularize.camelize.constantize)
|
55
|
+
query.add_transformation(:context, association)
|
56
|
+
end
|
53
57
|
end
|
54
58
|
|
55
|
-
def
|
56
|
-
|
59
|
+
def with(*fields)
|
60
|
+
self.copy.tap do |query|
|
61
|
+
fields.each do |field|
|
62
|
+
query.add_transformation(:with, field)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def order(*fields)
|
68
|
+
self.copy.tap do |query|
|
69
|
+
fields.each do |field|
|
70
|
+
query.add_transformation(:order, field)
|
71
|
+
end
|
72
|
+
end
|
57
73
|
end
|
58
74
|
|
59
75
|
def evaluate
|
60
|
-
self.result ||= self.
|
76
|
+
self.result ||= self.do_query()
|
61
77
|
end
|
62
78
|
|
63
|
-
def paginate(params
|
64
|
-
params = {page: 1, per_page: 10,
|
65
|
-
|
66
|
-
|
67
|
-
|
79
|
+
def paginate(params={})
|
80
|
+
params = {page: 1, per_page: 10,}.merge(params)
|
81
|
+
self.add_transformation(:paginate, params)
|
82
|
+
raw = self.do_raw_query()
|
83
|
+
result = raw[:parsed_data][:data]
|
84
|
+
objects = result[:objects].map { |h| self.instantiate(h) }
|
68
85
|
WillPaginate::Collection.create(params[:page], params[:per_page], result[:total]) do |pager|
|
69
86
|
pager.replace objects
|
70
87
|
end
|
71
88
|
end
|
72
89
|
|
73
90
|
def ids
|
74
|
-
|
75
|
-
|
91
|
+
self.add_transformation(:map_ids)
|
92
|
+
self.do_raw_query()[:parsed_data][:data]
|
76
93
|
end
|
77
94
|
|
78
95
|
def count
|
79
96
|
if self.result
|
80
97
|
self.result.count
|
81
98
|
else
|
82
|
-
|
99
|
+
self.add_transformation(:count)
|
100
|
+
r = self.do_raw_query()
|
83
101
|
r[:parsed_data][:data][:count]
|
84
102
|
end
|
85
103
|
end
|
86
104
|
|
105
|
+
def do_query
|
106
|
+
parsed_data = self.do_raw_query[:parsed_data]
|
107
|
+
if parsed_data[:data].is_a?(Array)
|
108
|
+
self.instantiate_collection(parsed_data)
|
109
|
+
else
|
110
|
+
self.instantiate(
|
111
|
+
self.parse(parsed_data[:data]).
|
112
|
+
merge(_metadata: parsed_data[:metadata], _errors: parsed_data[:errors])
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def do_raw_query
|
118
|
+
self.model.get_raw(:query, transformations: self.transformations)
|
119
|
+
end
|
120
|
+
|
121
|
+
def first(*args)
|
122
|
+
one(:first, *args)
|
123
|
+
end
|
124
|
+
|
125
|
+
def last(*args)
|
126
|
+
one(:last, *args)
|
127
|
+
end
|
128
|
+
|
87
129
|
def to_json(*args)
|
88
130
|
evaluate.to_json(*args)
|
89
131
|
end
|
@@ -98,10 +140,9 @@ module QueryInterface
|
|
98
140
|
if self.result
|
99
141
|
self.result.send(which)
|
100
142
|
else
|
101
|
-
self.
|
143
|
+
self.add_transformation(which)
|
144
|
+
self.do_query
|
102
145
|
end
|
103
|
-
rescue Faraday::Error::ResourceNotFound
|
104
|
-
nil
|
105
146
|
end
|
106
147
|
|
107
148
|
end
|
data/spec/lib/lazy_query_spec.rb
CHANGED
@@ -2,58 +2,77 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
|
4
4
|
def deep_copy_check(left, right)
|
5
|
-
left.
|
6
|
-
|
7
|
-
left[key].should_not be(right[key])
|
5
|
+
left.each_with_index do |item, idx|
|
6
|
+
right[idx].should_not be(item)
|
8
7
|
end
|
9
8
|
end
|
10
9
|
|
10
|
+
class Context
|
11
|
+
end
|
12
|
+
|
11
13
|
describe QueryInterface::Client::LazyQuery do
|
12
14
|
subject {QueryInterface::Client::LazyQuery}
|
13
15
|
let(:model) {double("Dummy Model")}
|
14
|
-
let(:
|
16
|
+
let(:transformations) {[{transformation: :filter, parameter: {field: "hase", value: "wuschel"}}]}
|
15
17
|
|
16
18
|
context "construction" do
|
17
|
-
let(:api_params) do
|
18
|
-
{conditions: {field: 'value'}, with: [:inclusion], order: ["-something"]}
|
19
|
-
end
|
20
19
|
|
21
20
|
it "initializes itself with empty parameters and a supplied model" do
|
22
21
|
query = subject.new(model)
|
23
|
-
query.
|
22
|
+
query.transformations.should == []
|
24
23
|
query.model.should eq(model)
|
25
24
|
end
|
26
25
|
|
27
|
-
it "honors passed
|
28
|
-
query = subject.new(model,
|
29
|
-
query.
|
26
|
+
it "honors passed transformations params" do
|
27
|
+
query = subject.new(model, transformations)
|
28
|
+
query.transformations.should eq(transformations)
|
30
29
|
end
|
31
30
|
|
32
|
-
it "does not alter the originally passed
|
33
|
-
query = subject.new(model,
|
34
|
-
deep_copy_check(
|
31
|
+
it "does not alter the originally passed transformations" do
|
32
|
+
query = subject.new(model, transformations)
|
33
|
+
deep_copy_check(transformations, query.transformations)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
37
|
context "copy" do
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
it "provides a copy method cloning api_params onto a new instance" do
|
43
|
-
query = subject.new(model, api_params)
|
38
|
+
it "provides a copy method cloning transformations onto a new instance" do
|
39
|
+
query = subject.new(model, transformations)
|
44
40
|
query_copy = query.copy
|
45
|
-
query_copy.
|
46
|
-
deep_copy_check(query_copy.
|
41
|
+
query_copy.transformations.should eq(query.transformations)
|
42
|
+
deep_copy_check(query_copy.transformations, query.transformations)
|
47
43
|
end
|
48
44
|
end
|
49
45
|
|
50
46
|
context "filtering" do
|
51
|
-
it "should create a new instance with updated
|
47
|
+
it "should create a new instance with updated transformations" do
|
52
48
|
query = subject.new(model)
|
53
49
|
query_copy = subject.new(model)
|
54
50
|
query.should_receive(:copy).and_return(query_copy)
|
55
51
|
query.filter(a: :b)
|
56
|
-
query_copy.
|
52
|
+
query_copy.transformations.should eq([{transformation: :filter, parameter: {field: :a, value: :b}}])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "instancing" do
|
57
|
+
it "sets the instance parameter" do
|
58
|
+
query = subject.new(model)
|
59
|
+
query.should_receive(:copy).and_return(query)
|
60
|
+
query.instance(5)
|
61
|
+
query.transformations.should eq([{transformation: :instance, parameter: 5}])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "context" do
|
66
|
+
let(:query) {subject.new(model)}
|
67
|
+
before do
|
68
|
+
query.should_receive(:copy).and_return(query)
|
69
|
+
query.context(:context)
|
70
|
+
end
|
71
|
+
it "should set the correct result model class" do
|
72
|
+
query.result_model.should == Context
|
73
|
+
end
|
74
|
+
it "sets the context parameter" do
|
75
|
+
query.transformations.should eq([{transformation: :context, parameter: :context}])
|
57
76
|
end
|
58
77
|
end
|
59
78
|
|
@@ -63,7 +82,7 @@ describe QueryInterface::Client::LazyQuery do
|
|
63
82
|
query_copy = subject.new(model)
|
64
83
|
query.should_receive(:copy).and_return(query_copy)
|
65
84
|
query.with(:c)
|
66
|
-
query_copy.
|
85
|
+
query_copy.transformations.should eq([{transformation: :with, parameter: :c}])
|
67
86
|
end
|
68
87
|
end
|
69
88
|
|
@@ -73,87 +92,140 @@ describe QueryInterface::Client::LazyQuery do
|
|
73
92
|
query_copy = subject.new(model)
|
74
93
|
query.should_receive(:copy).and_return(query_copy)
|
75
94
|
query.order("-something")
|
76
|
-
query_copy.
|
95
|
+
query_copy.transformations.should eq([{transformation: :order, parameter: "-something"}])
|
77
96
|
end
|
78
97
|
end
|
79
98
|
|
80
99
|
context "chaining" do
|
81
|
-
it "allows chaining
|
82
|
-
query = subject.new(model)
|
83
|
-
query_copy = query.filter(a: :b).filter(c: :d).with(:e).with(:f, :g)
|
84
|
-
query_copy.api_params[:conditions].should eq({a: :b, c: :d})
|
85
|
-
query_copy.api_params[:with].should eq([:e, :f, :g])
|
86
|
-
end
|
87
|
-
|
88
|
-
it "calling order multiple times overwrites" do
|
100
|
+
it "allows chaining transformations in order of appearance" do
|
89
101
|
query = subject.new(model)
|
90
|
-
query_copy = query.
|
91
|
-
query_copy.
|
102
|
+
query_copy = query.filter(a: :b, c: :d).filter(e: :f).with(:x, :y).instance(12).context(:context)
|
103
|
+
query_copy.transformations.should eq(
|
104
|
+
[
|
105
|
+
{transformation: :filter, parameter: {field: :a, value: :b}},
|
106
|
+
{transformation: :filter, parameter: {field: :c, value: :d}},
|
107
|
+
{transformation: :filter, parameter: {field: :e, value: :f}},
|
108
|
+
{transformation: :with, parameter: :x},
|
109
|
+
{transformation: :with, parameter: :y},
|
110
|
+
{transformation: :instance, parameter: 12},
|
111
|
+
{transformation: :context, parameter: :context}
|
112
|
+
]
|
113
|
+
)
|
92
114
|
end
|
93
115
|
end
|
94
116
|
|
95
117
|
context "first" do
|
118
|
+
let(:transformations) {[transformation: :first, parameter: nil]}
|
96
119
|
it "gets the first object via do_query" do
|
97
120
|
query = subject.new(model)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
query.first.should eq("result object")
|
121
|
+
query.should_receive(:do_query)
|
122
|
+
query.first
|
123
|
+
query.transformations.should eq(self.transformations)
|
102
124
|
end
|
103
125
|
|
104
126
|
it "uses the cached result" do
|
105
127
|
query = subject.new(model)
|
106
128
|
query.result = ["a", "b", "c"]
|
107
|
-
query.should_not_receive(:
|
129
|
+
query.should_not_receive(:do_raw_query)
|
108
130
|
query.first.should eq("a")
|
109
131
|
end
|
110
132
|
end
|
111
133
|
|
134
|
+
context "last" do
|
135
|
+
let(:transformations) {[transformation: :last, parameter: nil]}
|
136
|
+
it "gets the last object via do_query" do
|
137
|
+
query = subject.new(model)
|
138
|
+
query.should_receive(:do_query)
|
139
|
+
query.last
|
140
|
+
query.transformations.should eq(self.transformations)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "uses the cached result" do
|
144
|
+
query = subject.new(model)
|
145
|
+
query.result = ["a", "b", "c"]
|
146
|
+
query.should_not_receive(:do_raw_query)
|
147
|
+
query.last.should eq("c")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
112
151
|
context "evaluate" do
|
113
|
-
|
152
|
+
let(:transformations) {[]}
|
153
|
+
context "without instance set" do
|
154
|
+
before do
|
155
|
+
model.should_receive(:get_raw)
|
156
|
+
.with(:query, transformations: self.transformations)
|
157
|
+
.and_return({parsed_data: {data: ["result object"]}})
|
158
|
+
model.stub(:new_collection).and_return(["result object"])
|
159
|
+
end
|
160
|
+
|
161
|
+
it "add an evaluation transformation" do
|
162
|
+
query = subject.new(model)
|
163
|
+
query.evaluate
|
164
|
+
query.transformations.should eq(transformations)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "gets results via do_query and caches the result" do
|
168
|
+
query = subject.new(model)
|
169
|
+
query.evaluate.should eq(["result object"])
|
170
|
+
query.result.should eq(["result object"])
|
171
|
+
end
|
172
|
+
|
173
|
+
it "doesn't query the api twice" do
|
174
|
+
query = subject.new(model)
|
175
|
+
result = query.evaluate
|
176
|
+
result_second = query.evaluate
|
177
|
+
result.should be(result_second)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "ids" do
|
183
|
+
let(:transformations) { [{transformation: :map_ids, parameter: nil}] }
|
184
|
+
|
185
|
+
it "adds a map_ids transformation" do
|
114
186
|
query = subject.new(model)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
query.evaluate.should eq(["result object"])
|
119
|
-
query.result.should eq(["result object"])
|
187
|
+
query.stub!(:do_raw_query).and_return({parsed_data: {data: [1,2,3]}})
|
188
|
+
query.ids
|
189
|
+
query.transformations.should eq(self.transformations)
|
120
190
|
end
|
121
191
|
|
122
|
-
it "
|
192
|
+
it "returns the data of the parsed query" do
|
123
193
|
query = subject.new(model)
|
124
|
-
|
125
|
-
|
126
|
-
.and_return(["result object"])
|
127
|
-
result = query.evaluate
|
128
|
-
result_second = query.evaluate
|
129
|
-
result.should be(result_second)
|
194
|
+
query.should_receive(:do_raw_query).and_return({parsed_data: {data: [1,2,3]}})
|
195
|
+
query.ids.should eq([1, 2, 3])
|
130
196
|
end
|
131
197
|
end
|
132
198
|
|
133
199
|
context "count" do
|
134
|
-
|
200
|
+
let(:transformations) {[{transformation: :count, parameter: nil}]}
|
201
|
+
|
202
|
+
it "adds a count transformation" do
|
135
203
|
query = subject.new(model)
|
136
|
-
|
137
|
-
.and_return({parsed_data: {data: {count: 42}}})
|
204
|
+
query.should_receive(:do_raw_query).and_return({parsed_data: {data: {count: 42}}})
|
138
205
|
query.count.should eq(42)
|
206
|
+
query.transformations.should eq(self.transformations)
|
139
207
|
end
|
140
208
|
|
141
209
|
it "uses cached result for counting" do
|
142
210
|
query = subject.new(model)
|
143
211
|
query.result = ["a", "b", "c"]
|
144
|
-
query.should_not_receive(:
|
212
|
+
query.should_not_receive(:do_raw_query)
|
145
213
|
query.count.should eq(3)
|
146
214
|
end
|
147
215
|
end
|
148
216
|
|
149
217
|
context "paginate" do
|
150
|
-
|
218
|
+
let(:transformations) {[{transformation: :paginate, parameter: {page: 1, per_page: 10}}]}
|
219
|
+
|
220
|
+
|
221
|
+
it "adds a paginate transformation" do
|
151
222
|
query = subject.new(model)
|
152
223
|
objects = (1..10).to_a
|
153
|
-
model.
|
154
|
-
|
155
|
-
result = query.paginate
|
156
|
-
|
224
|
+
model.stub(:new).and_return(*objects)
|
225
|
+
query.should_receive(:do_raw_query).and_return({parsed_data: {data: {objects: objects, total: 15}, errors: []}})
|
226
|
+
result = query.paginate
|
227
|
+
query.transformations.should eq(self.transformations)
|
228
|
+
result.should eq(objects)
|
157
229
|
result.is_a?(WillPaginate::Collection)
|
158
230
|
result.total_entries.should eq(15)
|
159
231
|
end
|
@@ -169,4 +241,64 @@ describe QueryInterface::Client::LazyQuery do
|
|
169
241
|
end
|
170
242
|
end
|
171
243
|
|
244
|
+
context "do queries" do
|
245
|
+
it "queries the api raw" do
|
246
|
+
query = subject.new(model)
|
247
|
+
model.should_receive(:get_raw).with(:query, transformations: [])
|
248
|
+
query.do_raw_query
|
249
|
+
end
|
250
|
+
|
251
|
+
it "executes the actual query and creates a collection where appropriate" do
|
252
|
+
query = subject.new(model)
|
253
|
+
data = {parsed_data: {data: [1,2,3]}}
|
254
|
+
query.should_receive(:do_raw_query).and_return(data)
|
255
|
+
query.should_receive(:instantiate_collection).with(data[:parsed_data])
|
256
|
+
query.do_query
|
257
|
+
end
|
258
|
+
|
259
|
+
it "executes the actual query and creates an object where appropriate" do
|
260
|
+
query = subject.new(model)
|
261
|
+
data = {parsed_data: {data: {id: 1, bunny: 'wuschel'}}}
|
262
|
+
query.should_receive(:do_raw_query).and_return(data)
|
263
|
+
query.should_receive(:parse).and_return(data[:parsed_data])
|
264
|
+
query.should_receive(:instantiate).with(data[:parsed_data].merge(_metadata: nil, _errors: nil))
|
265
|
+
query.do_query
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
context "parsing" do
|
271
|
+
let(:result_model) { double("result model") }
|
272
|
+
let(:data) { double("data") }
|
273
|
+
|
274
|
+
it "parses the data via result model if set" do
|
275
|
+
query = subject.new(model)
|
276
|
+
query.result_model = result_model
|
277
|
+
result_model.should_receive(:parse).with(data)
|
278
|
+
query.parse(data)
|
279
|
+
end
|
280
|
+
|
281
|
+
it "parses the data via model if no result model set" do
|
282
|
+
query = subject.new(model)
|
283
|
+
model.should_receive(:parse).with(data)
|
284
|
+
query.parse(data)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
context "to_json" do
|
289
|
+
let(:transformations) {[]}
|
290
|
+
let(:result) { double("result") }
|
291
|
+
before do
|
292
|
+
model.should_receive(:get_raw)
|
293
|
+
.with(:query, transformations: self.transformations)
|
294
|
+
.and_return({parsed_data: {data: ["result object"]}})
|
295
|
+
model.stub(:new_collection).and_return(result)
|
296
|
+
end
|
297
|
+
it "calls to_json on the evaluated result" do
|
298
|
+
query = subject.new(model)
|
299
|
+
result.should_receive(:to_json)
|
300
|
+
query.to_json
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
172
304
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query-interface-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Kopecky <andreas.kopecky@radarservices.com>
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: her
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: activesupport
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: rake
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|