Hello i'm testing the Update action the User Controller using Rspec.
I get this error
1) UsersController POST #update user updated
Failure/Error: patch :update, {id: user.id }, { user_id: user.id }, user: user_params
ActionController::ParameterMissing:
param is missing or the value is empty: user
# /Users/joseph/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0/lib/action_controller/metal/strong_parameters.rb:249:in `require'
# ./app/controllers/users_controller.rb:60:in `user_params'
# ./app/controllers/users_controller.rb:39:in `update'
Weird thing is i used a binding.pry to test whats going on. There is a user and there are user_params
. So i don't understand why i receive the above error.
Please see below for the user and user params.
From: /Users/joseph/Documents/Safsy/Website/Safsy/Safsy/spec/controllers/users_controller_spec.rb @ line 76 :
71: end
72: end
73:
74: describe "POST #update" do
75: it "user updated" do
=> 76: binding.pry
77: patch :update, {id: user.id }, { user_id: user.id }, user: user_params
78: expect(response).to redirect_to(assigns(:user))
79: expect(assigns(:user)).to eq(user)
80: end
81: end
[1] pry(#<RSpec::ExampleGroups::UsersController::POSTUpdate>)> patch :update, {id: user.id }, { user_id: user.id }, user: user_params
ActionController::ParameterMissing: param is missing or the value is empty: user
from /Users/josephkonop/.rvm/gems/ruby-2.1.2/gems/actionpack-4.2.0/lib/action_controller/metal/strong_parameters.rb:249:in `require'
[2] pry(#<RSpec::ExampleGroups::UsersController::POSTUpdate>)> user
=> #<User:0x007fd91fe40458
id: 2,
username: "username2",
email: "user2@factory.com",
created_at: Thu, 08 Oct 2015 11:09:54 UTC +00:00,
updated_at: Thu, 08 Oct 2015 11:09:54 UTC +00:00,
password_digest: "$2a$04$YsvGZ05kdqMoa5fhJlkh1Oa9ISN6wuO7TBCT23vVDS.UO1k.vKTA2",
remember_digest: nil,
admin: false,
activation_digest: "$2a$04$GzFp9Otdlo7l1JBPOTeiQu7NUZELLQSIkLZUd7df1h2p4XpqNXLMm",
activated: true,
activated_at: nil,
reset_digest: nil,
>: nil,
reset_sent_at: nil,
avatar_file_name: nil,
avatar_content_type: nil,
avatar_file_size: nil,
avatar_updated_at: nil,
description: "Corporis odio magni repellendus.",
header_image_file_name: nil,
header_image_content_type: nil,
header_image_file_size: nil,
header_image_updated_at: nil>
[3] pry(#<RSpec::ExampleGroups::UsersController::POSTUpdate>)> user_params
=> {:username=>"username512",
:email=>"user463@factory.com",
:password=>"Password123",
:password_confirmation=>"Password123",
:admin=>false,
:description=>"Nihil eligendi ab debitis iure."}
[4] pry(#<RSpec::ExampleGroups::UsersController::POSTUpdate>)>
here is the User controller
def update
if @user.update_attributes(user_params)
flash[:success] = "Profile updated"
redirect_to @user
else
render 'edit'
end
end
private
def set_user
@user = User.find(params[:id])
end
def user_params
params.require(:user).permit(
:username,
:email,
:password,
:password_confirmation,
:avatar,
:header_image,
:description
)
end
Aucun commentaire:
Enregistrer un commentaire