query-interface-server 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fe1f66a6b0edf515d933d59737724c0ed93563f
|
4
|
+
data.tar.gz: 5736e9df8b09349166500456e6c9feda5483980c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4025850a28a293c04542ff1efb515b916a8cfbf0a2679299ba27bced35acd64594a86349439d7b5545a20899f1a1124ec59ea7926b60175f8bcfc7a4fa24ebc9
|
7
|
+
data.tar.gz: 4b2896f01b231e72c2289fa9ee0756937b1bf165f19b438deebca1470a2b253ae5ba4c69513b758151362a2ee4de34cd7a6bac71a27e506993d9e7a3eac82df4
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe QueryInterface::Server::Transformations do
|
4
|
+
class Foo
|
5
|
+
# TODO: Fiddle out a way to move this ONE dependency to Sequel somewhere else
|
6
|
+
def self.dataset_module(&block)
|
7
|
+
end
|
8
|
+
include QueryInterface::Server::Transformations
|
9
|
+
|
10
|
+
def self.model
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.table_name
|
15
|
+
'foo_table'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "on include" do
|
20
|
+
let(:lazy_query) { double("lazyquery") }
|
21
|
+
|
22
|
+
it "adds a query_transformations method to the class" do
|
23
|
+
Foo.should respond_to(:query_transformations)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "adds a query method to the class" do
|
27
|
+
Foo.should respond_to(:query)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should initialize a new LazyQuery object upon calling query" do
|
31
|
+
QueryInterface::Server::LazyQuery.should_receive(:new).with(Foo).and_return(lazy_query)
|
32
|
+
Foo.query.should eq(lazy_query)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "adds a @query_transformations hash as class instance variable" do
|
36
|
+
Foo.instance_variable_get(:@query_transformations).should eq({
|
37
|
+
filter: {}, with: {}, order: {}
|
38
|
+
})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "adding filter/with/order" do
|
43
|
+
it "adds auto filter methods as stored procs" do
|
44
|
+
Foo.query_transformations do
|
45
|
+
auto_filter :foo, :bar
|
46
|
+
end
|
47
|
+
transformations = Foo.instance_variable_get(:@query_transformations)
|
48
|
+
transformations[:filter].keys.should eq([:foo, :bar])
|
49
|
+
transformations[:filter][:foo].should be_a(Proc)
|
50
|
+
Foo.should_receive(:filter).with(foo_table__bar: 'bar_value')
|
51
|
+
Foo.instance_exec('bar_value', &transformations[:filter][:bar])
|
52
|
+
end
|
53
|
+
|
54
|
+
it "adds custom filters" do
|
55
|
+
Foo.query_transformations do
|
56
|
+
filter :foobar do |param|
|
57
|
+
filter(foobar: param)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
transformations = Foo.instance_variable_get(:@query_transformations)
|
61
|
+
transformations[:filter].keys.should eq([:foo, :bar, :foobar])
|
62
|
+
transformations[:filter][:foobar].should be_a(Proc)
|
63
|
+
Foo.should_receive(:filter).with(foobar: 'foo_bar_value')
|
64
|
+
Foo.instance_exec('foo_bar_value', &transformations[:filter][:foobar])
|
65
|
+
end
|
66
|
+
|
67
|
+
it "adds custom withs" do
|
68
|
+
Foo.query_transformations do
|
69
|
+
with :thingies do
|
70
|
+
join(:thingies_table)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
transformations = Foo.instance_variable_get(:@query_transformations)
|
74
|
+
transformations[:with].keys.should eq([:thingies])
|
75
|
+
transformations[:with][:thingies].should be_a(Proc)
|
76
|
+
Foo.should_receive(:join).with(:thingies_table)
|
77
|
+
Foo.instance_exec(&transformations[:with][:thingies])
|
78
|
+
end
|
79
|
+
|
80
|
+
it "adds custom order" do
|
81
|
+
Foo.query_transformations do
|
82
|
+
order :order_field do |direction|
|
83
|
+
order(:order_field_thingy, direction)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
transformations = Foo.instance_variable_get(:@query_transformations)
|
87
|
+
transformations[:order].keys.should eq([:order_field])
|
88
|
+
transformations[:order][:order_field].should be_a(Proc)
|
89
|
+
Foo.should_receive(:order).with(:order_field_thingy, :asc)
|
90
|
+
Foo.instance_exec(:asc, &transformations[:order][:order_field])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query-interface-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
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: 2014-02-
|
13
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sequel
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/query-interface-server/version.rb
|
105
105
|
- query-interface-server.gemspec
|
106
106
|
- spec/lib/resource_spec.rb
|
107
|
+
- spec/lib/transformations_spec.rb
|
107
108
|
- spec/spec_helper.rb
|
108
109
|
homepage: http://github.com/rs-dev/query-interface-server
|
109
110
|
licenses:
|