Skip to content
This repository
tree: 7e750d8ca8
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 60 lines (48 sloc) 1.537 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
require 'test_helper'

class UserTest < ActiveSupport::TestCase
  include Clearance::Test::Unit::UserTest
  
  should_allow_mass_assignment_of :atoken
  should_allow_mass_assignment_of :asecret
  
  context "authorized?" do
    setup do
      @user = User.new
    end
    
    should "be false if missing atoken and asecret" do
      @user.authorized?.should be(false)
    end
    
    should "be false if missing atoken" do
      @user.atoken = nil
      @user.asecret = 'some secret'
      @user.authorized?.should be(false)
    end
    
    should "be false if missing asecret" do
      @user.atoken = 'some token'
      @user.asecret = nil
      @user.authorized?.should be(false)
    end
    
    should "be true if both atoken and asecret present" do
      @user.atoken = 'some token'
      @user.asecret = 'some secret'
      @user.authorized?.should be(true)
    end
  end
  
  should "have oauth helper" do
    user = User.new
    user.oauth.class.should == Twitter::OAuth
  end
  
  context "twitter client object" do
    setup do
      @user = User.new(:atoken => 'atoken', :asecret => 'asecret')
      @oauth = Twitter::OAuth.new('token', 'secret')
      @user.stubs(:oauth).returns(@oauth)
    end

    should "authorize from access token and secret" do
      @user.expects(:oauth).returns(@oauth)
      @oauth.expects(:authorize_from_access).with('atoken', 'asecret').returns(nil)
      @user.client
    end
    
    should "return twitter base object" do
      @user.client.class.should == Twitter::Base
    end
  end
end
Something went wrong with that request. Please try again.