Skip to content

Instantly share code, notes, and snippets.

@tsnow
Created April 15, 2011 17:50
Show Gist options
  • Save tsnow/922126 to your computer and use it in GitHub Desktop.
Save tsnow/922126 to your computer and use it in GitHub Desktop.
A controller test example
require 'test_helper'
require 'shoulda_helper' #these affect AC::TestCase and need to go up here
require 'shoulda/action_controller'
class UsersControllerTest < ActionController::TestCase
require 'factories_helper'
require 'mocha_helper'
context "a visitor who wants to sign up" do
setup {get(:new)}
should respond_with(:success)
context "who enters their information" do
setup do
@user = Factory.build(:user)
#TODO: TrmsOfSvc
#TODO: Signup email
post(:create, {:user => {:email => @user.email, :login => @user.login, :password => @user.password, :password_confirmation => @user.password}})
end
should set_the_flash
should( "redirect to the home page" ){redirect_to(home_path)}
context "then wants to update their profile" do
setup{ put(:update, {:user => {:email => "blah+#{@user.email}"}}) }
# TODO: Avatars. # setup{put(:update, {:user => {:avatar => TestUploadedFile.new(Rails.root.join('public/img/avatar.jpg'))}})}
should set_the_flash
should( "redirect to the home page" ) {redirect_to(home_path)}
end
# TODO: this is probably what home controller is for
# context "and views their profile" do
# setup { get(:show) }
# should respond_with(:success)
# end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment