spec/lib/configuration_spec.rb in flexirest-1.2.2 vs spec/lib/configuration_spec.rb in flexirest-1.2.3
- old
+ new
@@ -1,20 +1,24 @@
require 'spec_helper'
describe Flexirest::Configuration do
before :each do
Object.send(:remove_const, :ConfigurationExample) if defined?(ConfigurationExample)
+ Object.send(:remove_const, :SubConfigurationExample) if defined?(SubConfigurationExample)
Flexirest::Base._reset_configuration!
class ConfigurationExample
include Flexirest::Configuration
base_url "http://www.example.com"
username "john"
password "smith"
request_body_type :json
end
+ class SubConfigurationExample < ConfigurationExample
+ end
+
class ConfigurationExampleBare
include Flexirest::Configuration
end
end
@@ -37,10 +41,14 @@
it "should remember the set base_url on a class, overriding a general one" do
Flexirest::Base.base_url = "http://general.example.com"
expect(ConfigurationExample.base_url).to eq("http://www.example.com")
end
+ it "should remember the set base_url on a class, overriding a general one" do
+ expect(SubConfigurationExample.base_url).to eq("http://www.example.com")
+ end
+
it "should remove a trailing slash from a globally configured base_url" do
Flexirest::Base.base_url = "http://general.example.com/"
expect(ConfigurationExample.base_url).to eq("http://www.example.com")
Flexirest::Base.base_url = ""
end
@@ -67,10 +75,14 @@
Flexirest::Base.username = "bill"
expect(ConfigurationExample.username).to eq("john")
Flexirest::Base.username = nil
end
+ it "should remember the set username on a class, overriding a general one" do
+ expect(SubConfigurationExample.username).to eq("john")
+ end
+
it "should escape the username" do
Flexirest::Base.username = "bill@example.com"
expect(Flexirest::Base.username).to eq("bill%40example.com")
Flexirest::Base.username = nil
end
@@ -89,10 +101,14 @@
Flexirest::Base.password = "bloggs"
expect(ConfigurationExample.password).to eq("smith")
Flexirest::Base.password = nil
end
+ it "should remember the set password on a class, overriding a general one" do
+ expect(SubConfigurationExample.password).to eq("smith")
+ end
+
it "should escape the password" do
Flexirest::Base.password = "something@else"
expect(Flexirest::Base.password).to eq("something%40else")
Flexirest::Base.password = nil
end
@@ -109,13 +125,17 @@
it "should remember the request_body_type" do
expect(ConfigurationExample.request_body_type).to eq(:json)
end
- it "should remember the set base_url on a class, overriding a general one" do
+ it "should remember the set request_body_type on a class, overriding a general one" do
Flexirest::Base.request_body_type = :unknown
expect(Flexirest::Base.request_body_type).to eq(:unknown)
expect(ConfigurationExample.request_body_type).to eq(:json)
+ end
+
+ it "should remember the set username on a class, overriding a general one" do
+ expect(SubConfigurationExample.request_body_type).to eq(:json)
end
it "should default to non-lazy loading" do
class LazyLoadingConfigurationExample1
include Flexirest::Configuration