<commit_before>require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

class Rack::Session::Phony
  def initialize(app); @app = app end
  def call(env)
    env['rack.session'] ||= {}
    @app.call(env)
  end
end

def app
  Rack::Builder.new {
    use Rack::Session::Phony
    use OmniAuth::Builder do
      provider :oauth, :twitter, 'abc', 'def', :site => 'https://api.twitter.com'
      provider :oauth, :linked_in, 'abc', 'def', :site => 'https://api.linkedin.com'
    end
    run lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).params.key?('auth').to_s] }
  }.to_app
end

def session
  last_request.env['rack.session']
end

describe "OmniAuth::Strategies::OAuth" do
  before do
    stub_request(:post, 'https://api.twitter.com/oauth/request_token').
      to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret&oauth_callback_confirmed=true")
    stub_request(:post, 'https://api.twitter.com/oauth/access_token').
      to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
  end
  
  describe '/auth/{name}' do
    before do
      get '/auth/twitter'
    end
    it 'should redirect to authorize_url' do
      last_response.should be_redirect
      last_response.headers['Location'].should == 'https://api.twitter.com/oauth/authorize?oauth_token=yourtoken'
    end
  
    it 'should set appropriate session variables' do
      session[:oauth].should == {:twitter => {:callback_confirmed => true, :request_token => 'yourtoken', :request_secret => 'yoursecret'}}
    end
  end
  <commit_msg>changed Rack endpoint in OAuth spec to return an enumerable body as per the Rack specification<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

class Rack::Session::Phony
  def initialize(app); @app = app end
  def call(env)
    env['rack.session'] ||= {}
    @app.call(env)
  end
end

def app
  Rack::Builder.new {
    use Rack::Session::Phony
    use OmniAuth::Builder do
      provider :oauth, :twitter, 'abc', 'def', :site => 'https://api.twitter.com'
      provider :oauth, :linked_in, 'abc', 'def', :site => 'https://api.linkedin.com'
    end
    run lambda { |env| [200, {'Content-Type' => 'text/plain'}, [Rack::Request.new(env).params.key?('auth').to_s]] }
  }.to_app
end

def session
  last_request.env['rack.session']
end

describe "OmniAuth::Strategies::OAuth" do
  before do
    stub_request(:post, 'https://api.twitter.com/oauth/request_token').
      to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret&oauth_callback_confirmed=true")
    stub_request(:post, 'https://api.twitter.com/oauth/access_token').
      to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
  end
  
  describe '/auth/{name}' do
    before do
      get '/auth/twitter'
    end
    it 'should redirect to authorize_url' do
      last_response.should be_redirect
      last_response.headers['Location'].should == 'https://api.twitter.com/oauth/authorize?oauth_token=yourtoken'
    end
  
    it 'should set appropriate session variables' do
      session[:oauth].should == {:twitter => {:callback_confirmed => true, :request_token => 'yourtoken', :request_secret => 'yoursecret'}}
    end
  end
  
{'fraction_non_alphanumeric': 0.15560358135226923, 'fraction_numerical': 0.0018524235875270144, 'mean_word_length': 4.046728971962617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3623742', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1086, 'n_words': 219}