heartcombo / devise

Flexible authentication solution for Rails with Warden.
http://blog.plataformatec.com.br/tag/devise/
MIT License
23.85k stars 5.53k forks source link

Problem with passing in "user" although "monster" works #5620

Open jackparsons93 opened 11 months ago

jackparsons93 commented 11 months ago

Ruby Version 3.2.1 Rails Version 7.0.7 Devise Version 4.9.2

require 'pry'
require "test_helper"
class MvcGeneratorTest < Rails::Generators::TestCase
  tests Devise::Generators::MvcGenerator
  destination File.expand_path("../../tmp", __FILE__)
  setup :prepare_destination

  test "Assert model is created with monster passed" do
    run_generator %w(monster)
    #binding.pry
    assert_file "app/models/monster.rb"

  end
  test "Assert model is created with test passed" do
    run_generator %w(test)
    #binding.pry
    assert_file "app/models/test.rb"

  end
  test "Assert model is created with test user" do
    run_generator %w(user)
    #binding.pry
    assert_file "app/models/User.rb"

  end
end

The Third test fails but the first two test succeed, I manually tested the app and with the argument user passed and I got the following code

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
end

These test also fail if you put them in active record, my MvcGenerator only invokes the active record generator. I can post a link to active record code failing with user passed, but succeeds with monster passed.

jackparsons210@DESKTOP-7RMUVKP:~/devise_tester$ rails generate devise:mvc user create db/migrate/20230817001455_devise_create_users.rb create app/models/user.rb invoke test_unit create test/models/user_test.rb create test/fixtures/users.yml insert app/models/user.rb

The following input is the failing test

The name 'User' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative or use --skip-collision-check or --force to skip this check and run this generator again. F

Failure: MvcGeneratorTest#test_Assert_model_is_created_with_test_user [/home/jackparsons210/test_devise/devise/test/generators/mvc_generator_test.rb:23]: Expected file "app/models/user.rb" to exist, but does not

bin/test /home/jackparsons210/test_devise/devise/test/generators/mvc_generator_test.rb:20

system temporary path is world-writable: /tmp /tmp is world-writable: /tmp .system temporary path is world-writable: /tmp /tmp is world-writable: /tmp .

Finished in 0.024781s, 121.0590 runs/s, 121.0590 assertions/s. 3 runs, 3 assertions, 1 failures, 0 errors, 0 skips

jackparsons93 commented 11 months ago

I am running the test in test/generators/active_record_generator_test.rb with

class ActiveRecordGeneratorTest < Rails::Generators::TestCase
    tests ActiveRecord::Generators::DeviseGenerator
    destination File.expand_path("../../tmp", __FILE__)
    setup :prepare_destination

    test "pass users" do
      run_generator %w(user)
      assert_file "app/models/user.rb"
    end

The unit test that does the same thing as this test with the parameters %(monster) and asserts monster.rb to be created passes, but this test where it passes in "user" fails. However using the pry gem, I can see a migration with the name user is created in the TMP file, however there is no app/models/user.rb file I think this is a bug, or I need to look deeper into the test, maybe devise tests automatically create a user file, idk.