From d3fd18a7002c15336c25e2ec0ddfb4cd7e104183 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Wed, 9 Mar 2011 19:16:48 +0300 Subject: [PATCH] Device users --- app/models/user.rb | 6 +++++ config/routes.rb | 2 ++ .../20110309144736_devise_create_users.rb | 18 ++++++++++++++ db/schema.rb | 17 ++++++++++++- db/seeds.rb | 24 +++++++++++++------ spec/models/user_spec.rb | 5 ++++ 6 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 app/models/user.rb create mode 100644 db/migrate/20110309144736_devise_create_users.rb create mode 100644 spec/models/user_spec.rb diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..b2423b3bd --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ActiveRecord::Base + devise :database_authenticatable, + :recoverable, :rememberable, :validatable + + attr_accessible :email, :password, :password_confirmation, :remember_me, :name +end diff --git a/config/routes.rb b/config/routes.rb index 525cbbd44..bb59c395c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ Rosa::Application.routes.draw do + devise_for :users + root :to => "platforms#index" end diff --git a/db/migrate/20110309144736_devise_create_users.rb b/db/migrate/20110309144736_devise_create_users.rb new file mode 100644 index 000000000..608013a61 --- /dev/null +++ b/db/migrate/20110309144736_devise_create_users.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 671c0daef..34ae0c791 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 664d8c74c..446698d82 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 000000000..44032b484 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe User do + pending "add some examples to (or delete) #{__FILE__}" +end