spec/whm/server_spec.rb in lumberg-1.1.1 vs spec/whm/server_spec.rb in lumberg-2.0.0.pre3
- old
+ new
@@ -14,11 +14,11 @@
it "should setup host and hash" do
@whm.hash.should == @login[:hash]
@whm.host.should == @login[:host]
end
- it "should set the url" do
+ it "sets the url" do
@whm.base_url.should == "https://#{@login[:host]}:2087/json-api/"
end
it "should default to 'root' as the username" do
@whm.user.should == 'root'
@@ -35,12 +35,29 @@
it "should allow setting of basic_auth" do
@whm = Whm::Server.new(@login.merge(:basic_auth => true))
@whm.basic_auth.should be_true
end
+
+ it "raises message for invalid domain" do
+ Resolv.stub(:getaddress).and_raise(Resolv::ResolvError)
+ expect do
+ Whm::Server.new(:host => "nxdomain.tld", :hash => "")
+ end.to raise_error(
+ Lumberg::WhmArgumentError, "Unable to resolve nxdomain.tld"
+ )
+ end
end
+ describe "setting timeout" do
+ it "allows setting of timeout" do
+ Whm::Server.new(
+ @login.merge(:timeout => 1000)
+ ).timeout.should == 1000
+ end
+ end
+
describe "#format_url" do
it "converts the host into an SSL URL by default" do
@whm.send(:format_url).should == "https://myhost.com:2087/json-api/"
end
@@ -55,12 +72,12 @@
end
end
describe "#format_hash" do
it "raises an error if hash is not a string" do
- expect{ Whm::Server.new(:host => @whm_host, :hash => nil) }.to
- raise_error(Lumberg::WhmArgumentError, "Missing WHM hash")
+ expect{ Whm::Server.new(:host => @whm_host, :hash => nil) }.
+ to raise_error(Lumberg::WhmArgumentError, "Missing WHM hash")
end
it "removes \\n's from the hash" do
hash = "my\nhash\n\n\n\n"
@whm = Whm::Server.new(:host => @whm_host, :hash => hash)
@@ -119,10 +136,42 @@
@whm.ssl_verify = false
@whm.ssl_verify.should be(false)
end
end
+ describe "@timeout" do
+ it "is nil by default" do
+ @whm.timeout.should be_nil
+ end
+
+ describe "setting HTTP timeout" do
+ let(:net_http) { double(Net::HTTP).as_null_object }
+
+ use_vcr_cassette "whm/server/applist"
+
+ before(:each) do
+ Net::HTTP.stub(:new) { net_http }
+ end
+
+ it "sets HTTP timeout when assigned" do
+ @whm.timeout = 1000
+
+ net_http.should_receive(:read_timeout=).with(1000)
+ net_http.should_receive(:open_timeout=).with(1000)
+
+ @whm.perform_request("applist")
+ end
+
+ it "uses default HTTP timeout when not assigned" do
+ net_http.should_not_receive(:read_timeout=)
+ net_http.should_not_receive(:open_timeout=)
+
+ @whm.perform_request("applist")
+ end
+ end
+ end
+
context "calling applist" do
use_vcr_cassette "whm/server/applist"
it "sets a response message" do
@whm = Whm::Server.new(:host => @whm_host, :hash => @whm_hash)
@@ -181,10 +230,19 @@
result[:params].size.to_i.should == 19
result[:params].should include "english"
end
end
+ describe "#themes" do
+ use_vcr_cassette "whm/server/themes"
+
+ it "returns list of themes" do
+ result = @whm.themes
+ result[:params].should include :x3
+ end
+ end
+
describe "#account" do
it "has an account accessor" do
@whm.account.should be_an(Whm::Account)
end
@@ -245,9 +303,27 @@
describe "#set_hostname" do
use_vcr_cassette "whm/server/sethostname"
it "changes the server's hostname" do
result = @whm.set_hostname(:hostname => "myhost.com")
+ result[:success].should be_true
+ end
+ end
+
+ describe "#get_tweaksetting" do
+ use_vcr_cassette "whm/server/gettweaksetting"
+
+ it "gets a tweak setting" do
+ result = @whm.get_tweaksetting(:key => 'skipwebalizer')
+ result[:success].should be_true
+ end
+ end
+
+ describe "#set_tweaksetting" do
+ use_vcr_cassette "whm/server/settweaksetting"
+
+ it "sets a tweak setting" do
+ result = @whm.set_tweaksetting(:key => 'skipwebalizer', :value => 0)
result[:success].should be_true
end
end
describe "#set_resolvers" do