Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def test_hate_method_should_record_vote
- initial_vote_count = Vote.count
- post :hate, { :id => 2 }, { :user => 7 }
- assert_equal initial_vote_count + 1, Vote.count
- end
- # before the method hate runs it must be authenticated with login_required from lib/authenticated_system.rb
- def login_required
- username, passwd = get_auth_data
- # I think the get_auth_data might be creating the error
- self.current_user ||= User.authenticate(username, passwd) || :false if username && passwd
- return true if logged_in? && authorized?
- respond_to do |accepts|
- accepts.html do
- session[:return_to] = request.request_uri
- redirect_to :controller => 'account', :action => 'login'
- end
- accepts.xml do
- headers["Status"] = "Unauthorized"
- headers["WWW-Authenticate"] = %(Basic realm="Web Password")
- render :text => "Could't authenticate you", :status => '401 Unauthorized'
- end
- end
- false
- end
- def get_auth_data
- user, pass = nil, nil
- # extract authorisation credentials
- if request.env.has_key? 'X-HTTP_AUTHORIZATION'
- # try to get it where mod_rewrite might have put it
- authdata = request.env['X-HTTP_AUTHORIZATION'].to_s.split
- elsif request.env.has_key? 'HTTP_AUTHORIZATION'
- # this is the regular location
- authdata = request.env['HTTP_AUTHORIZATION'].to_s.split
- end
- # at the moment we only support basic authentication
- if authdata && authdata[0] == 'Basic'
- user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
- end
- return [user, pass]
- end
Add Comment
Please, Sign In to add comment