Korzystałem z oficjalnego tutka z ruby on rails. Chciałem samodzielnie zrobić edycję użytkownika, więc zacząłem od pisania testu:

  describe "edit profile" do
    let(:user) { FactoryGirl.create(:user) }
    describe "not signed in users have no access" do
      before { visit user_profile_edit_path(user) }

      it { should have_selector('div.alert.alert-error', text: 'Need to be signed in') }
    end

    describe "only signed in users have access" do
      before do 
        visit signin_path
        fill_in "Email",              with: user.email
        fill_in "Password",           with: user.password
        click_button "Sign in"
        visit user_profile_edit_path(user) 
      end
      describe "with invalid password" do
        before do
          fill_in "Password",         with: "invalid"
          click_button "Edit profile" 
        end
        it { should have_selector('div.alert.alert-error', text: 'Invalid') }
      end

      describe "with valid password" do
        before do
          fill_in "Password",         with: user.password
        end
        describe "edit user's name" do
          before do
            fill_in "Name",           with: "My new name"
            click_button "Edit profile"
          end
          it { expect have_name("My new name")}
        end
      end
    end
  end

następnie zacząłem pisać akcję w kontrolerze, która wygląda tak:

  def edit
    if !signed_in?
      flash[:error] = "Need to be signed in"
      redirect_to signin_path
    end

    @user = current_user
  end

  def update
    if !signed_in?
      flash[:error] = "Need to be signed in"
      redirect_to signin_path
    end

    if !current_user.authenticate(params[:password])
      flash.now[:error] = "Wrong password"
      @user = current_user
      render 'edit'
    else
      current_user.name = params[:password]

      if current_user.save
        flash[:success] = "Changes saved"
      end

      redirect_to user_profile_edit_path
    end
  end

no i problem w tym, że w linijce

if !current_user.authenticate(params[:password])

użytkownik nie jest uwierzytelniany pomimo, że podaję poprawne hasło. What's wrong? Wykorzystuję bcrypt-ruby.