sinatra-mongo 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/lib/sinatra/mongo.rb +13 -10
- data/sinatra-mongo.gemspec +29 -14
- data/spec/fixtures/classic_app.rb +8 -0
- data/spec/fixtures/modular_app.rb +13 -0
- data/spec/sinatra-mongo_classic_style_spec.rb +13 -0
- data/spec/sinatra-mongo_modular_style_spec.rb +13 -0
- data/spec/sinatra-mongo_spec.rb +74 -3
- data/spec/spec_helper.rb +5 -2
- data/spec/support/rack_test.rb +1 -0
- data/spec/support/shared_examples.rb +17 -0
- metadata +60 -17
data/Rakefile
CHANGED
@@ -10,8 +10,9 @@ begin
|
|
10
10
|
gem.email = "josh@technicalpickles.com"
|
11
11
|
gem.homepage = "http://github.com/technicalpickles/sinatra-mongo"
|
12
12
|
gem.authors = ["Joshua Nichols"]
|
13
|
-
gem.version = "0.0
|
13
|
+
gem.version = "0.1.0"
|
14
14
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
gem.add_development_dependency "rack-test", ">= 0.5.3"
|
15
16
|
gem.add_dependency "mongo"
|
16
17
|
gem.add_dependency 'sinatra', '>= 0.9.4'
|
17
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/lib/sinatra/mongo.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'sinatra'
|
1
|
+
require 'sinatra/base'
|
2
2
|
require 'mongo'
|
3
3
|
|
4
4
|
module Sinatra
|
@@ -16,21 +16,24 @@ module Sinatra
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def mongo
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
synchronize do
|
20
|
+
@mongo ||= (
|
21
|
+
url = URI(mongo_url)
|
22
|
+
connection = Mongo::Connection.new(url.host, url.port)
|
23
|
+
mongo = connection.db(url.path[1..-1], mongo_settings)
|
24
|
+
if url.user && url.password
|
25
|
+
mongo.authenticate(url.user, url.password)
|
26
|
+
end
|
27
|
+
mongo
|
28
|
+
)
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
protected
|
31
33
|
|
32
34
|
def self.registered(app)
|
33
35
|
app.set :mongo_url, ENV['MONGO_URL'] || 'mongo://127.0.0.1:27017/default'
|
36
|
+
app.set :mongo_settings, Hash.new
|
34
37
|
app.helpers MongoHelper
|
35
38
|
end
|
36
39
|
|
data/sinatra-mongo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-mongo}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joshua Nichols"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-05-06}
|
13
13
|
s.description = %q{= sinatra-mongo
|
14
14
|
|
15
15
|
Extends Sinatra with an extension method for dealing with monogodb using the ruby driver.
|
@@ -63,28 +63,40 @@ Copyright (c) 2009 Joshua Nichols. See LICENSE for details.
|
|
63
63
|
s.email = %q{josh@technicalpickles.com}
|
64
64
|
s.extra_rdoc_files = [
|
65
65
|
"LICENSE",
|
66
|
-
|
66
|
+
"README.rdoc"
|
67
67
|
]
|
68
68
|
s.files = [
|
69
69
|
".document",
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
70
|
+
".gitignore",
|
71
|
+
"LICENSE",
|
72
|
+
"README.rdoc",
|
73
|
+
"Rakefile",
|
74
|
+
"lib/sinatra/mongo.rb",
|
75
|
+
"sinatra-mongo.gemspec",
|
76
|
+
"spec/fixtures/classic_app.rb",
|
77
|
+
"spec/fixtures/modular_app.rb",
|
78
|
+
"spec/sinatra-mongo_classic_style_spec.rb",
|
79
|
+
"spec/sinatra-mongo_modular_style_spec.rb",
|
80
|
+
"spec/sinatra-mongo_spec.rb",
|
81
|
+
"spec/spec.opts",
|
82
|
+
"spec/spec_helper.rb",
|
83
|
+
"spec/support/rack_test.rb",
|
84
|
+
"spec/support/shared_examples.rb"
|
79
85
|
]
|
80
86
|
s.homepage = %q{http://github.com/technicalpickles/sinatra-mongo}
|
81
87
|
s.rdoc_options = ["--charset=UTF-8"]
|
82
88
|
s.require_paths = ["lib"]
|
83
|
-
s.rubygems_version = %q{1.3.
|
89
|
+
s.rubygems_version = %q{1.3.6}
|
84
90
|
s.summary = %q{A light extension to sinatra for using mongo}
|
85
91
|
s.test_files = [
|
92
|
+
"spec/fixtures/classic_app.rb",
|
93
|
+
"spec/fixtures/modular_app.rb",
|
94
|
+
"spec/sinatra-mongo_classic_style_spec.rb",
|
95
|
+
"spec/sinatra-mongo_modular_style_spec.rb",
|
86
96
|
"spec/sinatra-mongo_spec.rb",
|
87
|
-
|
97
|
+
"spec/spec_helper.rb",
|
98
|
+
"spec/support/rack_test.rb",
|
99
|
+
"spec/support/shared_examples.rb"
|
88
100
|
]
|
89
101
|
|
90
102
|
if s.respond_to? :specification_version then
|
@@ -93,15 +105,18 @@ Copyright (c) 2009 Joshua Nichols. See LICENSE for details.
|
|
93
105
|
|
94
106
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
95
107
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
108
|
+
s.add_development_dependency(%q<rack-test>, [">= 0.5.3"])
|
96
109
|
s.add_runtime_dependency(%q<mongo>, [">= 0"])
|
97
110
|
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
|
98
111
|
else
|
99
112
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
113
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.3"])
|
100
114
|
s.add_dependency(%q<mongo>, [">= 0"])
|
101
115
|
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
102
116
|
end
|
103
117
|
else
|
104
118
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
119
|
+
s.add_dependency(%q<rack-test>, [">= 0.5.3"])
|
105
120
|
s.add_dependency(%q<mongo>, [">= 0"])
|
106
121
|
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
107
122
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra/mongo'
|
3
|
+
|
4
|
+
class ModularApp < Sinatra::Base
|
5
|
+
register Sinatra::MongoExtension
|
6
|
+
|
7
|
+
set :mongo, 'mongo://localhost:27017/sinatra-mongo-test'
|
8
|
+
|
9
|
+
get '/' do
|
10
|
+
mongo['test_collection'].find_one.inspect
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'fixtures/classic_app'
|
3
|
+
|
4
|
+
describe 'a classic style sinatra app' do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def app
|
8
|
+
Sinatra::Application
|
9
|
+
end
|
10
|
+
|
11
|
+
it_should_behave_like 'all sinatra-mongo test apps'
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'fixtures/modular_app'
|
3
|
+
|
4
|
+
describe 'a modular style sinatra app' do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def app
|
8
|
+
ModularApp
|
9
|
+
end
|
10
|
+
|
11
|
+
it_should_behave_like 'all sinatra-mongo test apps'
|
12
|
+
|
13
|
+
end
|
data/spec/sinatra-mongo_spec.rb
CHANGED
@@ -1,7 +1,78 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
3
|
+
describe "Sinatra::MongoExtension" do
|
4
|
+
before(:each) do
|
5
|
+
@app = Sinatra.new
|
6
|
+
@app.register Sinatra::MongoExtension
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#mongo' do
|
10
|
+
it 'creates and returns a Mongo::DB instance' do
|
11
|
+
@app.mongo.should be_kind_of(Mongo::DB)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'defaults to a db on localhost called default' do
|
15
|
+
@app.mongo.connection.host.should == '127.0.0.1'
|
16
|
+
@app.mongo.connection.port.should == 27017
|
17
|
+
@app.mongo.name.should == 'default'
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'mongo_url is set' do
|
21
|
+
before(:each) do
|
22
|
+
@mongo_url = 'mongo://127.0.0.1:27017/test'
|
23
|
+
@app.mongo = @mongo_url
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'creates the Mongo::DB instance with the supplied uri' do
|
27
|
+
@app.mongo.connection.host.should == '127.0.0.1'
|
28
|
+
@app.mongo.connection.port.should == 27017
|
29
|
+
@app.mongo.name.should == 'test'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#mongo=' do
|
35
|
+
before(:each) do
|
36
|
+
@mongo_uri = 'mongo://127.0.0.1:27017/test'
|
37
|
+
@mongo = mock('mongo')
|
38
|
+
@app.stub!(:mongo).and_return(@mongo)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sets the mongo_url environment variable' do
|
42
|
+
@app.mongo = @mongo_uri
|
43
|
+
@app.mongo_url.should == @mongo_uri
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'calls the #mongo method' do
|
47
|
+
@app.should_receive(:mongo)
|
48
|
+
@app.mongo = @mongo_uri
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'registration of the extension' do
|
54
|
+
before(:each) do
|
55
|
+
@app = Sinatra.new
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets the mongo_url variable' do
|
59
|
+
@app.register(Sinatra::MongoExtension)
|
60
|
+
@app.mongo_url.should == 'mongo://127.0.0.1:27017/default'
|
61
|
+
end
|
62
|
+
|
63
|
+
context "ENV['MONGO_URL'] is set" do
|
64
|
+
before(:each) do
|
65
|
+
@mongo_url = 'mongo://127.0.0.1:27017/via_mongo_url_env'
|
66
|
+
ENV['MONGO_URL'] = @mongo_url
|
67
|
+
@app.register(Sinatra::MongoExtension)
|
68
|
+
end
|
69
|
+
it 'sets the mongo_url variable to the value of the env variable' do
|
70
|
+
@app.mongo_url.should == @mongo_url
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'calls helpers with MongoHelper' do
|
75
|
+
@app.should_receive(:helpers).with(Sinatra::MongoHelper)
|
76
|
+
@app.register(Sinatra::MongoExtension)
|
6
77
|
end
|
7
78
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'sinatra
|
3
|
+
require 'sinatra/mongo'
|
4
4
|
require 'spec'
|
5
5
|
require 'spec/autorun'
|
6
6
|
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
10
|
+
|
7
11
|
Spec::Runner.configure do |config|
|
8
|
-
|
9
12
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/test'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
shared_examples_for 'all sinatra-mongo test apps' do
|
2
|
+
describe 'GET /' do
|
3
|
+
before(:each) do
|
4
|
+
3.times { |i| mongo['test_collection'].insert({'x' => i }) }
|
5
|
+
end
|
6
|
+
|
7
|
+
after(:each) do
|
8
|
+
mongo['test_collection'].remove
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'fetches and shows the first element in test_collection' do
|
12
|
+
get '/' do |response|
|
13
|
+
response.body.should match('"x"=>0')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Joshua Nichols
|
@@ -9,39 +14,63 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-05-06 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
23
31
|
version: 1.2.9
|
24
|
-
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rack-test
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 5
|
44
|
+
- 3
|
45
|
+
version: 0.5.3
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
25
48
|
- !ruby/object:Gem::Dependency
|
26
49
|
name: mongo
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
30
52
|
requirements:
|
31
53
|
- - ">="
|
32
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
33
57
|
version: "0"
|
34
|
-
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id003
|
35
60
|
- !ruby/object:Gem::Dependency
|
36
61
|
name: sinatra
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
40
64
|
requirements:
|
41
65
|
- - ">="
|
42
66
|
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
- 9
|
70
|
+
- 4
|
43
71
|
version: 0.9.4
|
44
|
-
|
72
|
+
type: :runtime
|
73
|
+
version_requirements: *id004
|
45
74
|
description: |
|
46
75
|
= sinatra-mongo
|
47
76
|
|
@@ -109,9 +138,15 @@ files:
|
|
109
138
|
- Rakefile
|
110
139
|
- lib/sinatra/mongo.rb
|
111
140
|
- sinatra-mongo.gemspec
|
141
|
+
- spec/fixtures/classic_app.rb
|
142
|
+
- spec/fixtures/modular_app.rb
|
143
|
+
- spec/sinatra-mongo_classic_style_spec.rb
|
144
|
+
- spec/sinatra-mongo_modular_style_spec.rb
|
112
145
|
- spec/sinatra-mongo_spec.rb
|
113
146
|
- spec/spec.opts
|
114
147
|
- spec/spec_helper.rb
|
148
|
+
- spec/support/rack_test.rb
|
149
|
+
- spec/support/shared_examples.rb
|
115
150
|
has_rdoc: true
|
116
151
|
homepage: http://github.com/technicalpickles/sinatra-mongo
|
117
152
|
licenses: []
|
@@ -125,21 +160,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
160
|
requirements:
|
126
161
|
- - ">="
|
127
162
|
- !ruby/object:Gem::Version
|
163
|
+
segments:
|
164
|
+
- 0
|
128
165
|
version: "0"
|
129
|
-
version:
|
130
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
167
|
requirements:
|
132
168
|
- - ">="
|
133
169
|
- !ruby/object:Gem::Version
|
170
|
+
segments:
|
171
|
+
- 0
|
134
172
|
version: "0"
|
135
|
-
version:
|
136
173
|
requirements: []
|
137
174
|
|
138
175
|
rubyforge_project:
|
139
|
-
rubygems_version: 1.3.
|
176
|
+
rubygems_version: 1.3.6
|
140
177
|
signing_key:
|
141
178
|
specification_version: 3
|
142
179
|
summary: A light extension to sinatra for using mongo
|
143
180
|
test_files:
|
181
|
+
- spec/fixtures/classic_app.rb
|
182
|
+
- spec/fixtures/modular_app.rb
|
183
|
+
- spec/sinatra-mongo_classic_style_spec.rb
|
184
|
+
- spec/sinatra-mongo_modular_style_spec.rb
|
144
185
|
- spec/sinatra-mongo_spec.rb
|
145
186
|
- spec/spec_helper.rb
|
187
|
+
- spec/support/rack_test.rb
|
188
|
+
- spec/support/shared_examples.rb
|