-
Notifications
You must be signed in to change notification settings - Fork 3.3k
STC-847 Include work package associated versions model #23841
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| class WorkPackageVersion < ApplicationRecord | ||
| enum :kind, { target: "target", observed_in: "observed_in" }, validate: true | ||
|
|
||
| belongs_to :work_package | ||
| belongs_to :version | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| class CreateWorkPackageVersions < ActiveRecord::Migration[8.1] | ||
| def change | ||
| create_enum :work_package_version_kind, ["target", "observed_in"] | ||
|
Member
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. TIL! Nice one, cheers Tom! #23841 (comment) |
||
|
|
||
| create_table :work_package_versions do |t| | ||
| t.references :work_package, null: false, foreign_key: { on_delete: :cascade }, index: false | ||
| t.references :version, null: false, foreign_key: { on_delete: :cascade }, index: false | ||
| t.enum :kind, enum_type: :work_package_version_kind, null: false | ||
| t.timestamps | ||
| end | ||
|
|
||
| add_index :work_package_versions, %i[work_package_id version_id kind], | ||
| unique: true, | ||
| name: "idx_wp_versions_on_wp_version_kind" | ||
| add_index :work_package_versions, :version_id, | ||
| name: "idx_wp_versions_on_version" | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| require "spec_helper" | ||
|
|
||
| RSpec.describe WorkPackageVersion do | ||
| subject(:record) { described_class.new(work_package:, version:, kind: "target") } | ||
|
|
||
| let(:work_package) { create(:work_package) } | ||
| let(:version) { create(:version, project: work_package.project) } | ||
|
|
||
| describe "associations" do | ||
| it { is_expected.to belong_to(:work_package) } | ||
| it { is_expected.to belong_to(:version) } | ||
| end | ||
|
|
||
| describe "validations" do | ||
| it { is_expected.to be_valid } | ||
|
|
||
| it "is invalid with an unknown kind" do | ||
| record.kind = "unknown" | ||
| expect(record).not_to be_valid | ||
| expect(record.errors[:kind]).to be_present | ||
| end | ||
|
|
||
| it do | ||
| expect(subject).to define_enum_for(:kind) | ||
| .with_values(target: "target", observed_in: "observed_in") | ||
| .backed_by_column_of_type(:enum) | ||
| end | ||
| end | ||
|
|
||
| describe "kind scoping via through associations" do | ||
| let(:other_version) { create(:version, project: work_package.project) } | ||
|
|
||
| before do | ||
| described_class.create!(work_package:, version:, kind: "target") | ||
| described_class.create!(work_package:, version: other_version, kind: "observed_in") | ||
| end | ||
|
|
||
| it "target version appears in target_versions but not observed_in_versions" do | ||
| expect(work_package.target_versions).to include(version) | ||
| expect(work_package.observed_in_versions).not_to include(version) | ||
| end | ||
|
|
||
| it "observed_in version appears in observed_in_versions but not target_versions" do | ||
| expect(work_package.observed_in_versions).to include(other_version) | ||
| expect(work_package.target_versions).not_to include(other_version) | ||
| end | ||
|
|
||
| it "all versions appear in work_package.versions" do | ||
| expect(work_package.versions).to include(version, other_version) | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You could name this "WorkPackage::Version". (Then the file goes to
app/models/work_package/version). This helps to keep the global namespace overseeable.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.
I like the idea of scoping models, but I don't like having two models called
version.rb. That and the fact thatWorkPackage&Versionare both core models of OpenProject. We could discuss for example if the model should be scoped the other way aroundVersion::WorKPackage.So at this moment I'd prefer to keep it
work_package_version.Open to being convinced otherwise, though.
Uh oh!
There was an error while loading. Please reload this page.
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.
Since
WorkPackageVersionis a join table, I don't think the namespacing semantics apply here, and we're better off keeping it as-is.With that said, it would be nice to pin down a single specific convention in place for these join tables -- AFAIK this is one of the two that are currently in use (= just concatenating the names of both models).