Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 无法验证用户以更改其密码_Ruby On Rails_Authentication_Devise - Fatal编程技术网

Ruby on rails 无法验证用户以更改其密码

Ruby on rails 无法验证用户以更改其密码,ruby-on-rails,authentication,devise,Ruby On Rails,Authentication,Devise,我想通过Desive对用户进行身份验证,然后访问他们的帐户页面并更改他们的密码 describe Users::UsersController do describe "abc" do it "abc" do user = FactoryGirl.create :user sign_in :user, user visit edit_user_registration_path save_and_open_page # -- use

我想通过Desive对用户进行身份验证,然后访问他们的帐户页面并更改他们的密码

describe Users::UsersController do
  describe "abc" do

    it "abc" do
      user = FactoryGirl.create :user
      sign_in :user, user
      visit edit_user_registration_path

      save_and_open_page # -- user isn't authenticated yet!

      fill_in # .......
    end

  end
但是,该测试效果良好

it "should sign in" do
  user = FactoryGirl.create :user
  sign_in :user, user
  subject.current_user.should_not be_nil
end

我所做的是在spec/support/utilities.rb中创建一个文件 还有我的utilities.rb有这个

def sign_in(user)
  visit new_user_session_path
  fill_in "Email",    with: user.email
  fill_in "Password", with: user.password
  click_button "Sign in" 
end
FactoryGirl.define do
  factory :user do
    sequence(:username)  { |n| "Person_#{n}" }
    sequence(:name)  { |n| "Person #{n}" }
    sequence(:email) { |n| "person_#{n}@example.com"} 
    password "foobar123"
    password_confirmation "foobar123"
  end
end
在spec/requests/authentication_pages_spec.rb(由我创建)之后,并以这种方式设计了身份验证

require 'spec_helper'

describe 'UserPages' do

  subject { page }

  describe "allow registered user to sign in successfully" do
       before do
          user = FactoryGirl.create(:user)
          sign_in user
        end
       it { should have_link("Logout") }
       it { should_not have_link("Login") }
  end

  describe "edit" do
        before do
           @user = FactoryGirl.create(:user)    
           sign_in @user
           visit edit_user_registration_path    
        end

        describe "with valid information" do
           let!(:new_name)  { "New Name" }
           let!(:new_password) { "newpassword" }

           before do
             fill_in "Name",                        with: new_name
             fill_in "Email",                       with: @user.email
             fill_in "user[password]",              with: new_password
             fill_in "user[password_confirmation]",     with: new_password
             click_button "Update"
           end
           specify { @user.reload.name.should  == new_name }
        end
   end
end
我的spec/factories.rb有这个

def sign_in(user)
  visit new_user_session_path
  fill_in "Email",    with: user.email
  fill_in "Password", with: user.password
  click_button "Sign in" 
end
FactoryGirl.define do
  factory :user do
    sequence(:username)  { |n| "Person_#{n}" }
    sequence(:name)  { |n| "Person #{n}" }
    sequence(:email) { |n| "person_#{n}@example.com"} 
    password "foobar123"
    password_confirmation "foobar123"
  end
end

你能添加你的控制台日志…来看看为什么会这样吗failing@RahulSingh,如何记录?@RahulSingh,也不例外,测试在“登录”后仍能正常运行。您将在终端上使用“$rspec spec”运行它,它是否在某个地方失败了。。。?如果是,则添加您的终端输出…这样我们就可以看到它失败的原因。@rahussing,在
fill\u in
之前没有异常。在fill_中,它表示找不到元素,这是有意义的,因为它没有经过身份验证。m/d中的bcoz sign_只需要一个参数,它应该是user not:user,