Skip to content

Commit

Permalink
Merge pull request #22 from npauzenga/tasks/interactor-specs
Browse files Browse the repository at this point in the history
Tasks/interactor specs
  • Loading branch information
npauzenga committed Nov 21, 2015
2 parents 40b724f + decf12a commit 3978d74
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spec/interactors/create_user_session_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "rails_helper"

RSpec.describe CreateUserSession do
subject { described_class }

let(:authenticate_user) { double("authenticate_user") }
let(:login_user) { double("login_user") }

before(:example) do
allow(AuthenticateUser).to receive(:new).and_return(authenticate_user)
allow(authenticate_user).to receive(:run!)
allow(authenticate_user).to receive(:run)
allow(authenticate_user).to receive(:context)

allow(LoginUser).to receive(:new).and_return(login_user)
allow(login_user).to receive(:run!)
allow(login_user).to receive(:run)
allow(login_user).to receive(:context)
end

describe ".call" do
it "calls the AuthenticateUser interactor" do
expect(authenticate_user).to receive(:run!)
subject.call
end

it "calls the LoginUser interactor" do
expect(login_user).to receive(:run!)
subject.call
end
end
end
62 changes: 62 additions & 0 deletions spec/interactors/create_user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require "rails_helper"

RSpec.describe CreateUser do
subject { described_class }

let(:user) { create(:unconfirmed_user) }

let(:interactor_context) do
Interactor::Context.new(errors: :val, user: user)
end

let(:make_new_user) { double("make_new_user") }
let(:encrypt_password) { double("encrypt_password") }
let(:create_confirmation_token) { double("create_confirmation_token") }
let(:send_new_user_confirmation) { double("send_new_user_confirmation") }

before(:example) do
allow(MakeNewUser).to receive(:new).and_return(make_new_user)
allow(make_new_user).to receive(:run!)
allow(make_new_user).to receive(:run)
allow(make_new_user).to receive(:context)

allow(EncryptPassword).to receive(:new).and_return(encrypt_password)
allow(encrypt_password).to receive(:run!)
allow(encrypt_password).to receive(:run)
allow(encrypt_password).to receive(:context)

allow(CreateConfirmationToken).to receive(:new).
and_return(create_confirmation_token)
allow(create_confirmation_token).to receive(:run!)
allow(create_confirmation_token).to receive(:run)
allow(create_confirmation_token).to receive(:context)

allow(SendNewUserConfirmation).to receive(:new).
and_return(send_new_user_confirmation)
allow(send_new_user_confirmation).to receive(:run!)
allow(send_new_user_confirmation).to receive(:run)
allow(send_new_user_confirmation).to receive(:context)
end

describe ".call" do
it "calls the MakeNewUser interactor" do
expect(make_new_user).to receive(:run!)
subject.call(interactor_context)
end

it "calls the EncryptPassword interactor" do
expect(encrypt_password).to receive(:run!)
subject.call(interactor_context)
end

it "calls the CreateConfirmationToken interactor" do
expect(create_confirmation_token).to receive(:run!)
subject.call(interactor_context)
end

it "calls the SendNewUserConfirmation interactor" do
expect(send_new_user_confirmation).to receive(:run!)
subject.call(interactor_context)
end
end
end
46 changes: 46 additions & 0 deletions spec/interactors/request_password_reset_token_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "rails_helper"

RSpec.describe RequestPasswordResetToken do
subject { described_class }

let(:find_password_reset_user) { double("find_password_reset_user") }
let(:create_password_reset_token) { double("create_password_reset_token") }
let(:send_password_reset_email) { double("send_password_reset_email") }

before(:example) do
allow(FindPasswordResetUser).to receive(:new).
and_return(find_password_reset_user)
allow(find_password_reset_user).to receive(:run!)
allow(find_password_reset_user).to receive(:run)
allow(find_password_reset_user).to receive(:context)

allow(CreatePasswordResetToken).to receive(:new).
and_return(create_password_reset_token)
allow(create_password_reset_token).to receive(:run!)
allow(create_password_reset_token).to receive(:run)
allow(create_password_reset_token).to receive(:context)

allow(SendPasswordResetEmail).to receive(:new).
and_return(send_password_reset_email)
allow(send_password_reset_email).to receive(:run!)
allow(send_password_reset_email).to receive(:run)
allow(send_password_reset_email).to receive(:context)
end

describe ".call" do
it "calls the FindPasswordResetUser interactor" do
expect(find_password_reset_user).to receive(:run!)
subject.call
end

it "calls the CreatePasswordResetToken interactor" do
expect(create_password_reset_token).to receive(:run!)
subject.call
end

it "calls the SendPasswordResetEmail interactor" do
expect(send_password_reset_email).to receive(:run!)
subject.call
end
end
end
32 changes: 32 additions & 0 deletions spec/interactors/reset_password_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "rails_helper"

RSpec.describe ResetPassword do
subject { described_class }

let(:update_password) { double("update_password") }
let(:login_user) { double("login_user") }

before(:example) do
allow(UpdatePassword).to receive(:new).and_return(update_password)
allow(update_password).to receive(:run!)
allow(update_password).to receive(:run)
allow(update_password).to receive(:context)

allow(LoginUser).to receive(:new).and_return(login_user)
allow(login_user).to receive(:run!)
allow(login_user).to receive(:run)
allow(login_user).to receive(:context)
end

describe ".call" do
it "calls the UpdatePassword interactor" do
expect(update_password).to receive(:run!)
subject.call
end

it "calls the LoginUser interactor" do
expect(login_user).to receive(:run!)
subject.call
end
end
end
37 changes: 37 additions & 0 deletions spec/interactors/verify_password_reset_user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require "rails_helper"

RSpec.describe VerifyPasswordResetUser do
subject { described_class }

let(:find_password_reset_token) { double("find_password_reset_token") }

let(:check_password_reset_expiration) do
double("check_password_reset_expiration")
end

before(:example) do
allow(FindPasswordResetToken).to receive(:new).
and_return(find_password_reset_token)
allow(find_password_reset_token).to receive(:run!)
allow(find_password_reset_token).to receive(:run)
allow(find_password_reset_token).to receive(:context)

allow(CheckPasswordResetExpiration).to receive(:new).
and_return(check_password_reset_expiration)
allow(check_password_reset_expiration).to receive(:run!)
allow(check_password_reset_expiration).to receive(:run)
allow(check_password_reset_expiration).to receive(:context)
end

describe ".call" do
it "calls the FindPasswordResetToken interactor" do
expect(find_password_reset_token).to receive(:run!)
subject.call
end

it "calls the CheckPasswordResetExpiration interactor" do
expect(check_password_reset_expiration).to receive(:run!)
subject.call
end
end
end

0 comments on commit 3978d74

Please sign in to comment.