public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Piotr Jakubowski (author)
Tue Jul 01 00:31:01 -0700 2008
Michael Hartl (committer)
Tue Jul 01 12:17:04 -0700 2008
commit  a886e7db53c67e7da3b270f6030c8d8ce22635fa
tree    c73f847f9f83a806ae92a18f4d25e0bc1b6d2c48
parent  96ca20f62dd7ecd9b0c2cd608749f51e766a5631
insoshi / lib / authenticated_test_helper.rb
100644 35 lines (32 sloc) 1.058 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
module AuthenticatedTestHelper
  # Sets the current person in the session from the person fixtures.
  # Returns the person to allow @person = login_as(:quentin) construction.
  def login_as(person)
    if person.is_a?(Person)
      id = person.id
    elsif person.is_a?(Symbol)
      person = people(person)
      id = person.id
    elsif person.nil?
      id = nil
    end
    # Stub out the controller if it's defined.
    # This means, e.g., that if a spec defines mocked-out photos for a person,
    # it current_person.photos will have the right assocation.
    if defined?(controller)
      controller.stub!(:current_person).and_return(person)
    else
      @request.session[:person_id] = id
    end
    person
  end
 
  def logout
    @request.session[:person_id] = nil
    if defined?(controller)
      controller.stub!(:current_person).and_return(:false)
    end
  end
 
  def authorize_as(user)
    @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).login, 'test') : nil
  end
end