mirror of https://github.com/docusealco/docuseal
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
49 lines
1.5 KiB
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe TemplateService do
|
|
describe '#assign_ownership' do
|
|
let(:template) { build(:template, account: nil, account_group: nil) }
|
|
let(:params) { { folder_name: 'Custom Folder' } }
|
|
|
|
context 'with account_group user' do
|
|
let(:account_group) { create(:account_group) }
|
|
let(:user) { create(:user, account: nil, account_group: account_group) }
|
|
|
|
it 'assigns account_group and default folder' do
|
|
service = described_class.new(template, user, params)
|
|
service.assign_ownership
|
|
|
|
expect(template.account_group).to eq(account_group)
|
|
expect(template.folder).to eq(account_group.default_template_folder)
|
|
end
|
|
end
|
|
|
|
context 'with account user' do
|
|
let(:account) { create(:account) }
|
|
let(:user) { create(:user, account: account, account_group: nil) }
|
|
|
|
it 'assigns account and finds/creates folder' do
|
|
service = described_class.new(template, user, params)
|
|
service.assign_ownership
|
|
|
|
expect(template.account).to eq(account)
|
|
expect(template.folder).to be_present
|
|
end
|
|
end
|
|
|
|
context 'with user having neither account nor account_group' do
|
|
let(:user) { build(:user, account: nil, account_group: nil) }
|
|
|
|
it 'does not assign ownership' do
|
|
service = described_class.new(template, user, params)
|
|
service.assign_ownership
|
|
|
|
expect(template.account).to be_nil
|
|
expect(template.account_group).to be_nil
|
|
end
|
|
end
|
|
end
|
|
end
|