I added assert_empty to check that an array is empty.
But the line number from test helper.rb was the first line of the test helper, not the line in the test.
Instead, I wanted to see the actual failure as the first line. Welcome remove_me_from_trace(exception)
class Test::Unit::TestCase
def assert_empty(*args)
begin
args.unshift []
assert_equal *args
rescue => e
raise remove_me_from_trace(e)
end
end
def remove_me_from_trace(e)
x=e.backtrace.shift until (x =~ /test_helper.rb/ )
e
end
end
I normally don’t like hacking rails files directly, but this is the only way I could extend rake db:migrate to support a friendly VERSION.
railities/lib/tasks/database.rake on line 111.
# was ENV["VERSION"] ? ENV["VERSION"].to_i : nil
# looks up version based upon migration files
def version_num
version=ENV["VERSION"]
if version.to_i==0 && version.present?
matches=Dir["db/migrate/*#{ENV["VERSION"]}*"]
if matches.length > 0
#prune off directory name
matches=matches.collect{|n| n.gsub(/^.*\//,'')}
unless matches.length == 1
raise "VERSION #{version} matches "+
"#{matches.join(', ')}"
end
#prune off version num
version=matches.first.gsub(/([^_]*)_.*$/) {$1}
puts "VERSION=#{version}"
end
end
version ? version.to_i : nil
end
In 3 places (migrate, up, down), the version code is changed from
ENV["VERSION"] ? ENV["VERSION"].to_i : nil
to
version_num
Now rake db:migrate:down VERSION=create_photo works like a charm.
I have been using a schell script so I don’t need to remember the long version number associated with ruby migrations.
#given a migration task, return the version
#e.g.: rake db:migrate:redo VERSION=$(mver create_photo)
function mver() {
scr=${1:?Please specify migration action}
ls db/migrate/*${scr}* | sed 's=^[^0-9]*\([0-9][^_]*\)_.*$=\1='
}
which will run migration 20100302214328_create_photos_and_folders.rb
I currently work on port 80, but coworkers work on port 3000. So the urls they send often do not work. I created an app that bounces all local 3000 requests to port 80.
mkdir -p bounce/public bounce/tmp
cd bounce
created
config.ru:
app = proc do |env|
url="http://#{env['SERVER_NAME']}#{env['REQUEST_URI']}"
return [302, { "Content-Type" => "text/html", "Location" => url }, "try <a href=\"#{url}\">#{url}</a>" ]
end
run app
enabled port 3000 in
/private/etc/apache2/httpd.conf:
Listen 3000
added entry to passenger pref pane. But it didn’t create the proper vhosts entry. I changed port 80 to 3000
<VirtualHost *:3000>
ServerName site1.local:3000
ServerAlias test.local:3000
DocumentRoot "/Users/kbrock/projects/bounce/public"
RackEnv development
<directory "/Users/kbrock/projects/bounce/public">
Order allow,deny
Allow from all
</directory>
</VirtualHost>
All is working.