OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add banner type for EnterpriseToken
Klaus Zandersaf4728db8bc5
diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rbindex 7aff6d7c8c0..55b2d0c44f8 100644--- a/app/models/enterprise_token.rb+++ b/app/models/enterprise_token.rb@@ -53,6 +53,14 @@ class EnterpriseToken < ApplicationRecordendend+ def banner_type_for(feature:)+ if !active?+ :no_token+ elsif !allows_to?(feature)+ :upsell+ end+ end+def set_current_tokentoken = EnterpriseToken.order(Arel.sql("created_at DESC")).firstdiff --git a/spec/models/enterprise_token_spec.rb b/spec/models/enterprise_token_spec.rbindex 9a3b045ff89..1475a548211 100644--- a/spec/models/enterprise_token_spec.rb+++ b/spec/models/enterprise_token_spec.rb@@ -118,6 +118,43 @@ RSpec.describe EnterpriseToken doendend+ describe ".banner_type_for" do+ before do+ allow(described_class).to receive(:allows_to?).with(:active_feature).and_return(true)+ allow(described_class).to receive(:allows_to?).with(:inactive_feature).and_return(false)+ end++ context "without an EnterpriseToken" do+ before do+ allow(described_class).to receive(:active?).and_return(false)+ end++ it "returns :no_token" do+ expect(described_class.banner_type_for(feature: :active_feature)).to eq(:no_token)+ end+ end++ context "with a feature that is included in the EnterpriseToken" do+ before do+ allow(described_class).to receive(:active?).and_return(true)+ end++ it "returns nil" do+ expect(described_class.banner_type_for(feature: :active_feature)).to be_nil+ end+ end++ context "with a feature that is not included in the EnterpriseToken" do+ before do+ allow(described_class).to receive(:active?).and_return(true)+ end++ it "returns :upsell" do+ expect(described_class.banner_type_for(feature: :inactive_feature)).to eq(:upsell)+ end+ end+ end+describe "existing token" dobefore doallow_any_instance_of(EnterpriseToken).to receive(:token_object).and_return(object)