From b53ff188fc765cfedc93c5ff908c2cdf8fda5131 Mon Sep 17 00:00:00 2001 From: junv Date: Fri, 17 Jan 2014 23:00:41 +0800 Subject: [PATCH] Start integration with Devise --- Gemfile | 5 +++-- Gemfile.lock | 13 ++++++++++++- app/models/user.rb | 7 +++++++ config/application.rb | 2 ++ config/initializers/secret_token.rb | 2 ++ config/routes.rb | 1 + db/schema.rb | 16 ++++++++++++++-- spec/models/book_spec.rb | 5 ++--- spec/models/user_spec.rb | 2 +- 9 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 5f412fb..688e2b4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ -source 'https://rubygems.org' +#source 'https://rubygems.org' -#source 'http://ruby.taobao.org' +source 'http://ruby.taobao.org' ruby '2.0.0' @@ -15,6 +15,7 @@ gem 'thin' gem 'will_paginate' gem 'nokogiri' gem 'unicorn' +gem 'devise' gem 'activesupport','4.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index a7c2b1b..9c8b3fb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: https://rubygems.org/ + remote: http://ruby.taobao.org/ specs: actionmailer (4.0.0) actionpack (= 4.0.0) @@ -29,6 +29,7 @@ GEM arel (4.0.1) atomic (1.1.14) awesome_print (1.2.0) + bcrypt-ruby (3.1.2) builder (3.1.4) capybara (2.2.1) mime-types (>= 1.16) @@ -55,6 +56,12 @@ GEM daemons (1.1.9) dalli (2.6.4) database_cleaner (1.2.0) + devise (3.2.2) + bcrypt-ruby (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 3.2.6, < 5) + thread_safe (~> 0.1) + warden (~> 1.2.3) diff-lcs (1.2.5) docile (1.1.2) erubis (2.7.0) @@ -89,6 +96,7 @@ GEM multi_test (0.0.3) nokogiri (1.6.1) mini_portile (~> 0.5.0) + orm_adapter (0.5.0) pg (0.17.1) polyglot (0.3.3) protected_attributes (1.0.3) @@ -189,6 +197,8 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) + warden (1.2.3) + rack (>= 1.0) websocket (1.0.7) will_paginate (3.0.5) xpath (2.0.0) @@ -203,6 +213,7 @@ DEPENDENCIES cucumber-rails dalli database_cleaner + devise flay jquery-rails kgio diff --git a/app/models/user.rb b/app/models/user.rb index 7f72c60..aa17408 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,11 @@ require 'utils' class User < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + #devise :database_authenticatable, :registerable, + # :recoverable, :rememberable, :trackable, :validatable + + devise :database_authenticatable, :recoverable, :stretches => 20 include Utils attr_accessible :email, :name, :avatar, :id, :location, :preferred_name @@ -16,6 +22,7 @@ class User < ActiveRecord::Base def self.create_user(name, avatar) User.create name: name, avatar: avatar + end def borrow(instance) diff --git a/config/application.rb b/config/application.rb index 76b0fbb..85f205d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -70,5 +70,7 @@ module Libr config.assets.precompile += [ Proc.new {|path| File.basename(path) =~ /^[^_].*\.\w+$/} ] + config.i18n.enforce_available_locales = true + end end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 4454429..fc304ca 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -5,3 +5,5 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Libr::Application.config.secret_token = 'ceb13c7522932aa2b100468c03f32b5eb3360df00a8d4abf9f4d770dbbcd2094ee403c5865834c9b963ecf7ad2aafdd0aad7fc0406cba260cc93f830bd322cbe' + +#Libr::Application.config.secret_key_base = 'wef323b4jh3brjhsdf98usefbhwefh' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0e6e2a3..dc88326 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Libr::Application.routes.draw do + devise_for :users root to: 'home#index' get 'books/new' => 'book#new' get 'books/:id' => 'book#view' diff --git a/db/schema.rb b/db/schema.rb index aa11639..2c31243 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20130417050322) do +ActiveRecord::Schema.define(version: 20140117135051) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -71,13 +71,25 @@ ActiveRecord::Schema.define(version: 20130417050322) do end create_table "users", force: true do |t| - t.string "email" + t.string "email", default: "", null: false t.string "name" t.datetime "created_at" t.datetime "updated_at" t.string "avatar" t.string "location" t.string "preferred_name" + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" end + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb index c14c439..ec5995e 100644 --- a/spec/models/book_spec.rb +++ b/spec/models/book_spec.rb @@ -46,7 +46,7 @@ describe :Book do it 'ensure total_borrowers will count the user who returned the book' do instance_1 = BookInstance.create book_id: @book.id, user_id: @user.id - user_1 = User.create name: 'Tom' + user_1 = User.create name: 'Tom', email: 'a@a.com' @user.borrow @instance user_1.borrow instance_1 @user.should_not == nil @@ -57,7 +57,6 @@ describe :Book do end - describe :total_available_instances do it 'ensure total available instance should be 1 after borrowed' do instance_1 = BookInstance.create book_id: @book.id, user_id: @user.id @@ -76,7 +75,7 @@ describe :Book do end it 'ensure total available instance will not include the private book' do - user_1 = User.create name: 'Nick' + user_1 = User.create name: 'Nick', email: 'a@a.com' book_1 = Book.create name: 'Big data', image: 'none', isbn: '1234567890123' instance = BookInstance.create book_id: book_1.id, user_id: user_1.id instance_2 = BookInstance.create book_id: book_1.id, user_id: user_1.id diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b870e9e..2c8a91a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -15,7 +15,7 @@ describe :User do @user.borrowed_and_not_returned_books.count.should == 1 end it 'ensure when there are two books,users can borrow these two books.' do - user_1 = User.create name: 'Nick' + user_1 = User.create name: 'Nick',email: 'a@a.com' book_1 = Book.create name: 'Big data',image:'none', isbn:'1234567890123' instance = BookInstance.create book_id: book_1.id, user_id: user_1.id instance_2 = BookInstance.create book_id: book_1.id, user_id: user_1.id