|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# -- copyright |
| 4 | +# OpenProject is an open source project management software. |
| 5 | +# Copyright (C) the OpenProject GmbH |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU General Public License version 3. |
| 9 | +# |
| 10 | +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
| 11 | +# Copyright (C) 2006-2013 Jean-Philippe Lang |
| 12 | +# Copyright (C) 2010-2013 the ChiliProject Team |
| 13 | +# |
| 14 | +# This program is free software; you can redistribute it and/or |
| 15 | +# modify it under the terms of the GNU General Public License |
| 16 | +# as published by the Free Software Foundation; either version 2 |
| 17 | +# of the License, or (at your option) any later version. |
| 18 | +# |
| 19 | +# This program is distributed in the hope that it will be useful, |
| 20 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +# GNU General Public License for more details. |
| 23 | +# |
| 24 | +# You should have received a copy of the GNU General Public License |
| 25 | +# along with this program; if not, write to the Free Software |
| 26 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 27 | +# |
| 28 | +# See COPYRIGHT and LICENSE files for more details. |
| 29 | +# ++ |
| 30 | + |
| 31 | +require "spec_helper" |
| 32 | + |
| 33 | +RSpec.describe Grids::Overview do |
| 34 | + let(:instance) { described_class.new(row_count: 5, column_count: 5) } |
| 35 | + |
| 36 | + context "when altering widgets" do |
| 37 | + shared_examples_for "removing a query widget" do |identifier| |
| 38 | + let(:project) { create(:project) } |
| 39 | + let(:query) do |
| 40 | + create(:query, |
| 41 | + public: true, |
| 42 | + project:) |
| 43 | + end |
| 44 | + |
| 45 | + current_user { build_stubbed(:user) } |
| 46 | + |
| 47 | + before do |
| 48 | + widget = Grids::Widget.new(identifier:, |
| 49 | + start_row: 1, |
| 50 | + end_row: 2, |
| 51 | + start_column: 1, |
| 52 | + end_column: 2, |
| 53 | + options: { "queryId" => query.id }) |
| 54 | + |
| 55 | + instance.widgets = [widget] |
| 56 | + instance.save! |
| 57 | + end |
| 58 | + |
| 59 | + context "when the current user has the permission to manage public queries" do |
| 60 | + before do |
| 61 | + mock_permissions_for(current_user) do |mock| |
| 62 | + mock.allow_in_project :manage_public_queries, project: |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + it "removes the widget's query" do |
| 67 | + instance.widgets = [] |
| 68 | + |
| 69 | + expect(Query.find_by(id: query.id)) |
| 70 | + .to be_nil |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + context "when the current user lacks the permission to manage public queries" do |
| 75 | + current_user { create(:user) } |
| 76 | + |
| 77 | + it "removes the widget but keeps the query" do |
| 78 | + instance.widgets = [] |
| 79 | + |
| 80 | + expect(Query.find_by(id: query.id)) |
| 81 | + .to eql query |
| 82 | + end |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + it_behaves_like "removing a query widget", "work_packages_table" |
| 87 | + it_behaves_like "removing a query widget", "work_packages_graph" |
| 88 | + end |
| 89 | +end |
0 commit comments