Created
December 31, 2010 14:15
-
-
Save dangalipo/761044 to your computer and use it in GitHub Desktop.
DARCY!!!!!!!
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
#in spec | |
before :each do | |
@supplier = Supplier.make | |
stub(Supplier).find(1) { @supplier } | |
stub(@supplier).save { true } | |
@user_a = User.make | |
@user_b = User.make | |
stub(@supplier).users { [@user_a, @user_b] } | |
end | |
context 'supplier is active' do | |
before :each do | |
@supplier.active = true | |
post :deactivate, :id => 1 | |
end | |
it 'should deactivate all the users that belong to that supplier' do | |
mock(@user_a).lock_access! { true } | |
mock(@user_b).lock_access! { true } | |
end | |
end | |
#in controller | |
def deactivate | |
@supplier = Supplier.find(params[:id]) | |
if [email protected]? | |
flash[:notice] = t('object.supplier') + ' ' + t('flash.already_deactivated') | |
else | |
@supplier.active = false | |
if @supplier.save | |
@supplier.users.each do |user| | |
user.lock_access! | |
end | |
flash[:notice] = t('flash.successfully_deactivated') + ' ' + t('object.supplier') | |
else | |
flash[:error] = t('flash.couldnt_deactivate') + ' ' + t('object.supplier') | |
end | |
end | |
redirect_to manage_suppliers_path | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment