Skip to content

Instantly share code, notes, and snippets.

@diabolo
Created February 4, 2010 23:36
Show Gist options
  • Save diabolo/295274 to your computer and use it in GitHub Desktop.
Save diabolo/295274 to your computer and use it in GitHub Desktop.
module UserStepHelper
def user_fill_in_login(name, password=nil)
login = name =~ /@/ ? name : remove_non_ascii(name)+'@example.com'
login.downcase!
password ||= name + 'pass'
fill_in('login', :with => login)
fill_in('password', :with => password)
end
def user_fill_in_signup(name)
fill_in('user[email]', :with => remove_non_ascii(name) + '@example.com')
fill_in('user[password]', :with => name + 'pass')
fill_in('user[password_confirmation]', :with => name + 'pass')
end
def user_create_with_login(login)
User.generate!(:password => login + "pass",
:password_confirmation => login + "pass",
:email => remove_non_ascii(login.downcase) + "@example.com",
:name => login)
end
def user_create_registered_user(login)
@user = user_create_with_login(login)
@user.register!
@user.state.should == 'pending'
@user
end
def user_create_activated_user(login)
@user = user_create_with_login(login)
@user.register!
@user.activate!
@user.state.should == 'active'
@user
end
def user_create_admin_user(login)
user = user_create_activated_user(login)
user.admin = true
user.save!
user.is_admin?.should be_true
end
# retrieve user from db
def user_get_record(login)
User.find_by_email(login.remove_non_ascii + "@example.com")
end
end
World(UserStepHelper)
Given /^a registered user (\w*) exists$/ do |user|
user_create_registered_user(user)
end
Given /^an activated user (\w*) exists$/ do |user|
user_create_activated_user(user)
end
Given /^an admin user (\w*) exists$/ do |user|
user_create_admin_user(user)
end
When /^I fill in (.*) signup details$/ do |user|
user_fill_in_signup(user)
end
When /^I signup as (\w*)$/ do |user|
visit signup_path
user_fill_in_signup(user)
click_button
end
When /^I signup as (.*) with wrong confirmation$/ do |user|
visit signup_path
user_fill_in_signup(user)
fill_in('user[password_confirmation]', :with => 'poopypoop')
click_button
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment