Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/2.3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed May 2, 2013
2 parents 2ef6a31 + 41f43a3 commit 5273971
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 53 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## v2.3.5

* Improve "remove server" button and confirmation dialog to clarify that this removes settings but not data.
* Expose server error when adding duplicate collection (or GridFS collection) names.
* [Fix #108][i108] — Don't add servers with malformed (or empty) DSNs.

[i108]: https://github.com/bobthecow/genghis/issues/108


## v2.3.4

* [Fix #100][i100] — Work around backwards compatibility break in `mongo` gem 1.8.4 (Ruby backend).
Expand Down
4 changes: 3 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ Genghis Dependencies

### PHP

You will need [the PECL MongoDB driver](http://www.mongodb.org/display/DOCS/PHP+Language+Center).
You will need at least PHP 5.2 and [the PECL MongoDB driver](http://www.mongodb.org/display/DOCS/PHP+Language+Center).


### Ruby

Genghis requires Ruby 1.8 or awesomer.

The easiest way to install Genghis and all dependencies is via RubyGems:

```
Expand Down
6 changes: 0 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'rake/clean'
require 'rake/packagetask'
require 'yaml'
require 'erb'
require 'less'
Expand Down Expand Up @@ -254,10 +253,5 @@ Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new(:spec)
task :test => :spec

Rake::PackageTask.new('genghis', GENGHIS_VERSION) do |p|
p.need_tar = true
p.package_files.include('genghis.php', 'genghis.rb', '.htaccess', 'README.markdown', 'LICENSE', 'CHANGELOG.markdown')
end

CLEAN.include('tmp/*')
CLOBBER.include('tmp/*', 'genghis.php', 'genghis.rb')
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.4
2.3.5
26 changes: 13 additions & 13 deletions genghis.php

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions genghis.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion genghisapp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'vegas', '~> 0.1.8'
gem.add_dependency 'sinatra', '~> 1.3.3'
gem.add_dependency 'sinatra-contrib', '~> 1.3.1'
gem.add_dependency 'sinatra-mustache', '~> 0.0.4'
gem.add_dependency 'sinatra-mustache', '>= 0.0.4', '< 0.2.0'
gem.add_dependency 'mongo', '~> 1.8.0'
gem.add_dependency 'json', '~> 1.7.0'

Expand Down
23 changes: 17 additions & 6 deletions spec/requests/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,30 @@
end


it 'adds the server but returns an error if the DSN is not valid' do
it 'returns 400 if the DSN is empty' do
res = @api.post do |req|
req.url '/servers'
req.headers['Content-Type'] = 'application/json'
req.body = { name: '' }.to_json
end

res.status.should eq 400
res.body.should match_json_expression \
error: 'Malformed server DSN',
status: 400
end

it 'returns 400 if the DSN is not valid' do
res = @api.post do |req|
req.url '/servers'
req.headers['Content-Type'] = 'application/json'
req.body = { name: 'http://foo/bar' }.to_json
end

res.status.should eq 200
res.status.should eq 400
res.body.should match_json_expression \
id: 'http://foo/bar',
name: 'http://foo/bar',
editable: true,
error: /^Malformed server DSN/
error: 'Malformed server DSN',
status: 400
end
end

Expand Down
14 changes: 9 additions & 5 deletions src/js/genghis/base/views/base_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ Genghis.Views.BaseRow = Backbone.View.extend({
}
});
} else {
new Genghis.Views.Confirm({
var options = {
confirmText: this.destroyConfirmButton(name),
confirm: function() {
model.destroy();
}
});
confirm: function() { model.destroy(); }
};

if (this.destroyConfirmText) {
options.body = this.destroyConfirmText(name);
}

new Genghis.Views.Confirm(options);
}
},
destroyConfirmButton: function(name) {
Expand Down
29 changes: 24 additions & 5 deletions src/js/genghis/views/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,32 @@ Genghis.Views.Collections = Genghis.Views.BaseSection.extend({
if (this.addButton.hasClass('add-gridfs')) {
name = name.replace(/\.(files|chunks)$/, '');

this.collection.create({name: name + '.files'});
this.collection.create({name: name + '.chunks'});
var closeAfterTwo = _.after(2, this.closeAddForm);

this.collection.create({name: name + '.files'}, {
wait: true,
success: closeAfterTwo,
error: function(model, response) {
window.app.alerts.handleError(response);
}
});

this.collection.create({name: name + '.chunks'}, {
wait: true,
success: closeAfterTwo,
error: function(model, response) {
window.app.alerts.handleError(response);
}
});
} else {
this.collection.create({name: name});
this.collection.create({name: name}, {
wait: true,
success: this.closeAddForm,
error: function(model, response) {
window.app.alerts.handleError(response);
}
});
}

this.closeAddForm();
},
showAddForm: function() {
var wrap = this.$('.input-wrapper');
Expand Down
5 changes: 5 additions & 0 deletions src/js/genghis/views/server_row.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Genghis.Views.ServerRow = Genghis.Views.BaseRow.extend({
template: Genghis.Templates.ServerRow,

destroyConfirmText: function(name) {
return 'Remove ' + name + ' from the server list?<br><br>This will not affect any data, and you can add it back at any time.';
},

destroyConfirmButton: function(name) {
return '<strong>Yes</strong>, remove '+name+' from server list';
}
Expand Down
4 changes: 4 additions & 0 deletions src/php/Genghis/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ public function serversAction($method)

case 'POST':
$server = new Genghis_Models_Server($this->getRequestParam('name'));
if ($server->error) {
throw new Genghis_HttpException(400, $server->error);
}

$this->servers[] = $server;

return $server;
Expand Down
1 change: 1 addition & 0 deletions src/php/Genghis/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Genghis_Models_Server implements ArrayAccess, Genghis_JsonEncodable
public $options;
public $default;
public $db;
public $error;

private $connection;
private $databases = array();
Expand Down
2 changes: 1 addition & 1 deletion src/php/Genghis/ServerCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function saveServers()
{
$servers = array();
foreach ($this->servers as $server) {
if (!$server->default) {
if (!$server->default && $server->name) {
$servers[] = $server->dsn;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rb/genghis/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def init_servers(dsn_list, opts={})

def add_server(dsn)
server = Genghis::Models::Server.new(dsn)
raise Genghis::MalformedDocument.new(server.error) if server.error
raise Genghis::ServerAlreadyExists.new(server.name) unless servers[server.name].nil?
servers[server.name] = server
save_servers
Expand Down
5 changes: 3 additions & 2 deletions src/rb/genghis/models/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Models
class Server
attr_reader :name
attr_reader :dsn
attr_reader :error
attr_accessor :default

@default = false
Expand Down Expand Up @@ -30,8 +31,8 @@ def initialize(dsn)
end

@name = name
rescue Mongo::MongoArgumentError => e
@error = "Malformed server DSN: #{e.message}"
rescue Mongo::MongoArgumentError
@error = 'Malformed server DSN'
@name = dsn
end
@dsn = dsn
Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/server_row.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
</td>
{{/ error }}
<td class="action-column">
{{# editable }}<button class="btn btn-mini btn-danger destroy">Remove</button>{{/ editable }}
{{# editable }}<button class="btn btn-mini btn-danger destroy">Remove from list</button>{{/ editable }}
</td>
2 changes: 1 addition & 1 deletion src/templates/partials/servers.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>
<div class="add-form inactive form-horizontal">
<span class="input-append">
<input class="name span4" type="text" size="30"><span class="add-on help" title="user:pass@localhost:27017">?</span>
<input class="name span4" type="text" size="30"><span class="add-on help" title="user:pass@localhost:27017\db">?</span>
</span>
<button class="show btn">Add server</button>
<button class="add btn btn-primary">Add server</button>
Expand Down

0 comments on commit 5273971

Please sign in to comment.