<commit_before>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

require File.join(File.dirname(__FILE__), "..", "spec_helper")

describe RegistrationsController do
  include Devise::TestHelpers

  render_views

  before do
    request.env["devise.mapping"] = Devise.mappings[:user]
    @valid_params = {"user" => {"username" => "jdoe",
                                "email" => "<EMAIL>",
                                "password" => "password",
                                "password_confirmation" => "password"}}
  end

  describe "#create" do
    context "with valid parameters" do
      before do
        user = Factory.build(:user)
        User.stub!(:build).and_return(user)
      end
      it "creates a user" do
        lambda { get :create, @valid_params }.should change(User, :count).by(1)
      end
      it "assigns @user" do
        get :create, @valid_params
        assigns(:user).should_not be_nil
      end
      it "sets the flash" do
        get :create, @valid_params
        flash[:notice].should_not be_empty
      end
      it "redirects to the root path" do
        get :create, @valid_params
        response.should redirect_to root_path
      end
    end
    context "with invalid parameters" do
      before do
        @valid_params["user"]["password_confirmation"] = "<PASSWORD>"
        @invalid_params = @valid_params
        user = Factory.build(:user)
        user.stub!(:save){user.errors.add_to_base("hello"); false}
        User.stub!(:build).and_return(user)
      end
      it "does not create a user" do
        lambda { get :create, @invalid_params }.should_not change(User, :count)
      end
      it "assigns @user" do
        get :create, @invalid_params<commit_msg>Get rid of deprecation warning<commit_after>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

require File.join(File.dirname(__FILE__), "..", "spec_helper")

describe RegistrationsController do
  include Devise::TestHelpers

  render_views

  before do
    request.env["devise.mapping"] = Devise.mappings[:user]
    @valid_params = {"user" => {"username" => "jdoe",
                                "email" => "<EMAIL>",
                                "password" => "password",
                                "password_confirmation" => "password"}}
  end

  describe "#create" do
    context "with valid parameters" do
      before do
        user = Factory.build(:user)
        User.stub!(:build).and_return(user)
      end
      it "creates a user" do
        lambda { get :create, @valid_params }.should change(User, :count).by(1)
      end
      it "assigns @user" do
        get :create, @valid_params
        assigns(:user).should_not be_nil
      end
      it "sets the flash" do
        get :create, @valid_params
        flash[:notice].should_not be_empty
      end
      it "redirects to the root path" do
        get :create, @valid_params
        response.should redirect_to root_path
      end
    end
    context "with invalid parameters" do
      before do
        @valid_params["user"]["password_confirmation"] = "<PASSWORD>"
        @invalid_params = @valid_params
        user = Factory.build(:user)
        user.stub!(:save){user.errors.add(:base, "hello"); false}
        User.stub!(:build).and_return(user)
      end
      it "does not create a user" do
        lambda { get :create, @invalid_params }.should_not change(User, :count)
      end
      it "assigns @user" do
        get :create, @invalid_params
{'fraction_non_alphanumeric': 0.11001642036124795, 'fraction_numerical': 0.003284072249589491, 'mean_word_length': 2.3227272727272728, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '6264980', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1062, 'n_words': 304}