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 Jan 25, 2017 · 15 revisions

Summary

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 and this rails-dev-box is created for testing purpose only, then please do not apply changes such as changing mysql root password 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
ubuntu@rails-dev-box:~$ ruby -v
jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae OpenJDK 64-Bit Server VM 25.111-b14 on 1.8.0_111-8u111-b14-2ubuntu0.16.10.2-b14 +jit [linux-x86_64]
  • Update git config (if necessary)
ubuntu@rails-dev-box:~$ git config --global url."https://".insteadOf git://
  • clone ActiveRecord JDBC Adapter and checkout rails-5 branch
ubuntu@rails-dev-box:~$ git clone https://github.com/jruby/activerecord-jdbc-adapter
ubuntu@rails-dev-box:~$ cd activerecord-jdbc-adapter/
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ git checkout rails-5
  • Update AR_VERSION environment variable to 5-0-stable for ActiveRecord JDBC Adapter unit test
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ echo 'export AR_VERSION=5-0-stable' >> ~/.bashrc
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ . ~/.bashrc
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ echo $AR_VERSION
5-0-stable
  • Execute bundle install to install necessary gems
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ bundle install

Execute ActiveRecord JDBC Adapter unit test

  • Execute test_sqlite3 of ActiveRecord JDBC Adapter
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake test_sqlite3
... snip ...
138 tests, 310 assertions, 0 failures, 0 errors, 1 pendings, 3 omissions, 0 notifications
99.2593% passed
  • Execute test_mysql of ActiveRecord JDBC Adapter
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake test_mysql
... snip ...
211 tests, 433 assertions, 26 failures, 14 errors, 0 pendings, 2 omissions, 0 notifications
80.8612% passed
  • Execute test_postgresql of ActiveRecord JDBC Adapter
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake test_postgresql
... snip ...
364 tests, 598 assertions, 52 failures, 65 errors, 2 pendings, 6 omissions, 0 notifications
67.0391% passed

Execute Rails ActiveRecord unit test from ActiveRecord JDBC Adapter

  • Clone Rails and checkout 5-0-stable branch to execute Rails ActiveRecord unit test
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ cd ~
ubuntu@rails-dev-box:~$ git clone https://github.com/rails/rails
ubuntu@rails-dev-box:~$ cd rails/activerecord
ubuntu@rails-dev-box:~/rails/activerecord$ git checkout 5-0-stable
  • Add AR_JDBC environment variable to use ActiveRecord JDBC Adapter rails-5 branch
ubuntu@rails-dev-box:~/rails/activerecord$ echo 'export AR_JDBC=true' >> ~/.bashrc
ubuntu@rails-dev-box:~/rails/activerecord$ . ~/.bashrc
ubuntu@rails-dev-box:~/rails/activerecord$ echo $AR_JDBC
true
  • 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
ubuntu@rails-dev-box:~/rails/activerecord$ bundle install
ubuntu@rails-dev-box:~/rails/activerecord$ bundle show |grep jdbc
  * activerecord-jdbc-adapter (5.0 ee68c18)
  * activerecord-jdbcmysql-adapter (5.0 ee68c18)
  * activerecord-jdbcpostgresql-adapter (5.0 ee68c18)
  * activerecord-jdbcsqlite3-adapter (5.0 ee68c18)
  * jdbc-mysql (5.1.31 ee68c18)
  * jdbc-postgres (9.3.1102 ee68c18)
  * jdbc-sqlite3 (3.7.2.1 ee68c18)
ubuntu@rails-dev-box:~/rails/activerecord$ 
  • Configure RAILS location to point the local file system which has cloned rails
ubuntu@rails-dev-box:~/rails/activerecord$ cd ~/activerecord-jdbc-adapter
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ echo 'export RAILS=$HOME/rails/' >> ~/.bashrc
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ . ~/.bashrc 
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ echo $RAILS
/home/ubuntu/rails/
  • Execute Rails ActiveRecord unit test for sqlite3
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ cd
ubuntu@rails-dev-box:~$ cd activerecord-jdbc-adapter
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake rails:test_sqlite3
... snip ...
4680 runs, 8611 assertions, 3 failures, 1908 errors, 1 skips
  • Execute Rails ActiveRecord unit test for mysql
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake rails:test_mysql
... snip ...
rake aborted!
  • Execute Rails ActiveRecord unit test postgres
ubuntu@rails-dev-box:~/activerecord-jdbc-adapter$ bundle exec rake rails:test_postgres
... snip ...
rake aborted!

End of instructions.

Clone this wiki locally