Device users

This commit is contained in:
Alexey Nayden 2011-03-09 19:16:48 +03:00
parent d27aff0509
commit d3fd18a700
6 changed files with 64 additions and 8 deletions

6
app/models/user.rb Normal file
View File

@ -0,0 +1,6 @@
class User < ActiveRecord::Base
devise :database_authenticatable,
:recoverable, :rememberable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :name
end

View File

@ -1,3 +1,5 @@
Rosa::Application.routes.draw do
devise_for :users
root :to => "platforms#index"
end

View File

@ -0,0 +1,18 @@
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.string :name
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
end
def self.down
drop_table :users
end
end

View File

@ -10,6 +10,21 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 0) do
ActiveRecord::Schema.define(:version => 20110309144736) do
create_table "users", :force => true do |t|
t.string "name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token"
t.string "remember_token"
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end

View File

@ -1,7 +1,17 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)
require 'digest/md5'
TEST_USERS =
[
['yaroslav@markin.net' , 'Yaroslav Markin'] ,
['timothy.tsvetkov@gmail.com' , 'Timothy Tsvetkov'] ,
['alexey.nayden@gmail.com' , 'Alexey Nayden']
]
TEST_USERS.each do |tuser|
email = tuser[0]
next if User.find_by_email(email)
name = tuser[1]
pass = Digest::MD5.hexdigest(name)[0..6]
User.create! :name => name, :email => email, :password => pass, :password_confirmation => pass
puts "Created user #{name} (#{email}) and password #{pass}"
end

5
spec/models/user_spec.rb Normal file
View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe User do
pending "add some examples to (or delete) #{__FILE__}"
end