mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Fix tests
This commit is contained in:
parent
600c88ae01
commit
67916c10c4
4 changed files with 13 additions and 13 deletions
|
|
@ -100,6 +100,10 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_subscribe?
|
||||||
|
active_until&.past? && !DawarichSettings.self_hosted?
|
||||||
|
end
|
||||||
|
|
||||||
def generate_subscription_token
|
def generate_subscription_token
|
||||||
payload = {
|
payload = {
|
||||||
user_id: id,
|
user_id: id,
|
||||||
|
|
@ -149,8 +153,4 @@ class User < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/MethodLength
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
|
||||||
def can_subscribe?
|
|
||||||
active_until&.past? && !DawarichSettings.self_hosted?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
</li>
|
</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>
|
<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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<%= link_to 'Dawarich', root_path, class: 'btn btn-ghost normal-case text-xl'%>
|
<%= link_to 'Dawarich', root_path, class: 'btn btn-ghost normal-case text-xl'%>
|
||||||
|
|
@ -70,9 +70,9 @@
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
<ul class="menu menu-horizontal bg-base-100 rounded-box px-1">
|
<ul class="menu menu-horizontal bg-base-100 rounded-box px-1">
|
||||||
<% if user_signed_in? %>
|
<% 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>
|
<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"
|
<div class="dropdown dropdown-end dropdown-bottom dropdown-hover"
|
||||||
data-controller="notifications"
|
data-controller="notifications"
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ RSpec.describe VisitSuggestingJob, type: :job do
|
||||||
|
|
||||||
context 'when user is inactive' do
|
context 'when user is inactive' do
|
||||||
before 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(Visits::Suggest).to receive(:new).and_call_original
|
||||||
allow_any_instance_of(Visits::Suggest).to receive(:call)
|
allow_any_instance_of(Visits::Suggest).to receive(:call)
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is active' do
|
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
|
it 'returns false' do
|
||||||
expect(user.can_subscribe?).to be_falsey
|
expect(user.can_subscribe?).to be_falsey
|
||||||
|
|
@ -194,7 +194,7 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is inactive' do
|
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
|
it 'returns false' do
|
||||||
expect(user.can_subscribe?).to be_falsey
|
expect(user.can_subscribe?).to be_falsey
|
||||||
|
|
@ -208,7 +208,7 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is active' do
|
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
|
it 'returns false' do
|
||||||
expect(user.can_subscribe?).to be_falsey
|
expect(user.can_subscribe?).to be_falsey
|
||||||
|
|
@ -216,7 +216,7 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user is inactive' do
|
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
|
it 'returns true' do
|
||||||
expect(user.can_subscribe?).to be_truthy
|
expect(user.can_subscribe?).to be_truthy
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue