Skip to content

Commit

Permalink
WIP: Modify Group#deletable? for soft deleted projects
Browse files Browse the repository at this point in the history
projectsが全て論理削除されていた場合もdeletable?が真を返すようにした
  • Loading branch information
noriyotcp committed Sep 12, 2018
1 parent 65036b6 commit 08c773e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 6 additions & 6 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def destroy
return
end

projects = @group.projects.where(is_deleted: false)
projects.each { |p| p.update!(is_deleted: true) }
@group.destroy!
redirect_to :groups
rescue ActiveRecord::RecordNotSaved, ActiveRecord::RecordNotDestroyed
redirect_to [:edit, @group], alert: 'Group was not deleted.'
# TODO: soft delete
if @group.destroy
redirect_to :groups
else
redirect_to [:edit, @group], alert: 'Group was not deleted.'
end
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def generate_draft
end

def deletable?
projects.none?
projects.none? || projects.pluck(:is_deleted).all?
end

private
Expand Down
6 changes: 6 additions & 0 deletions spec/models/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,11 @@

it { is_expected.to eq false }
end

context 'when projects are all deleted' do
before { FactoryBot.create_list(:project, 2, owner: group, is_deleted: true) }

it { is_expected.to eq true }
end
end
end

0 comments on commit 08c773e

Please sign in to comment.