mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Update tests
This commit is contained in:
parent
85049b398b
commit
080da9f2de
2 changed files with 11 additions and 7 deletions
|
|
@ -16,6 +16,7 @@ class User < ApplicationRecord
|
||||||
has_many :trips, dependent: :destroy
|
has_many :trips, dependent: :destroy
|
||||||
|
|
||||||
after_create :create_api_key
|
after_create :create_api_key
|
||||||
|
after_commit :activate, on: :create, if: -> { DawarichSettings.self_hosted? }
|
||||||
before_save :sanitize_input
|
before_save :sanitize_input
|
||||||
|
|
||||||
validates :email, presence: true
|
validates :email, presence: true
|
||||||
|
|
@ -107,7 +108,7 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def activate
|
def activate
|
||||||
update(status: :active) if DawarichSettings.self_hosted?
|
update(status: :active)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_input
|
def sanitize_input
|
||||||
|
|
|
||||||
|
|
@ -30,25 +30,28 @@ RSpec.describe User, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#activate' do
|
describe '#activate' do
|
||||||
let(:user) { create(:user) }
|
|
||||||
|
|
||||||
context 'when self-hosted' do
|
context 'when self-hosted' do
|
||||||
|
let!(:user) { create(:user, status: :inactive) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
|
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'activates user' do
|
it 'activates user after creation' do
|
||||||
expect { user.send(:activate) }.to change(user, :status).to('active')
|
expect(user.active?).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when not self-hosted' do
|
context 'when not self-hosted' do
|
||||||
|
let!(:user) { create(:user, status: :inactive) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
stub_const('SELF_HOSTED', false)
|
||||||
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
|
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not activate user' do
|
xit 'does not activate user' do
|
||||||
expect { user.send(:activate) }.to_not change(user, :status)
|
expect(user.active?).to be_falsey
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue