spec/base_spec.rb in logworm-0.7.6 vs spec/base_spec.rb in logworm-0.7.7

- old
+ new

@@ -5,10 +5,15 @@ $: << File.dirname(__FILE__) + '/../lib' require 'logworm.rb' describe Logworm::DB, " initialization" do + before do + File.delete(".logworm") if File.exist?(".logworm") + Logworm::Config.instance.reset + end + it "should only accept proper URLs" do lambda {Logworm::DB.new('')}.should raise_exception(Logworm::ForbiddenAccessException) lambda {Logworm::DB.new('http://www.test.com')}.should raise_exception(Logworm::ForbiddenAccessException) lambda {Logworm::DB.new('logworm://a:b@xxx/c/d')}.should raise_exception(Logworm::ForbiddenAccessException) lambda {Logworm::DB.new('logworm://a:b@/c/d/')}.should raise_exception(Logworm::ForbiddenAccessException) @@ -24,13 +29,55 @@ db.consumer_secret.should == "b" db.token.should == "c" db.token_secret.should == "d" end - it "should be able to read its configuration from a file" - it "should be able to read its configuration from the current Heroku application" + it "should be able to read its configuration from a file" do + File.open(".logworm", "w") do |f| + f.puts 'logworm://a:b@localhost:9401/c/d/' + end + db = Logworm::DB.from_config + db.host.should == "localhost:9401" + db.consumer_key.should == "a" + db.consumer_secret.should == "b" + db.token.should == "c" + db.token_secret.should == "d" + end + + it "should fail if no logworm file (and no current Heroku application)" do + db = Logworm::DB.from_config + db.should == nil + end + + # Note that this will fail unless it's run from the command line! + it "should not be nil if we pass a proper app parameter" do + db = Logworm::DB.from_config("lw-client") + db.should_not == nil + db.host.should == "db.logworm.com" + end + + # Note that this will fail unless it's run from the command line! + it "should not use a config file if app is passed" do + File.open(".logworm", "w") do |f| + f.puts 'logworm://a:b@xxx:9401/c/d/' + end + db = Logworm::DB.from_config("lw-client") + db.host.should == "db.logworm.com" # The one from the app, not the config file + end + + # Note that this will fail unless it's run from the command line! + it "should not overwrite a config file if app is passed" do + File.open(".logworm", "w") do |f| + f.puts 'logworm://a:b@xxx:9401/c/d/' + end + db = Logworm::DB.from_config("lw-client") + Logworm::Config.instance.reset + Logworm::Config.instance.read + Logworm::Config.instance.url.should == 'logworm://a:b@xxx:9401/c/d/' + end + end describe Logworm::DB, " functioning" do host = "http://localhost:9401" @@ -57,10 +104,10 @@ @db.query("tbl1", "a good query") end it "should just parse and return the results of the call to query" do return_body = {"id" => 10, "query" => "q", "self_uri" => "/queries/10", "results_uri" => "/queries/10/results"} - stub_request(:post, "#{host}/queries").with(:body => "table=table1&query=q").to_return(:body => return_body.to_json) + stub_request(:post, "#{host}/queries").with(:body => "query=q&table=table1").to_return(:body => return_body.to_json) @db.query("table1", "q").should == return_body end it "should support a call to retrieve the results of a query --> GET /queries/10/results" do @db.should_receive(:db_call).with(:get, "#{host}/queries/10/results")