Skip to content

Commit

Permalink
Merge pull request #13565 from opf/bug/49782-error-on-creating-versio…
Browse files Browse the repository at this point in the history
…n-boards

[#49782] Fix out-of-bounds widgets error when creating Version Boards
  • Loading branch information
cbliard committed Aug 25, 2023
2 parents b8e91e3 + 85de0f9 commit ad9f819
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def before_perform(params, _service_result)

private

def column_count_for_board
[super, versions(params).count].max
end

def create_queries(params)
versions(params).map do |version|
Queries::CreateService.new(user: User.current)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
RSpec.describe Boards::VersionBoardCreateService do
shared_let(:project) { create(:project) }
shared_let(:other_project) { create(:project) }
shared_let(:versions) { create_list(:version, 3, project:) }
# Amount of versions is important to test that the right column count is
# set by the service. It should set the column count to the number of versions
# and avoid out of bounds errors.
shared_let(:versions) { create_list(:version, 5, project:) }
shared_let(:excluded_versions) do
[
create(:version, project:, status: 'closed'),
Expand Down Expand Up @@ -68,6 +71,25 @@
expect(board.options[:type]).to eq('action')
end

describe 'column_count' do
it 'matches the column_count to the version count' do
board = subject.result

expect(board.column_count).to eq(versions.count)
end

context 'when there are no versions that apply for the project' do
before do
versions.each { _1.update!(status: 'closed') }
end

it 'sets the column_count to the default value' do
board = subject.result
expect(board.column_count).to eq(4)
end
end
end

describe 'widgets and queries' do
let(:board) { subject.result }
let(:widgets) { board.widgets }
Expand Down

0 comments on commit ad9f819

Please sign in to comment.