Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: dskecse/microblogging
base: 35d7c1d334
...
head fork: dskecse/microblogging
compare: fa77bb124f
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
1  Gemfile
@@ -5,6 +5,7 @@ ruby '2.0.0'
gem 'rails', '4.0.3'
gem 'pg', '0.17.1'
+gem 'bcrypt-ruby', '~> 3.1.2'
gem 'bootstrap-sass', '~> 2.3.2'
gem 'coffee-rails', '~> 4.0.0'
gem 'sass-rails', '~> 4.0.0'
View
4 Gemfile.lock
@@ -27,6 +27,9 @@ GEM
tzinfo (~> 0.3.37)
arel (4.0.2)
atomic (1.1.14)
+ bcrypt (3.1.7)
+ bcrypt-ruby (3.1.5)
+ bcrypt (>= 3.1.3)
bootstrap-sass (2.3.2.2)
sass (~> 3.2)
builder (3.1.4)
@@ -205,6 +208,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ bcrypt-ruby (~> 3.1.2)
bootstrap-sass (~> 2.3.2)
capybara (~> 2.2.0)
childprocess (~> 0.5.1)
View
3  app/models/user.rb
@@ -6,4 +6,7 @@ class User < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 50 }
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
+ validates :password, length: { minimum: 6 }
+
+ has_secure_password
end
View
1  config/application.rb
@@ -25,6 +25,7 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
+ I18n.enforce_available_locales = true
# Precompile images for Bootstrap-Sass gem
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
View
5 db/migrate/20140304191443_add_password_digest_to_users.rb
@@ -0,0 +1,5 @@
+class AddPasswordDigestToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :password_digest, :string
+ end
+end
View
3  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: 20140302222602) do
+ActiveRecord::Schema.define(version: 20140304191443) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -21,6 +21,7 @@
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "password_digest"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
View
40 spec/models/user_spec.rb
@@ -2,12 +2,19 @@
describe User do
before do
- @user = User.new(name: 'Example User', email: 'user@example.com')
+ @user = User.new(name: 'Example User',
+ email: 'user@example.com',
+ password: 'foobar',
+ password_confirmation: 'foobar')
end
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
+ it { should respond_to(:password_digest) }
+ it { should respond_to(:password) }
+ it { should respond_to(:password_confirmation) }
+ it { should respond_to(:authenticate) }
it { should be_valid }
@@ -54,4 +61,35 @@
it { should_not be_valid }
end
+
+ context 'when password is not present' do
+ before { @user.password = @user.password_confirmation = ' ' }
+ it { should_not be_valid }
+ end
+
+ context 'when password does not match confirmation' do
+ before { @user.password_confirmation = 'mismatch' }
+ it { should_not be_valid }
+ end
+
+ context 'when password is short' do
+ before { @user.password = @user.password_confirmation = 'a' * 5 }
+ it { should_not be_valid }
+ end
+
+ context 'return value of authenticate method' do
+ before { @user.save }
+ let(:found_user) { User.find_by(email: @user.email) }
+
+ context 'with valid password' do
+ it { should eq found_user.authenticate(@user.password) }
+ end
+
+ context 'with invalid password' do
+ let(:user_for_invalid_password) { found_user.authenticate('invalid') }
+
+ it { should_not eq user_for_invalid_password }
+ specify { expect(user_for_invalid_password).to be_false }
+ end
+ end
end

No commit comments for this range

Something went wrong with that request. Please try again.