Skip to content

Instantly share code, notes, and snippets.

@Oshuma
Created November 30, 2008 16:35
Show Gist options
  • Select an option

  • Save Oshuma/30473 to your computer and use it in GitHub Desktop.

Select an option

Save Oshuma/30473 to your computer and use it in GitHub Desktop.
Merb spec helpers to test authenticated actions.
def create_article(options = {})
create_and_authenticate_user
Article.all.destroy!
request(resource(:articles), :method => "POST",
:params => { :article => { :id => nil, :title => 'Title',
:content => 'Blog post.' }})
end
def create_and_authenticate_user
User.all.destroy!
User.new(:login => 'luser',
:password => 'secret', :password_confirmation => 'secret').save
authenticate_user
end
def authenticate_user
request(url(:perform_login), :method => "PUT",
:params => {:login => 'luser', :password => 'secret'})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment