Skip to content

Commit

Permalink
completed specs for password reset token and added fail condition
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Nov 27, 2015
1 parent 93221a8 commit b0f46e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/interactors/create_password_reset_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class CreatePasswordResetToken
include Interactor

def call
context.fail! unless context.user
context.user.reset_token = generate_reset_token
update_reset_attributes(context.enc, Time.zone.now)
end
Expand Down
35 changes: 35 additions & 0 deletions spec/interactors/create_password_reset_token_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "rails_helper"

RSpec.describe CreatePasswordResetToken do
describe ".call" do
let(:user) { create(:confirmed_user, reset_token: nil) }

context "when successful" do
subject do
described_class.call(user: user)
end

it "sets the user's reset token" do
expect(subject.user.reset_token).to eq(subject.raw)
end

it "sets the user's reset_digest" do
expect(subject.user.reset_digest).to eq(subject.enc)
end

it "sets the user's reset_sent_at" do
expect(subject.user.reset_sent_at).to be_an(ActiveSupport::TimeWithZone)
end
end

context "when there isn't a valid user" do
subject do
described_class.call(user: nil)
end

it "fails" do
is_expected.to be_a_failure
end
end
end
end

0 comments on commit b0f46e2

Please sign in to comment.