Browse files

Add an index on User#email that validates case-insensitive uniqueness…

…, and add a User#password_digest field.
  • Loading branch information...
1 parent c3ac72a commit ede33f0bba36c5de23b8e01dee88dcd5324220be @amonat committed Apr 28, 2012
Showing with 12 additions and 3 deletions.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +2 −0 app/models/user.rb
  4. +6 −3 db/schema.rb
  5. +1 −0 spec/models/user_spec.rb
View
1 Gemfile
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'bootstrap-sass', '2.0.0'
+gem 'bcrypt-ruby', '3.0.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
2 Gemfile.lock
@@ -30,6 +30,7 @@ GEM
multi_json (~> 1.0)
annotate (2.4.1.beta1)
arel (3.0.2)
+ bcrypt-ruby (3.0.1)
bootstrap-sass (2.0.0)
builder (3.0.0)
capybara (1.1.2)
@@ -151,6 +152,7 @@ PLATFORMS
DEPENDENCIES
annotate (~> 2.4.1.beta)
+ bcrypt-ruby (= 3.0.1)
bootstrap-sass (= 2.0.0)
capybara (= 1.1.2)
coffee-rails (= 3.2.2)
View
2 app/models/user.rb
@@ -12,6 +12,8 @@
class User < ActiveRecord::Base
attr_accessible :email, :name
+ before_save { |user| user.email = email.downcase }
+
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
View
9 db/schema.rb
@@ -11,13 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120428154448) do
+ActiveRecord::Schema.define(:version => 20120428184958) do
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "password_digest"
end
+ add_index "users", ["email"], :name => "index_users_on_email", :unique => true
+
end
View
1 spec/models/user_spec.rb
@@ -18,6 +18,7 @@
it { should respond_to(:name) }
it { should respond_to(:email) }
+ it { should respond_to(:password_digest) }
it { should be_valid }

0 comments on commit ede33f0

Please sign in to comment.