rack-mongoid 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 +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +1 -0
- data/lib/rack-mongoid.rb +1 -0
- data/lib/rack/mongoid.rb +55 -0
- data/lib/rack/mongoid/controllers/base.rb +72 -0
- data/lib/rack/mongoid/controllers/create_controller.rb +19 -0
- data/lib/rack/mongoid/controllers/destroy_controller.rb +24 -0
- data/lib/rack/mongoid/controllers/index_controller.rb +13 -0
- data/lib/rack/mongoid/controllers/show_controller.rb +25 -0
- data/lib/rack/mongoid/controllers/single_resource_controller.rb +24 -0
- data/lib/rack/mongoid/controllers/update_controller.rb +27 -0
- data/lib/rack/mongoid/version.rb +5 -0
- data/rack-mongoid.gemspec +30 -0
- data/spec/config/mongoid.yml +6 -0
- data/spec/rack/mongoid_spec.rb +170 -0
- data/spec/spec_helper.rb +17 -0
- metadata +222 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 609b45f78481f17c849544793d24dd0ab55f6bc2
|
4
|
+
data.tar.gz: 0d80d2a0b78c98f48b08ce126e8f4265c7147fc5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec6b84b4ccdfbe9dcb4f7dc516c783d5ba453c69e6f9836e80cef75386703adca6cc0723ccd51e74b938d2ab2c0b19d6488f3ea569cc5308a08b4a7c57142e9a
|
7
|
+
data.tar.gz: d2d04cbff6d795f0ec09971ff8a7dc8dafc94ab1072b7d5127aa36a28b475f9a1aec069c09d70442f5c51e334bf855af3ac23c8a84e53c74a708b3ab25ed50d1
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
## 0.1.0
|
2
|
+
* Rename from rack-mongoid_adapter to rack-mongoid
|
3
|
+
|
4
|
+
## 0.0.3
|
5
|
+
* Return prettified JSON response
|
6
|
+
|
7
|
+
## 0.0.2
|
8
|
+
* Accepts JSON request body on POST and PUT request
|
9
|
+
* Return response body on PUT and DELETE request
|
10
|
+
|
11
|
+
## 0.0.1
|
12
|
+
* 1st release
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ryo Nakamura
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Rack::Mongoid
|
2
|
+
Provides RESTful interface for MongoDB as a rack middleware.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
Here is the simplest example for Heroku with MongoLab plugin.
|
6
|
+
You can try this example via [r7kamura/rack-mongoid-example](https://github.com/r7kamura/rack-mongoid-example).
|
7
|
+
|
8
|
+
### Operation
|
9
|
+
```
|
10
|
+
# settings
|
11
|
+
$ mkdir config
|
12
|
+
$ vi config/mongoid.yml
|
13
|
+
$ vi config.ru
|
14
|
+
$ vi Gemfile
|
15
|
+
$ bundle install
|
16
|
+
$ git init
|
17
|
+
$ git add .
|
18
|
+
$ git commit -m "Initial commit"
|
19
|
+
$ heroku create my-test-app
|
20
|
+
$ heroku addons:add mongolab
|
21
|
+
$ git push heroku master
|
22
|
+
```
|
23
|
+
|
24
|
+
### Code
|
25
|
+
```yaml
|
26
|
+
# config/mongoid.yml
|
27
|
+
production:
|
28
|
+
sessions:
|
29
|
+
default:
|
30
|
+
uri: <%= ENV["MONGOLAB_URI"] %>
|
31
|
+
```
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# config.ru
|
35
|
+
require "rack/mongoid"
|
36
|
+
run Rack::Mongoid
|
37
|
+
```
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# Gemfile
|
41
|
+
source "https://rubygems.org"
|
42
|
+
gem "rack-mongoid"
|
43
|
+
```
|
44
|
+
|
45
|
+
### POST /{resource_name} - Create a new resource
|
46
|
+
```sh
|
47
|
+
$ curl http://my-example-app.herokuapp.com/users -d '{"name":"alice"}' -H "Content-Type: application/json" -i
|
48
|
+
HTTP/1.1 201 Created
|
49
|
+
Content-Type: application/json
|
50
|
+
Date: Tue, 10 Jun 2014 16:47:26 GMT
|
51
|
+
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
|
52
|
+
Content-Length: 59
|
53
|
+
Connection: keep-alive
|
54
|
+
|
55
|
+
{
|
56
|
+
"name": "alice",
|
57
|
+
"_id": "5397369e3061380002010000"
|
58
|
+
}
|
59
|
+
```
|
60
|
+
|
61
|
+
### GET /{resource_name} - List resources
|
62
|
+
```sh
|
63
|
+
$ curl http://my-example-app.herokuapp.com/users -i
|
64
|
+
HTTP/1.1 200 OK
|
65
|
+
Content-Type: application/json
|
66
|
+
Date: Tue, 10 Jun 2014 16:48:19 GMT
|
67
|
+
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
|
68
|
+
Content-Length: 109
|
69
|
+
Connection: keep-alive
|
70
|
+
|
71
|
+
[
|
72
|
+
{"name":"alice","_id":"5397369e3061380002010000"}
|
73
|
+
]
|
74
|
+
```
|
75
|
+
|
76
|
+
### GET /{resource_name}/{id} - Show the resource
|
77
|
+
```sh
|
78
|
+
$ curl http://my-example-app.herokuapp.com/users/5397369e3061380002010000 -i
|
79
|
+
HTTP/1.1 200 OK
|
80
|
+
Content-Type: application/json
|
81
|
+
Date: Tue, 10 Jun 2014 16:48:48 GMT
|
82
|
+
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
|
83
|
+
Content-Length: 55
|
84
|
+
Connection: keep-alive
|
85
|
+
|
86
|
+
{"name":"alice","_id":"5397369e3061380002010000"}
|
87
|
+
```
|
88
|
+
|
89
|
+
### PUT /{resource_name}/{id} - Update the resource
|
90
|
+
```sh
|
91
|
+
$ curl http://my-example-app.herokuapp.com/users/5397369e3061380002010000 -X PUT -d '{"name":"bob"}' -H "Content-Type: application/json" -i
|
92
|
+
HTTP/1.1 200 OK
|
93
|
+
Content-Type: application/json
|
94
|
+
Date: Tue, 10 Jun 2014 16:50:15 GMT
|
95
|
+
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
|
96
|
+
Content-Length: 48
|
97
|
+
Connection: keep-alive
|
98
|
+
|
99
|
+
{"name":"bob","_id":"5397369e3061380002010000"}
|
100
|
+
```
|
101
|
+
|
102
|
+
### DELETE /{resource_name}/{id} - Delete the resource
|
103
|
+
```sh
|
104
|
+
$ curl http://my-example-app.herokuapp.com/users/5397369e3061380002010000 -X DELETE -i
|
105
|
+
HTTP/1.1 200 OK
|
106
|
+
Content-Type: application/json
|
107
|
+
Date: Tue, 10 Jun 2014 16:50:47 GMT
|
108
|
+
Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
|
109
|
+
Content-Length: 48
|
110
|
+
Connection: keep-alive
|
111
|
+
|
112
|
+
{"name":"bob","_id":"5397369e3061380002010000"}
|
113
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/rack-mongoid.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rack/mongoid"
|
data/lib/rack/mongoid.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "mem"
|
2
|
+
require "mongoid"
|
3
|
+
require "rack"
|
4
|
+
require "rack-multiplexer"
|
5
|
+
require "rack/mongoid/controllers/base"
|
6
|
+
require "rack/mongoid/controllers/single_resource_controller"
|
7
|
+
require "rack/mongoid/controllers/create_controller"
|
8
|
+
require "rack/mongoid/controllers/destroy_controller"
|
9
|
+
require "rack/mongoid/controllers/index_controller"
|
10
|
+
require "rack/mongoid/controllers/show_controller"
|
11
|
+
require "rack/mongoid/controllers/update_controller"
|
12
|
+
require "rack/mongoid/version"
|
13
|
+
|
14
|
+
module Rack
|
15
|
+
class Mongoid
|
16
|
+
DEFAULT_MONGOID_CONFIGURATION_PATH = "config/mongoid.yml"
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def call(env)
|
20
|
+
configure_mongoid_unless_configured
|
21
|
+
instance.call(env)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def instance
|
27
|
+
@instance ||= new
|
28
|
+
end
|
29
|
+
|
30
|
+
def configure_mongoid_unless_configured
|
31
|
+
Mongoid.load!(DEFAULT_MONGOID_CONFIGURATION_PATH) unless Mongoid.configured?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(app = nil)
|
36
|
+
@app = app
|
37
|
+
end
|
38
|
+
|
39
|
+
def call(env)
|
40
|
+
router.call(env)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def router
|
46
|
+
@router ||= Rack::Multiplexer.new(@app) do
|
47
|
+
get "/:resource_name", Controllers::IndexController
|
48
|
+
get "/:resource_name/:id", Controllers::ShowController
|
49
|
+
post "/:resource_name", Controllers::CreateController
|
50
|
+
put "/:resource_name/:id", Controllers::UpdateController
|
51
|
+
delete "/:resource_name/:id", Controllers::DestroyController
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Rack
|
2
|
+
class Mongoid
|
3
|
+
module Controllers
|
4
|
+
class Base
|
5
|
+
class << self
|
6
|
+
def call(env)
|
7
|
+
new(env).call
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :env
|
12
|
+
|
13
|
+
def initialize(env)
|
14
|
+
@env = env
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
response.to_a
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def response_status
|
24
|
+
200
|
25
|
+
end
|
26
|
+
|
27
|
+
def response_header
|
28
|
+
{ "Content-Type" => "application/json" }
|
29
|
+
end
|
30
|
+
|
31
|
+
def response_body
|
32
|
+
raise NotImplementedError
|
33
|
+
end
|
34
|
+
|
35
|
+
def response_body_for_not_found
|
36
|
+
JSON.pretty_generate(message: "Not found") + "\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
def request
|
40
|
+
@request ||= Rack::Request.new(env)
|
41
|
+
end
|
42
|
+
|
43
|
+
def response
|
44
|
+
@response ||= Rack::Response.new([response_body], response_status, response_header)
|
45
|
+
end
|
46
|
+
|
47
|
+
def resource_name
|
48
|
+
request.params["resource_name"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def connection
|
52
|
+
::Mongoid.default_session[resource_name]
|
53
|
+
end
|
54
|
+
|
55
|
+
def params
|
56
|
+
case
|
57
|
+
when request.request_method == "GET"
|
58
|
+
request.GET
|
59
|
+
when !request_body.empty?
|
60
|
+
JSON.parse(request_body)
|
61
|
+
else
|
62
|
+
{}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def request_body
|
67
|
+
@request_body ||= request.body.read.tap { request.body.rewind }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rack
|
2
|
+
class Mongoid
|
3
|
+
module Controllers
|
4
|
+
class CreateController < Base
|
5
|
+
private
|
6
|
+
|
7
|
+
def response_status
|
8
|
+
201
|
9
|
+
end
|
10
|
+
|
11
|
+
def response_body
|
12
|
+
attributes = params.merge(_id: BSON::ObjectId.new.to_s)
|
13
|
+
connection.insert(attributes)
|
14
|
+
JSON.pretty_generate(attributes) + "\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rack
|
2
|
+
class Mongoid
|
3
|
+
module Controllers
|
4
|
+
class DestroyController < SingleResourceController
|
5
|
+
def response_status
|
6
|
+
if resource
|
7
|
+
200
|
8
|
+
else
|
9
|
+
404
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def response_body
|
14
|
+
if resource
|
15
|
+
connection.find(_id: id).remove
|
16
|
+
JSON.pretty_generate(resource) + "\n"
|
17
|
+
else
|
18
|
+
response_body_for_not_found
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Rack
|
2
|
+
class Mongoid
|
3
|
+
module Controllers
|
4
|
+
class ShowController < SingleResourceController
|
5
|
+
private
|
6
|
+
|
7
|
+
def response_status
|
8
|
+
if resource
|
9
|
+
200
|
10
|
+
else
|
11
|
+
404
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def response_body
|
16
|
+
if resource
|
17
|
+
JSON.pretty_generate(resource) + "\n"
|
18
|
+
else
|
19
|
+
response_body_for_not_found
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rack
|
2
|
+
class Mongoid
|
3
|
+
module Controllers
|
4
|
+
class SingleResourceController < Base
|
5
|
+
include Mem
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def id
|
10
|
+
request.params["id"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_resource
|
14
|
+
connection.find(_id: id).first
|
15
|
+
end
|
16
|
+
|
17
|
+
def resource
|
18
|
+
find_resource
|
19
|
+
end
|
20
|
+
memoize :resource
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rack
|
2
|
+
class Mongoid
|
3
|
+
module Controllers
|
4
|
+
class UpdateController < SingleResourceController
|
5
|
+
private
|
6
|
+
|
7
|
+
def response_status
|
8
|
+
if resource
|
9
|
+
200
|
10
|
+
else
|
11
|
+
404
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def response_body
|
16
|
+
if resource
|
17
|
+
attributes = resource.merge(params)
|
18
|
+
connection.find(_id: id).update(attributes)
|
19
|
+
JSON.pretty_generate(attributes) + "\n"
|
20
|
+
else
|
21
|
+
response_body_for_not_found
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "rack/mongoid/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rack-mongoid"
|
7
|
+
spec.version = Rack::Mongoid::VERSION
|
8
|
+
spec.authors = ["Ryo Nakamura"]
|
9
|
+
spec.email = ["r7kamura@gmail.com"]
|
10
|
+
spec.summary = "A rack application working as an adapter for Mongoid"
|
11
|
+
spec.homepage = "https://github.com/r7kamura/rack-mongoid"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "bson_ext", ">= 1.5.1"
|
20
|
+
spec.add_dependency "mem", ">= 0.0.5"
|
21
|
+
spec.add_dependency "mongoid", ">= 4.0.0.alpha2"
|
22
|
+
spec.add_dependency "rack"
|
23
|
+
spec.add_dependency "rack-multiplexer", ">= 0.0.6"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "pry", "0.9.12.6"
|
26
|
+
spec.add_development_dependency "rack-test", "0.6.2"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec", "2.14.1"
|
29
|
+
spec.add_development_dependency "rspec-json_matcher", "0.1.3"
|
30
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rack::Mongoid do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
subject do
|
7
|
+
send method, path, params, env
|
8
|
+
response.status
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:app) do
|
12
|
+
described_class.new
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:params) do
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:env) do
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:response) do
|
24
|
+
last_response
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:connection) do
|
28
|
+
double
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:id) do
|
32
|
+
resource["_id"]
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:resource_name) do
|
36
|
+
"recipes"
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:resource) do
|
40
|
+
post "/#{resource_name}", { name: "test" }.to_json, env
|
41
|
+
JSON.parse(last_response.body)
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:request_body) do
|
45
|
+
case method
|
46
|
+
when "POST", "PUT"
|
47
|
+
params.to_json
|
48
|
+
else
|
49
|
+
params
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
subject do
|
54
|
+
send method.downcase, path, request_body, env
|
55
|
+
response.status
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "GET /:resource_name" do
|
59
|
+
let(:method) do
|
60
|
+
"GET"
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:path) do
|
64
|
+
"/#{resource_name}"
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with valid condition" do
|
68
|
+
it "returns 200 with an array of resources" do
|
69
|
+
should == 200
|
70
|
+
response.body.should be_json_as(Array)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "GET /:resource_name/:id" do
|
76
|
+
let(:method) do
|
77
|
+
"GET"
|
78
|
+
end
|
79
|
+
|
80
|
+
let(:path) do
|
81
|
+
"/#{resource_name}/#{id}"
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when resource is not found" do
|
85
|
+
let(:id) do
|
86
|
+
BSON::ObjectId.new.to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns 404" do
|
90
|
+
should == 404
|
91
|
+
response.body.should be_json
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "with valid condition" do
|
96
|
+
it "returns 200 with a resource" do
|
97
|
+
should == 200
|
98
|
+
response.body.should be_json_as(resource)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "POST /:resource_name" do
|
104
|
+
before do
|
105
|
+
params[:name] = "test"
|
106
|
+
end
|
107
|
+
|
108
|
+
let(:method) do
|
109
|
+
"POST"
|
110
|
+
end
|
111
|
+
|
112
|
+
let(:path) do
|
113
|
+
"/#{resource_name}"
|
114
|
+
end
|
115
|
+
|
116
|
+
context "with valid condition" do
|
117
|
+
it "returns 201 with a newly-created resource" do
|
118
|
+
should == 201
|
119
|
+
response.body.should be_json_as(
|
120
|
+
_id: String,
|
121
|
+
name: "test"
|
122
|
+
)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "PUT /:resource_name/:id" do
|
128
|
+
before do
|
129
|
+
params[:name] = "test"
|
130
|
+
end
|
131
|
+
|
132
|
+
let(:method) do
|
133
|
+
"PUT"
|
134
|
+
end
|
135
|
+
|
136
|
+
let(:path) do
|
137
|
+
"/#{resource_name}/#{id}"
|
138
|
+
end
|
139
|
+
|
140
|
+
context "with valid condition" do
|
141
|
+
it "returns 200" do
|
142
|
+
should == 200
|
143
|
+
response.body.should be_json_as(
|
144
|
+
_id: String,
|
145
|
+
name: "test",
|
146
|
+
)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "DELETE /:resource_name/:id" do
|
152
|
+
let(:method) do
|
153
|
+
"DELETE"
|
154
|
+
end
|
155
|
+
|
156
|
+
let(:path) do
|
157
|
+
"/#{resource_name}/#{id}"
|
158
|
+
end
|
159
|
+
|
160
|
+
context "with valid condition" do
|
161
|
+
it "returns 200" do
|
162
|
+
should == 200
|
163
|
+
response.body.should be_json_as(
|
164
|
+
_id: String,
|
165
|
+
name: "test",
|
166
|
+
)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
require "rack/mongoid"
|
3
|
+
require "rack/test"
|
4
|
+
require "rspec/json_matcher"
|
5
|
+
|
6
|
+
ENV["RACK_ENV"] ||= "test"
|
7
|
+
Mongoid.load!(File.expand_path("../config/mongoid.yml", __FILE__))
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
config.include RSpec::JsonMatcher
|
14
|
+
end
|
15
|
+
|
16
|
+
# Fix for awesome-print
|
17
|
+
Moped::BSON = BSON
|
metadata
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryo Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bson_ext
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mem
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mongoid
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.0.0.alpha2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.0.alpha2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-multiplexer
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.0.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.0.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.12.6
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.9.12.6
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rack-test
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.6.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.6.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 2.14.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.14.1
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec-json_matcher
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.1.3
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.1.3
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- r7kamura@gmail.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- CHANGELOG.md
|
176
|
+
- Gemfile
|
177
|
+
- LICENSE.txt
|
178
|
+
- README.md
|
179
|
+
- Rakefile
|
180
|
+
- lib/rack-mongoid.rb
|
181
|
+
- lib/rack/mongoid.rb
|
182
|
+
- lib/rack/mongoid/controllers/base.rb
|
183
|
+
- lib/rack/mongoid/controllers/create_controller.rb
|
184
|
+
- lib/rack/mongoid/controllers/destroy_controller.rb
|
185
|
+
- lib/rack/mongoid/controllers/index_controller.rb
|
186
|
+
- lib/rack/mongoid/controllers/show_controller.rb
|
187
|
+
- lib/rack/mongoid/controllers/single_resource_controller.rb
|
188
|
+
- lib/rack/mongoid/controllers/update_controller.rb
|
189
|
+
- lib/rack/mongoid/version.rb
|
190
|
+
- rack-mongoid.gemspec
|
191
|
+
- spec/config/mongoid.yml
|
192
|
+
- spec/rack/mongoid_spec.rb
|
193
|
+
- spec/spec_helper.rb
|
194
|
+
homepage: https://github.com/r7kamura/rack-mongoid
|
195
|
+
licenses:
|
196
|
+
- MIT
|
197
|
+
metadata: {}
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
requirements: []
|
213
|
+
rubyforge_project:
|
214
|
+
rubygems_version: 2.2.2
|
215
|
+
signing_key:
|
216
|
+
specification_version: 4
|
217
|
+
summary: A rack application working as an adapter for Mongoid
|
218
|
+
test_files:
|
219
|
+
- spec/config/mongoid.yml
|
220
|
+
- spec/rack/mongoid_spec.rb
|
221
|
+
- spec/spec_helper.rb
|
222
|
+
has_rdoc:
|