Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8580435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:49:47+00:00 2026-06-11T20:49:47+00:00

I got as far as Listing 9.28. in Michael Hartl’s Ruby on Rails Tutorial,

  • 0

I got as far as Listing 9.28. in Michael Hartl’s Ruby on Rails Tutorial, and I am getting the following errors when running bundle exec rspec spec/. I am not sure how to clear these errors.

$ bundle exec rspec spec/
................................................FF...........FFFFFFFF

Failures:

  1) User pages index profile page 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:29:in `block (4 levels) in <top (required)>'

  2) User pages index profile page 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:29:in `block (4 levels) in <top (required)>'

  3) User pages index edit page 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:95:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:97:in `block (4 levels) in <top (required)>'

  4) User pages index edit page 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:95:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:97:in `block (4 levels) in <top (required)>'

  5) User pages index edit page 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:95:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:97:in `block (4 levels) in <top (required)>'

  6) User pages index edit with valid information 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:95:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:97:in `block (4 levels) in <top (required)>'

  7) User pages index edit with valid information 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:95:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:97:in `block (4 levels) in <top (required)>'

  8) User pages index edit with valid information 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:95:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:97:in `block (4 levels) in <top (required)>'

  9) User pages index edit with valid information 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:95:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:97:in `block (4 levels) in <top (required)>'

  10) User pages index edit with valid information 
     Failure/Error: let(:user) { FactoryGirl.create(:user) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/user_pages_spec.rb:95:in `block (4 levels) in <top (required)>'
     # ./spec/requests/user_pages_spec.rb:97:in `block (4 levels) in <top (required)>'

Finished in 7.29 seconds
69 examples, 10 failures

Failed examples:

rspec ./spec/requests/user_pages_spec.rb:31 # User pages index profile page 
rspec ./spec/requests/user_pages_spec.rb:32 # User pages index profile page 
rspec ./spec/requests/user_pages_spec.rb:102 # User pages index edit page 
rspec ./spec/requests/user_pages_spec.rb:103 # User pages index edit page 
rspec ./spec/requests/user_pages_spec.rb:104 # User pages index edit page 
rspec ./spec/requests/user_pages_spec.rb:118 # User pages index edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:119 # User pages index edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:120 # User pages index edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:121 # User pages index edit with valid information 
rspec ./spec/requests/user_pages_spec.rb:122 # User pages index edit with valid information

My user_pages_spec.rb:

require 'spec_helper'

describe "User pages" do

  subject { page }


describe "index" do
    before do
      sign_in FactoryGirl.create(:user)
      FactoryGirl.create(:user, name: "Bob", email: "bob@example.com")
      FactoryGirl.create(:user, name: "Ben", email: "ben@example.com")
      visit users_path
    end

    it { should have_selector('title', text: 'All users') }


    it "should list each user" do
      User.all.each do |user|
        page.should have_selector('li', text: user.name)
      end

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 page" do
    before { visit signup_path }

    it { should have_selector('h1',    text: 'Sign up') }
    it { should have_selector('title', text: 'Sign up') }
  end

 describe "signup page" do
    before { visit signup_path }

    it { should have_selector('h1',    text: 'Sign up') }
    it { should have_selector('title', text: full_title('Sign up')) }
  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 "error messages" do
        before { click_button submit }

        it { should have_selector('title', text: 'Sign up') }
        it { should have_content('error') }
      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 do
      sign_in user
      visit edit_user_path(user)
    end

    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 valid information" do
      let(:new_name)  { "New Name" }
      let(:new_email) { "new@example.com" }
      before do
        fill_in "Name",             with: new_name
        fill_in "Email",            with: new_email
        fill_in "Password",         with: user.password
        fill_in "Confirm Password", with: user.password
        click_button "Save changes"
      end

      it { should have_selector('title', text: new_name) }
      it { should have_selector('div.alert.alert-success') }
      it { should have_link('Sign out', href: signout_path) }
      specify { user.reload.name.should  == new_name }
      specify { user.reload.email.should == new_email }
    end
    end


  end
end

