<commit_before>require 'spec_helper_integration'

describe Doorkeeper::TokensController do
  describe "when authorization has succeeded" do
    let :token do
      double(:token, :authorize => true)
    end

    before do
      controller.stub(:token) { token }
    end

    it "returns the authorization" do
      token.should_receive(:authorization)
      post :create
    end
  end

  describe "when authorization has failed" do
    let :token do
      double(:token, :authorize => false)
    end

    before do
      controller.stub(:token) { token }
    end

    it "returns the error response" do
      token.stub(:error_response => stub(:to_json => [], :status => :unauthorized))
      post :create
      response.status.should == 401
    end
  end

  describe "when requesting tokeninfo with valid token" do

    let(:doorkeeper_token) { Factory(:access_token) }

    before(:each) do
      controller.stub(:doorkeeper_token) { doorkeeper_token }  
    end

    def do_get
      get :tokeninfo
    end

    describe "successful request" do

      it "responds with tokeninfo" do
        do_get  
        response.body.should eq doorkeeper_token.to_json
      end

      it "responds with a 200 status" do<commit_msg>changed to new factory girl syntax for create<commit_after>require 'spec_helper_integration'

describe Doorkeeper::TokensController do
  describe "when authorization has succeeded" do
    let :token do
      double(:token, :authorize => true)
    end

    before do
      controller.stub(:token) { token }
    end

    it "returns the authorization" do
      token.should_receive(:authorization)
      post :create
    end
  end

  describe "when authorization has failed" do
    let :token do
      double(:token, :authorize => false)
    end

    before do
      controller.stub(:token) { token }
    end

    it "returns the error response" do
      token.stub(:error_response => stub(:to_json => [], :status => :unauthorized))
      post :create
      response.status.should == 401
    end
  end

  describe "when requesting tokeninfo with valid token" do

    let(:doorkeeper_token) { FactoryGirl.create(:access_token) }

    before(:each) do
      controller.stub(:doorkeeper_token) { doorkeeper_token }  
    end

    def do_get
      get :tokeninfo
    end

    describe "successful request" do

      it "responds with tokeninfo" do
        do_get  
        response.body.should eq doorkeeper_token.to_json
      end

      it "responds with a 200 status" do
{'fraction_non_alphanumeric': 0.0806904857486953, 'fraction_numerical': 0.004817342432757929, 'mean_word_length': 2.7138599105812222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '7138981', 'n_tokens_mistral': 736, 'n_tokens_neox': 696, 'n_words': 222}