Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f4cb3b826b
Fetching contributors…

Cannot retrieve contributors at this time

file 29 lines (25 sloc) 1.221 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe GoogleAnalyticsFeeds::Session do
  it "raises an AuthenticationError if login is not a success" do
    connection = stub(:connection, :post => stub(:response, :success? => false))
    expect {
      described_class.new(connection).login('name', 'password')
    }.to raise_error(GoogleAnalyticsFeeds::AuthenticationError)
  end

  it "sets and returns a token if login is a success" do
    connection = stub(:connection, :post => stub(:response, :success? => true, :body => "Auth=MYTOKEN"))
    described_class.new(connection).login('name', 'password').should == "MYTOKEN"
  end

  it "posts the username and email to Google Analytics" do
    connection = mock(:connection)
    connection.should_receive(:post).
      with("https://www.google.com/accounts/ClientLogin",
           'Email' => 'me@example.com',
           'Passwd' => 'password',
           'accountType' => 'HOSTED_OR_GOOGLE',
           'service' => 'analytics',
           'source' => 'ruby-google-analytics-feeds').
      and_return(stub(:response, :success? => true, :body => "Auth=MYTOKEN"))

    described_class.new(connection).login('me@example.com', 'password')
  end
end
Something went wrong with that request. Please try again.