Skip to content

Commit

Permalink
Improved getting the Role IDs(master) (agileware-jp#53)
Browse files Browse the repository at this point in the history
* Fixed a factory of NoteTemplate

* Add test

* Fixed getting role ids
  • Loading branch information
yui-har authored Jan 26, 2023
1 parent f214000 commit 776d4ab
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/controllers/note_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def update
if template_params.key?(:role_ids)
template_params[:role_ids]
else
@note_template.note_visible_role_ids
@note_template.note_visible_roles.pluck(:role_id)
end

save_and_flash(:notice_successful_update, :show)
Expand Down
3 changes: 1 addition & 2 deletions spec/factories/note_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
sequence(:memo) { |n| "note-template-memo: #{n}" }
enabled { true }
sequence(:position) { |n| n }
visibility { 1 }
role_ids { [1] }
visibility { NoteTemplate::visibilities[:open] }
end
end
100 changes: 74 additions & 26 deletions spec/features/drag_and_drop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,80 @@
}.from([4, 1, 2, 3]).to([3, 1, 4, 2])
end

scenario 'Can drag and drop on Note Templates' do
FactoryBot.create_list(:note_template, 4, project_id: project.id, tracker_id: tracker.id)

visit_note_template_list(user)

first_target = table.find('tr:nth-child(1) > td.buttons > span')
last_target = table.find('tr:nth-child(4) > td.buttons > span')

# change id: 1, 2, 3, 4 to 4, 1, 2, 3
expect do
first_target.drag_to(last_target)
wait_for_ajax
end.to change {
NoteTemplate.reorder(:id).pluck(:position).to_a
}.from([1, 2, 3, 4]).to([4, 1, 2, 3])

# change id: 4, 1, 2, 3 to 3, 1, 4, 2
second_target = table.find('tr:nth-child(2) > td.buttons > span')
last_target = table.find('tr:nth-child(4) > td.buttons > span')

expect do
second_target.drag_to(last_target)
wait_for_ajax
end.to change {
NoteTemplate.reorder(:id).pluck(:position).to_a
}.from([4, 1, 2, 3]).to([3, 1, 4, 2])
feature 'Note Templates' do
background do
FactoryBot.rewind_sequences
end

scenario 'Can drag and drop on Note Templates' do
FactoryBot.create_list(:note_template, 4, project_id: project.id, tracker_id: tracker.id)

visit_note_template_list(user)

first_target = table.find('tr:nth-child(1) > td.buttons > span')
last_target = table.find('tr:nth-child(4) > td.buttons > span')

# id: 1, 2, 3, 4 1, 2, 3, 4
#--------------------------------------------
# change position: 1, 2, 3, 4 to 4, 1, 2, 3
expect do
first_target.drag_to(last_target)
wait_for_ajax
end.to change {
NoteTemplate.reorder(:id).pluck(:position).to_a
}.from([1, 2, 3, 4]).to([4, 1, 2, 3])

# id: 1, 2, 3, 4 1, 2, 3, 4
#--------------------------------------------
# change position: 4, 1, 2, 3 to 3, 1, 4, 2
second_target = table.find('tr:nth-child(2) > td.buttons > span')
last_target = table.find('tr:nth-child(4) > td.buttons > span')

expect do
second_target.drag_to(last_target)
wait_for_ajax
end.to change {
NoteTemplate.reorder(:id).pluck(:position).to_a
}.from([4, 1, 2, 3]).to([3, 1, 4, 2])
end

scenario 'After changing the sort position, Role settings should not change' do
developer_role = FactoryBot.create(:role)
template_list =
FactoryBot.create_list(:note_template, 2,
project_id: project.id, tracker_id: tracker.id,
visibility: NoteTemplate::visibilities[:roles],
role_ids: [role.id, developer_role.id],
)
template_list.each(&:reload)

template1 = template_list.first
expect(template1.position).to eq(1)
expect(template1.roles?).to be_truthy
expect(template1.note_visible_roles.pluck(:role_id)).to eq([role.id, developer_role.id])

visit_note_template_list(user)

expect do
tr_idx = [1, 2]
5.times do
first_target = table.find("tr:nth-child(#{tr_idx.first}) > td.buttons > span")
last_target = table.find("tr:nth-child(#{tr_idx.last}) > td.buttons > span")

first_target.drag_to(last_target)
wait_for_ajax
tr_idx.reverse!
end
end.to \
change {
NoteTemplate.reorder(:id).pluck(:position).to_a
}.from([1, 2]).to([2, 1])

template1.reload
expect(template1.position).to eq(2)
expect(template1.roles?).to be_truthy
expect(template1.note_visible_roles.pluck(:role_id)).to eq([role.id, developer_role.id])
end
end

scenario 'Can drag and drop on Global Issue Templates' do
Expand Down

0 comments on commit 776d4ab

Please sign in to comment.