fix issue #217 (memberships not correctly removed)
This commit is contained in:
parent
544e9e5c3c
commit
016d773b2d
@ -47,12 +47,12 @@ class Account
|
|||||||
|
|
||||||
def remove_memberships!
|
def remove_memberships!
|
||||||
self.sites.each do |site|
|
self.sites.each do |site|
|
||||||
site.memberships.delete_if { |m| m.account_id == self._id }
|
membership = site.memberships.where(:account_id => self._id).first
|
||||||
|
|
||||||
if site.admin_memberships.empty?
|
if site.admin_memberships.size == 1 && membership.admin?
|
||||||
raise I18n.t('errors.messages.needs_admin_account')
|
raise I18n.t('errors.messages.needs_admin_account')
|
||||||
else
|
else
|
||||||
site.save
|
membership.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,13 +47,14 @@ describe Account do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should also delete memberships' do
|
it 'should also delete memberships' do
|
||||||
Site.any_instance.stubs(:admin_memberships).returns(['junk'])
|
Site.any_instance.stubs(:admin_memberships).returns(['junk', 'dirt'])
|
||||||
|
@site_1.memberships.first.expects(:destroy)
|
||||||
|
@site_2.memberships.first.expects(:destroy)
|
||||||
@account.destroy
|
@account.destroy
|
||||||
@site_1.memberships.should be_empty
|
|
||||||
@site_2.memberships.should be_empty
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise an exception if account is the only remaining admin' do
|
it 'should raise an exception if account is the only remaining admin' do
|
||||||
|
@site_1.memberships.first.stubs(:admin?).returns(true)
|
||||||
@site_1.stubs(:admin_memberships).returns(['junk'])
|
@site_1.stubs(:admin_memberships).returns(['junk'])
|
||||||
lambda {
|
lambda {
|
||||||
@account.destroy
|
@account.destroy
|
||||||
|
Loading…
Reference in New Issue
Block a user