开发者

Ruby On Rails Tutorial 10.3.1 User Index

The sample test has names that will not pass validation.

require 'spec_helper'

describe UsersController do
  render_views

  describe "GET 'index'" do


    describe "for signed-in users" do

      before(:each) do
        @user = test_sign_in(Factory(:user))
        second = Factory(:user, :name => "Bob", :email => "another@example.com")
        third  = Factory(:user, :name => "Ben", :email => "another@example.net")

        @users = [@user, second, third]
      end

      it "should be successful" do
        get :index
        response.should be_success
      end

      it "should have the right title" do
        get :index
        response.should have_selector("title", :content => "All users")
      end

      it "should have an element for each user" do
        get :index
        @users.each do |user|
          response.should开发者_开发百科 have_selector("li", :content => user.name)
        end
      end
    end
  end
  .
  .
  .
end

The name has to be six characters long. Bob and Ben will not pass.

class User < ActiveRecord::Base
  attr_accessor :password
  attr_accessible :name, :email,:password,:password_confirmation

  email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates :name, :presence => true,
  :length   =>{ :within => 6..40}

The solution (albeit trivial) was to change the names to Bobbob and Benben.

I hope that is helpful for someone.

Best,

Evan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