<commit_before># require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
# 
# def mock_user_session(extra_stubs = {})
#   # unless UserSession.find.nil?
#   #   puts "Getting existing member<br/>"
#   #   @user = UserSession.find.invision_user
#   # else
#   #   puts "Making user from scratch<br/>"
#   #   @user = UserSession.create(InvisionUser.make()).invision_user
#   # end
#   # 
#   # # @user = @current_user = UserSession.find.invision_user
#   # UserSession.stub!(:new).and_return(@user)
# end
# 
# # -----------------------------------------------------------------------------
# # New
# # -----------------------------------------------------------------------------
# 
# # GET /user_session/new
# describe UserSessionsController, "#new" do
#   def get_response
#     get :new
#   end
#   
#   describe "when logged in" do
#     it "should redirect somewhere else" do
#       login
#       UserSession.should_receive(:new).exactly(:once)
#       get_response
#       response.should redirect_to(root_path)
#     end
#   end
#   
#   describe "when logged out" do
#     it "should assign @user_session" do
#       # mock_user_session
#       get_response
#       response.should_not redirect_to(root_url)
#       assigns[:user_session].should_not be_nil
#     end
#   end
# end
# 
# # -----------------------------------------------------------------------------
# # Create
# # -----------------------------------------------------------------------------
# 
# # POST /user_session
# describe UserSessionsController, "#create" do
#   def get_response
#     post :create, :user_session => @params
#   end
#   
#   describe "when logged in" do
#     it "should redirect somewhere else" do
#       login
#       UserSessionsController.should_not_receive(:new)
#       get_response
#       response.should redirect_to(root_path)
#     end
#   end
#   
#   describe "when logged out" do
#     describe "when successful" do
#       before(:each) do
#         # mock_user_session
#         
#         # UserSession.should_receive(:new).at_least(:once).
#         #   and_return(UserSession.create(InvisionUser.make))
#         get_response
#       end
#       
#       # it "should assign @user_session" do
#       #   assigns[:user_session].should_not be_nil
#       # end
#     
#       it "should add a flash success message" do
#         flash[:success].should == 'Login successful!'
#       end
#       
#       it "should redirect back to default of members_url" do
#         response.should redirect_to(members_url)
#       end
#     end
#     
#     describe "when unsuccessful" do
#       it "should render action :new" do
#         # mock_user_session(:save => false)
#         get_response
#         response.should render_template(:new)
#       end
#     end
#   end
# end
# 
# # -----------------------------------------------------------------------------
# # Destroy
# # -----------------------------------------------------------------------------
# 
# # DELETE /user_session
# describe UserSessionsController, "#destroy" do
#   def get_response
#     delete :destroy
#   end
#   
#   describe "when logged in" do
#     before(:each) do
#       login
#       @current_user.should_receive(:destroy)
#       get_response
#     end
#     
#     it "should destroy the current session" do
#     end
#     
#     it "should add a flash success message" do
#       flash[:success].should == 'Logout successful.'
#     end
#     
#     it "should redirect to root_url" do
#       response.should redirect_to(root_url)
#     end
#   end
#   
#   describe "when logged out" do
#     it "should redirect to new_user_session_url" do
#       get_response
#       response.should redirect_to(new_user_session_url)
#     end
#   end
# end<commit_msg>Fix and re-enable UserSessionsController spec<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

# -----------------------------------------------------------------------------
# New
# -----------------------------------------------------------------------------

# GET /user_session/new
describe UserSessionsController, "#new" do
  def get_response
    get :new
  end
  
  describe "when logged in" do
    it "should redirect somewhere else" do
      login
      get_response
      response.should redirect_to(root_path)
    end
  end
  
  describe "when logged out" do
    it "should assign @user_session" do
      get_response
      response.should_not redirect_to(root_url)
      assigns[:user_session].should_not be_nil
    end
  end
end

# -----------------------------------------------------------------------------
# Create
# -----------------------------------------------------------------------------

# POST /user_session
describe UserSessionsController, "#create" do
  def get_response
    post :create, :user_session => {}
  end
  
  describe "when logged in" do
    it "should redirect somewhere else" do
      login
      get_response
      response.should redirect_to(root_path)
    end
  end
  
  describe "when logged out" do
    describe "when successful" do
      before(:each) do
        @user = mock_model(UserSession, :save => true)
        UserSession.stub!(:find).and_return(nil) # current_user_session
        UserSession.should_receive(:new).and_return(@user)
        get_response
      end
      
      it "should assign @user_session" do
        assigns[:user_session].should_not be_nil
      end
    
      it "should add a flash success message" do
        flash[:success].should == 'Login successful!'
      end
      
      it "should redirect back to default of members_url" do
        response.should redirect_to(members_url)
      end
    end
    
    describe "when unsuccessful" do
      it "should render action :new" do
        get_response
        response.should render_template(:new)
      end
    end
  end
end

# -----------------------------------------------------------------------------
# Destroy
# -----------------------------------------------------------------------------

# DELETE /user_session
describe UserSessionsController, "#destroy" do
  def get_response
    delete :destroy
  end
  
  describe "when logged in" do
    before(:each) do
      login
      get_response
    end
    
    # NOTE: I don't know how we should add an expection for should_receive(:destroy)
    # on current_user_session since we can't access that method here
    it "should destroy the current session" do
    end
    
    it "should add a flash success message" do
      flash[:success].should == 'Logout successful.'
    end
    
    it "should redirect to root_url" do
      response.should redirect_to(root_url)
    end
  end
  
  describe "when logged out" do
    it "should redirect to new_user_session_url" do
      get_response
      response.should redirect_to(new_user_session_url)
    end
  end
end
{'fraction_non_alphanumeric': 0.21714369158878505, 'fraction_numerical': 0.0, 'mean_word_length': 1.6352443247402848, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1363970', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1857, 'n_words': 490}