-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue95: Interactor for Volunteers#reactivate
- Loading branch information
Showing
3 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ReactivateVolunteer | ||
include Interactor | ||
|
||
delegate :volunteer, | ||
:fail!, | ||
to: :context | ||
|
||
def call | ||
fail! unless volunteer.update_attribute(:active, true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ReactivateVolunteer do | ||
describe '::call' do | ||
subject do | ||
described_class.call( | ||
volunteer: volunteer | ||
) | ||
end | ||
|
||
let(:volunteer) do | ||
create(:volunteer, active: false) | ||
end | ||
|
||
it 'activates the volunteer' do | ||
expect(subject.success?).to eq(true) | ||
expect(volunteer.reload.active).to eq(true) | ||
end | ||
|
||
it 'fails if it cannot save the volunteer' do | ||
expect(volunteer).to receive(:update_attribute).and_return false | ||
expect(subject.success?).to eq(false) | ||
end | ||
|
||
context 'volunteer is already active' do | ||
let(:volunteer) do | ||
create(:volunteer, active: true) | ||
end | ||
|
||
it 'leaves volunteer active' do | ||
expect(subject.success?).to eq(true) | ||
expect(volunteer.reload.active).to eq(true) | ||
end | ||
end | ||
end | ||
end |