Skip to content

Commit 83591b2

Browse files
authored
Merge pull request #291 from espoo-dev/feat-devise-confirmable
Configs Devise Confirmable for Users
2 parents ec0c235 + 0755409 commit 83591b2

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

app/models/user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
class User < ApplicationRecord
44
# Include default devise modules. Others available are:
5-
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
5+
# :lockable, :timeoutable, :trackable and :omniauthable
66
devise :database_authenticatable, :registerable,
77
:recoverable, :rememberable, :validatable, :api,
8-
:omniauthable, omniauth_providers: %i[github strava]
8+
:omniauthable, :confirmable, omniauth_providers: %i[github strava]
99

1010
has_many :event_procedures, dependent: :destroy
1111
has_many :medical_shifts, dependent: :destroy

config/environments/test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
# ActionMailer::Base.deliveries array.
4747
config.action_mailer.delivery_method = :test
4848

49+
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
50+
4951
# Print deprecation notices to the stderr.
5052
config.active_support.deprecation = :stderr
5153

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
class AddConfirmableFieldsToUsers < ActiveRecord::Migration[7.1]
4+
def change
5+
change_table :users, bulk: true do |t|
6+
t.timestamp :confirmed_at
7+
t.timestamp :confirmation_sent_at
8+
t.text :confirmation_token
9+
t.text :unconfirmed_email
10+
end
11+
end
12+
end

db/schema.rb

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/models/user_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,33 @@
1616
describe "validations" do
1717
it { is_expected.to validate_uniqueness_of(:email).case_insensitive }
1818
end
19+
20+
describe "confirmations" do
21+
it "is not confirmed by default" do
22+
user = create(:user)
23+
expect(user).not_to be_confirmed
24+
end
25+
26+
it "can be confirmed" do
27+
user = create(:user)
28+
user.confirm
29+
expect(user).to be_confirmed
30+
end
31+
32+
it "generates a confirmation token" do
33+
user = create(:user)
34+
expect(user.confirmation_token).not_to be_nil
35+
end
36+
37+
it "do not allow login before confirmation" do
38+
user = create(:user)
39+
expect(user).not_to be_active_for_authentication
40+
end
41+
42+
it "allows login after confirmation" do
43+
user = create(:user)
44+
user.confirm
45+
expect(user).to be_active_for_authentication
46+
end
47+
end
1948
end

0 commit comments

Comments
 (0)