I'm following Michael Hartl's lessons on Ruby On Rails Chapter 7. I've finished reading Chapter 7 and followed step by step. However, I'm getting errors but I'm not sure what I've missed.
Failures:
1) User pages signup page with valid information should create a user
Failure/Error: expect { click_button submit }.to change(User, :count).by(1)
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/controllers/users_controller.rb:24:in `user_params'
# ./app/controllers/users_controller.rb:12:in `create'
# ./spec/requests/user_pages_spec.rb:36:in `block (5 levels) in <top (required)>'
# ./spec/requests/user_pages_spec.rb:36:in `block (4 levels) in <top (required)>'
2) User pages signup page with invalid information should not create a user
Failure/Error: expect { click_button submit }.not_to change(User, :count)
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/controllers/users_controller.rb:24:in `user_params'
# ./app/controllers/users_controller.rb:12:in `create'
# ./spec/requests/user_pages_spec.rb:23:in `block (5 levels) in <top (required)>'
# ./spec/requests/user_pages_spec.rb:23:in `block (4 levels) in <top (required)>'
user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_content(user.name) }
it { should have_title(user.name) }
end
describe "signup page" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
flash[:sucess] = "You've successfully created your account!"
redirect_to @user
else
render 'new'
end
end
private
def user_params
params.require.(:user).permit(:name, :email, :password, :password_confirmation)
end
end
views/users/new.html.erb:
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<form>
<div class="row">
<div class="large-6 columns">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "button [radius round]" %>
<% end %>
</div>
</div>
</form>
Result I get when I try to create an account using the signup page:
*No messages are generated.
*Return to users#new page (all the info typed in before are deleted)
*No account created (Even if I enter information with correct format)
--- !ruby/hash:ActionController::Parameters
utf8: ✓
authenticity_token: 87UYaLE5HupPdMf/Q0SCmNnvOGd6SXdRvNTtOOAruJI=
user: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
name: ''
email: ''
password: ''
password_confirmation: ''
commit: Create my account
controller: users
action: new