jeudi 27 août 2015

Rspec & Rails create action testing Rspec

Hey guys I'm trying to test this create method in controller spec :

def create
    @user = User.new(user_params)
    if @user.save
      UserMailer.account_activation(@user).deliver_now
      flash[:info] = "Please check your email to activate your account."
      redirect_to root_url
    else
      render 'new'
    end
  end

I tried this but the user model doesn't seem to increment, in addition I would like to test mailer account activation as well:

  it "creates a new user" do
    expect{
      post :create, user: FactoryGirl.attributes_for(:user)
    }.to change(User,:count).by(1)
  end

Aucun commentaire:

Enregistrer un commentaire