mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
@@ -32,10 +32,18 @@ module WorkPackageTypes
|
||||
class UpdateSubjectPatternContract < BaseContract
|
||||
attribute :patterns
|
||||
|
||||
validate :enterprise_edition
|
||||
validate :validate_subject_generation_pattern
|
||||
|
||||
private
|
||||
|
||||
def enterprise_edition
|
||||
action = :work_package_subject_generation
|
||||
if model.patterns.subject&.enabled && !EnterpriseToken.allows_to?(action)
|
||||
errors.add(:patterns, :error_enterprise_only, action: action.to_s.titleize)
|
||||
end
|
||||
end
|
||||
|
||||
def validate_subject_generation_pattern
|
||||
blueprint = model.patterns.subject&.blueprint
|
||||
return if blueprint.nil?
|
||||
|
||||
@@ -104,32 +104,25 @@ RSpec.describe WorkPackageTypes::SubjectConfigurationComponent, type: :component
|
||||
end
|
||||
|
||||
context "when enterprise edition is not activated", with_ee: %i[] do
|
||||
it "shows the enterprise banner" do
|
||||
it "shows the large enterprise banner" do
|
||||
render_component
|
||||
|
||||
expect(page).to have_enterprise_banner(:professional)
|
||||
end
|
||||
|
||||
it "disables only automatic mode selector", :aggregate_failures do
|
||||
render_component
|
||||
|
||||
expect(page.find("input[type=radio][value=generated]")).to be_disabled
|
||||
expect(page.find("input[type=radio][value=manual]")).not_to be_disabled
|
||||
expect(page).to have_enterprise_banner(:professional, class: "op-enterprise-banner_large")
|
||||
end
|
||||
|
||||
context "and when the subject is already automatically generated" do
|
||||
let(:type) { create(:type, patterns: { subject: { blueprint: "Hello world", enabled: true } }) }
|
||||
|
||||
it "shows the enterprise banner" do
|
||||
it "shows the inline enterprise banner" do
|
||||
render_component
|
||||
|
||||
expect(page).to have_enterprise_banner(:professional)
|
||||
expect(page).to have_enterprise_banner(:professional, class: "op-enterprise-banner_medium")
|
||||
end
|
||||
|
||||
it "enables mode selectors", :aggregate_failures do
|
||||
render_component
|
||||
|
||||
expect(page.find("input[type=radio][value=generated]")).not_to be_disabled
|
||||
expect(page.find("input[type=radio][value=generated]")).to be_disabled
|
||||
expect(page.find("input[type=radio][value=manual]")).not_to be_disabled
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
require "spec_helper"
|
||||
|
||||
module WorkPackageTypes
|
||||
RSpec.describe UpdateSubjectPatternContract do
|
||||
RSpec.describe UpdateSubjectPatternContract, with_ee: [:work_package_subject_generation] do
|
||||
let(:model) { create(:type, :with_subject_pattern) }
|
||||
let(:user) { create(:admin) }
|
||||
|
||||
@@ -44,12 +44,28 @@ module WorkPackageTypes
|
||||
expect(contract.validate).to be_falsey
|
||||
end
|
||||
|
||||
it "adds and error to the contract" do
|
||||
it "adds an error to the contract" do
|
||||
contract.validate
|
||||
expect(contract.errors.details).to eq(base: [{ error: :error_unauthorized }])
|
||||
end
|
||||
end
|
||||
|
||||
context "if there is no enterprise token that allows subject configuration", with_ee: [] do
|
||||
it "adds an error to the contract" do
|
||||
contract.validate
|
||||
expect(contract.errors.details)
|
||||
.to eq(patterns: [{ action: "Work Package Subject Generation", error: :error_enterprise_only }])
|
||||
end
|
||||
|
||||
context "with manual subject configuration" do
|
||||
let(:model) { create(:type) }
|
||||
|
||||
it "succeeds" do
|
||||
expect(contract.validate).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "subject_pattern validation" do
|
||||
let(:valid_pattern) { { subject: { blueprint: "{{author}}", enabled: true } } }
|
||||
let(:invalid_pattern) { { subject: { blueprint: "{{vader_s_rubber_duck}}", enabled: true } } }
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
require "spec_helper"
|
||||
|
||||
module WorkPackageTypes
|
||||
RSpec.describe SetAttributesService do
|
||||
RSpec.describe SetAttributesService, with_ee: [:work_package_subject_generation] do
|
||||
let(:user) { create(:admin) }
|
||||
let(:model) { create(:type, :with_subject_pattern) }
|
||||
let(:params) { Hash.new }
|
||||
|
||||
Reference in New Issue
Block a user