Skip to content

Instantly share code, notes, and snippets.

@ratnikov
Forked from mrichman/accounts_controller.rb
Created January 6, 2010 19:22
Show Gist options
  • Save ratnikov/270547 to your computer and use it in GitHub Desktop.
Save ratnikov/270547 to your computer and use it in GitHub Desktop.
class AccountsController < ApplicationController
def new
@account = Account.new
end
def create
@account = Account.new(params[:account])
if @account.save
session[:account_id] = @account.id
flash[:notice] = "Thank you for signing up! You are now logged in."
redirect_to root_url
else
logger.debug "Failed to save account. Errors: #{@account.errors.full_messages.inspect}"
render :action => 'new'
end
end
end
require 'test_helper'
class AccountsControllerTest < ActionController::TestCase
def setup
@valid_params = {:username => "foo",
:password => "secret",
:password_confirmation => "secret",
:email => "foo@example.com"}
end
def test_new
get :new
assert_template 'new'
end
def test_create_invalid
post :create, :account => {}
assert_template 'new'
end
def test_create_valid
post :create, :account => @valid_params
assert_redirected_to root_url
assert_equal assigns['account'].id, session['account_id']
end
end
# Logfile created on Wed Jan 06 14:14:19 -0500 2010 SQL (0.2ms) SET NAMES 'utf8'
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
SQL (0.1ms) BEGIN
Processing AccountsController#create (for 0.0.0.0 at 2010-01-06 14:14:20) [POST]
Parameters: {"action"=>"create", "account"=>{}, "controller"=>"accounts"}
SQL (0.1ms) SAVEPOINT active_record_1
Account Load (0.1ms) SELECT `accounts`.id FROM `accounts` WHERE (`accounts`.`username` IS NULL) LIMIT 1
Account Load (0.1ms) SELECT `accounts`.id FROM `accounts` WHERE (`accounts`.`email` IS NULL) LIMIT 1
SQL (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
Rendering template within layouts/application
Rendering accounts/new
Completed in 24ms (View: 19, DB: 4) | 200 OK [http://test.host/accounts?]
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing AccountsController#create (for 0.0.0.0 at 2010-01-06 14:14:20) [POST]
Parameters: {"action"=>"create", "account"=>{"password_confirmation"=>"[FILTERED]", "username"=>"foo", "password"=>"[FILTERED]", "email"=>"foo@example.com"}, "controller"=>"accounts"}
SQL (0.1ms) SAVEPOINT active_record_1
Account Load (0.2ms) SELECT `accounts`.id FROM `accounts` WHERE (`accounts`.`username` = BINARY 'foo') LIMIT 1
Account Load (0.1ms) SELECT `accounts`.id FROM `accounts` WHERE (`accounts`.`email` = BINARY 'foo@example.com') LIMIT 1
SQL (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
Rendering template within layouts/application
Rendering accounts/new
Completed in 10ms (View: 8, DB: 1) | 200 OK [http://test.host/accounts?account%5Bemail%5D=foo%40example.com&account%5Bpassword%5D=secret&account%5Bpassword_confirmation%5D=secret&account%5Busername%5D=foo]
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing AccountsController#new (for 0.0.0.0 at 2010-01-06 14:14:20) [GET]
Parameters: {"action"=>"new", "controller"=>"accounts"}
Rendering template within layouts/application
Rendering accounts/new
Completed in 3ms (View: 3, DB: 0) | 200 OK [http://test.host/accounts/new]
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing HomeController#index (for 0.0.0.0 at 2010-01-06 14:14:20) [GET]
Parameters: {"action"=>"index", "controller"=>"home"}
Rendering template within layouts/application
Rendering home/index
Completed in 2ms (View: 1, DB: 0) | 200 OK [http://test.host/]
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing JobsController#create (for 0.0.0.0 at 2010-01-06 14:14:20) [POST]
Parameters: {"action"=>"create", "controller"=>"jobs"}
Job Columns (1.6ms) SHOW FIELDS FROM `jobs`
SQL (0.1ms) SAVEPOINT active_record_1
SQL (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
Rendering template within layouts/application
Rendering jobs/new
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing JobsController#create (for 0.0.0.0 at 2010-01-06 14:14:20) [POST]
Parameters: {"action"=>"create", "controller"=>"jobs"}
SQL (0.1ms) SAVEPOINT active_record_1
Job Create (0.0ms) Mysql::Error: Column 'company' cannot be null: INSERT INTO `jobs` (`company`, `company_logo_url`, `address`, `city`, `zip`, `pay_rate`, `category`, `created_at`, `title`, `company_url`, `country`, `travel_percent`, `updated_at`, `required_skills`, `pay_period`, `length_of_employment`, `how_to_apply`, `description`, `job_type`, `hours`, `internal_id`, `desired_skills`, `state`, `onsite`, `email`) VALUES(NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2010-01-06 19:14:20', NULL, NULL, NULL, NULL, '2010-01-06 19:14:20', NULL, NULL, NULL, NULL, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL)
SQL (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Job Load (0.2ms) SELECT * FROM `jobs` LIMIT 1
Processing JobsController#destroy (for 0.0.0.0 at 2010-01-06 14:14:20) [DELETE]
Parameters: {"action"=>"destroy", "id"=>nil, "controller"=>"jobs"}
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Job Load (0.1ms) SELECT * FROM `jobs` LIMIT 1
Processing JobsController#edit (for 0.0.0.0 at 2010-01-06 14:14:20) [GET]
Parameters: {"action"=>"edit", "id"=>nil, "controller"=>"jobs"}
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing JobsController#index (for 0.0.0.0 at 2010-01-06 14:14:20) [GET]
Parameters: {"action"=>"index", "controller"=>"jobs"}
Job Load (0.1ms) SELECT * FROM `jobs` 
Rendering template within layouts/application
Rendering jobs/index
Completed in 2ms (View: 1, DB: 1) | 200 OK [http://test.host/jobs]
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing JobsController#new (for 0.0.0.0 at 2010-01-06 14:14:20) [GET]
Parameters: {"action"=>"new", "controller"=>"jobs"}
Rendering template within layouts/application
Rendering jobs/new
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Job Load (0.1ms) SELECT * FROM `jobs` LIMIT 1
Processing JobsController#show (for 0.0.0.0 at 2010-01-06 14:14:20) [GET]
Parameters: {"action"=>"show", "id"=>nil, "controller"=>"jobs"}
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Job Load (0.1ms) SELECT * FROM `jobs` LIMIT 1
Processing JobsController#update (for 0.0.0.0 at 2010-01-06 14:14:20) [PUT]
Parameters: {"action"=>"update", "id"=>nil, "controller"=>"jobs"}
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Job Load (0.1ms) SELECT * FROM `jobs` LIMIT 1
Processing JobsController#update (for 0.0.0.0 at 2010-01-06 14:14:20) [PUT]
Parameters: {"action"=>"update", "id"=>nil, "controller"=>"jobs"}
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing SessionsController#create (for 0.0.0.0 at 2010-01-06 14:14:20) [POST]
Parameters: {"action"=>"create", "controller"=>"sessions"}
Rendering template within layouts/application
Rendering sessions/new
Completed in 4ms (View: 2, DB: 1) | 200 OK [http://test.host/sessions]
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Account Load (0.1ms) SELECT * FROM `accounts` LIMIT 1
Processing SessionsController#create (for 0.0.0.0 at 2010-01-06 14:14:20) [POST]
Parameters: {"action"=>"create", "controller"=>"sessions"}
Redirected to http://test.host/
Completed in 0ms (DB: 0) | 302 Found [http://test.host/sessions]
Account Load (0.1ms) SELECT * FROM `accounts` LIMIT 1
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
Processing SessionsController#new (for 0.0.0.0 at 2010-01-06 14:14:20) [GET]
Parameters: {"action"=>"new", "controller"=>"sessions"}
Rendering template within layouts/application
Rendering sessions/new
Completed in 2ms (View: 1, DB: 0) | 200 OK [http://test.host/sessions/new]
SQL (0.1ms) ROLLBACK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment