Update tests

This commit is contained in:
Eugene Burmakin 2025-02-25 00:16:42 +01:00
parent 85049b398b
commit 080da9f2de
2 changed files with 11 additions and 7 deletions

View file

@ -16,6 +16,7 @@ class User < ApplicationRecord
has_many :trips, dependent: :destroy
after_create :create_api_key
after_commit :activate, on: :create, if: -> { DawarichSettings.self_hosted? }
before_save :sanitize_input
validates :email, presence: true
@ -107,7 +108,7 @@ class User < ApplicationRecord
end
def activate
update(status: :active) if DawarichSettings.self_hosted?
update(status: :active)
end
def sanitize_input

View file

@ -30,25 +30,28 @@ RSpec.describe User, type: :model do
end
describe '#activate' do
let(:user) { create(:user) }
context 'when self-hosted' do
let!(:user) { create(:user, status: :inactive) }
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
end
it 'activates user' do
expect { user.send(:activate) }.to change(user, :status).to('active')
it 'activates user after creation' do
expect(user.active?).to be_truthy
end
end
context 'when not self-hosted' do
let!(:user) { create(:user, status: :inactive) }
before do
stub_const('SELF_HOSTED', false)
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
end
it 'does not activate user' do
expect { user.send(:activate) }.to_not change(user, :status)
xit 'does not activate user' do
expect(user.active?).to be_falsey
end
end
end