From Linguistic Team International Wiki
|The following is a tutorial on setting up and running Ruby on Rails v3.x. It will be relocated if/when a more generic page is required here.|
The ZMChapters application is a Ruby on Rails application designed around Rails 3.
http://www.rubyinside.com/how-to-install-ruby-1-9-2-and-rails-3-0-on-ubuntu-10-10-4148.html Source Control, git and github.com
The source is under version control with git and is made publicly available on the github.com website. An account on github.com is not required to clone the repository, it is required if you want to share your changes or commit back to the master repository. There is also the option of forking, this requires a fairly decent understanding of git and how git branches work. Cloning via readonly (does not require a github account)
git clone git://github.com/cluster444/zmchapters.git
Cloning with write access (requires a github account and to be added to the collaborators on the account)¶
git clone firstname.lastname@example.org:cluster444/zmchapters.git
Ruby, bundler, gems and rvm
A bit of an upfront warning. There is a known issue with Ruby 1.9.1 and Bundler. This issue is fixed in the Ruby 1.9.2 release, but because distributions often lag behind by many months, the issue persists when using the ruby versions that come with a distribution. For this reason it is not recommended to use the platform default ruby. Below I will outline how I have setup my dev environment so these issues are not a problem. RVM (Ruby Version Manager)¶
This is not necessarily a requirement but is highly recommended. RVM allows you to install multiple ruby versions such that they do not conflict with each other and you can switch between them with ease. Full documentation for rvm is available at the rvm website : http://rvm.beginrescueend.com .
$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) # This will setup rvm for your user account. # Add the following line to ~/.bash_profile, this will load rvm for you each time you login # -s "$HOME/.rvm/scripts/rvm" && . "$HOME/.rvm/scripts/rvm" # To get access to rvm immediately, source in rvm $ source ~/.rvm/scripts/rvm # Finally, rvm has platform specific notes for dependencies that may need to be installed in order to complie your rubies $ rvm notes
Once rvm has loaded you can start building the rubies.
# First we start with Ruby 1.8.7 rvm install 1.8.7 # Then we can install Ruby 1.9.2 # Please not that there may be missing dependencies depending on if your system has appropriate development libraries. # Unfortunately you won't find this out until after the ruby has compiled... rvm install 1.9.2 # To be safe, i recommend the following instead # Replace /home/cluster with your own account's home directory $ rvm package install zlib $ rvm package install openssl $ rvm install 1.9.2 --with-zlib-dir=/home/cluster/.rvm/usr --with-openssl-dir=/home/cluster/.rvm/usr # That should take a few minutes depending on the speed of your computer. # If you get any error output after compilation finishes, check to make sure that you entered everything properly. # If you run @gem install bundler@ and get errors about missing libraries then double check that you typed everything correctly # In case you have to try again, the command below will refresh everything and you can try again. $ rvm remove 1.9.2
Now that you have some rubies installed, you'll have to tell rvm which one to use.
# This will tell rvm to setup your path to use the ruby 1.9.2 that you just installed $ rvm use 1.9.2 # In case you ever need to get back to the ruby installed on your system, the following command will do just that. $ rvm use system # To see a list of all the rubies installed via rvm $ rvm list # You'll probably want to setup an addition line in your .bash_profile below the line that sources rvm into your shell. rvm use 1.9.2 2>&1 >/dev/null # That will load your rvm ruby for you each time you login.
The final part of handling ruby is gem management. Gems are the libraries of ruby and are mostly handled automatically for you by another program, which itself is a gem, called bundler. rvm deals with gems through what are called gemsets. You don't technically have to setup a gemset. By default rvm will use a gemset called 'global'. If you are not using ruby on multiple projects within the same system, then using the global gemset is ok. Once you get into dealing with multiple projects, there may be version conflicts, at which point you can setup independent gemsets for each project.
So basically if your only dealing with a single project, like zmchapters, then your basically done. The following will get your gems setup for the project your working on.
$ gem install bundler $ cd zmchapters $ bundle # This will setup and install all of the gems required by the project.
If you wanted to setup a specific gemset for the project your working on, this can be done as follows. Again, this is only really recommended if your working with multiple projects that have specific version requirements that conflict with other projects.
$ rvm gemset create zmchapters $ rvm gemset use zmchapters $ gem install bundler $ cd zmchapters $ bundle
Running tests with rspec
The ZMChapters application uses Test Driven Development using the RSpec testing framework. This helps to ensure that new code does not cause regressions and makes refactoring easier. The project also makes use of spork which helps to make running tests faster by preloading the rails environment (reduces the load time for test running from around 10 seconds to under 1).
You don't have to have spork running to run the tests, and it is a good idea if you run the full suite of tests, especially before committing new changes to kill spork and run the tests without it to ensure that spork is not caching something that has changed. Cases where you will need to kill and restart spork include any changes to the Gemfile, and any changes within config/ or lib/.
# Run spork in the current shell $ spork # Run spork in the background $ spork &
Running the test suite can be done as follows.
# Run the full test suite. $ rspec spec # Run only the controllers or models $ rspec spec/models $ rspec spec/controllers # To run a specific controller or model, tell it specifically which spec file to run $ rspec spec/models/chapter_spec.rb
The last method, running a specific test suite is recommended when working on that specific piece of code. This allows you to run the tests fairly quickly as an individual test spec usually takes less than 1 second to complete.