require File.expand_path('../spec_helper', __FILE__) require 'yammer/http_adapter' describe Yammer::HttpAdapter do before :all do Yammer.configure do |conf| conf.access_token = 'TolNOFka9Uls2DxahNi78A' end end context "initialization" do context "with user options" do before do @options = { :verify_ssl => false, :max_redirects => 2 } end subject { @conn = Yammer::HttpAdapter.new('https://www.example.com', @options) } it "overrides default options" do expect(subject.instance_variable_get(:"@connection_options")).to eq @options end end context "with invalid url" do it "should raise argument error" do expect { Yammer::HttpAdapter.new('www.example.com') }.to raise_error(ArgumentError) end end end context "with no options" do subject { @conn = Yammer::HttpAdapter.new('https://www.yammer.com') } describe "#scheme" do it "returns the http scheme" do expect(subject.scheme).to eq 'https' end end describe "#host" do it "returns the host server" do expect(subject.host).to eq 'www.yammer.com' end end describe "site_url" do it "returns site_url" do expect(subject.site_url).to eq 'https://www.yammer.com' end end describe "site_url=" do it "sets new site_url on client" do subject.site_url = 'https://www.elpmaxe.com' expect(subject.site_url).to eq 'https://www.elpmaxe.com' end end describe "connection_options=" do it "sets new connection_options" do subject.connection_options = { :max_redirects => 6 } expect(subject.connection_options).to eq({ :max_redirects => 6 }) end it "should raise error" do expect { subject.connection_options = '' }.to raise_error(ArgumentError) end end describe "#absolute_url" do context "with no parameters" do it "returns a uri without path" do expect(subject.send(:absolute_url)).to eq "https://www.yammer.com" end end context "with parameters" do it "returns a uri with path" do expect(subject.send(:absolute_url, '/oauth/v2/authorize')).to eq "https://www.yammer.com/oauth/v2/authorize" end end end end end