Lessons from Ruby on Rails Tutorial
=== ####Initialization
- Run
rails new _project_name_ --skip-test-unit, if you don't want to use the Unit::Test. However, you can still typerails generate rspec:installif you want RSpec for testing. - Modify your Gemfile to group useful gem. Use
bundle install --without productionto avoid future invocation of Bundler for production gems. - Modify config/initializers/secret_token.rb to make sure the secret token is dynamically generated. And, be sure to make the .secret file ignored by .gitignore.
def secure_token
token_file = Rails.root.join('.secret')
if File.exist?(token_file)
File.read(token_file).chomp
else
token = SecureRandom.hex(64)
File.write(token_file, token)
token
end
end
SampleApp::Application.config.secret_key_base = secret_token####Controllers
- Creating controller
rails generate controller name(in plurals).
####Testing
- Functional tests for testing functions. Integration test for testing the whole process flow.
- TDD is writing tests first, before application code. By writing failing test first, implementing later and pass, to ensure the test is actually covering the functionality.