No migration at deploy - ruby-on-rails-3

I have simple question. My app at deploy dont't start rake db:migrate at production env. I Did not create deploy.rb I got it already prepared. deploy.rb is working, but command 'deploy:migrate' don't work. I don't know, how correctly ask this question. But I think this problem with :role. Maybe rake db:migrate need to describe? Like this:
namespace :db do
desc "Rake migration"
task :migrate, :roles => :db do
run "cd #{current_path} && #{rake} RAILS_ENV=production db:migrate"
end
end
end

I'm not sure if I've understood your question...
There is already a deploy:migrate task defined as part of capistrano, which you just have to add a hook for in your deploy.rb and it will run. See this answer for details on doing that.
You shouldn't need the code you've defined above, but if you do then note that you aren't defining deploy:migrate you're defining db:migrate.

Related

Is it possible to run test in rails without db:create and db:migrate?

i just want to know and want to try, is it possible run rails test without db:create and db:migrate?
I'm new with ruby on rails (rails 5.2.3). i've tried and it cant run the test, i think fixture already handle the data for dummy. Or maybe i missed some steps?
You still have to create the db test before you can run any test. Try this in terminal:
RAILS_ENV=test bin/rails db:create
RAILS_ENV=test bin/rails db:migrate
then try again with your tests. Hope this helps

Invoking rake with whenever

I just started using Rails Whenever plugin. I have rake file cron. with task:
task :cron => :environment do
puts "Task invoked!"
end
And in schedule.rb I have this:
every 2.minutes do
rake "cron", enviroment => "development"
end
Once I start my app and specified interval passes, nothing happens? I am pretty new to Ruby and Rails so what am I doing wrong?
You'll need to write the schedule to your crontab. Run this command in your app:
bundle exec whenever --update-crontab myapp
When you run this command, whenever takes the Ruby syntax, translates it to cron syntax and adds it to your crontab.

How do I create a rake task for a Rails engine which is not exposed to the host application?

# lib/tasks/test.rake
task :hello do
puts 'hello'
end
$ rake app:hello
To run the task I need to prefix it with "app:" and it runs in the context of the dummy app. It is also exposed to the host application (i.e when used as a plugin in a parent Rails app) as rake hello.
I want to run a rake task which does not require a Rails environment and runs some command, but it is run from the engine root, not the dummy app root.
I know that's a bit late, but for others here searching for the correct answer, do the following :
Create your task :
# lib/tasks/your_engine_tasks.rake
desc "Explaining what the task does"
task :your_task do
# Task goes here
end
Then go to your engine ./Rakefile and add
load 'lib/tasks/your_engine_tasks.rake'
Here we go, now:
$ rake -T
gives you your task.
Hope I helped.
I want a better answer to this question however I did figure out that you can add tasks in the Rakefile for the engine (so ./Rakefile not in the spec/dummy application) like so:
task :my_task do
puts "hi!"
end
task :default => [:spec, :my_task]
I would prefer to have my task in another file but at least this provides a way to go forward. In my case, I want to run Konacha javascript tests in the dummy application so my Rakefile looks like this:
task :spec_javascript do
exec 'cd spec/dummy && rake konacha:run' # exec passes command return value up stack!
end
task :default => [:spec, :spec_javascript]

System rake test task doesn't run my tests

I'm sure I'm doing something naive or stupid, I'm just not sure what it is.
I'm writing a simple library for parsing data URIs. Being so simple, I figured I'd go ahead and just give ruby-1.9's minitest a whirl. The tests run great when I run them by hand, but when I try to run them with 'rake test', hoping to invoke the system rake test task, I get no joy. Specifically, with trace and verbose:
Donalds-Decisiv-MacBook-Pro:data_uri dball$ rake test -t -v
(in /Users/dball/src/data_uri)
** Invoke test (first_time, not_needed)
I've got tests in the test folder, they all start with test_ and end in .rb. Any ideas?
The repository of the project is http://github.com/dball/data_uri
Tests are not invoked because you didn't give rake any information about them.
Put this task in Rakefile:
require 'rake/testtask'
Rake::TestTask.new do |i|
i.test_files = FileList['test/test_*.rb']
i.verbose = true
end
Or grab a patch for your project.

Automatically run gem tasks in test environment

I have a Rails 3 gem which has some rake tasks that should only be run in the test environment. Running in other environments doesn't really make sense.
My problem is Rake loads the Rails system in order to find my tasks in my gem. So by the time it gets to my tasks Rails is already loaded in the "development" environment (or whatever environment the user specified). This means in order to run my rake tasks properly the user must do:
RAILS_ENV=test rake mytask
Since my task only make sense in the "test" environment this is annoying as I would much rather the user be able to just type:
rake mytask
This is similar to how test:units and test:functionals automatically assume the test environment and the user doesn't need to specify RAILS_ENV=test at the command line. So the question is how do I modify my test so that Rails switches to the test environment?
My current workaround is:
Rails.env = 'test'
ActionMailer::Base.delivery_method = :test
require Rails.root.join('test/test_helper')
This seems to somewhat work but it is still logging to log/development.log and I think it is still actually running the "development" config. Anybody have any ideas? Looking at how the test tasks are defined in Rails itself doesn't reveal how to do it that I can see.
https://github.com/rails/rails/blob/master/railties/lib/rails/test_unit/testing.rake
UPDATE: I've updated my code after taking inputs from Eric's implementation at https://github.com/eric1234/test_inline/commit/fe3da7efa3a2cdb7824c23cfa41697b0ceb9e8e2.
For original code see - https://stackoverflow.com/posts/4600524/revisions
desc "Do something in Test environment"
task :example => :environment do
if not Rails.env.test?
Dir.chdir(Rails.root) do
system "rake example RAILS_ENV=test"
end
else
#.... stuff ....
end
end
I didn't check for the correctness of code, but you get the idea, right?