Sha256: 9f13eb610bf695f9c712c93bb85c704b028d91f9cc83a3f9279e3427e802cf9f
Contents?: true
Size: 1.26 KB
Versions: 15
Compression:
Stored size: 1.26 KB
Contents
class UsersDataset < Dataset::Base def load create_user "Existing" create_user "Another" create_user "Admin", :admin => true create_user "Developer", :developer => true create_user "Non-admin", :admin => false end helpers do def create_user(name, attributes={}) create_model :user, name.symbolize, user_attributes(attributes.update(:name => name)) end def user_attributes(attributes={}) name = attributes[:name] || "John Doe" symbol = name.symbolize attributes = { :name => name, :email => "#{symbol}@example.com", :login => symbol.to_s, :password => "password" }.merge(attributes) attributes[:password_confirmation] = attributes[:password] attributes end def user_params(attributes={}) password = attributes[:password] || "password" user_attributes(attributes).update(:password => password, :password_confirmation => password) end def login_as(user) login_user = user.is_a?(User) ? user : users(user) flunk "Can't login as non-existing user #{user.to_s}." unless login_user request.session['user_id'] = login_user.id login_user end def logout request.session['user_id'] = nil end end end
Version data entries
15 entries across 15 versions & 2 rubygems