Error devise don't generate factory with factory_bot - ruby-on-rails

I'm using rails 5.1.4
devise 4.4.1
factory_bot_rails 4.8.2
rails g devise User
Running via Spring preloader in process 15889
invoke active_record
create db/migrate/20180213152941_devise_create_users.rb
create app/models/user.rb
invoke rspec
create spec/models/user_spec.rb
error factory_bot_rails [not found]
insert app/models/user.rb
route devise_for :users

Thanks for replay, the problem was that in config/application.rb, fixture_replacement need to pass :factory_bot and not factory_bot_rails, reading the doc I see that are distinct gems.

Related

rails generate migration error mongo_mapper not found

Follow Installation in Rails 3 of Mongo Mapper i add to config/application.rb file :
config.generators do |g|
g.orm :mongo_mapper
end
when rails generate migration my_migration i got :
error mongo_mapper [not found]
but when rails generate model my_model, i got a fine model class with include MongoMapper::Document and this output :
invoke mongo_mapper
create app/models/user.rb
invoke test_unit
create test/unit/user_test.rb
create test/fixtures/users.yml
You don't have migrations while working with MongoDB.
Because MongoDB is a schema less database.
That's the reason you can't generate migrations with mongo mapper.

Rails - uninitialised constant AdminUser with ActiveAdmin gem

I'm new in Rails and I'll try to install ActiveAdmin to my existing project (Rails 3.2.1).
i've had activeadmin, meta_search, devise and sass-rails in my gemfile. Require devise in the configuration/application.rb.
When I try to run "rails generate active_admin:install" or "rails server", i have an error :
C:/RailsInstaller/Ruby1.9.3/l
ive_support/inflector/methods
connstant AdminUser (NameError)
I dont know how to fix.
Thanks :)
Just delete the following line on routes.rb
devise_for :admin_users, ActiveAdmin::Devise.config
Then rerun
rails g active_admin:install
I got this same error after uninstalling and resintalling activeadmin (as I wanted to remove it from admin_user to install it in my own user).
Solution was to search through my project for "admin", and comment all the code that activeadmin had left after uninstall.
The files where I found activeadmin code were:
routes.rb
schema.rb

Rails migration error database_authenticatable

-- create_table(:admin_users)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `database_authenticatable' for #
Tasks: TOP => db:migrate
How to solv it? Thanx!
migration
create_table(:admin_users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.timestamps
end
have all gems in gemfile and installed
Make sure you have devise in the Gemfile and the bundle is installed.
Answer is simple device team sucks!!!
to solve this need make cnanges in GEMFILE
gem 'devise', "~> 1.5"
because in 1.5 there is database_authenticatable type support and in 2.1.0 there is support of only compatibility not creation of fields with this type
thanx everybody.
If you're just getting started with devise (vs updating from previous verions), you might have missed the following step before doing rake db:migrate
rails generate devise:install
This creates
create config/initializers/devise.rb
create config/locales/devise.en.yml
which define the method rake is complaining about above.
Source:
https://github.com/plataformatec/devise
With Devise 2.0 and newer, the migration helper methods (t.database_authenticatable for example) are not available (as stated on the wiki here ) If you're making a new model for users, just use the devise migration generator like so:
rails g devise admin_users (If you're installing devise on your app)
If you're adding the required fields to an existing user model, you should check this page on the devise wiki.
Check out the main README for devise, which has up-to-date information for installing the latest version of devise on Rails.

Rails - can't make database migration on Heroku for app using Devise authentication

My application uses Devise authentication gem.
When i do
rake db:migrate
locally, everything is going well, but when I do this on Heroku:
heroku run rake db:migrate --app myappname
I get
rake aborted!
uninitialized constant Devise::Encryptors::Base
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
I have no Idea what could go wrong.
I run into the same issue because I implemented a custom encryptor. Since version 2.1 of devise custom encryptors have been extracted to a separate gem. To get it working do the following.
Add the devise-encryptable gem to your Gemfile.
gem 'devise-encryptable'
Subclass from Devise::Encryptable::Encryptors::Base instead of Devise::Encryptors::Base.
# lib/devise/encryptors/md5.rb
require 'digest/md5'
module Devise
module Encryptable
module Encryptors
class Md5 < Base
def self.digest(password, stretches, salt, pepper)
str = [password, salt].flatten.compact.join
Digest::MD5.hexdigest(str)
end
end
end
end
end
I updated the how-to page of devise as well. I hope this solves your problem.

Rails Unit Test Issue with rake

I am working on writing tests for a rails 2.3.4 application and I am running into the following error when I try to run the tests
1) Failure:
default_test(ReportTest) [rake (0.8.7) lib/rake/rake_test_loader.rb:5]:
No tests were specified.
This is what the only test file looks like:
require File.dirname(__FILE__) + '/../test_helper'
class UserTest < ActiveSupport::TestCase
include Authlogic::TestCase
setup :activate_authlogic
fixtures :users
def setup
#user = users(:one)
end
def test_user_is_valid
assert #user.valid?
end
end
One issue I could forsee being a problem is that I have multiple versions of rails installed and rake as well
rails (3.0.0, 2.3.8, 2.3.5, 2.3.4, 1.2.6)
rake (0.8.7, 0.8.3)
Anyone know what's going on?
Somehow the search for tests that rake test does has turned up a file named _test.rb which doesn't have a test in it. It will look through all the files under the test/units /functionals and /integration directories to try and locate tests.
I also once had the strange behaviour that a rails application in a sub directory of another rails application was finding more tests than it should have done as it was picking up tests from the 'parent' application. Might be worth checking that too.

Resources