<commit_before>require 'rails_helper'

describe UsersController do


  before(:each) do
    User.destroy_all
    @user = FactoryGirl.create(:user, :email => '<EMAIL>',
                                          :password => 'password',
                                          :password_confirmation => 'password',
                                          :oauth_token => 'a_token',
                                          :oauth_secret => 'a_secret')
  end

  it "should authenticate user successfully with given credentials" do
    expect(@user).to be_app_authorized
    post :authenticate, :email => '<EMAIL>', :password => 'password'
    expect(response.code).to eq('200')
  end

  it "should authenticate user successfully but app not connected" do
    @user.oauth_token = nil
    @user.oauth_secret = nil
    @user.save!
    expect(@user).not_to be_app_authorized
    post :authenticate, :email => '<EMAIL>', :password => 'password'
    expect(response.code).to eq('403')
    expect(response.body).to match /Application needs to be authorized/
  end

  it "should not authenticate user with wrong credentials" do
    post :authenticate, :email => '<EMAIL>', :password => '<PASSWORD>'
    expect(response.code).to eq('400')
  end

  context "widget" do
    let(:user){
      FactoryGirl.create(:user, :email => '<EMAIL>',
                                            :password => 'password',
                                            :password_confirmation => 'password',
                                            :oauth_token => 'a_token',
                                            :oauth_secret => 'a_secret')
    }

    before :each do
      sign_in user
    end

    it "will be assigned to the current user" do
      get :widgets
      expect(response.code).to eq('200')
      expect(assigns(:widget))
    end

  end
end<commit_msg>Add a regression test for #422.<commit_after>require 'rails_helper'

describe UsersController do


  before(:each) do
    User.destroy_all
    @user = FactoryGirl.create(:user, :email => '<EMAIL>',
                                          :password => 'password',
                                          :password_confirmation => 'password',
                                          :oauth_token => 'a_token',
                                          :oauth_secret => 'a_secret')
  end

  it "should authenticate user successfully with given credentials" do
    expect(@user).to be_app_authorized
    post :authenticate, :email => '<EMAIL>', :password => 'password'
    expect(response.code).to eq('200')
  end

  it "should authenticate user successfully but app not connected" do
    @user.oauth_token = nil
    @user.oauth_secret = nil
    @user.save!
    expect(@user).not_to be_app_authorized
    post :authenticate, :email => '<EMAIL>', :password => 'password'
    expect(response.code).to eq('403')
    expect(response.body).to match /Application needs to be authorized/
  end

  it "should not authenticate user with wrong credentials" do
    post :authenticate, :email => '<EMAIL>', :password => '<PASSWORD>'
    expect(response.code).to eq('400')
  end

  it "should reset a users authentication token when requested" do
    sign_in @user
    old_token = @user.authentication_token
    post :reset_token
    expect(@user.reload.authentication_token).not_to eq(old_token)
  end

  context "widget" do
    let(:user){
      FactoryGirl.create(:user, :email => '<EMAIL>',
                                            :password => 'password',
                                            :password_confirmation => 'password',
                                            :oauth_token => 'a_token',
                                            :oauth_secret => 'a_secret')
    }

    before :each do
      sign_in user
    end

    it "will be assigned to the current user" do
      get :widgets
      expect(response.code).to eq('200')
      expect(assigns(:widget))
    end

  end
end
{'fraction_non_alphanumeric': 0.10933536276002029, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 1.9035346097201766, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3857906', 'n_tokens_mistral': 1047, 'n_tokens_neox': 996, 'n_words': 283}