mongo_browser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.simplecov +5 -0
- data/README.md +30 -10
- data/app/assets/images/breadcrumb-separator.png +0 -0
- data/app/assets/stylesheets/application.css.scss +16 -3
- data/app/views/collections/show.erb +2 -2
- data/app/views/databases/show.erb +2 -2
- data/app/views/index.erb +2 -2
- data/app/views/layout/_navbar.erb +28 -16
- data/app/views/layout.erb +4 -4
- data/app/views/server_info.erb +1 -1
- data/lib/mongo_browser/application.rb +19 -19
- data/lib/mongo_browser/version.rb +1 -1
- data/log/.gitkeep +0 -0
- data/mongo_browser.gemspec +1 -1
- data/spec/features/collections_list_spec.rb +7 -5
- data/spec/features/databases_list_spec.rb +6 -1
- data/spec/features/documents_list_spec.rb +9 -7
- data/spec/features/server_info_spec.rb +6 -0
- data/spec/lib/mongo_browser_spec.rb +9 -0
- data/spec/spec_helper.rb +17 -25
- data/spec/support/{integration.rb → feature_example_group.rb} +23 -1
- data/spec/{fixtures → support/fixtures}/databases.json +0 -0
- data/spec/support/fixtures.rb +34 -0
- data/spec/support/{have_flash_message_matcher.rb → matchers/have_flash_message.rb} +0 -0
- data/spec/support/mongod.rb +75 -0
- metadata +19 -14
- data/README.rdoc +0 -19
- data/app/views/layout/_breadcrumb.erb +0 -13
- data/spec/support/mongo_test_server.rb +0 -50
data/.gitignore
CHANGED
data/.simplecov
ADDED
data/README.md
CHANGED
@@ -1,26 +1,46 @@
|
|
1
1
|
# MongoBrowser
|
2
2
|
|
3
3
|
[![Build status](https://secure.travis-ci.org/lucassus/mongo_browser.png)](http://travis-ci.org/lucassus/mongo_browser)
|
4
|
+
[![Dependency Status](https://gemnasium.com/lucassus/mongo_browser.png)](http://gemnasium.com/lucassus/mongo_browser)
|
4
5
|
|
5
|
-
|
6
|
+
Simple but powerful tool for managing mongodb databases
|
6
7
|
|
7
|
-
|
8
|
+
Install the gem:
|
8
9
|
|
9
|
-
|
10
|
+
$ gem install mongo_browser
|
10
11
|
|
11
|
-
|
12
|
+
## Usage
|
12
13
|
|
13
|
-
|
14
|
+
Run the application
|
14
15
|
|
15
|
-
$
|
16
|
+
$ mongo_browser
|
16
17
|
|
17
|
-
|
18
|
+
Run the application as a daemon
|
18
19
|
|
19
|
-
$
|
20
|
+
$ mongo_browser --demonize
|
20
21
|
|
21
|
-
|
22
|
+
Application will be available by default at http://localhost:4567
|
23
|
+
In order to run it on custom port number pass the `--port` option with selected port.
|
24
|
+
|
25
|
+
Other options are:
|
26
|
+
|
27
|
+
$ mongo_browser --help
|
28
|
+
[17/11 16:10:06] Usage: mongo_browser [options]
|
29
|
+
|
30
|
+
v0.1.0
|
22
31
|
|
23
|
-
|
32
|
+
Options:
|
33
|
+
--version Show help/version info
|
34
|
+
--port PORT MongoBrowser port
|
35
|
+
(Default: 4567)
|
36
|
+
--mongodb-host HOST Mongodb database host
|
37
|
+
(Default: localhost)
|
38
|
+
--mongodb-port PORT Mongodb database port
|
39
|
+
(Default: 27017)
|
40
|
+
--demonize Run the app in the background
|
41
|
+
--log-level LEVEL Set the logging level
|
42
|
+
(debug|info|warn|error|fatal)
|
43
|
+
(Default: info)
|
24
44
|
|
25
45
|
## Contributing
|
26
46
|
|
Binary file
|
@@ -5,18 +5,31 @@
|
|
5
5
|
*/
|
6
6
|
body {
|
7
7
|
position: relative;
|
8
|
-
padding-top:
|
8
|
+
padding-top: 40px;
|
9
9
|
background-color: #fff;
|
10
10
|
background-repeat: repeat-x;
|
11
11
|
background-position: 0 40px;
|
12
12
|
}
|
13
13
|
|
14
14
|
table.table {
|
15
|
-
tr
|
16
|
-
pre {
|
15
|
+
tr {
|
16
|
+
&.document pre {
|
17
17
|
background: none;
|
18
18
|
border: 0px;
|
19
19
|
display: inline;
|
20
20
|
}
|
21
|
+
|
22
|
+
th.actions {
|
23
|
+
min-width: 90px;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
ul.nav.breadcrumbs {
|
29
|
+
a {
|
30
|
+
background-image: url("breadcrumb-separator.png");
|
31
|
+
background-repeat: no-repeat;
|
32
|
+
background-position: left center;
|
33
|
+
background-color: transparent;
|
21
34
|
}
|
22
35
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<div class="page-header">
|
2
|
-
<h2
|
2
|
+
<h2><%= params[:collection_name] %> documents</h2>
|
3
3
|
</div>
|
4
4
|
|
5
5
|
<ul class="nav nav-tabs">
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<tr>
|
19
19
|
<th>Id</th>
|
20
20
|
<th>Data</th>
|
21
|
-
<th> </th>
|
21
|
+
<th class="actions"> </th>
|
22
22
|
</tr>
|
23
23
|
</thead>
|
24
24
|
<tbody>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<div class="page-header">
|
2
|
-
<h2
|
2
|
+
<h2><%= params[:db_name] %> collections</h2>
|
3
3
|
</div>
|
4
4
|
|
5
5
|
<ul class="nav nav-tabs">
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<tr>
|
19
19
|
<th>Name</th>
|
20
20
|
<th>Size</th>
|
21
|
-
<th> </th>
|
21
|
+
<th class="actions"> </th>
|
22
22
|
</tr>
|
23
23
|
</thead>
|
24
24
|
<tbody>
|
data/app/views/index.erb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<div class="page-header">
|
2
|
-
<h2>
|
2
|
+
<h2>localhost databases</h2>
|
3
3
|
</div>
|
4
4
|
|
5
5
|
<%= erb :"shared/_filter", {}, { filter_for: "databases", placeholder: "Database name" } %>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<tr>
|
10
10
|
<th>Name</th>
|
11
11
|
<th>Size</th>
|
12
|
-
<th> </th>
|
12
|
+
<th class="actions"> </th>
|
13
13
|
</tr>
|
14
14
|
</thead>
|
15
15
|
<tbody>
|
@@ -1,21 +1,33 @@
|
|
1
|
-
<div class="navbar
|
2
|
-
<div class="
|
3
|
-
<
|
4
|
-
<
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
<div class="navbar-inner">
|
2
|
+
<div class="container">
|
3
|
+
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
4
|
+
<span class="icon-bar"></span>
|
5
|
+
<span class="icon-bar"></span>
|
6
|
+
<span class="icon-bar"></span>
|
7
|
+
</a>
|
8
|
+
<a class="brand" href="/">MongoBrowser</a>
|
9
|
+
<div class="nav-collapse collapse">
|
10
|
+
<!--<ul class="nav">-->
|
11
|
+
<!--<li class="dropdown-toggle">-->
|
12
|
+
<!--<a class="dropdown">Test</a>-->
|
13
|
+
<!--</li>-->
|
14
|
+
<!--</ul>-->
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
<% if params[:db_name] %>
|
17
|
+
<ul class="nav breadcrumbs">
|
18
|
+
<% unless params[:collection_name] %>
|
19
|
+
<li><a href="#"><%= params[:db_name] %></a></li>
|
20
|
+
<% else %>
|
21
|
+
<li><a href="/databases/<%= params[:db_name] %>"><%= params[:db_name] %></a></li>
|
22
|
+
<li><a href="#"><%= params[:collection_name] %></a></li>
|
23
|
+
<% end %>
|
17
24
|
</ul>
|
18
|
-
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
<ul class="nav pull-right">
|
28
|
+
<li><a href="/server_info">Server Info</a></li>
|
29
|
+
<li><a>v. <%= MongoBrowser::VERSION %></a></li>
|
30
|
+
</ul>
|
19
31
|
</div>
|
20
32
|
</div>
|
21
33
|
</div>
|
data/app/views/layout.erb
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
<link href="/assets/application.css" rel="stylesheet" media="screen">
|
6
6
|
</head>
|
7
7
|
<body>
|
8
|
-
|
8
|
+
<div class="navbar navbar navbar-fixed-top">
|
9
|
+
<%= erb :"layout/_navbar" %>
|
10
|
+
</div>
|
9
11
|
|
10
|
-
<div class="container">
|
12
|
+
<div class="container-fluid">
|
11
13
|
<%= erb :"layout/_flash_messages" %>
|
12
|
-
<%= erb :"layout/_breadcrumb" %>
|
13
|
-
|
14
14
|
<%= yield %>
|
15
15
|
</div>
|
16
16
|
|
data/app/views/server_info.erb
CHANGED
@@ -20,8 +20,8 @@ module MongoBrowser
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# Collections list
|
23
|
-
get "/databases/:db_name" do
|
24
|
-
database = connection.db(
|
23
|
+
get "/databases/:db_name" do |db_name|
|
24
|
+
database = connection.db(db_name)
|
25
25
|
@collections = database.collections
|
26
26
|
@stats = database.stats
|
27
27
|
|
@@ -29,17 +29,17 @@ module MongoBrowser
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# Delete a database
|
32
|
-
delete "/databases/:db_name" do
|
33
|
-
connection.drop_database(
|
32
|
+
delete "/databases/:db_name" do |db_name|
|
33
|
+
connection.drop_database(db_name)
|
34
34
|
|
35
|
-
flash[:info] = "Database #{
|
35
|
+
flash[:info] = "Database #{db_name} has been deleted."
|
36
36
|
redirect "/"
|
37
37
|
end
|
38
38
|
|
39
39
|
# Documents list
|
40
|
-
get "/databases/:db_name/collections/:collection_name" do
|
41
|
-
database = connection.db(
|
42
|
-
collection = database.collection(
|
40
|
+
get "/databases/:db_name/collections/:collection_name" do |db_name, collection_name|
|
41
|
+
database = connection.db(db_name)
|
42
|
+
collection = database.collection(collection_name)
|
43
43
|
|
44
44
|
@stats = collection.stats
|
45
45
|
@documents, @pagination = paginate_documents_for(collection, params[:page])
|
@@ -48,29 +48,29 @@ module MongoBrowser
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# Delete a collection
|
51
|
-
delete "/databases/:db_name/collections/:collection_name" do
|
51
|
+
delete "/databases/:db_name/collections/:collection_name" do |db_name, collection_name|
|
52
52
|
begin
|
53
|
-
database = connection.db(
|
54
|
-
database.drop_collection(
|
53
|
+
database = connection.db(db_name)
|
54
|
+
database.drop_collection(collection_name)
|
55
55
|
|
56
|
-
flash[:info] = "Collection #{
|
56
|
+
flash[:info] = "Collection #{collection_name} has been deleted."
|
57
57
|
rescue Mongo::OperationFailure => e
|
58
58
|
flash[:error] = e.message
|
59
59
|
end
|
60
60
|
|
61
|
-
redirect "/databases/#{
|
61
|
+
redirect "/databases/#{db_name}"
|
62
62
|
end
|
63
63
|
|
64
64
|
# Delete a document
|
65
|
-
delete "/databases/:db_name/collections/:collection_name/:id" do
|
66
|
-
database = connection.db(
|
67
|
-
collection = database.collection(
|
65
|
+
delete "/databases/:db_name/collections/:collection_name/:id" do |db_name, collection_name, id|
|
66
|
+
database = connection.db(db_name)
|
67
|
+
collection = database.collection(collection_name)
|
68
68
|
|
69
|
-
id = BSON::ObjectId(
|
69
|
+
id = BSON::ObjectId(id)
|
70
70
|
collection.remove(_id: id)
|
71
71
|
|
72
|
-
flash[:info] = "Document #{
|
73
|
-
redirect "/databases/#{
|
72
|
+
flash[:info] = "Document #{id} has been deleted."
|
73
|
+
redirect "/databases/#{db_name}/collections/#{collection_name}"
|
74
74
|
end
|
75
75
|
|
76
76
|
# Server info
|
data/log/.gitkeep
ADDED
File without changes
|
data/mongo_browser.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_development_dependency("rdoc")
|
19
19
|
gem.add_development_dependency("aruba")
|
20
|
-
gem.add_development_dependency("rake", "~> 0.
|
20
|
+
gem.add_development_dependency("rake", "~> 10.0.1")
|
21
21
|
|
22
22
|
gem.add_dependency("mongo", "~> 1.7.0")
|
23
23
|
gem.add_dependency("bson_ext", "~> 1.7.0")
|
@@ -8,14 +8,16 @@ describe "Collections list", type: :request do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "displays the breadcrumb" do
|
11
|
-
within ".
|
11
|
+
within ".breadcrumbs" do
|
12
12
|
within "li:nth-child(1)" do
|
13
|
-
expect(page).to have_link("
|
13
|
+
expect(page).to have_link("first_database", href: "#")
|
14
14
|
end
|
15
|
+
end
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
it "has a valid title" do
|
19
|
+
within "h2" do
|
20
|
+
expect(page).to have_content("first_database collections")
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -7,8 +7,13 @@ describe "Databases list", type: :request do
|
|
7
7
|
expect(page).not_to have_css(".breadcrumb")
|
8
8
|
end
|
9
9
|
|
10
|
+
it "has a valid title" do
|
11
|
+
within "h2" do
|
12
|
+
expect(page).to have_content("localhost databases")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
it "displays list with available databases" do
|
11
|
-
expect(page).to have_content("Available databases")
|
12
17
|
|
13
18
|
within "table" do
|
14
19
|
expect(page).to have_link("first_database")
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Documents list", type: :request do
|
4
|
-
let(:connection) {
|
4
|
+
let(:connection) { Fixtures.instance.connection }
|
5
5
|
|
6
6
|
before do
|
7
7
|
visit "/"
|
@@ -12,18 +12,20 @@ describe "Documents list", type: :request do
|
|
12
12
|
|
13
13
|
shared_examples "breadcrumbs for documents list" do
|
14
14
|
it "displays the breadcrumb" do
|
15
|
-
within ".
|
15
|
+
within ".breadcrumbs" do
|
16
16
|
within "li:nth-child(1)" do
|
17
|
-
expect(page).to have_link("
|
17
|
+
expect(page).to have_link("first_database")
|
18
18
|
end
|
19
19
|
|
20
20
|
within "li:nth-child(2)" do
|
21
|
-
expect(page).to have_link(
|
21
|
+
expect(page).to have_link(current_collection_name, href: "#")
|
22
22
|
end
|
23
|
+
end
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
it "has a valid title" do
|
27
|
+
within "h2" do
|
28
|
+
expect(page).to have_content("#{current_collection_name} documents")
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -7,6 +7,12 @@ describe "Server info", type: :request do
|
|
7
7
|
within(".navbar") { click_link "Server Info" }
|
8
8
|
end
|
9
9
|
|
10
|
+
it "has a valid title" do
|
11
|
+
within "h2" do
|
12
|
+
expect(page).to have_content("server info")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
it "displays information about the server" do
|
11
17
|
within "table" do
|
12
18
|
%w(version gitVersion sysInfo versionArray bits debug maxBsonObjectSize ok).each do |field|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__))
|
2
|
-
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
-
|
4
1
|
require "simplecov"
|
5
|
-
SimpleCov.start do
|
6
|
-
add_group "Application", "lib"
|
7
|
-
end
|
8
2
|
|
9
3
|
require "mongo_browser"
|
10
4
|
|
@@ -14,16 +8,6 @@ require "capybara"
|
|
14
8
|
require "capybara/rspec"
|
15
9
|
require "socket"
|
16
10
|
|
17
|
-
def find_available_port
|
18
|
-
server = TCPServer.new("127.0.0.1", 0)
|
19
|
-
server.addr[1]
|
20
|
-
ensure
|
21
|
-
server.close if server
|
22
|
-
end
|
23
|
-
|
24
|
-
MongoBrowser.mongodb_host = "localhost"
|
25
|
-
MongoBrowser.mongodb_port = find_available_port
|
26
|
-
|
27
11
|
require "capybara/webkit"
|
28
12
|
Capybara.javascript_driver = :webkit
|
29
13
|
|
@@ -34,23 +18,31 @@ Capybara.app = MongoBrowser::Application
|
|
34
18
|
# from spec/support/ and its subdirectories.
|
35
19
|
Dir[File.expand_path("spec/support/**/*.rb")].each { |f| require f }
|
36
20
|
|
21
|
+
test_server = Mongod.instance
|
22
|
+
fixtures = Fixtures.instance
|
23
|
+
|
37
24
|
RSpec.configure do |config|
|
38
|
-
config.include
|
25
|
+
config.include FeatureExampleGroup, type: :request
|
26
|
+
|
27
|
+
# Run test mongod instance and load database fixtures
|
28
|
+
config.before type: :request do
|
29
|
+
test_server.start! do |port|
|
30
|
+
MongoBrowser.mongodb_host = "localhost"
|
31
|
+
MongoBrowser.mongodb_port = port
|
32
|
+
end
|
39
33
|
|
40
|
-
|
41
|
-
MongoTestServer.ensure_test_server_is_running
|
42
|
-
MongoTestServer.load_fixtures
|
34
|
+
fixtures.load!
|
43
35
|
end
|
44
36
|
|
45
|
-
|
46
|
-
|
47
|
-
if example.
|
37
|
+
# Take a screenshot and html dump when the scenario has failed
|
38
|
+
config.after type: :request do
|
39
|
+
if example.exception
|
48
40
|
file_name = example.full_description.downcase.gsub(/\s/, "-")
|
49
|
-
|
41
|
+
capture_page(file_name)
|
50
42
|
end
|
51
43
|
end
|
52
44
|
end
|
53
45
|
|
54
46
|
at_exit do
|
55
|
-
|
47
|
+
test_server.shutdown!
|
56
48
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module FeatureExampleGroup
|
2
2
|
|
3
3
|
def fill_in_filter(value)
|
4
4
|
page.execute_script <<-JS
|
@@ -23,4 +23,26 @@ module Integration
|
|
23
23
|
expect(page).to_not have_css("table.databases")
|
24
24
|
expect(page).to have_content("Nothing has been found.")
|
25
25
|
end
|
26
|
+
|
27
|
+
# Take a screenshot and html dump for the page
|
28
|
+
def capture_page(file_name = Time.now.to_i.to_s)
|
29
|
+
reports_path = File.expand_path("reports/capybara")
|
30
|
+
FileUtils.mkdir_p(reports_path)
|
31
|
+
|
32
|
+
file_path = File.join(reports_path, file_name)
|
33
|
+
|
34
|
+
captured_files = []
|
35
|
+
|
36
|
+
html_file = "#{file_path}.html"
|
37
|
+
File.open(html_file, "w") { |f| f.write(page.body) }
|
38
|
+
captured_files << html_file
|
39
|
+
|
40
|
+
if example.metadata[:js]
|
41
|
+
image_file = "#{file_path}.png"
|
42
|
+
page.driver.render(image_file, full: true)
|
43
|
+
captured_files << image_file
|
44
|
+
end
|
45
|
+
|
46
|
+
captured_files
|
47
|
+
end
|
26
48
|
end
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Fixtures
|
2
|
+
include Singleton
|
3
|
+
|
4
|
+
# Load all fixtures from json file
|
5
|
+
def load!
|
6
|
+
cleanup!
|
7
|
+
|
8
|
+
data = JSON.parse(File.open(File.expand_path("spec/support/fixtures/databases.json"), "r").read)
|
9
|
+
data.each do |database_data|
|
10
|
+
database = connection.db(database_data["name"])
|
11
|
+
|
12
|
+
(database_data["collections"] || []).each do |collection_data|
|
13
|
+
collection = database.create_collection(collection_data["name"])
|
14
|
+
|
15
|
+
(collection_data["documents"] || []).each do |document_data|
|
16
|
+
collection.insert(document_data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Delete all databases
|
23
|
+
def cleanup!
|
24
|
+
connection.database_names.each do |db_name|
|
25
|
+
connection.drop_database(db_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def connection
|
30
|
+
@connection ||= begin
|
31
|
+
Mongo::Connection.new(MongoBrowser.mongodb_host, MongoBrowser.mongodb_port)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
File without changes
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class Mongod
|
2
|
+
include Singleton
|
3
|
+
|
4
|
+
MONGODB_DBPATH = "/tmp/mongo_browser/db"
|
5
|
+
|
6
|
+
attr_reader :port
|
7
|
+
attr_reader :pid
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@port = find_available_port
|
11
|
+
end
|
12
|
+
|
13
|
+
def start!
|
14
|
+
return if running?
|
15
|
+
|
16
|
+
FileUtils.mkdir_p(MONGODB_DBPATH)
|
17
|
+
|
18
|
+
@pid = Mongod.start(port)
|
19
|
+
wait_until_responsive
|
20
|
+
|
21
|
+
yield port if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def shutdown!
|
25
|
+
return unless running?
|
26
|
+
|
27
|
+
Process.kill('HUP', pid)
|
28
|
+
FileUtils.rm_rf(MONGODB_DBPATH)
|
29
|
+
|
30
|
+
@pid = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns true is mongodb server is ready to use
|
34
|
+
def responsive?
|
35
|
+
Mongo::Connection.new(MongoBrowser.mongodb_host, port)
|
36
|
+
true
|
37
|
+
rescue Mongo::ConnectionFailure
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
def running?
|
42
|
+
not pid.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def find_available_port
|
48
|
+
server = TCPServer.new("127.0.0.1", 0)
|
49
|
+
server.addr[1]
|
50
|
+
ensure
|
51
|
+
server.close if server
|
52
|
+
end
|
53
|
+
|
54
|
+
# Starts a core MongoDB daemon on the given port.
|
55
|
+
def self.start(port)
|
56
|
+
command = "mongod --port #{port} --dbpath #{MONGODB_DBPATH} --nojournal"
|
57
|
+
log_file = File.open(File.expand_path("log/test_mongod.log"), "w")
|
58
|
+
|
59
|
+
Process.spawn(command, out: log_file)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Uses exponential back-off technique for waiting for the mongodb server
|
63
|
+
def wait_until_responsive
|
64
|
+
wait_time = 0.01
|
65
|
+
start_time = Time.now
|
66
|
+
timeout = 10
|
67
|
+
|
68
|
+
until responsive?
|
69
|
+
raise "Could not start mongd" if Time.now - start_time >= timeout
|
70
|
+
|
71
|
+
sleep wait_time
|
72
|
+
wait_time *= 2
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_browser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
53
|
+
version: 10.0.1
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 10.0.1
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: mongo
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -229,14 +229,15 @@ extra_rdoc_files: []
|
|
229
229
|
files:
|
230
230
|
- .gitignore
|
231
231
|
- .rspec
|
232
|
+
- .simplecov
|
232
233
|
- .travis.yml
|
233
234
|
- Gemfile
|
234
235
|
- LICENSE
|
235
236
|
- README.md
|
236
|
-
- README.rdoc
|
237
237
|
- Rakefile
|
238
238
|
- app/assets/images/bootstrap/glyphicons-halflings-white.png
|
239
239
|
- app/assets/images/bootstrap/glyphicons-halflings.png
|
240
|
+
- app/assets/images/breadcrumb-separator.png
|
240
241
|
- app/assets/javascripts/app/table_filter.js.coffee
|
241
242
|
- app/assets/javascripts/application.js.coffee
|
242
243
|
- app/assets/javascripts/vendor/bootbox.js
|
@@ -249,7 +250,6 @@ files:
|
|
249
250
|
- app/views/databases/show.erb
|
250
251
|
- app/views/index.erb
|
251
252
|
- app/views/layout.erb
|
252
|
-
- app/views/layout/_breadcrumb.erb
|
253
253
|
- app/views/layout/_flash_messages.erb
|
254
254
|
- app/views/layout/_navbar.erb
|
255
255
|
- app/views/server_info.erb
|
@@ -263,16 +263,19 @@ files:
|
|
263
263
|
- lib/mongo_browser/application.rb
|
264
264
|
- lib/mongo_browser/middleware/sprockets_sinatra.rb
|
265
265
|
- lib/mongo_browser/version.rb
|
266
|
+
- log/.gitkeep
|
266
267
|
- mongo_browser.gemspec
|
267
268
|
- spec/features/collections_list_spec.rb
|
268
269
|
- spec/features/databases_list_spec.rb
|
269
270
|
- spec/features/documents_list_spec.rb
|
270
271
|
- spec/features/server_info_spec.rb
|
271
|
-
- spec/
|
272
|
+
- spec/lib/mongo_browser_spec.rb
|
272
273
|
- spec/spec_helper.rb
|
273
|
-
- spec/support/
|
274
|
-
- spec/support/
|
275
|
-
- spec/support/
|
274
|
+
- spec/support/feature_example_group.rb
|
275
|
+
- spec/support/fixtures.rb
|
276
|
+
- spec/support/fixtures/databases.json
|
277
|
+
- spec/support/matchers/have_flash_message.rb
|
278
|
+
- spec/support/mongod.rb
|
276
279
|
homepage: https://github.com/lucassus/mongo_browser
|
277
280
|
licenses: []
|
278
281
|
post_install_message:
|
@@ -305,9 +308,11 @@ test_files:
|
|
305
308
|
- spec/features/databases_list_spec.rb
|
306
309
|
- spec/features/documents_list_spec.rb
|
307
310
|
- spec/features/server_info_spec.rb
|
308
|
-
- spec/
|
311
|
+
- spec/lib/mongo_browser_spec.rb
|
309
312
|
- spec/spec_helper.rb
|
310
|
-
- spec/support/
|
311
|
-
- spec/support/
|
312
|
-
- spec/support/
|
313
|
+
- spec/support/feature_example_group.rb
|
314
|
+
- spec/support/fixtures.rb
|
315
|
+
- spec/support/fixtures/databases.json
|
316
|
+
- spec/support/matchers/have_flash_message.rb
|
317
|
+
- spec/support/mongod.rb
|
313
318
|
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= mongo_browser - DESCRIBE YOUR GEM
|
2
|
-
|
3
|
-
Author:: YOUR NAME (YOUR EMAIL)
|
4
|
-
Copyright:: Copyright (c) 2012 YOUR NAME
|
5
|
-
|
6
|
-
|
7
|
-
DESCRIBE YOUR GEM HERE
|
8
|
-
|
9
|
-
== Links
|
10
|
-
|
11
|
-
* {Source on Github}[LINK TO GITHUB]
|
12
|
-
* RDoc[LINK TO RDOC.INFO]
|
13
|
-
|
14
|
-
== Install
|
15
|
-
|
16
|
-
== Examples
|
17
|
-
|
18
|
-
== Contributing
|
19
|
-
|
@@ -1,13 +0,0 @@
|
|
1
|
-
<% if params[:db_name] %>
|
2
|
-
<ul class="breadcrumb">
|
3
|
-
<li><a href="/">Databases</a><span class="divider">/</span></li>
|
4
|
-
|
5
|
-
<% unless params[:collection_name] %>
|
6
|
-
<li>db: <%= params[:db_name] %></li>
|
7
|
-
<% else %>
|
8
|
-
<li><a href="/databases/<%= params[:db_name] %>">db: <%= params[:db_name] %></a>
|
9
|
-
<span class="divider">/</span></li>
|
10
|
-
<li>collection: <%= params[:collection_name] %></li>
|
11
|
-
<% end %>
|
12
|
-
</ul>
|
13
|
-
<% end %>
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module MongoTestServer
|
2
|
-
extend self
|
3
|
-
|
4
|
-
MONGODB_DBPATH = "/tmp/mongo_browser/db"
|
5
|
-
|
6
|
-
def ensure_test_server_is_running
|
7
|
-
if `lsof -i :#{MongoBrowser.mongodb_port}`.size == 0
|
8
|
-
clean_up
|
9
|
-
|
10
|
-
FileUtils.mkdir_p(MONGODB_DBPATH)
|
11
|
-
`mongod --port #{MongoBrowser.mongodb_port} --dbpath #{MONGODB_DBPATH} --fork --logpath #{MONGODB_DBPATH}/../db.log`
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def load_fixtures
|
16
|
-
# Delete all databases
|
17
|
-
connection.database_names.each do |db_name|
|
18
|
-
connection.drop_database(db_name)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Load fixtures
|
22
|
-
data = JSON.parse(File.open(File.expand_path("spec/fixtures/databases.json"), "r").read)
|
23
|
-
data.each do |database_data|
|
24
|
-
database = connection.db(database_data["name"])
|
25
|
-
|
26
|
-
(database_data["collections"] || []).each do |collection_data|
|
27
|
-
collection = database.create_collection(collection_data["name"])
|
28
|
-
|
29
|
-
(collection_data["documents"] || []).each do |document_data|
|
30
|
-
collection.insert(document_data)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def connection
|
37
|
-
@connection ||= Mongo::Connection.new(MongoBrowser.mongodb_host, MongoBrowser.mongodb_port)
|
38
|
-
end
|
39
|
-
|
40
|
-
def clean_up
|
41
|
-
out = `ps aux | grep "mongod"`
|
42
|
-
out.lines.each do |line|
|
43
|
-
if line.include?("mongod") and line.include?("--dbpath #{MONGODB_DBPATH}")
|
44
|
-
pid = line.split[1]
|
45
|
-
`kill -9 #{pid}`
|
46
|
-
end
|
47
|
-
end
|
48
|
-
FileUtils.rm_rf("#{MONGODB_DBPATH}/..")
|
49
|
-
end
|
50
|
-
end
|