Skip to content

Commit

Permalink
Merge 7ead975 into 345ff2f
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Jan 12, 2016
2 parents 345ff2f + 7ead975 commit e677202
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/interactors/find_user_by_reset_token.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
class FindUserByResetToken
include Interactor
class FindUserByResetToken < StandardInteraction
def validate_input
context.fail!(errors: "invalid input") unless context.reset_token
end

def execute
context.user = User.find_by(reset_digest: digest_token)
end

def validate_output
context.fail!(errors: "invalid output") unless context.user
end

private

def call
def digest_token
Encryptor.digest_token(context.reset_token)
end
end
59 changes: 59 additions & 0 deletions spec/interactors/find_user_by_reset_token_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
RSpec.describe FindUserByResetToken do
describe ".call" do
let(:token) { Encryptor.generate_token }

context "when successful" do
before do
@user = create(:confirmed_user, reset_digest: token[0])
end

subject do
described_class.call(reset_token: token[1])
end

it "is a success" do
is_expected.to be_a_success
end

it "find the user" do
expect(subject.user).to eq(@user)
end
end

context "when reset token not provided" do
before do
create(:confirmed_user, reset_digest: token[0])
end

subject do
described_class.call(reset_token: nil)
end

it "fails" do
is_expected.to be_a_failure
end

it "adds an error to errors" do
expect(subject.errors).to eq("invalid input")
end
end

context "when user not found" do
before do
create(:confirmed_user, reset_digest: "differenttoken")
end

subject do
described_class.call(reset_token: token[1])
end

it "fails" do
is_expected.to be_a_failure
end

it "adds an error to errors" do
expect(subject.errors).to eq("invalid output")
end
end
end
end

0 comments on commit e677202

Please sign in to comment.