dimanche 26 janvier 2020

NoMethodError: undefined method `users' within a setup

maybe is a dumb question, but I am having an issue when I am trying to run a test on Ruby, this is the error:

Error: UsersLoginTest#test_login_with_valid_information:

NoMethodError: undefined method User' for #<UsersLoginTest:0x0000555ef3ec15b0> Did you mean? super test/integration/users_login_test.rb:6:insetup'

I tried to fix the fixture .yml but I am not sure that the problem is there anymore.

This is my users.yml

michael:
  name: Michael Example
  email: michael@example.com
  password_digest: <%= User.digest('password') %>

this is my users_login_test.rb

require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

  def setup
    @user = users(:michael)
  end

  test "login with valid information" do
    get login_path
    post login_path, params: { session: { email:    @user.email,
                                          password: 'password' } }
    assert_redirected_to @user
    follow_redirect!
    assert_template 'users/show'
    assert_select "a[href=?]", login_path, count: 0
    assert_select "a[href=?]", logout_path
    assert_select "a[href=?]", user_path(@user)
  end
end

and this is my test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'

class UserTest < ActiveSupport::TestCase
  fixtures :all
  include ApplicationHelper

  setup do
    @user = User.new(name: "Example User", email: "user@example.com",
                     password: "foobar", password_confirmation: "foobar")
  end
  test "should be valid" do
    assert @user.valid?
  end

end

where could be the problem? thank you very much for your help

Aucun commentaire:

Enregistrer un commentaire