My spec/requests/authentication_pages_spec.rb Looks like this:

    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_selector('div.flash.error', text: 'Invalid') }

      describe "after visiting another page" do
        before { click_link "Home" }
        it { should_not have_selector('div.flash.error') }
      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('Users',    href: users_path) }
      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

  describe "authorization" do

    describe "for non-signed-in users" do
      let(:user) { Factory(:user) }

      describe "in the Users controller" do

        describe "visiting the edit page" do
          before { visit edit_user_path(user) }
          it { should have_selector('title', text: 'Sign in') }
        end

        describe "submitting to the update action" do
          before { put user_path(user) }
          specify { response.should redirect_to(signin_path) }
        end

        describe "visiting user index" do
          before { visit users_path }
          #it { should have_selector('title', text: 'Sign in') }
        end

      end
    end

    describe "as wrong user" do
      let(:user) { FactoryGirl.create(:user) }
      let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
      before { sign_in user }

      describe "visiting Users#edit page" do
        before { visit edit_user_path(wrong_user) }
        it { should_not have_selector('title', text: full_title('Edit user')) }
      end

      describe "submitting a PUT request to the Users#update action" do
        before { put user_path(wrong_user) }
        specify { response.should redirect_to(root_path) }
      end
    end
  end
end

My users.controller.rb looks like this:

class UsersController < ApplicationController
  before_filter :signed_in_user, only: [:edit, :update]
  before_filter :correct_user,   only: [:edit, :update]

  def index
    @users = User.all
  end

  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])
      flash[:success] = "Profile updated"
      sign_in @user
      redirect_to @user
    else
      render 'edit'
    end
  end

  private

    def signed_in_user
      redirect_to signin_url, notice: "Please sign in." unless signed_in?
    end

    def correct_user
      @user = User.find(params[:id])
      redirect_to(root_path) unless current_user?(@user)
    end

end

sessions.helper.rb:

module SessionsHelper

  def sign_in(user)
    cookies.permanent[:remember_token] = user.remember_token
    self.current_user = user
  end

  def signed_in?
    !current_user.nil?
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
    @current_user ||= User.find_by_remember_token(cookies[:remember_token])
  end

  def current_user?(user)
    user == current_user
  end

  def signed_in_user
    unless signed_in?
      store_location
      redirect_to signin_url, notice: "Please sign in."
    end
  end

  def sign_out
    current_user = nil
    cookies.delete(:remember_token)
  end

  def redirect_back_or(default)
    redirect_to(session[:return_to] || default)
    session.delete(:return_to)
  end

  def store_location
    session[:return_to] = request.url
  end
  end

header.html.erb:

<header class="navbar navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
      <%= link_to "sample app", root_path, id: "logo" %>
      <nav>
        <ul class="nav pull-right">
          <li><%= link_to "Home", root_path %></li>
          <li><%= link_to "Help", help_path %></li>
          <% if signed_in? %>
            <li><%= link_to "Users", users_path %></li>
            <li id="fat-menu" class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                Account <b class="caret"></b>
              </a>
              <ul class="dropdown-menu">
                <li><%= link_to "Profile", current_user %></li>
                <li><%= link_to "Settings", edit_user_path(current_user) %></li>
                <li class="divider"></li>
                <li>
                  <%= link_to "Sign out", signout_path, method: "delete" %>
                </li>
              </ul>
            </li>
          <% else %>
            <li><%= link_to "Sign in", signin_path %></li>
          <% end %>
        </ul>
      </nav>
    </div>
  </div>
</header>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:49:48+00:00Added an answer on June 11, 2026 at 8:49 pm

    Compare the structure of your user_pages_spec.rb with mhartl’s original. You have definitely misplaced some end‘s because the describe "profile page" do and describe "edit" do blocks are embedded in your describe "index" do block when they shouldn’t be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to recreate the Notes application. So far I got the following:
getting text from a .rtf file : this is what i've got so far...
I am following this guide and havent got very far http://www.c-sharpcorner.com/UploadFile/casperboekhoudt/SendingEmailsThroughOutlook12052005000124AM/SendingEmailsThroughOutlook.aspx I am getting
I'm making a facebook app and have got as far as getting the user
I got this far: :~ curl -u username:password -d status=new_status http://twitter.com/statuses/update.xml Now, how can
Here is what I got so far. Please read the comment in the code.
Here is what i've got so far: /(netscape)|(navigator)\/(\d+)(\.(\d+))?/.test(UserAgentString.toLowerCase()) ? ' netscape'+RegExp.$3+RegExp.$4 : '' I'm
Here's what I've got so far: # A. match_ends # Given a list of
Here is what I've got so far.. I'm using this as a keybind. I
I've used some neat example's from attached URL's. What I've got so far is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.