Skip to content

How to execute ActiveRecord JDBC Adapter unit test and Rails ActiveRecord unit test using rails dev box

Yasuo Honda edited this page May 26, 2016 · 15 revisions

Summmary

This document explains how to execute ActiveRecord JDBC Adapter unit test and Rails ActiveRecord unit test using rails-dev-box for those who are interested in ActiveRecord JDBC Adapter Rails 5 support.

Since this document is created for testing purpose only, then please do not apply changes such as changing mysql root assword to empty, allowing all IPv4 connection for PostgreSQL to your production systems.

Requirements

  • Install Virtual Box
  • Install Vagrant
  • Install git

Steps to execute at host OS

  • Clone rails-dev-box
> git clone -b runs_ar_jdbc https://github.com/yahonda/rails-dev-box.git
  • Bring up rails-dev-box
> cd rails-dev-box
> vagrant up
  • Log in to rails-dev-box via ssh
> vagrant ssh

steps to execute at guest (rails-dev-box)

  • Validate which JRuby version is installed
vagrant@rails-dev-box:~$ ruby -v
jruby 9.1.1.0 (2.3.0) 2016-05-19 fe84e89 OpenJDK 64-Bit Server VM 25.91-b14 on 1.8.0_91-8u91-b14-0ubuntu4~15.10.1-b14 +jit [linux-x86_64]

  • Update git config (if necessary)
vagrant@rails-dev-box:~$ git config --global url."https://".insteadOf git://
  • clone ActiveRecord JDBC Adapter and checkout rails-5 branch
vagrant@rails-dev-box:~$ git clone https://github.com/jruby/activerecord-jdbc-adapter
vagrant@rails-dev-box:~$ cd activerecord-jdbc-adapter/
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ git checkout rails-5
  • Update AR_VERSION environment variable for ActiveRecord JDBC Adapter unit test
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ echo 'export AR_VERSION=5.0.0.rc1' >> ~/.bashrc
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ . ~/.bashrc

You can change 5.0.0.rc1 to newer version when released.

Execute ActiveRecord JDBC Adapter unit test

  • Bundle and execute rake
vagrant@rails-dev-box:~$ cd ~/activerecord-jdbc-adapter/
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ bundle
... snip ...
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake
... snip ...
(in rails-5 branch `bundle exec rake` also executes `test_mysql`)
230 tests, 436 assertions, 9 failures, 38 errors, 0 pendings, 7 omissions, 0 notifications
78.9238% passed
  • Execute test_sqlite3 of ActiveRecord JDBC Adapter
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake test_sqlite3
... snip ...
176 tests, 336 assertions, 17 failures, 16 errors, 1 pendings, 10 omissions, 0 notifications
79.5181% passed
  • Execute test_mysql of ActiveRecord JDBC Adapter
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake test_mysql
... snip ...

230 tests, 436 assertions, 9 failures, 38 errors, 0 pendings, 7 omissions, 0 notifications
78.9238% passed
  • Execute test_postgresql of ActiveRecord JDBC Adapter
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake test_postgresql
... snip ...
382 tests, 604 assertions, 31 failures, 88 errors, 2 pendings, 10 omissions, 0 notifications
67.7419% passed

Execute Rails ActiveRecord unit test v5.0.0.rc1 from ActiveRecord JDBC Adapter

  • Clone Rails and checkout v5.0.0.rc1 to execute Rails ActiveRecord unit test
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ cd ~
vagrant@rails-dev-box:~$ git clone https://github.com/rails/rails
vagrant@rails-dev-box:~$ cd rails/activerecord
vagrant@rails-dev-box:~$ git checkout v5.0.0.rc1
  • Add AR_JDBC environment variable to use ActiveRecord JDBC Adapter rails-5 branch
vagrant@rails-dev-box:~$ echo 'export AR_JDBC=true' >> ~/.bashrc
vagrant@rails-dev-box:~/rails/activerecord$ . ~/.bashrc
  • Modify Gemfile to use rails-5 branch
vagrant@rails-dev-box:~/rails/activerecord$ vi ../Gemfile
  • Replace branch: 'master' with branch: 'rails-5'
platforms :jruby do
  if ENV['AR_JDBC']
    gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5'
    group :db do
      gem 'activerecord-jdbcmysql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5'
      gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter', branch: 'rails-5'
    end
  else
    gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0'
    group :db do
      gem 'activerecord-jdbcmysql-adapter', '>= 1.3.0'
      gem 'activerecord-jdbcpostgresql-adapter', '>= 1.3.0'
    end
  end
end
  • Bundle to see if rails-5 branch appears
vagrant@rails-dev-box:~/rails/activerecord$ bundle
...
Using jdbc-mysql 5.1.31 from git://github.com/jruby/activerecord-jdbc-adapter.git (at rails-5@d9076e9)
Using jdbc-postgres 9.3.1102 from git://github.com/jruby/activerecord-jdbc-adapter.git (at rails-5@d9076e9)
Using jdbc-sqlite3 3.7.2.1 from git://github.com/jruby/activerecord-jdbc-adapter.git (at rails-5@d9076e9)
... snip ...
Using activerecord-jdbc-adapter 1.3.20 from git://github.com/jruby/activerecord-jdbc-adapter.git (at rails-5@d9076e9)
... snip ...
Using activerecord-jdbcmysql-adapter 1.3.20 from git://github.com/jruby/activerecord-jdbc-adapter.git (at rails-5@d9076e9)
Using activerecord-jdbcpostgresql-adapter 1.3.20 from git://github.com/jruby/activerecord-jdbc-adapter.git (at rails-5@d9076e9)
Using activerecord-jdbcsqlite3-adapter 1.3.20 from git://github.com/jruby/activerecord-jdbc-adapter.git (at rails-5@d9076e9)
  • Configure RAILS location to point the local file system which has cloned rails
vagrant@rails-dev-box:~/rails/activerecord$ cd ~/activerecord-jdbc-adapter
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ echo 'export RAILS=/home/vagrant/rails/' >> ~/.bashrc
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ . ~/.bashrc
  • Execute Rails ActiveRecord unit test v5.0.0.rc1 for sqlite3
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake rails:test_sqlite3
  • Execute Rails ActiveRecord unit test v5.0.0.rc1 for mysql
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake rails:test_mysql
  • Execute Rails ActiveRecord unit test v5.0.0.rc1 for postgres
vagrant@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake rails:test_postgres

Execute Rails ActiveRecord unit test v5.0.0.rc1 from Rails (alternative)

vagrant@rails-dev-box:~/rails/activerecord$ cd ~/rails/activerecord
vagrant@rails-dev-box:~/rails/activerecord$ bundle exec rake test:jdbcsqlite3
vagrant@rails-dev-box:~/rails/activerecord$ bundle exec rake test:jdbcmysql
vagrant@rails-dev-box:~/rails/activerecord$ bundle exec rake test:jdbcpostgresql
Clone this wiki locally