Fix tests

This commit is contained in:
Eugene Burmakin 2025-04-04 21:39:59 +02:00
parent 600c88ae01
commit 67916c10c4
4 changed files with 13 additions and 13 deletions

View file

@ -100,6 +100,10 @@ class User < ApplicationRecord
end
end
def can_subscribe?
active_until&.past? && !DawarichSettings.self_hosted?
end
def generate_subscription_token
payload = {
user_id: id,
@ -149,8 +153,4 @@ class User < ApplicationRecord
)
end
# rubocop:enable Metrics/MethodLength
def can_subscribe?
active_until&.past? && !DawarichSettings.self_hosted?
end
end

View file

@ -19,9 +19,9 @@
</ul>
</details>
</li>
<%# if user_signed_in? && current_user.can_subscribe? %>
<% if user_signed_in? && current_user.can_subscribe? %>
<li><%= link_to 'Subscribe', "#{ENV['SUBSCRIPTION_URL']}/auth/dawarich?token=#{current_user.generate_subscription_token}", class: 'btn btn-sm btn-success' %></li>
<%# end %>
<% end %>
</ul>
</div>
<%= link_to 'Dawarich', root_path, class: 'btn btn-ghost normal-case text-xl'%>
@ -70,9 +70,9 @@
<div class="navbar-end">
<ul class="menu menu-horizontal bg-base-100 rounded-box px-1">
<% if user_signed_in? %>
<%# if current_user.can_subscribe? %>
<% if current_user.can_subscribe? %>
<li><%= link_to 'Subscribe', "#{ENV['SUBSCRIPTION_URL']}/auth/dawarich?token=#{current_user.generate_subscription_token}", class: 'btn btn-sm btn-success' %></li>
<%# end %>
<% end %>
<div class="dropdown dropdown-end dropdown-bottom dropdown-hover"
data-controller="notifications"

View file

@ -98,7 +98,7 @@ RSpec.describe VisitSuggestingJob, type: :job do
context 'when user is inactive' do
before do
user.update(status: :inactive)
user.update(status: :inactive, active_until: 1.day.ago)
allow(Visits::Suggest).to receive(:new).and_call_original
allow_any_instance_of(Visits::Suggest).to receive(:call)

View file

@ -186,7 +186,7 @@ RSpec.describe User, type: :model do
end
context 'when user is active' do
let(:user) { create(:user, status: :active) }
let!(:user) { create(:user, status: :active, active_until: 1000.years.from_now) }
it 'returns false' do
expect(user.can_subscribe?).to be_falsey
@ -194,7 +194,7 @@ RSpec.describe User, type: :model do
end
context 'when user is inactive' do
let(:user) { create(:user, status: :inactive) }
let(:user) { create(:user, status: :inactive, active_until: 1.day.ago) }
it 'returns false' do
expect(user.can_subscribe?).to be_falsey
@ -208,7 +208,7 @@ RSpec.describe User, type: :model do
end
context 'when user is active' do
let(:user) { create(:user, status: :active) }
let(:user) { create(:user, status: :active, active_until: 1000.years.from_now) }
it 'returns false' do
expect(user.can_subscribe?).to be_falsey
@ -216,7 +216,7 @@ RSpec.describe User, type: :model do
end
context 'when user is inactive' do
let(:user) { create(:user, status: :inactive) }
let(:user) { create(:user, status: :inactive, active_until: 1.day.ago) }
it 'returns true' do
expect(user.can_subscribe?).to be_truthy