Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails Tutorial - Chapter 9: Missing template update
    primarykey
    data
    text
    <p>I just finished <a href="http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users.html#sec-unsuccessful_edits" rel="nofollow">Section 9.3 - Unsuccessful Edits</a> of Michael Hartl's book Ruby on Rails Tutorial. I've been trying for hours to figure out why I can't get the test to pass that checks for an unsuccessful edit.</p> <p>Here is the code I've added for the chapter:</p> <p><strong>spec/requests/authentication_pages_spec.rb</strong></p> <pre><code>require 'spec_helper' describe "Authentication" do subject { page } describe "signin page" do before { visit signin_path } it { should have_selector('h1', text: 'Sign in') } it { should have_selector('title', text: 'Sign in') } end describe "signin" do before { visit signin_path } describe "with invalid information" do before { click_button "Sign in" } it { should have_selector('title', text: 'Sign in') } it { should have_error_message('Invalid') } describe "after visiting another page" do before { click_link "Home" } it { should_not have_error_message } end end describe "with valid information" do let(:user) { FactoryGirl.create(:user) } before { sign_in user } it { should have_selector('title', text: user.name) } it { should have_link('Profile', href: user_path(user)) } it { should have_link('Settings', href: edit_user_path(user)) } it { should have_link('Sign out', href: signout_path) } it { should_not have_link('Sign in', href: signin_path) } describe "followed by signout" do before { click_link "Sign out" } it { should have_link('Sign in') } end end end end </code></pre> <p><strong>spec/requests/user_pages_spec.rb:</strong></p> <pre><code>require 'spec_helper' describe "User pages" do subject { page } describe "signup page" do before { visit signup_path } it { should have_selector('h1', text: 'Sign up') } it { should have_selector('title', text: 'Sign up') } end describe "profile page" do let(:user) { FactoryGirl.create(:user) } before { visit user_path(user) } it { should have_selector('h1', text: user.name) } it { should have_selector('title', text: user.name) } end describe "signup" 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 describe "after submission" do before { click_button submit } it { should have_selector('title', text: 'Sign up') } it { should have_content("Name can't be blank") } it { should have_content("Email can't be blank") } it { should have_content("Email is invalid") } it { should have_content("Password can't be blank") } it { should have_content("Password is too short") } it { should have_content("Password confirmation can't be blank") } 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 describe "after saving the user" do before { click_button submit } let(:user) { User.find_by_email('user@example.com') } it { should have_selector('title', text: user.name) } it { should have_selector('div.alert.alert-success', text: 'Welcome') } it { should have_link('Sign out') } end end end describe "edit" do let(:user) { FactoryGirl.create(:user) } before { visit edit_user_path(user) } describe "page" do it { should have_selector('h1', text: "Update your profile") } it { should have_selector('title', text: "Edit user") } it { should have_link('change', href: 'http://gravatar.com/emails') } end describe "with invalid information" do before { click_button "Save changes" } it { should have_content('error') } end end end </code></pre> <p><strong>spec/support/utilities.rb:</strong></p> <pre><code>include ApplicationHelper def full_title(page_title) base_title = "Ruby on Rails Tutorial Sample App" if page_title.empty? base_title else "#{base_title} | #{page_title}" end end def valid_signin(user) fill_in "Email", with: user.email fill_in "Password", with: user.password click_button "Sign in" end def sign_in(user) visit signin_path fill_in "Email", with: user.email fill_in "Password", with: user.password click_button "Sign in" # Sign in when not using Capybara as well. cookies[:remember_token] = user.remember_token end RSpec::Matchers.define :have_error_message do |message| match do |page| page.should have_selector('div.alert.alert-error', text: message) end end </code></pre> <p><strong>app/controllers/users_controllers.rb:</strong></p> <pre><code>class UsersController &lt; ApplicationController def show @user = User.find(params[:id]) end def new @user = User.new end def create @user = User.new(params[:user]) if @user.save sign_in @user flash[:success] = "Welcome to the Sample App!" redirect_to @user else render 'new' end end def edit @user = User.find(params[:id]) end def update @user = User.find(params[:id]) if @user.update_attributes(params[:user]) # Handle a successful update. else render 'edit' end end end </code></pre> <p><strong>app/models/users.rb</strong></p> <pre><code>class User &lt; ActiveRecord::Base attr_accessible :email, :name, :password, :password_confirmation has_secure_password before_save { self.email.downcase! } before_save :create_remember_token # Validate that a name is not blank and is no longer than50 characters validates :name, presence: true, length: { maximum: 50 } # Validate that an email address is not blank, contains a valid pattern, and # is not already in the database VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } #Validate the password is there and is at least 6 characters validates :password, length: { minimum: 6 }, on: :create validates :password_confirmation, presence: true, on: :create # Everything below this private is only visibile to this user model private # Creates a remember token for the user (not a local variable) # Used to keep a user login active indefinitely after sign in def create_remember_token self.remember_token = SecureRandom.urlsafe_base64 end end </code></pre> <p><strong>app/views/layouts/_header.html.erb</strong></p> <pre><code>&lt;header class="navbar navbar-fixed-top"&gt; &lt;div class="navbar-inner"&gt; &lt;div class="container"&gt; &lt;%= link_to "sample app", root_path, id: "logo" %&gt; &lt;nav&gt; &lt;ul class="nav pull-right"&gt; &lt;li&gt;&lt;%= link_to "Home", root_path %&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to "Help", help_path %&gt;&lt;/li&gt; &lt;% if signed_in? %&gt; &lt;li&gt;&lt;%= link_to "Users", '#' %&gt;&lt;/li&gt; &lt;li id="fat-menu" class="dropdown"&gt; &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt; Account &lt;b class="caret"&gt;&lt;/b&gt; &lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;%= link_to "Profile", current_user %&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to "Settings", edit_user_path(current_user) %&gt;&lt;/li&gt; &lt;li class="divider"&gt;&lt;/li&gt; &lt;li&gt; &lt;%= link_to "Sign out", signout_path, method: "delete" %&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;% else %&gt; &lt;li&gt;&lt;%= link_to "Sign in", signin_path %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/nav&gt; &lt;/div&gt; &lt;/div&gt; &lt;/header&gt; </code></pre> <p><strong>app/views/users/edit.html.erb:</strong></p> <pre><code>&lt;% provide(:title, "Edit user") %&gt; &lt;h1&gt;Update your profile&lt;/h1&gt; &lt;div class="row"&gt; &lt;div class="span6 offset3"&gt; &lt;%= form_for(@user) do |f| %&gt; &lt;%= render 'shared/error_messages' %&gt; &lt;%= f.label :name %&gt; &lt;%= f.text_field :name %&gt; &lt;%= f.label :email %&gt; &lt;%= f.text_field :email %&gt; &lt;%= f.label :password %&gt; &lt;%= f.password_field :password %&gt; &lt;%= f.label :password_confirmation, "Confirm Password" %&gt; &lt;%= f.password_field :password_confirmation %&gt; &lt;%= f.submit "Save changes", class: "btn btn-large btn-primary" %&gt; &lt;% end %&gt; &lt;%= gravatar_for @user %&gt; &lt;a href="http://gravatar.com/emails"&gt;change&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I'm receiving the following errors:</p> <pre><code>Failures: 1) User pages edit with invalid information Failure/Error: before { click_button "Save changes" } ActionView::MissingTemplate: Missing template users/update, application/update with {:locale=&gt;[:en], :formats=&gt;[:html], :handlers=&gt;[:erb, :builder, :coffee]}. Searched in: * "/home/cbachich/Development/rails_projects/sample_app/app/views" # (eval):2:in `click_button' # ./spec/requests/user_pages_spec.rb:79:in `block (4 levels) in &lt;top (required)&gt;' Finished in 2.65 seconds 67 examples, 1 failure Failed examples: rspec ./spec/requests/user_pages_spec.rb:81 # User pages edit with invalid information </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload