Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding the need db check for other commands and tests

  • Loading branch information...
commit 91ac9da705e3a4c0eaeff15d1869cf2ffc8ac6e8 1 parent ed21293
@sreeix authored
View
3  lib/couchup/commands/drop.rb
@@ -4,11 +4,10 @@ class Drop
include ::Couchup::CommandExtensions
def run(*params)
op_type = params.shift.to_s
- (params.first.nil? ? Couchup.database : Couchup.new_database(params.first)).delete! if op_type == 'database'
+ (params.first.nil? ? Couchup.database : Couchup.new_database(params.first.to_s)).delete!
::Couchup::View.new(params.first).delete! if op_type == 'view'
Couchup.delete_doc(params.first) if op_type == 'doc'
Couchup.delete_all_docs(params.first) if op_type == 'all_docs'
-
end
def self.describe
View
2  lib/couchup/commands/get.rb
@@ -1,7 +1,9 @@
module Couchup
module Commands
class Get
+ include ::Couchup::CommandExtensions
def run(id = nil)
+ needs_db!
match = id.nil? ? Couchup.all.collect{|c| c["doc"]} : Couchup.get(id)
ap match
match
View
2  lib/couchup/commands/replicate_to.rb
@@ -1,9 +1,11 @@
module Couchup
module Commands
class ReplicateTo
+ include ::Couchup::CommandExtensions
def run(*params)
dest = params.shift
option = params.shift
+ needs_db!
dest_db = (dest =~ /(http\w:\/\/.*)\/(.*)/) ? CouchRest::Database.new(CouchRest::Server.new($1), $2) : CouchRest::Database.new(Couchup.server, dest)
Couchup.database.replicate_to dest_db, (option.to_s == "continous")
end
View
2  lib/couchup/commands/show.rb
@@ -1,11 +1,13 @@
module Couchup
module Commands
class Show
+ include ::Couchup::CommandExtensions
def run(*param)
option = param.first.to_s
if(option.blank? || option == 'databases' )
ap Couchup.databases
else
+ needs_db!
ap Couchup.views(param.second)
end
end
View
7 spec/commands/compact_spec.rb
@@ -14,8 +14,11 @@ module Commands
it "should fail when on no database" do
Couchup.database = nil
- res = Compact.new.run()
- res.should be_nil
+ begin
+ Compact.new.run()
+ fail("Expected compact to fail")
+ rescue ArgumentError => e
+ end
end
end
View
7 spec/commands/use_spec.rb
@@ -3,10 +3,11 @@
module Couchup
module Commands
describe Use do
- it "stays on the same databse if db does not exist" do
- res = Use.new.run(TEST_DATABASE)
+ it "stays on the same database if db does not exist" do
+ Couchup.database.name.should == TEST_DATABASE
+ res = Use.new.run("xxxxxx")
res.should be_nil
- # Couchup.database.name.should == TEST_DATABASE
+ Couchup.database.name.should == TEST_DATABASE
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.