alf-rack 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +76 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +12 -0
- data/README.md +58 -0
- data/Rakefile +11 -0
- data/lib/alf-rack.rb +1 -0
- data/lib/alf/rack.rb +11 -0
- data/lib/alf/rack/config.rb +62 -0
- data/lib/alf/rack/connect.rb +45 -0
- data/lib/alf/rack/errors.rb +15 -0
- data/lib/alf/rack/helpers.rb +34 -0
- data/lib/alf/rack/loader.rb +3 -0
- data/lib/alf/rack/query.rb +148 -0
- data/lib/alf/rack/response.rb +74 -0
- data/lib/alf/rack/version.rb +16 -0
- data/spec/config/test_database.rb +28 -0
- data/spec/config/test_viewpoint.rb +18 -0
- data/spec/connect/test_principle.rb +54 -0
- data/spec/query/test_logical_behavior.rb +41 -0
- data/spec/query/test_metadata_behavior.rb +45 -0
- data/spec/query/test_root_behavior.rb +98 -0
- data/spec/response/class/test_renderer.rb +52 -0
- data/spec/response/class/test_renderer_bang.rb +26 -0
- data/spec/response/class/test_supported_media_types.rb +18 -0
- data/spec/response/test_initialize.rb +30 -0
- data/spec/response/test_principle.rb +66 -0
- data/spec/sap.db +0 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/test_rack.rb +10 -0
- data/tasks/examples.rake +7 -0
- data/tasks/gem.rake +8 -0
- data/tasks/test.rake +7 -0
- metadata +280 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Rack
|
4
|
+
describe Response, '.supported_media_types' do
|
5
|
+
|
6
|
+
subject{ Response.supported_media_types }
|
7
|
+
|
8
|
+
it{ should be_a(Array) }
|
9
|
+
|
10
|
+
it{ should_not be_empty }
|
11
|
+
|
12
|
+
it{ should include("text/plain") }
|
13
|
+
it{ should include("text/csv") }
|
14
|
+
it{ should include("application/json") }
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Rack
|
4
|
+
describe Response, 'initialize' do
|
5
|
+
|
6
|
+
subject{ Response.new({"HTTP_ACCEPT" => accept}) }
|
7
|
+
|
8
|
+
context 'when supported' do
|
9
|
+
let(:accept){ "application/json" }
|
10
|
+
|
11
|
+
it{ should be_a(Response) }
|
12
|
+
|
13
|
+
it 'sets the Content-Type header immediately' do
|
14
|
+
subject['Content-Type'].should eq(accept)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when not supported' do
|
19
|
+
let(:accept){ "text/unknown" }
|
20
|
+
|
21
|
+
it 'raises an AcceptError' do
|
22
|
+
lambda{
|
23
|
+
subject
|
24
|
+
}.should raise_error(AcceptError, /Unsupported(.*?)`text\/unknown`/)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Alf
|
3
|
+
module Rack
|
4
|
+
describe Response, 'the underlying principle' do
|
5
|
+
|
6
|
+
let(:env){
|
7
|
+
{"HTTP_ACCEPT" => "text/unknown, text/*;q=0.8, */*;q=0.5"}
|
8
|
+
}
|
9
|
+
|
10
|
+
subject{
|
11
|
+
Response.new(env){|r| r.body = body }.finish
|
12
|
+
}
|
13
|
+
|
14
|
+
shared_examples_for "the expected Response object" do
|
15
|
+
it{ should be_a(Array) }
|
16
|
+
|
17
|
+
it 'sets the Content-Type according to found renderer' do
|
18
|
+
subject[1]['Content-Type'].should eq("text/csv")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when the body is a Relation' do
|
23
|
+
let(:body){
|
24
|
+
Relation(id: [1, 2, 3])
|
25
|
+
}
|
26
|
+
|
27
|
+
it 'encodes the body with found renderer' do
|
28
|
+
seen = []
|
29
|
+
subject.last.each do |x|
|
30
|
+
seen << x
|
31
|
+
end
|
32
|
+
seen.should eq(["id\n","1\n","2\n","3\n"])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when the body is a Tuple' do
|
37
|
+
let(:body){
|
38
|
+
Tuple(name: "Alf", version: "0.15.0")
|
39
|
+
}
|
40
|
+
|
41
|
+
it 'encodes the body with found renderer' do
|
42
|
+
seen = []
|
43
|
+
subject.last.each do |x|
|
44
|
+
seen << x
|
45
|
+
end
|
46
|
+
seen.should eq(["name,version\n","Alf,0.15.0\n"])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when the body is a Hash' do
|
51
|
+
let(:body){
|
52
|
+
{name: "Alf", version: "0.15.0"}
|
53
|
+
}
|
54
|
+
|
55
|
+
it 'encodes the body with found renderer' do
|
56
|
+
seen = []
|
57
|
+
subject.last.each do |x|
|
58
|
+
seen << x
|
59
|
+
end
|
60
|
+
seen.should eq(["name,version\n","Alf,0.15.0\n"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/sap.db
ADDED
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'alf-rack'
|
3
|
+
require 'alf-sequel'
|
4
|
+
require "rspec"
|
5
|
+
require 'rack'
|
6
|
+
require 'rack/test'
|
7
|
+
require "sequel"
|
8
|
+
require 'sinatra'
|
9
|
+
require 'path'
|
10
|
+
|
11
|
+
module Helpers
|
12
|
+
|
13
|
+
def sap
|
14
|
+
Alf::Adapter.factor Path.dir/"sap.db"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |c|
|
20
|
+
c.include Helpers
|
21
|
+
c.extend Helpers
|
22
|
+
end
|
data/spec/test_rack.rb
ADDED
data/tasks/examples.rake
ADDED
data/tasks/gem.rake
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'rubygems/package_task'
|
2
|
+
gemspec_file = File.expand_path('../../alf-rack.gemspec', __FILE__)
|
3
|
+
gemspec = Kernel.eval(File.read(gemspec_file))
|
4
|
+
Gem::PackageTask.new(gemspec) do |t|
|
5
|
+
t.name = gemspec.name
|
6
|
+
t.version = gemspec.version
|
7
|
+
t.package_files = gemspec.files
|
8
|
+
end
|
data/tasks/test.rake
ADDED
metadata
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alf-rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.15.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bernard Lambeau
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: path
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sinatra
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.4'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.4'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack-test
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.6.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: alf-sequel
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.15.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.15.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: sequel
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '4.2'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '4.2'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: sqlite3
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.3'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.3'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '10.1'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '2.14'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '2.14'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: rack
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '1.5'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '1.5'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: rack-accept
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ~>
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 0.4.5
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.4.5
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: alf-core
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ~>
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: 0.15.0
|
182
|
+
type: :runtime
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ~>
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 0.15.0
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: ruby_cop
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ~>
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '1.0'
|
198
|
+
type: :runtime
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ~>
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '1.0'
|
206
|
+
description: ! 'This gems provides Rack middleware to use the full power of Alf in
|
207
|
+
web
|
208
|
+
|
209
|
+
applications.'
|
210
|
+
email:
|
211
|
+
- blambeau at gmail.com
|
212
|
+
executables: []
|
213
|
+
extensions: []
|
214
|
+
extra_rdoc_files: []
|
215
|
+
files:
|
216
|
+
- CHANGELOG.md
|
217
|
+
- Gemfile
|
218
|
+
- Gemfile.lock
|
219
|
+
- lib/alf/rack/config.rb
|
220
|
+
- lib/alf/rack/connect.rb
|
221
|
+
- lib/alf/rack/errors.rb
|
222
|
+
- lib/alf/rack/helpers.rb
|
223
|
+
- lib/alf/rack/loader.rb
|
224
|
+
- lib/alf/rack/query.rb
|
225
|
+
- lib/alf/rack/response.rb
|
226
|
+
- lib/alf/rack/version.rb
|
227
|
+
- lib/alf/rack.rb
|
228
|
+
- lib/alf-rack.rb
|
229
|
+
- LICENCE.md
|
230
|
+
- Manifest.txt
|
231
|
+
- Rakefile
|
232
|
+
- README.md
|
233
|
+
- spec/config/test_database.rb
|
234
|
+
- spec/config/test_viewpoint.rb
|
235
|
+
- spec/connect/test_principle.rb
|
236
|
+
- spec/query/test_logical_behavior.rb
|
237
|
+
- spec/query/test_metadata_behavior.rb
|
238
|
+
- spec/query/test_root_behavior.rb
|
239
|
+
- spec/response/class/test_renderer.rb
|
240
|
+
- spec/response/class/test_renderer_bang.rb
|
241
|
+
- spec/response/class/test_supported_media_types.rb
|
242
|
+
- spec/response/test_initialize.rb
|
243
|
+
- spec/response/test_principle.rb
|
244
|
+
- spec/sap.db
|
245
|
+
- spec/spec_helper.rb
|
246
|
+
- spec/test_rack.rb
|
247
|
+
- tasks/examples.rake
|
248
|
+
- tasks/gem.rake
|
249
|
+
- tasks/test.rake
|
250
|
+
homepage: http://github.com/blambeau/alf
|
251
|
+
licenses: []
|
252
|
+
post_install_message:
|
253
|
+
rdoc_options: []
|
254
|
+
require_paths:
|
255
|
+
- lib
|
256
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
257
|
+
none: false
|
258
|
+
requirements:
|
259
|
+
- - ! '>='
|
260
|
+
- !ruby/object:Gem::Version
|
261
|
+
version: '0'
|
262
|
+
segments:
|
263
|
+
- 0
|
264
|
+
hash: -638038250692388014
|
265
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
266
|
+
none: false
|
267
|
+
requirements:
|
268
|
+
- - ! '>='
|
269
|
+
- !ruby/object:Gem::Version
|
270
|
+
version: '0'
|
271
|
+
segments:
|
272
|
+
- 0
|
273
|
+
hash: -638038250692388014
|
274
|
+
requirements: []
|
275
|
+
rubyforge_project:
|
276
|
+
rubygems_version: 1.8.25
|
277
|
+
signing_key:
|
278
|
+
specification_version: 3
|
279
|
+
summary: A collection of Rack middlewares for using Alf in web applications
|
280
|
+
test_files: []
|