Skip to content

Commit af4728d

Browse files
klaustopheroliverguenther
authored andcommitted
Add banner type for EnterpriseToken
1 parent d8885ff commit af4728d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

app/models/enterprise_token.rb

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ def show_banners?(feature: nil)
5353
end
5454
end
5555

56+
def banner_type_for(feature:)
57+
if !active?
58+
:no_token
59+
elsif !allows_to?(feature)
60+
:upsell
61+
end
62+
end
63+
5664
def set_current_token
5765
token = EnterpriseToken.order(Arel.sql("created_at DESC")).first
5866

spec/models/enterprise_token_spec.rb

+37
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,43 @@
118118
end
119119
end
120120

121+
describe ".banner_type_for" do
122+
before do
123+
allow(described_class).to receive(:allows_to?).with(:active_feature).and_return(true)
124+
allow(described_class).to receive(:allows_to?).with(:inactive_feature).and_return(false)
125+
end
126+
127+
context "without an EnterpriseToken" do
128+
before do
129+
allow(described_class).to receive(:active?).and_return(false)
130+
end
131+
132+
it "returns :no_token" do
133+
expect(described_class.banner_type_for(feature: :active_feature)).to eq(:no_token)
134+
end
135+
end
136+
137+
context "with a feature that is included in the EnterpriseToken" do
138+
before do
139+
allow(described_class).to receive(:active?).and_return(true)
140+
end
141+
142+
it "returns nil" do
143+
expect(described_class.banner_type_for(feature: :active_feature)).to be_nil
144+
end
145+
end
146+
147+
context "with a feature that is not included in the EnterpriseToken" do
148+
before do
149+
allow(described_class).to receive(:active?).and_return(true)
150+
end
151+
152+
it "returns :upsell" do
153+
expect(described_class.banner_type_for(feature: :inactive_feature)).to eq(:upsell)
154+
end
155+
end
156+
end
157+
121158
describe "existing token" do
122159
before do
123160
allow_any_instance_of(EnterpriseToken).to receive(:token_object).and_return(object)

0 commit comments

Comments
 (0)