Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue95 Interactor for Volunteers#reactivate #109

Merged
merged 2 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,15 @@ def knight

def reactivate
v = Volunteer.send(:with_exclusive_scope){ Volunteer.find(params[:id]) }
if (current_volunteer.admin_region_ids & v.region_ids).length > 0
v.active = true
v.save
inactive
return
else
if (current_volunteer.admin_region_ids & v.region_ids).length <= 0
flash[:error] = "You're not permitted to do that!"
redirect_to(root_path)
return
end
unless ReactivateVolunteer.call(volunteer: v).success?
flash[:error] = 'Update failed :('
end
inactive
end

def admin_only
Expand Down
11 changes: 11 additions & 0 deletions app/interactors/reactivate_volunteer.rb
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
36 changes: 36 additions & 0 deletions spec/interactors/reactivate_volunteer_spec.rb
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
2 changes: 1 addition & 1 deletion spec/interactors/toggle_super_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

subject do
described_class.call(
volunteer: volunteer
volunteer: volunteer
)
end

Expand Down