rake db:migrate rake aborted! NoMethodEr - ruby-on-rails

When I try to run rake db:migrate I am getting following error:
DEPRECATION WARNING: The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from <top (required)> at /var/www/html/sophy_web/config/application.rb:14)
/root/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-4.2.8/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::PDF
/root/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-4.2.8/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of PDF was here
rake aborted!
NoMethodError: undefined method `>' for nil:NilClass
/var/www/html/application/config/initializers/rollbar.rb:2:in `<top (required)>'
/var/www/html/application/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
I am using ruby version 2.5.1 and rails 4.2.8.
Code of my rollbar.rb:
require 'rollbar/rails'
Rollbar.configure do |config|
config.access_token = '9234902384023843203fsd23'
# Here we'll disable in 'test':
if Rails.env.test?
config.enabled = false
end
end
Code of my environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!

Related

Rails::TestUnit::Runner.run NameError: uninitialized constant

On Rails 6 (6.1.4.1) we had a RakeFile that would run a subset of tests. For example:
# lib/tasks/carrier.rake
namespace :test do
task carriers: "test:prepare" do
$: << "test"
test_files = FileList["test/models/carrier_test.rb",
"test/controllers/admin/carriers/**/*_test.rb",
"test/system/admin/carriers/**/*_test.rb"]
Rails::TestUnit::Runner.run(test_files)
end
end
This would execute just fine when called:
rails test:carriers
However, somewhere along the way, something changed and we began seeing errors when trying to run our RakeFile test tasks. (I haven't tracked down exactly what changed and when it changed -- perhaps it was part of the Rails 7 release.) Here's the error we began seeing:
rails aborted!
NameError: uninitialized constant Shoulda
Shoulda::Matchers.configure do |config|
^^^^^^^
/path/test/test_helper.rb:15:in `<main>'
/path/test/models/carrier_test.rb:1:in `<main>'
/path/lib/tasks/carriers.rake:11:in `block (2 levels) in <main>'
Tasks: TOP => test:carriers
(See full trace by running task with --trace)
The error appeared with no changes to our tests or environment configuration. (Running a full rake worked just fine.)
When reviewing the source code for Rails::TestUnit::Runner, I came across rake_run. Simply replacing Rails::TestUnit::Runner.run with Rails::TestUnit::Runner.rake_run addressed the issue (no other changes required):
# lib/tasks/carrier.rake
namespace :test do
task carriers: "test:prepare" do
$: << "test"
test_files = FileList["test/models/carrier_test.rb",
"test/controllers/admin/carriers/**/*_test.rb",
"test/system/admin/carriers/**/*_test.rb"]
Rails::TestUnit::Runner.rake_run(test_files)
end
end

When using 'bundle exec rake db:create', rake always aborts How to solve?

Every time I execute bundle exec rake db:create I'm always getting this error in the terminal:
rake aborted!
LoadError: cannot load such file -- /Users/davidnoldner/Documents/GitHub/RatatamBot/rakefile/User/Documents/RatatamBot
/Users/davidnoldner/Documents/GitHub/RatatamBot/rakefile:1:in `require'
/Users/davidnoldner/Documents/GitHub/RatatamBot/rakefile:1:in `<top (required)>'
/Users/davidnoldner/.rvm/gems/ruby-head/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
/Users/davidnoldner/.rvm/gems/ruby-head/bin/ruby_executable_hooks:24:in `eval'
/Users/davidnoldner/.rvm/gems/ruby-head/bin/ruby_executable_hooks:24:in `<main>'
(See full trace by running task with --trace)
I've been stuck at this since yesterday and was looking for the answer often here on Stackoverflow but didn't find any solution matching to my problem. That's kinda frustrating. I really need your help.
Rakefile:
require File.expand_path('/Users/davidnoldner/Documents/GitHub/RatatamBot/rakefile', __FILE__)
require 'rake'
require 'resque/tasks'
+ # temp fix for NoMethodError: undefined method `last_comment'
+ # remove when fixed in Rake 11.x
+ module TempFixForRakeLastComment
+ def last_comment
+ last_description
+ end
+ end
+ Rake::Application.send :include, TempFixForRakeLastComment
+ ### end of temfix
+
task "resque:preload" => :environment
Rails.application.load_tasks

Where is db:create defined in Rails?

The following command is supposed to create a new database.
rails db:create
Where is this function defined? Or is this a pre-packaged function in rails?
It's in the databases.rake file of the framework:
namespace :create do
task all: :load_config do
ActiveRecord::Tasks::DatabaseTasks.create_all
end
ActiveRecord::Tasks::DatabaseTasks.for_each do |spec_name|
desc "Create #{spec_name} database for current environment"
task spec_name => :load_config do
db_config = ActiveRecord::DatabaseConfigurations.config_for_env_and_spec(Rails.env, spec_name)
ActiveRecord::Tasks::DatabaseTasks.create(db_config.config)
end
end
end
Whenever you doubt or want to know where a task has been defined, you can use the rails -W (or rake) command, passing the task:
$ rails -W db:create
rails db:create /path/databases.rake:26:in `block in <top (required)>'
rails db:create:all /path/databases.rake:20:in `block (2 levels) in <top (required)>'
Note it was introduced in the version 0.9 of Rake. This might or might not work depending on the versions which you're working with.

Error: Rake Aborted. Uninitialized Constant Settings

Newbie here trying to create a development environment for a project. I've installed MySQL and Ruby on Rails on my device already. However, I'm running into the below error message when trying to run the 3 commands below after "bundle install" runs successfully. Any ideas?
bundle exec rake db:setup RAILS_ENV="development"
bundle exec rake db:migrate RAILS_ENV="development"
bundle exec rake db:seed RAILS_ENV=“development"
error message is as follows:
wcai-projects already exists
rake aborted!
uninitialized constant Settings
EDIT-here's the console log:
$ bundle exec rake db:setup RAILS_ENV=development
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-3.2.12/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
wcai-projects already exists
rake aborted!
uninitialized constant Settings
/wcai-web/config/initializers/carrier_wave.rb:4:in `block in <top (required)>'
/wcai-web/config/initializers/carrier_wave.rb:1:in `<top (required)>'
/wcai-web/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => environment
(See full trace by running task with --trace)
EDIT-contents of config/initializers/carrier_wave.rb:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => Settings.aws_access_key, # required
:aws_secret_access_key => Settings.aws_secret_key # required
# :region => 'eu-west-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = Settings.aws_bucket # required
config.fog_public = false
config.fog_authenticated_url_expiration = 120
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
#config.asset_host = 'https://assets.example.com' # optional, defaults to nil
end
Update your Rails version in Gemfile to 4.2.4. Then type bundle update rails and try again.

NameError: uninitialized constant Roo::Excelx::Zip

I am using ruby 2.2.1 and rails 4.2.1.
I am using following gems.
roo (2.0.1)
roo-xls (1.0.0)
rubyzip (1.1.7)
I have written a rake task as follows.
check_roo.rake
require 'rubygems'
require 'roo-xls'
require 'roo'
desc "desc"
task :check_roo => :environment do |task, args|
xlsx = Roo::Excelx.new("#{Rails.root}/v15_Data.xlsx")
end
Output for bundle exec rake check_roo:
NameError: uninitialized constant Roo::Excelx::Zip
/home/abhimanyu/.rvm/gems/ruby-2.2.1#newerp/gems/roo-2.0.1/lib/roo/excelx.rb:412:in `process_zipfile'
/home/abhimanyu/.rvm/gems/ruby-2.2.1#newerp/gems/roo-2.0.1/lib/roo/excelx.rb:100:in `initialize'
/home/abhimanyu/Documents/projects/abc/lib/tasks/check_roo.rake:9:in `new'
/home/abhimanyu/Documents/projects/abc/lib/tasks/check_roo.rake:9:in `block in <top (required)>'
But when I run the following command in rails console it works fine.
xlsx = Roo::Excelx.new("#{Rails.root}/v15_Data.xlsx")
Output:
<#Roo::Excelx:320135634 #tmpdirs #tmpdir #filename #comments_files #rels_files #sheet_files #workbook #sheet_names #sheets #styles #shared_strings #sheets_by_name #options #cell #cell_type #cells_read #first_row #last_row #first_column #last_column #header_line>
Not able to understand why the same command works in console but not inside a rake file.
Any help would be appreciated. Thanks in advance.

Resources