Help write a test for action create
spec / controllers / users_controller_spec.rb

describe '#create' do let(:user) { FactoryGirl.create(:user) } before { post :create, user: user } it { is_expected.to have_http_status :redirect } end 

app / controller / users_controller.rb

  def create @user = User.new(user_params) if @user.save session[:current_user_id] = @user.token redirect_to new_user_profile_path UserMailer.registration_confirmation(@user).deliver_now else flash[:error] = 'some have invalid' render :new end end private def user_params params.require(:user).permit(:email, :password, :password_confirmation) end 

LOG

 andrey@asus:~/dev/note_work$ rspec spec/controllers/users_controller_spec.rb .....F Failures: 1) UsersController#create Failure/Error: params.require(:user).permit(:email, :password, :password_confirmation) NoMethodError: undefined method `permit' for "7":String # ./app/controllers/users_controller.rb:45:in `user_params' # ./app/controllers/users_controller.rb:14:in `create' # ./spec/controllers/users_controller_spec.rb:42:in `block (3 levels) in <top (required)>' Finished in 0.40948 seconds (files took 18.21 seconds to load) 6 examples, 1 failure Failed examples: rspec ./spec/controllers/users_controller_spec.rb:45 # UsersController#create 

    1 answer 1

    Use better attributes_for instead of create by creating a hash for the create user operation.

     describe '#create' do let(:user) { attributes_for(:user) } it 'изменяет счетчик' do expect do post :create, user: new_faq end.to change(User, :count).by(1) end end end 

    You can omit the FactoryGirl in the let-design. In addition, it would be good to bring the contents of the user's factory in the question.

    • Thanks, I understood that I passed the object, when I transferred the attributes, everything went away - Andrey Shostik