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
Unassign guiders from groups #52
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class DestroyGroupAssignments | ||
def initialize(user_ids, group_id) | ||
@user_ids = user_ids | ||
@group_id = group_id | ||
end | ||
|
||
def call | ||
GroupAssignment | ||
.where(user_id: user_ids, group_id: group_id) | ||
.delete_all | ||
end | ||
|
||
private | ||
|
||
attr_reader :user_ids | ||
attr_reader :group_id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these needed? |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,30 @@ | |
end | ||
end | ||
|
||
scenario 'Unassigning a group from multiple guiders', js: true do | ||
given_the_user_is_a_resource_manager do | ||
and_there_are_guiders_assigned_to_groups | ||
when_they_visit_the_guiders_page | ||
and_they_choose_to_remove_groups_from_multiple_guiders | ||
then_they_see_the_guiders_they_will_affect | ||
when_they_remove_a_group | ||
then_the_group_is_unassigned_from_those_guiders | ||
end | ||
end | ||
|
||
def and_they_choose_to_remove_groups_from_multiple_guiders | ||
and_they_choose_to_add_groups_to_multiple_guiders | ||
end | ||
|
||
def when_they_remove_a_group | ||
@page.groups.first.remove.click | ||
end | ||
|
||
def then_the_group_is_unassigned_from_those_guiders | ||
expect(@page).to have_flash_of_success | ||
expect(@page).to have_no_text(@team_one.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tempting to check the groups are removed in the database too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behaviour is covered in the spec I added for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I read the description now. Why is that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They could be reassigned in future as providing the name of an existing group would use that particular instance. Also it cuts out on the need for weird logic checking that the group doesn't have associated assignments and deleting on that basis. I'm adding a typeahead on the group text field so this would expose the existing groups too. |
||
end | ||
|
||
def and_they_choose_to_add_groups_to_multiple_guiders | ||
@page.guiders.map(&:checkbox).each { |c| c.set(true) } | ||
@page.wait_for_action_panel | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe DestroyGroupAssignments, '#call' do | ||
let(:group) { create(:group) } | ||
let(:users) { create_list(:guider, 2) } | ||
let(:user_ids) { users.map(&:id) } | ||
|
||
before do | ||
users.each { |u| u.groups << group } | ||
end | ||
|
||
subject { described_class.new(user_ids, group.id) } | ||
|
||
context 'for the given users' do | ||
it 'unassigns the given group' do | ||
expect { subject.call }.to change { GroupAssignment.count }.by(-2) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The users were assigned from the specified groups"
should this be changed to:
go_back_with_success('assigned to')