<commit_before>require 'spec_helper'
require 'ruby-debug'

describe SessionsController do
  describe "POST index" do
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      @user = FactoryGirl.create(:user)
    end

    it "fails when bad credentials are supplied" do
      user = @user.email
      pw = '<PASSWORD>'
      @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)

      xhr :post, :create
      response.status.should == 401
    end

    it "receives an auth token on success" do
      user = @user.email
      pw = 'password'      # don't use user.password since it should get deleted in the model
      @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)

      xhr :post, :create
      response.status.should == 200
      result = ActiveSupport::JSON.decode(response.body)
      result['user']['email'].should == user
      result['authentication_token'].should be_present
    end

    it "fails with a bad token" do
      user = @user.email
      token = @user.authentication_token

      xhr :post, :create, :user => user, :auth_token => "this is a bad token"
      response.status.should == 401
    end

    it "can auth with a user's token" do
      user = @user.email
      token = @user.authentication_token

      xhr :post, :create, :user => user, :auth_token => token
      response.status.should == 200
      result = ActiveSupport::JSON.decode(response.body)
      result['user']['email'].should == user
      result['authentication_token'].should == token
    end
  end
end<commit_msg>don't auth witht the user/token, only token is needed<commit_after>require 'spec_helper'
require 'ruby-debug'

describe SessionsController do
  describe "POST index" do
    before(:each) do
      @request.env["devise.mapping"] = Devise.mappings[:user]
      @user = FactoryGirl.create(:user)
    end

    it "fails when bad credentials are supplied" do
      user = @user.email
      pw = '<PASSWORD>'
      @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)

      xhr :post, :create
      response.status.should == 401
    end

    it "receives an auth token on success" do
      user = @user.email
      pw = 'password'      # don't use user.password since it should get deleted in the model
      @request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)

      xhr :post, :create
      response.status.should == 200
      result = ActiveSupport::JSON.decode(response.body)
      result['user']['email'].should == user
      result['authentication_token'].should be_present
    end

    it "fails with a bad token" do
      user = @user.email
      token = @user.authentication_token

      xhr :post, :create, :auth_token => "this is a bad token"
      response.status.should == 401
    end

    it "can auth with a user's token" do
      user = @user.email
      token = @user.authentication_token

      xhr :post, :create, :auth_token => token
      response.status.should == 200
      result = ActiveSupport::JSON.decode(response.body)
      result['user']['email'].should == user
      result['authentication_token'].should == token
    end
  end
end
{'fraction_non_alphanumeric': 0.11448317307692307, 'fraction_numerical': 0.007211538461538462, 'mean_word_length': 3.130272952853598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3393614', 'n_tokens_mistral': 1011, 'n_tokens_neox': 953, 'n_words': 263}