mongo3 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bnignore +3 -0
- data/.bnsignore +16 -0
- data/.gitignore +1 -0
- data/HISTORY +11 -1
- data/README.rdoc +2 -0
- data/bin/mongo3 +7 -6
- data/config/mongo3.yml +33 -0
- data/data/populate +37 -0
- data/lib/controllers/collections.rb +2 -10
- data/lib/controllers/databases.rb +12 -1
- data/lib/controllers/explore.rb +20 -6
- data/lib/helpers/collection_helper.rb +34 -2
- data/lib/helpers/explore_helper.rb +0 -5
- data/lib/helpers/main_helper.rb +5 -0
- data/lib/helpers/paths_helper.rb +15 -0
- data/lib/mongo3/connection.rb +39 -24
- data/lib/mongo3/user.rb +10 -4
- data/lib/mongo3/zone.rb +24 -8
- data/lib/mongo3.rb +4 -7
- data/lib/public/.DS_Store +0 -0
- data/lib/public/images/favicon.png +0 -0
- data/lib/public/images/information.png +0 -0
- data/lib/public/images/tree/Thumbs.db +0 -0
- data/lib/public/images/tree/array.png +0 -0
- data/lib/public/images/tree/arrow_refresh.png +0 -0
- data/lib/public/images/tree/collapsable-last.gif +0 -0
- data/lib/public/images/tree/collapsable.gif +0 -0
- data/lib/public/images/tree/collection.png +0 -0
- data/lib/public/images/tree/cross.png +0 -0
- data/lib/public/images/tree/disk.png +0 -0
- data/lib/public/images/tree/expandable-last.gif +0 -0
- data/lib/public/images/tree/expandable-last.png +0 -0
- data/lib/public/images/tree/expandable.gif +0 -0
- data/lib/public/images/tree/expandable.png +0 -0
- data/lib/public/images/tree/folder_add.png +0 -0
- data/lib/public/images/tree/folder_delete.png +0 -0
- data/lib/public/images/tree/folder_edit.png +0 -0
- data/lib/public/images/tree/icons.png +0 -0
- data/lib/public/images/tree/leaf-last.gif +0 -0
- data/lib/public/images/tree/leaf-last.png +0 -0
- data/lib/public/images/tree/leaf.gif +0 -0
- data/lib/public/images/tree/leaf.png +0 -0
- data/lib/public/images/tree/line_bg.gif +0 -0
- data/lib/public/images/tree/line_bg_over.gif +0 -0
- data/lib/public/images/tree/line_bg_over_last.gif +0 -0
- data/lib/public/images/tree/minus.gif +0 -0
- data/lib/public/images/tree/page_add.png +0 -0
- data/lib/public/images/tree/page_delete.png +0 -0
- data/lib/public/images/tree/page_edit.png +0 -0
- data/lib/public/images/tree/plus.gif +0 -0
- data/lib/public/images/tree/root.gif +0 -0
- data/lib/public/images/tree/spacer.gif +0 -0
- data/lib/public/images/tree/spinner.gif +0 -0
- data/lib/public/images/tree/tree_line.gif +0 -0
- data/lib/public/javascripts/.DS_Store +0 -0
- data/lib/public/javascripts/jquery.simple.tree.js +451 -0
- data/lib/public/javascripts/jquery.tiptip.min.js +6 -0
- data/lib/public/javascripts/jquery.tree.min.js +1 -0
- data/lib/public/javascripts/jstree/jquery.tree.js +2058 -0
- data/lib/public/javascripts/themes/mongo3/bg.jpg +0 -0
- data/lib/public/javascripts/themes/mongo3/dot_for_ie.gif +0 -0
- data/lib/public/javascripts/themes/mongo3/icons.png +0 -0
- data/lib/public/javascripts/themes/mongo3/style.css +39 -0
- data/lib/public/javascripts/themes/mongo3/throbber.gif +0 -0
- data/lib/public/stylesheets/mongo3.css +201 -65
- data/lib/views/collections/_fields_form.erb +1 -1
- data/lib/views/collections/_index_form.erb +1 -1
- data/lib/views/collections/_index_rows.erb +40 -15
- data/lib/views/collections/_nodes.erb +0 -0
- data/lib/views/collections/_results.erb +4 -4
- data/lib/views/collections/{_rows.erb → _rows_table.erb} +11 -9
- data/lib/views/collections/_rows_tree.erb +81 -0
- data/lib/views/collections/_search_form.erb +1 -1
- data/lib/views/collections/blee.erb +20 -0
- data/lib/views/collections/list.erb +1 -1
- data/lib/views/collections/update.js.erb +1 -1
- data/lib/views/databases/_results.erb +9 -7
- data/lib/views/explore/_node_info.erb +21 -4
- data/lib/views/explore/explore.erb +11 -1
- data/lib/views/explore/load_collection.js.erb +1 -0
- data/lib/views/explore/load_database.js.erb +1 -0
- data/lib/views/layout.erb +13 -7
- data/lib/views/users/_results.erb +2 -2
- data/spec/configs/crap.yml +20 -0
- data/spec/configs/hosed.yml +4 -0
- data/spec/configs/landscape.yml +9 -0
- data/spec/mongo3/connection_spec.rb +105 -12
- data/spec/mongo3/node_spec.rb +38 -0
- data/spec/mongo3/user_spec.rb +72 -0
- data/spec/mongo3/zone_spec.rb +69 -0
- data/spec/mongo3_spec.rb +20 -0
- data/spec/spec_helper.rb +13 -0
- data/tasks/setup.rb +1 -1
- metadata +71 -6
- data/spec/landscape.yml +0 -3
@@ -4,7 +4,7 @@
|
|
4
4
|
<fieldset>
|
5
5
|
<input id="search" type="text" name="search" class="search" value="<%=@query%>"/>
|
6
6
|
<button type="submit" id="submit_button" class="button search" style="display:none">search</button>
|
7
|
-
<img id="search_load" src="/images/loading.gif" style="width:25px;height:25px;vertical-align:sub;display:none"
|
7
|
+
<img id="search_load" src="/images/loading.gif" style="width:25px;height:25px;vertical-align:sub;display:none"/>
|
8
8
|
</fieldset>
|
9
9
|
</form>
|
10
10
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<div class="borders" style="padding:10px;font-size:0.4em">
|
2
|
+
<div id="tree">
|
3
|
+
<ul>
|
4
|
+
<li id="phtml_1" class="open"><a href="#"><ins> </ins>Root node 1</a>
|
5
|
+
<ul>
|
6
|
+
<li id="phtml_2"><a href="#"><ins> </ins>Child node 1</a></li>
|
7
|
+
<li id="phtml_3"><a href="#"><ins> </ins>Child node 2</a></li>
|
8
|
+
<li id="phtml_4"><a href="#"><ins> </ins>Some other child node with longer text</a></li>
|
9
|
+
</ul>
|
10
|
+
</li>
|
11
|
+
<li id="phtml_5"><a href="#"><ins> </ins>Root node 2</a></li>
|
12
|
+
</ul>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<script>
|
17
|
+
$( function() {
|
18
|
+
$('div#tree').tree( { ui: { theme_name: 'apple', theme_path: '/javascripts/themes/apple/style.css'} });
|
19
|
+
});
|
20
|
+
</script>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<div class="title"><%=title_for( session[:path_names] )%></div>
|
7
7
|
|
8
8
|
<div id="mgmt_actions">
|
9
|
-
<img id="action_load" src="/images/loading.gif" style="width:25px;height:25px;vertical-align:sub;display:none"
|
9
|
+
<img id="action_load" src="/images/loading.gif" style="width:25px;height:25px;vertical-align:sub;display:none"/>
|
10
10
|
<button class="action clear" rel="#confirm_clear" title="Delete all records from collection">clear</button>
|
11
11
|
<button class="action drop" rel="#confirm_drop" title="Drop the entire collection">drop</button>
|
12
12
|
</div>
|
@@ -6,18 +6,20 @@
|
|
6
6
|
<div class="borders" style="padding:10px">
|
7
7
|
<table id="cltn" class="cltn" border="0" cellpadding="10" cellspacing="20">
|
8
8
|
<thead>
|
9
|
-
<
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
<tr>
|
10
|
+
<th width="3%"> </th>
|
11
|
+
<% cols = @cltns.first.keys %>
|
12
|
+
<% cols.each do |col| %>
|
13
|
+
<th align="<%=align_for( @cltns.first[col] )%>"><%=col%></th>
|
14
|
+
<% end %>
|
15
|
+
</tr>
|
14
16
|
</thead>
|
15
17
|
<tbody>
|
16
18
|
<% count = 0; @cltns.each do |cltn| %>
|
17
19
|
<tr id="<%=count%>" valign="top">
|
18
20
|
<td id="<%=count%>">
|
19
21
|
<img rel="div#confirm_drop" class="drop" id="<%=cltn[:name]%>" rel="<%=count%>" src="/images/delete.png" title="drop this collection" style="display:none"/>
|
20
|
-
<img class="wait" id="wait_<%=count%>" src="/images/loading.gif"
|
22
|
+
<img class="wait" id="wait_<%=count%>" src="/images/loading.gif"/>
|
21
23
|
</td>
|
22
24
|
<td><a href="/databases/collection/<%=cltn[:name]%>/"><%= cltn[:name] %></a></td>
|
23
25
|
<td align="<%=align_for( cltn[:count] )%>"><%= format_number(cltn[:count]) %></td>
|
@@ -43,7 +45,7 @@
|
|
43
45
|
|
44
46
|
<script>
|
45
47
|
$( function() {
|
46
|
-
$("table#cltn tr" ).hover(
|
48
|
+
$("table#cltn tbody tr" ).hover(
|
47
49
|
function() {
|
48
50
|
$(this).addClass( 'highlight' );
|
49
51
|
$("td#" + $(this).attr('id') + " img.drop" ).show();
|
@@ -25,9 +25,16 @@
|
|
25
25
|
<% unless zone_path?( session[:path_names] ) %>
|
26
26
|
<img id="<%=count%>" rel="div#confirm_drop" class="drop" href="/explore/database/<%=node.oid%>/<%=node.name%>/drop" title="drop <%=legend%>..." src="/images/delete.png"/>
|
27
27
|
<% end %>
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
<% if zone_path?( session[:path_names] ) %>
|
29
|
+
<p rel="#details" href="/explore/info/<%=CGI.escape(node.data[:path_ids])%>/<%=CGI.escape(node.data[:path_names])%>" class="info" title="<%=node.name%>">
|
30
|
+
<%=truncate(node.name, 30)%>
|
31
|
+
</p>
|
32
|
+
<% else %>
|
33
|
+
<p href="/explore/show/<%=CGI.escape(node.data[:path_ids])%>/<%=CGI.escape(node.data[:path_names])%>" class="show" title="<%=node.name%>">
|
34
|
+
<%=truncate(node.name, 30)%>
|
35
|
+
</p>
|
36
|
+
<img class="info" rel="#details" id="<%=count%>" href="/explore/info/<%=CGI.escape(node.data[:path_ids])%>/<%=CGI.escape(node.data[:path_names])%>" title="info for <%=legend%>..." src="/images/information.png"/>
|
37
|
+
<% end %>
|
31
38
|
</div>
|
32
39
|
<% count+=1; end %>
|
33
40
|
</div>
|
@@ -43,6 +50,8 @@
|
|
43
50
|
|
44
51
|
<script>
|
45
52
|
$( function() {
|
53
|
+
$( ".[title]").tipTip( {maxWidth:'auto', edgeOffset:5} );
|
54
|
+
|
46
55
|
$("div.scrollable").scrollable({
|
47
56
|
vertical:true,
|
48
57
|
size: 13,
|
@@ -80,7 +89,15 @@
|
|
80
89
|
});
|
81
90
|
});
|
82
91
|
|
83
|
-
$('div.item p
|
92
|
+
$('div.item p.show').click( function() {
|
93
|
+
$.ajax( {
|
94
|
+
dataType: 'script',
|
95
|
+
type: 'get',
|
96
|
+
url: $(this).attr('href') } );
|
97
|
+
return false;
|
98
|
+
});
|
99
|
+
|
100
|
+
$('div.item .info[rel]').overlay( {
|
84
101
|
top: '15%',
|
85
102
|
expose: '#1c1c1c',
|
86
103
|
onBeforeLoad: function() {
|
@@ -90,6 +90,11 @@
|
|
90
90
|
onCreateLabel: function(domElement, node){
|
91
91
|
domElement.innerHTML = truncate( unescape(node.name), 15 );
|
92
92
|
|
93
|
+
$(domElement).attr('title', node.name );
|
94
|
+
$(domElement).css('z-index', 10 );
|
95
|
+
$(domElement).tipTip( {maxWidth:'auto', edgeOffset:5} );
|
96
|
+
|
97
|
+
|
93
98
|
addEvent(domElement, 'click', function () {
|
94
99
|
var children_count = 0;
|
95
100
|
for( var i in node.adjacencies )
|
@@ -128,7 +133,12 @@
|
|
128
133
|
} });
|
129
134
|
}
|
130
135
|
else {
|
131
|
-
Log.write( "
|
136
|
+
Log.write( "loading collection..." );
|
137
|
+
$.ajax( {
|
138
|
+
dataType: 'script',
|
139
|
+
type: 'GET',
|
140
|
+
url: "/explore/show/" + escape(node.data.path_ids) + "/" + escape(node.data.path_names)
|
141
|
+
});
|
132
142
|
}
|
133
143
|
}
|
134
144
|
});
|
@@ -0,0 +1 @@
|
|
1
|
+
window.location = "/collections/1";
|
@@ -0,0 +1 @@
|
|
1
|
+
window.location = "/databases/1";
|
data/lib/views/layout.erb
CHANGED
@@ -3,24 +3,30 @@
|
|
3
3
|
<head>
|
4
4
|
<title>M O N G O 3</title>
|
5
5
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
6
|
-
<link rel="icon" href="/favicon.
|
7
|
-
<link rel="shortcut icon" href="/favicon.
|
6
|
+
<link rel="icon" href="/images/favicon.png" type="image/x-icon"/>
|
7
|
+
<link rel="shortcut icon" href="/images/favicon.png" type="image/x-icon"/>
|
8
8
|
<%= stylesheets %w[mongo3] %>
|
9
|
-
<%= javascripts %w[jquery_min jquery_ui_min jquery.tools.min application jit.min] %>
|
9
|
+
<%= javascripts %w[jquery_min jquery_ui_min jquery.tools.min application jit.min jquery.tree.min jquery.tiptip.min] %>
|
10
10
|
</head>
|
11
11
|
|
12
12
|
<body id="body">
|
13
13
|
<div id="overall">
|
14
14
|
<div id="logo">
|
15
15
|
<a href="/explore" style="float:left">
|
16
|
-
<img src='/images/mongo3.png'
|
17
|
-
<
|
16
|
+
<img id="logo" src='/images/mongo3.png'/>
|
17
|
+
<div id="version"><%=Mongo3.version%></div>
|
18
18
|
</a>
|
19
|
-
<div class="flash"
|
19
|
+
<div class="flash"></div>
|
20
20
|
</div>
|
21
21
|
<div id="main">
|
22
22
|
<%= yield %>
|
23
23
|
</div>
|
24
24
|
</div>
|
25
25
|
</body>
|
26
|
-
</html>
|
26
|
+
</html>
|
27
|
+
|
28
|
+
<script>
|
29
|
+
$( function() {
|
30
|
+
$( "[title]").tipTip( {maxWidth:'auto', edgeOffset:5} );
|
31
|
+
});
|
32
|
+
</script>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<div class="borders" style="padding:10px">
|
9
9
|
<table id="cltn" class="cltn" border="0" cellpadding="10" cellspacing="20">
|
10
10
|
<thead>
|
11
|
-
<th width="
|
11
|
+
<th width="3%"> </th>
|
12
12
|
<th>Id</th>
|
13
13
|
<th>Name</th>
|
14
14
|
</thead>
|
@@ -43,7 +43,7 @@
|
|
43
43
|
|
44
44
|
<script>
|
45
45
|
$( function() {
|
46
|
-
$("table#cltn tr" ).hover(
|
46
|
+
$("table#cltn tbody tr" ).hover(
|
47
47
|
function() {
|
48
48
|
$(this).addClass( 'highlight' );
|
49
49
|
$("td#" + $(this).attr('id') + " img.drop" ).show();
|
@@ -7,7 +7,7 @@ describe Mongo3::Connection do
|
|
7
7
|
before( :all ) do
|
8
8
|
@con = Mongo::Connection.new( 'localhost', 12345 )
|
9
9
|
@db = @con.db( 'mongo3_test_db', :strict => true )
|
10
|
-
@mongo3 = Mongo3::Connection.new( File.join(File.dirname(__FILE__), %w[.. landscape.yml]) )
|
10
|
+
@mongo3 = Mongo3::Connection.new( File.join(File.dirname(__FILE__), %w[.. configs landscape.yml]) )
|
11
11
|
end
|
12
12
|
|
13
13
|
before( :each ) do
|
@@ -31,6 +31,63 @@ describe Mongo3::Connection do
|
|
31
31
|
@cltn2.insert( {:name => "test_#{i}", :value => i } )
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
describe "configs" do
|
36
|
+
before( :all ) do
|
37
|
+
@crapola = Mongo3::Connection.new( File.join(File.dirname(__FILE__), %w[.. configs crap.yml]) )
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should raise an error on bogus yml" do
|
41
|
+
lambda {
|
42
|
+
con = Mongo3::Connection.new( File.join(File.dirname(__FILE__), %w[.. configs hosed.yml]) )
|
43
|
+
con.send( :config )
|
44
|
+
}.should raise_error( /Unable to grok yaml landscape file/ )
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should crap out if the zone host is missing correctly" do
|
48
|
+
lambda {
|
49
|
+
@crapola.send( :connect_for, "bozo" )
|
50
|
+
}.should raise_error( /Unable to find `host/ )
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should crap out if the zone port is missing correctly" do
|
54
|
+
lambda {
|
55
|
+
@crapola.send( :connect_for, "blee" )
|
56
|
+
}.should raise_error( /Unable to find `port/ )
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should crap out if the zone is not correctly configured" do
|
60
|
+
lambda {
|
61
|
+
@crapola.send( :connect_for, "nowhere" )
|
62
|
+
}.should raise_error( /MongoDB connection failed for `"funky_town"/ )
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "zones" do
|
67
|
+
it "should crap out if the zone does not exist" do
|
68
|
+
lambda {
|
69
|
+
@mongo3.send( :connect_for, "shit for brains" )
|
70
|
+
}.should raise_error( /Unable to find zone/ )
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should connect to a zone with auth correctly" do
|
74
|
+
@mongo3.send( :connect_for, "admin" ) do |con|
|
75
|
+
con.should_not be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "drop database" do
|
81
|
+
it "should drop a database correctly" do
|
82
|
+
dbs = @con.database_names
|
83
|
+
# Quirk? a db does not really exists unless it has a collection
|
84
|
+
db = @con.db( "dead_meat" )
|
85
|
+
db.create_collection( "dead_weight" )
|
86
|
+
@con.database_names.should have( dbs.size + 1 ).items
|
87
|
+
@mongo3.drop_db( "home|test|dead_meat" )
|
88
|
+
@con.database_names.should have( dbs.size ).items
|
89
|
+
end
|
90
|
+
end
|
34
91
|
|
35
92
|
it "should clear out a cltn correctly" do
|
36
93
|
@mongo3.clear_cltn( "home|test|mongo3_test_db|test1_cltn" )
|
@@ -49,13 +106,7 @@ describe Mongo3::Connection do
|
|
49
106
|
@mongo3.drop_cltn( "home|test|mongo3_test_db|test1_cltn" )
|
50
107
|
lambda { @db['test1_cltn'] }.should raise_error( /Collection test1_cltn/ )
|
51
108
|
end
|
52
|
-
|
53
|
-
it "should drop a db correctly" do
|
54
|
-
@mongo3.drop_db( "home|test|mongo3_test_db" )
|
55
|
-
@con.database_names.include?( 'mongo3_test_db' ).should == false
|
56
|
-
@db = @con.db( 'mongo3_test_db', :strict => true )
|
57
|
-
end
|
58
|
-
|
109
|
+
|
59
110
|
it "should load a landscape file correctly" do
|
60
111
|
test = @mongo3.landscape['test']
|
61
112
|
|
@@ -72,10 +123,13 @@ describe Mongo3::Connection do
|
|
72
123
|
root.data[:path_names].should == 'home'
|
73
124
|
|
74
125
|
children = root.children
|
75
|
-
children.should have(
|
76
|
-
children.first.name.should
|
77
|
-
|
78
|
-
children.
|
126
|
+
children.should have(2).item
|
127
|
+
children.first.name.should == 'admin'
|
128
|
+
|
129
|
+
test = children.last
|
130
|
+
test.name.should == 'test'
|
131
|
+
test.oid.should == 'test'
|
132
|
+
test.children.should be_empty
|
79
133
|
end
|
80
134
|
|
81
135
|
describe "#show" do
|
@@ -144,8 +198,31 @@ describe Mongo3::Connection do
|
|
144
198
|
rows.size.should == 4
|
145
199
|
rows.total_entries.should == 4
|
146
200
|
end
|
201
|
+
|
202
|
+
it "should paginate db with regex q correctly" do
|
203
|
+
pending do
|
204
|
+
rows = @mongo3.paginate_cltn( "home|test|mongo3_test_db|test1_cltn", [{"name"=>"\/test_*\/", "value"=>{"$gt"=>5}}, []] )
|
205
|
+
rows.size.should == 4
|
206
|
+
rows.total_entries.should == 4
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
147
210
|
end
|
148
211
|
|
212
|
+
describe "slaves" do
|
213
|
+
it "should differentiate with a zone path" do
|
214
|
+
@mongo3.send( :slave_zone?, %w[home test] ).should == false
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should differentiate with a db path" do
|
218
|
+
@mongo3.send( :slave_zone?, %w[home test fred] ).should == false
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should detect a slave zone correctly" do
|
222
|
+
@mongo3.send( :slave_zone?, %w[home test test] ).should == true
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
149
226
|
describe "indexes" do
|
150
227
|
it "should list indexes correctly" do
|
151
228
|
indexes = @mongo3.indexes_for( "home|test|mongo3_test_db|test1_cltn" )
|
@@ -178,4 +255,20 @@ describe Mongo3::Connection do
|
|
178
255
|
indexes.size.should == before - 1
|
179
256
|
end
|
180
257
|
end
|
258
|
+
|
259
|
+
it "should detect a collection correctly" do
|
260
|
+
@mongo3.send( :cltn_request?, %w[blee duh] ).should == false
|
261
|
+
@mongo3.send( :cltn_request?, %w[blee duh fred] ).should == true
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "#zone_for" do
|
265
|
+
it "should find a zone correctly" do
|
266
|
+
@mongo3.send( :zone_for, "localhost", "12345" ).should == "admin"
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should fail if a zone does not exist" do
|
270
|
+
@mongo3.send( :zone_for, "ghost", 27017 ).should be_nil
|
271
|
+
@mongo3.send( :zone_for, "localhost", 8888 ).should be_nil
|
272
|
+
end
|
273
|
+
end
|
181
274
|
end
|
data/spec/mongo3/node_spec.rb
CHANGED
@@ -99,4 +99,42 @@ describe Mongo3::Node do
|
|
99
99
|
# @dbs.first.to_adjacencies.should ==
|
100
100
|
# [{:adjacencies=>[102, 103, 104, 105], :name=>"db_0", :id=>102, :data=>{:path_ids=>"0|100|102", :path_names=>"root|env_0|db_0"}}, {:adjacencies=>[], :name=>"cltn_0", :id=>102, :data=>{:path_ids=>"0|100|102|102", :path_names=>"root|env_0|db_0|cltn_0"}}, {:adjacencies=>[], :name=>"cltn_1", :id=>103, :data=>{:path_ids=>"0|100|102|103", :path_names=>"root|env_0|db_0|cltn_1"}}, {:adjacencies=>[], :name=>"cltn_2", :id=>104, :data=>{:path_ids=>"0|100|102|104", :path_names=>"root|env_0|db_0|cltn_2"}}, {:adjacencies=>[], :name=>"cltn_3", :id=>105, :data=>{:path_ids=>"0|100|102|105", :path_names=>"root|env_0|db_0|cltn_3"}}]
|
101
101
|
end
|
102
|
+
|
103
|
+
describe "slave node" do
|
104
|
+
before :all do
|
105
|
+
@node = Mongo3::Node.make_node( "fred" )
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should mark a slave node correctly" do
|
109
|
+
@node.mark_slave!
|
110
|
+
@node.data.has_key?( :master ).should == false
|
111
|
+
@node.data[:slave].should == true
|
112
|
+
@node.data['$dim'].should == 15
|
113
|
+
@node.data['$lineWidth'].should == 3
|
114
|
+
@node.data['$color'].should == "#434343"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should detect a slave node correctly" do
|
118
|
+
@node.should be_slave
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "master node" do
|
123
|
+
before :all do
|
124
|
+
@node = Mongo3::Node.make_node( "fred" )
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should mark a master not correctly" do
|
128
|
+
@node.mark_master!
|
129
|
+
@node.data.has_key?( :slave ).should == false
|
130
|
+
@node.data[:master].should == true
|
131
|
+
@node.data['$dim'].should == 15
|
132
|
+
@node.data['$lineWidth'].should == 3
|
133
|
+
@node.data['$color'].should == "#92b948"
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should detect a master node correctly" do
|
137
|
+
@node.should be_master
|
138
|
+
end
|
139
|
+
end
|
102
140
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname(__FILE__), %w[.. spec_helper] ) )
|
2
|
+
require 'ostruct'
|
3
|
+
require 'mongo'
|
4
|
+
|
5
|
+
describe Mongo3::User do
|
6
|
+
|
7
|
+
before( :each ) do
|
8
|
+
@users = Mongo3::User.new( File.join(File.dirname(__FILE__), %w[.. configs landscape.yml] ) )
|
9
|
+
@users.clear!( "home|test" )
|
10
|
+
@users.list( "home|test", 1 ).should have(0).items
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#add" do
|
14
|
+
it "should add users correctly" do
|
15
|
+
result = @users.add( "home|test", "fred", "blee" )
|
16
|
+
result.should_not be_nil
|
17
|
+
@users.list( "home|test", 1 ).should have(1).item
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should crap out if a user exists" do
|
21
|
+
result = @users.add( "home|test", "fred", "blee" )
|
22
|
+
result.should_not be_nil
|
23
|
+
@users.list( "home|test", 1 ).should have(1).item
|
24
|
+
lambda {
|
25
|
+
@users.add( "home|test", "fred", "blee" )
|
26
|
+
}.should raise_error( /User fred already exists!/ )
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should clear out users correctly" do
|
31
|
+
10.times { |i| @users.add( "home|test", "fred_#{i}", "secret" ) }
|
32
|
+
@users.list( "home|test", 1 ).should have(10).items
|
33
|
+
@users.clear!( "home|test" )
|
34
|
+
@users.list( "home|test", 1 ).should have(0).item
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#delete" do
|
38
|
+
it "should delete a user correctly" do
|
39
|
+
user_ids = []
|
40
|
+
10.times { |i| user_ids << @users.add( "home|test", "fred_#{i}", "secret" ) }
|
41
|
+
|
42
|
+
count = 1
|
43
|
+
user_ids.each do |id|
|
44
|
+
result = @users.delete( "home|test", id.to_s )
|
45
|
+
result.should_not be_nil
|
46
|
+
@users.list( "home|test", 1 ).should have(10-count).items
|
47
|
+
count += 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#list" do
|
53
|
+
it "should list users correctly" do
|
54
|
+
users = @users.list( "home|test", 1 )
|
55
|
+
users.should have(0).items
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should paginate users correctly" do
|
59
|
+
10.times { |i| @users.add( "home|test", "fred_#{i}", "secret" ) }
|
60
|
+
users = @users.list( "home|test", 1, 2 )
|
61
|
+
users.should have(2).items
|
62
|
+
users.total_pages.should == 5
|
63
|
+
users.total_entries.should == 10
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "it should rename a user correctly" do
|
68
|
+
pending do
|
69
|
+
@users.rename( "home|test", "fred", "blee" )
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname(__FILE__), %w[.. spec_helper] ) )
|
2
|
+
require 'ostruct'
|
3
|
+
require 'mongo'
|
4
|
+
|
5
|
+
describe Mongo3::Zone do
|
6
|
+
|
7
|
+
before( :each ) do
|
8
|
+
@zones = Mongo3::Zone.new( File.join(File.dirname(__FILE__), %w[.. configs landscape.yml] ) )
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#connect_for" do
|
12
|
+
it "should connect to a zone correctly" do
|
13
|
+
@zones.send( :connect_for, "home|test" ) do |con|
|
14
|
+
con.should_not be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should connect to an admin zone correctly" do
|
19
|
+
@zones.send( :connect_for, "home|admin" ) do |con|
|
20
|
+
con.should_not be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#zone_for" do
|
26
|
+
it "should find a zone correctly" do
|
27
|
+
@zones.send( :zone_for, "localhost", "12345" ).should == "admin"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should fail if a zone does not exist" do
|
31
|
+
@zones.send( :zone_for, "ghost", 27017 ).should be_nil
|
32
|
+
@zones.send( :zone_for, "localhost", 8888 ).should be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "configs" do
|
37
|
+
before( :all ) do
|
38
|
+
@crapola = Mongo3::Zone.new( File.join(File.dirname(__FILE__), %w[.. configs crap.yml]) )
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise an error on bogus yml" do
|
42
|
+
lambda {
|
43
|
+
con = Mongo3::Zone.new( File.join(File.dirname(__FILE__), %w[.. configs hosed.yml]) )
|
44
|
+
con.send( :config )
|
45
|
+
}.should raise_error( /Unable to grok yaml landscape file/ )
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should crap out if the zone host is missing correctly" do
|
49
|
+
lambda {
|
50
|
+
@crapola.send( :connect_for, "home|bozo" )
|
51
|
+
}.should raise_error( /Unable to find `host/ )
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should crap out if the zone port is missing correctly" do
|
55
|
+
lambda {
|
56
|
+
@crapola.send( :connect_for, "home|blee" )
|
57
|
+
}.should raise_error( /Unable to find `port/ )
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should crap out if the zone is not correctly configured" do
|
61
|
+
lambda {
|
62
|
+
@crapola.send( :connect_for, "home|nowhere" )
|
63
|
+
}.should raise_error( /MongoDB connection failed for `funky_town/ )
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
data/spec/mongo3_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
2
|
+
|
3
|
+
describe Mongo3 do
|
4
|
+
before( :all ) do
|
5
|
+
@root = ::File.expand_path( ::File.join(::File.dirname(__FILE__), ".." ) )
|
6
|
+
end
|
7
|
+
|
8
|
+
it "is versioned" do
|
9
|
+
Mongo3.version.should =~ /\d+\.\d+\.\d+/
|
10
|
+
end
|
11
|
+
|
12
|
+
it "generates a correct path relative to root" do
|
13
|
+
Mongo3.path( "mongo3.rb" ).should == ::File.join(@root, "mongo3.rb" )
|
14
|
+
end
|
15
|
+
|
16
|
+
it "generates a correct path relative to lib" do
|
17
|
+
Mongo3.libpath(%w[ mongo3 node.rb]).should == ::File.join( @root, "lib", "mongo3", "node.rb" )
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,5 +7,18 @@ require 'will_paginate/collection'
|
|
7
7
|
|
8
8
|
require File.expand_path( File.join( File.dirname(__FILE__), %w[.. lib mongo3] ) )
|
9
9
|
|
10
|
+
begin
|
11
|
+
Mongo::Connection.new( 'localhost', 12345 )
|
12
|
+
rescue => boom
|
13
|
+
puts "\n"*3
|
14
|
+
puts "<OH SNAP!!>"
|
15
|
+
puts ""
|
16
|
+
puts "To run the tests you need to a local instance of mongodb on port 12345"
|
17
|
+
puts ""
|
18
|
+
puts "> mongodb --dbpath /data/db/mongo3 --port 12345"
|
19
|
+
puts "\n"*3
|
20
|
+
raise "Bailing out"
|
21
|
+
end
|
22
|
+
|
10
23
|
Spec::Runner.configure do |config|
|
11
24
|
end
|
data/tasks/setup.rb
CHANGED
@@ -21,7 +21,7 @@ PROJ = OpenStruct.new(
|
|
21
21
|
:email => nil,
|
22
22
|
:url => "\000",
|
23
23
|
:version => ENV['VERSION'] || '0.0.0',
|
24
|
-
:exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/),
|
24
|
+
:exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/ exps/* \.psd ),
|
25
25
|
:release_name => ENV['RELEASE'],
|
26
26
|
|
27
27
|
# System Defaults
|