Archive for the ‘sessions’ tag
If you ever tried running your tests and find yourself getting the error:
your_controller_test.rb:3:in `require': no such file to load -- test_helper (LoadError)
it’s probably because the generated require call,
require test_helper is not being properly recognized. Instead of the default
require 'test_helper', replace it with:
require File.dirname(__FILE__) + '/../test_helper'
If you’re doing functional testing, make sure that the controller being tested is also required (e.g. add the line
require 'your_controller' on top). Be sure that you also have installed the package
libtest-unit-ruby (if using Linux), before testing.
Also, thanks to Jeff Balogh, make sure that you append test_ on all your test cases to make sure that they actually run (I know it’s obvious, but it’s nice to be reminded once in a while).
On database constraints:
If you want to enforce foreign key constraints, remember to create the required indexes first. ActiveRecord Migration supports this using add_index. This only applies if the column being referred to is not a primary key, if it is then there’s no need to create the index. Once this is set, you can now enforce foreign keys using ActiveRecord Migrations by implementing this.
On implementing sessions:
By default, the rails session handler stores session information on a file in the server. This can cause scalability issues in the long run if file space runs out or when using multiple servers. Thus, it’s recommended to use
:active_record_store instead. To do this make sure that you do the following:
rake db:sessions:createto add a create table migration for sessions
rake db:migrateto apply the new schema
- change session store to active session store by adding this line to
config.action_controller.session_store = :active_record_store
- Make sure that you comment out or add this line to your ApplicationController:
protect_from_forgery :secret => <32_hex_digit_secret_key>
Here are also some helpful links regarding sessions and implementing it: