Merge rails_port as of r4613 & fix tests.