|
| 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 WorkPackageVersion do |
| 34 | + subject(:record) { described_class.new(work_package:, version:, kind: "target") } |
| 35 | + |
| 36 | + let(:work_package) { create(:work_package) } |
| 37 | + let(:version) { create(:version, project: work_package.project) } |
| 38 | + |
| 39 | + describe "associations" do |
| 40 | + it { is_expected.to belong_to(:work_package) } |
| 41 | + it { is_expected.to belong_to(:version) } |
| 42 | + end |
| 43 | + |
| 44 | + describe "validations" do |
| 45 | + it { is_expected.to be_valid } |
| 46 | + |
| 47 | + it "is invalid with an unknown kind" do |
| 48 | + record.kind = "unknown" |
| 49 | + expect(record).not_to be_valid |
| 50 | + expect(record.errors[:kind]).to be_present |
| 51 | + end |
| 52 | + |
| 53 | + it do |
| 54 | + expect(subject).to define_enum_for(:kind) |
| 55 | + .with_values(target: "target", observed_in: "observed_in") |
| 56 | + .backed_by_column_of_type(:enum) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + describe "kind scoping via through associations" do |
| 61 | + let(:other_version) { create(:version, project: work_package.project) } |
| 62 | + |
| 63 | + before do |
| 64 | + described_class.create!(work_package:, version:, kind: "target") |
| 65 | + described_class.create!(work_package:, version: other_version, kind: "observed_in") |
| 66 | + end |
| 67 | + |
| 68 | + it "target version appears in target_versions but not observed_in_versions" do |
| 69 | + expect(work_package.target_versions).to include(version) |
| 70 | + expect(work_package.observed_in_versions).not_to include(version) |
| 71 | + end |
| 72 | + |
| 73 | + it "observed_in version appears in observed_in_versions but not target_versions" do |
| 74 | + expect(work_package.observed_in_versions).to include(other_version) |
| 75 | + expect(work_package.target_versions).not_to include(other_version) |
| 76 | + end |
| 77 | + |
| 78 | + it "all versions appear in work_package.versions" do |
| 79 | + expect(work_package.versions).to include(version, other_version) |
| 80 | + end |
| 81 | + end |
| 82 | +end |
0 commit comments