Mantas Masalskis 2019-09-16 17:04:17 +02:00 committed by Thorsten Eckel
parent a93250e210
commit 2e3b7e07ad
27 changed files with 237 additions and 243 deletions

View file

@ -456,7 +456,7 @@ GEM
rubocop-rails (2.3.2) rubocop-rails (2.3.2)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 0.72.0) rubocop (>= 0.72.0)
rubocop-rspec (1.33.0) rubocop-rspec (1.35.0)
rubocop (>= 0.60.0) rubocop (>= 0.60.0)
ruby-progressbar (1.10.1) ruby-progressbar (1.10.1)
ruby-saml (1.10.2) ruby-saml (1.10.2)

View file

@ -19,6 +19,6 @@ RSpec.describe SearchIndexJob, type: :job do
it 'retries on exception' do it 'retries on exception' do
expect(::User).to receive(:lookup).and_raise(RuntimeError) expect(::User).to receive(:lookup).and_raise(RuntimeError)
described_class.perform_now('User', 1) described_class.perform_now('User', 1)
expect(SearchIndexJob).to have_been_enqueued expect(described_class).to have_been_enqueued
end end
end end

View file

@ -17,7 +17,7 @@ RSpec.describe TicketOnlineNotificationSeenJob, type: :job do
ticket.save! ticket.save!
expect do expect do
TicketOnlineNotificationSeenJob.perform_now(ticket.id, user.id) described_class.perform_now(ticket.id, user.id)
end.to change { online_notification.reload.seen } end.to change { online_notification.reload.seen }
end end
end end

View file

@ -30,7 +30,7 @@ RSpec.describe TicketUserTicketCounterJob, type: :job do
end end
it 'checks if customer ticket count has been updated in preferences' do it 'checks if customer ticket count has been updated in preferences' do
TicketUserTicketCounterJob.perform_now( described_class.perform_now(
customer.id, customer.id,
customer.id, customer.id,
) )

View file

@ -110,7 +110,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do
context 'ticket' do context 'ticket' do
it 'from index after ticket delete' do it 'from index after ticket delete' do
skip('No ES configured') if !SearchIndexBackend.enabled? skip('No ES configured') if !described_class.enabled?
ticket = create :ticket ticket = create :ticket
described_class.add('Ticket', ticket) described_class.add('Ticket', ticket)

View file

@ -5,14 +5,14 @@ RSpec.describe Calendar, type: :model do
describe 'attributes' do describe 'attributes' do
describe '#default' do describe '#default' do
before { expect(Calendar.pluck(:default)).to eq([true]) } before { expect(described_class.pluck(:default)).to eq([true]) }
context 'when set to true on creation' do context 'when set to true on creation' do
subject(:calendar) { build(:calendar, default: true) } subject(:calendar) { build(:calendar, default: true) }
it 'stays true and sets all other calendars to default: false' do it 'stays true and sets all other calendars to default: false' do
expect { calendar.tap(&:save).reload }.not_to change(calendar, :default) expect { calendar.tap(&:save).reload }.not_to change(calendar, :default)
expect(Calendar.where(default: true) - [calendar]).to be_empty expect(described_class.where(default: true) - [calendar]).to be_empty
end end
end end
@ -23,14 +23,14 @@ RSpec.describe Calendar, type: :model do
it 'stays true and sets all other calendars to default: false' do it 'stays true and sets all other calendars to default: false' do
expect { calendar.tap(&:save).reload }.not_to change(calendar, :default) expect { calendar.tap(&:save).reload }.not_to change(calendar, :default)
expect(Calendar.where(default: true) - [calendar]).to be_empty expect(described_class.where(default: true) - [calendar]).to be_empty
end end
end end
context 'when set to false on update' do context 'when set to false on update' do
it 'sets default: true on earliest-created calendar' do it 'sets default: true on earliest-created calendar' do
expect { Calendar.first.update(default: false) } expect { described_class.first.update(default: false) }
.not_to change { Calendar.first.default } .not_to change { described_class.first.default }
end end
end end
@ -38,7 +38,7 @@ RSpec.describe Calendar, type: :model do
subject!(:calendar) { create(:calendar, default: false) } subject!(:calendar) { create(:calendar, default: false) }
it 'sets default: true on earliest-created remaining calendar' do it 'sets default: true on earliest-created remaining calendar' do
expect { Calendar.first.destroy } expect { described_class.first.destroy }
.to change { calendar.reload.default }.to(true) .to change { calendar.reload.default }.to(true)
end end
end end

View file

@ -40,7 +40,7 @@ RSpec.describe Channel::EmailParser, type: :model do
describe 'auto-creating new users' do describe 'auto-creating new users' do
context 'with one unrecognized email address' do context 'with one unrecognized email address' do
it 'creates one new user' do it 'creates one new user' do
expect { Channel::EmailParser.new.process({}, <<~RAW) }.to change(User, :count).by(1) expect { described_class.new.process({}, <<~RAW) }.to change(User, :count).by(1)
From: #{Faker::Internet.unique.email} From: #{Faker::Internet.unique.email}
RAW RAW
end end
@ -48,7 +48,7 @@ RSpec.describe Channel::EmailParser, type: :model do
context 'with a large number of unrecognized recipient addresses' do context 'with a large number of unrecognized recipient addresses' do
it 'never creates more than 40 users' do it 'never creates more than 40 users' do
expect { Channel::EmailParser.new.process({}, <<~RAW) }.to change(User, :count).by(40) expect { described_class.new.process({}, <<~RAW) }.to change(User, :count).by(40)
From: nicole.braun@zammad.org From: nicole.braun@zammad.org
To: #{Array.new(20) { Faker::Internet.unique.email }.join(', ')} To: #{Array.new(20) { Faker::Internet.unique.email }.join(', ')}
Cc: #{Array.new(21) { Faker::Internet.unique.email }.join(', ')} Cc: #{Array.new(21) { Faker::Internet.unique.email }.join(', ')}
@ -59,7 +59,7 @@ RSpec.describe Channel::EmailParser, type: :model do
describe 'auto-updating existing users' do describe 'auto-updating existing users' do
context 'with a previous email with no real name in the From: header' do context 'with a previous email with no real name in the From: header' do
let!(:customer) { Channel::EmailParser.new.process({}, previous_email).first.customer } let!(:customer) { described_class.new.process({}, previous_email).first.customer }
let(:previous_email) { <<~RAW.chomp } let(:previous_email) { <<~RAW.chomp }
From: customer@example.com From: customer@example.com
@ -79,7 +79,7 @@ RSpec.describe Channel::EmailParser, type: :model do
RAW RAW
it 'updates the customers #firstname and #lastname' do it 'updates the customers #firstname and #lastname' do
expect { Channel::EmailParser.new.process({}, new_email) } expect { described_class.new.process({}, new_email) }
.to change { customer.reload.firstname }.from('').to('Max') .to change { customer.reload.firstname }.from('').to('Max')
.and change { customer.reload.lastname }.from('').to('Smith') .and change { customer.reload.lastname }.from('').to('Smith')
end end
@ -98,19 +98,19 @@ RSpec.describe Channel::EmailParser, type: :model do
RAW RAW
it 'creates a ticket and article' do it 'creates a ticket and article' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.to change(Ticket, :count).by(1) .to change(Ticket, :count).by(1)
.and change(Ticket::Article, :count).by_at_least(1) .and change(Ticket::Article, :count).by_at_least(1)
end end
it 'sets #title to email subject' do it 'sets #title to email subject' do
Channel::EmailParser.new.process({}, raw_mail) described_class.new.process({}, raw_mail)
expect(Ticket.last.title).to eq('Foo') expect(Ticket.last.title).to eq('Foo')
end end
it 'sets #state to "new"' do it 'sets #state to "new"' do
Channel::EmailParser.new.process({}, raw_mail) described_class.new.process({}, raw_mail)
expect(Ticket.last.state.name).to eq('new') expect(Ticket.last.state.name).to eq('new')
end end
@ -119,13 +119,13 @@ RSpec.describe Channel::EmailParser, type: :model do
let!(:agent) { create(:agent_user, email: 'foo@bar.com') } let!(:agent) { create(:agent_user, email: 'foo@bar.com') }
it 'sets article.sender to "Agent"' do it 'sets article.sender to "Agent"' do
Channel::EmailParser.new.process({}, raw_mail) described_class.new.process({}, raw_mail)
expect(Ticket::Article.last.sender.name).to eq('Agent') expect(Ticket::Article.last.sender.name).to eq('Agent')
end end
it 'sets ticket.state to "new"' do it 'sets ticket.state to "new"' do
Channel::EmailParser.new.process({}, raw_mail) described_class.new.process({}, raw_mail)
expect(Ticket.last.state.name).to eq('new') expect(Ticket.last.state.name).to eq('new')
end end
@ -135,13 +135,13 @@ RSpec.describe Channel::EmailParser, type: :model do
let!(:customer) { create(:customer_user, email: 'foo@bar.com') } let!(:customer) { create(:customer_user, email: 'foo@bar.com') }
it 'sets article.sender to "Customer"' do it 'sets article.sender to "Customer"' do
Channel::EmailParser.new.process({}, raw_mail) described_class.new.process({}, raw_mail)
expect(Ticket.last.articles.first.sender.name).to eq('Customer') expect(Ticket.last.articles.first.sender.name).to eq('Customer')
end end
it 'sets ticket.state to "new"' do it 'sets ticket.state to "new"' do
Channel::EmailParser.new.process({}, raw_mail) described_class.new.process({}, raw_mail)
expect(Ticket.last.state.name).to eq('new') expect(Ticket.last.state.name).to eq('new')
end end
@ -149,7 +149,7 @@ RSpec.describe Channel::EmailParser, type: :model do
context 'when from address is unrecognized' do context 'when from address is unrecognized' do
it 'sets article.sender to "Customer"' do it 'sets article.sender to "Customer"' do
Channel::EmailParser.new.process({}, raw_mail) described_class.new.process({}, raw_mail)
expect(Ticket.last.articles.first.sender.name).to eq('Customer') expect(Ticket.last.articles.first.sender.name).to eq('Customer')
end end
@ -825,7 +825,7 @@ RSpec.describe Channel::EmailParser, type: :model do
context 'when "postmaster_sender_is_agent_search_for_customer" setting is true (default)' do context 'when "postmaster_sender_is_agent_search_for_customer" setting is true (default)' do
it 'sets ticket.customer to user with To: email' do it 'sets ticket.customer to user with To: email' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.to change(Ticket, :count).by(1) .to change(Ticket, :count).by(1)
expect(Ticket.last.customer).to eq(customer) expect(Ticket.last.customer).to eq(customer)
@ -836,7 +836,7 @@ RSpec.describe Channel::EmailParser, type: :model do
before { Setting.set('postmaster_sender_is_agent_search_for_customer', false) } before { Setting.set('postmaster_sender_is_agent_search_for_customer', false) }
it 'sets ticket.customer to user with To: email' do it 'sets ticket.customer to user with To: email' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.to change(Ticket, :count).by(1) .to change(Ticket, :count).by(1)
expect(Ticket.last.customer).to eq(agent) expect(Ticket.last.customer).to eq(agent)
@ -1020,23 +1020,23 @@ RSpec.describe Channel::EmailParser, type: :model do
before { ticket.update(state: Ticket::State.find_by(name: 'closed')) } before { ticket.update(state: Ticket::State.find_by(name: 'closed')) }
it 'sets #preferences on resulting ticket to { "send-auto-responses" => false, "is-auto-reponse" => true }' do it 'sets #preferences on resulting ticket to { "send-auto-responses" => false, "is-auto-reponse" => true }' do
article = Channel::EmailParser.new.process({}, raw_mail).second article = described_class.new.process({}, raw_mail).second
expect(article.preferences) expect(article.preferences)
.to include('send-auto-response' => false, 'is-auto-response' => true) .to include('send-auto-response' => false, 'is-auto-response' => true)
end end
it 'returns a Mail object with an x-zammad-out-of-office header' do it 'returns a Mail object with an x-zammad-out-of-office header' do
output_mail = Channel::EmailParser.new.process({}, raw_mail).last output_mail = described_class.new.process({}, raw_mail).last
expect(output_mail).to include('x-zammad-out-of-office': true) expect(output_mail).to include('x-zammad-out-of-office': true)
end end
it 'finds the article referenced in the bounce message headers, then adds the bounce message to its ticket' do it 'finds the article referenced in the bounce message headers, then adds the bounce message to its ticket' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.to change { ticket.articles.count }.by(1) .to change { ticket.articles.count }.by(1)
end end
it 'does not re-open the ticket' do it 'does not re-open the ticket' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.not_to change { ticket.reload.state.name }.from('closed') .not_to change { ticket.reload.state.name }.from('closed')
end end
end end
@ -1047,18 +1047,18 @@ RSpec.describe Channel::EmailParser, type: :model do
context 'for original message sent by Agent' do context 'for original message sent by Agent' do
it 'sets #preferences on resulting ticket to { "send-auto-responses" => false, "is-auto-reponse" => true }' do it 'sets #preferences on resulting ticket to { "send-auto-responses" => false, "is-auto-reponse" => true }' do
article = Channel::EmailParser.new.process({}, raw_mail).second article = described_class.new.process({}, raw_mail).second
expect(article.preferences) expect(article.preferences)
.to include('send-auto-response' => false, 'is-auto-response' => true) .to include('send-auto-response' => false, 'is-auto-response' => true)
end end
it 'finds the article referenced in the bounce message headers, then adds the bounce message to its ticket' do it 'finds the article referenced in the bounce message headers, then adds the bounce message to its ticket' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.to change { ticket.articles.count }.by(1) .to change { ticket.articles.count }.by(1)
end end
it 'does not alter the ticket state' do it 'does not alter the ticket state' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.not_to change { ticket.reload.state.name }.from('open') .not_to change { ticket.reload.state.name }.from('open')
end end
end end
@ -1067,18 +1067,18 @@ RSpec.describe Channel::EmailParser, type: :model do
let(:article) { create(:ticket_article, sender_name: 'Customer', message_id: message_id) } let(:article) { create(:ticket_article, sender_name: 'Customer', message_id: message_id) }
it 'sets #preferences on resulting ticket to { "send-auto-responses" => false, "is-auto-reponse" => true }' do it 'sets #preferences on resulting ticket to { "send-auto-responses" => false, "is-auto-reponse" => true }' do
article = Channel::EmailParser.new.process({}, raw_mail).second article = described_class.new.process({}, raw_mail).second
expect(article.preferences) expect(article.preferences)
.to include('send-auto-response' => false, 'is-auto-response' => true) .to include('send-auto-response' => false, 'is-auto-response' => true)
end end
it 'finds the article referenced in the bounce message headers, then adds the bounce message to its ticket' do it 'finds the article referenced in the bounce message headers, then adds the bounce message to its ticket' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.to change { ticket.articles.count }.by(1) .to change { ticket.articles.count }.by(1)
end end
it 'does not alter the ticket state' do it 'does not alter the ticket state' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.not_to change { ticket.reload.state.name }.from('new') .not_to change { ticket.reload.state.name }.from('new')
end end
end end
@ -1088,12 +1088,12 @@ RSpec.describe Channel::EmailParser, type: :model do
let(:mail_file) { Rails.root.join('test', 'data', 'mail', 'mail055.box') } let(:mail_file) { Rails.root.join('test', 'data', 'mail', 'mail055.box') }
it 'finds the article referenced in the bounce message headers, then adds the bounce message to its ticket' do it 'finds the article referenced in the bounce message headers, then adds the bounce message to its ticket' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.to change { ticket.articles.count }.by(1) .to change { ticket.articles.count }.by(1)
end end
it 'does not alter the ticket state' do it 'does not alter the ticket state' do
expect { Channel::EmailParser.new.process({}, raw_mail) } expect { described_class.new.process({}, raw_mail) }
.not_to change { ticket.reload.state.name }.from('open') .not_to change { ticket.reload.state.name }.from('open')
end end
end end
@ -1173,7 +1173,7 @@ RSpec.describe Channel::EmailParser, type: :model do
shared_examples 'postmaster reply' do shared_examples 'postmaster reply' do
it 'composes postmaster reply' do it 'composes postmaster reply' do
reply = Channel::EmailParser.new.send(:compose_postmaster_reply, raw_incoming_mail, locale) reply = described_class.new.send(:compose_postmaster_reply, raw_incoming_mail, locale)
expect(reply[:to]).to eq('smith@example.com') expect(reply[:to]).to eq('smith@example.com')
expect(reply[:content_type]).to eq('text/plain') expect(reply[:content_type]).to eq('text/plain')
expect(reply[:subject]).to eq(expected_subject) expect(reply[:subject]).to eq(expected_subject)
@ -1233,7 +1233,7 @@ RSpec.describe Channel::EmailParser, type: :model do
shared_examples 'postmaster reply' do shared_examples 'postmaster reply' do
it 'composes postmaster reply' do it 'composes postmaster reply' do
reply = Channel::EmailParser.new.send(:compose_postmaster_reply, raw_incoming_mail, locale) reply = described_class.new.send(:compose_postmaster_reply, raw_incoming_mail, locale)
expect(reply[:to]).to eq('smith@example.com') expect(reply[:to]).to eq('smith@example.com')
expect(reply[:content_type]).to eq('text/plain') expect(reply[:content_type]).to eq('text/plain')
expect(reply[:subject]).to eq(expected_subject) expect(reply[:subject]).to eq(expected_subject)

View file

@ -11,7 +11,7 @@ RSpec.describe History, type: :model do
let!(:object) { create(:'cti/log') } let!(:object) { create(:'cti/log') }
it 'returns an empty array' do it 'returns an empty array' do
expect(History.list(object.class.name, object.id)) expect(described_class.list(object.class.name, object.id))
.to be_an(Array).and be_empty .to be_an(Array).and be_empty
end end
end end
@ -23,7 +23,7 @@ RSpec.describe History, type: :model do
before { object.update(email: 'foo@example.com') } before { object.update(email: 'foo@example.com') }
context 'or "assets" flag' do context 'or "assets" flag' do
let(:list) { History.list(object.class.name, object.id) } let(:list) { described_class.list(object.class.name, object.id) }
it 'returns an array of attribute hashes for those histories' do it 'returns an array of attribute hashes for those histories' do
expect(list).to match_array( expect(list).to match_array(
@ -58,9 +58,9 @@ RSpec.describe History, type: :model do
end end
context 'but with "assets" flag' do context 'but with "assets" flag' do
let(:list) { History.list(object.class.name, object.id, nil, true) } let(:list) { described_class.list(object.class.name, object.id, nil, true) }
let(:matching_histories) do let(:matching_histories) do
History.where( described_class.where(
o_id: object.id, o_id: object.id,
history_object_id: History::Object.lookup(name: object.class.name).id history_object_id: History::Object.lookup(name: object.class.name).id
) )
@ -100,7 +100,7 @@ RSpec.describe History, type: :model do
before { object.update(title: 'Lorem ipsum dolor') } before { object.update(title: 'Lorem ipsum dolor') }
context 'but no "assets" flag' do context 'but no "assets" flag' do
let(:list) { History.list(object.class.name, object.id, 'Ticket::Article') } let(:list) { described_class.list(object.class.name, object.id, 'Ticket::Article') }
it 'returns an array of attribute hashes for those histories' do it 'returns an array of attribute hashes for those histories' do
expect(list).to match_array( expect(list).to match_array(
@ -145,12 +145,12 @@ RSpec.describe History, type: :model do
end end
context 'and "assets" flag' do context 'and "assets" flag' do
let(:list) { History.list(object.class.name, object.id, 'Ticket::Article', true) } let(:list) { described_class.list(object.class.name, object.id, 'Ticket::Article', true) }
let(:matching_histories) do let(:matching_histories) do
History.where( described_class.where(
o_id: object.id, o_id: object.id,
history_object_id: History::Object.lookup(name: object.class.name).id history_object_id: History::Object.lookup(name: object.class.name).id
) + History.where( ) + described_class.where(
o_id: related_object.id, o_id: related_object.id,
history_object_id: History::Object.lookup(name: related_object.class.name).id history_object_id: History::Object.lookup(name: related_object.class.name).id
) )

View file

@ -3,17 +3,22 @@ require 'rails_helper'
RSpec.describe ImportJob do RSpec.describe ImportJob do
before do before do
module Import stub_const test_backend_name, test_backend_class
class Test < Import::Base stub_const test_backend_noreschedule_name, test_backend_noreschedule_class
end
let(:test_backend_name) { 'Import::Test' }
let(:test_backend_class) do
Class.new(Import::Base) do
def start def start
@import_job.result = { state: 'Done' } @import_job.result = { state: 'Done' }
end end
end end
end end
module Import let(:test_backend_noreschedule_name) { 'Import::NoRescheduleMethod' }
class NoRescheduleMethod let(:test_backend_noreschedule_class) do
Class.new do
def initialize(import_job) def initialize(import_job)
@import_job = import_job @import_job = import_job
end end
@ -27,15 +32,6 @@ RSpec.describe ImportJob do
end end
end end
end end
end
after do
Import.send(:remove_const, :Test)
Import.send(:remove_const, :NoRescheduleMethod)
end
let(:test_backend_name) { 'Import::Test' }
let(:test_backend_class) { test_backend_name.constantize }
describe '#dry_run' do describe '#dry_run' do

View file

@ -37,7 +37,7 @@ RSpec.describe Job, type: :model do
end end
it 'runs all executable jobs (and no others)' do it 'runs all executable jobs (and no others)' do
expect { Job.run } expect { described_class.run }
.to change { executable_jobs.map(&:reload).map(&:last_run_at).any?(&:nil?) }.to(false) .to change { executable_jobs.map(&:reload).map(&:last_run_at).any?(&:nil?) }.to(false)
.and not_change { nonexecutable_jobs.map(&:reload).map(&:last_run_at).all?(&:nil?) } .and not_change { nonexecutable_jobs.map(&:reload).map(&:last_run_at).all?(&:nil?) }
end end

View file

@ -6,7 +6,7 @@ RSpec.describe KnowledgeBase, type: :model do
subject(:knowledge_base) { create(:knowledge_base) } subject(:knowledge_base) { create(:knowledge_base) }
# make sure there's no KBs from seed data # make sure there's no KBs from seed data
before { KnowledgeBase.all.each(&:full_destroy!) } before { described_class.all.each(&:full_destroy!) }
include_context 'factory' include_context 'factory'
@ -40,25 +40,25 @@ RSpec.describe KnowledgeBase, type: :model do
before { knowledge_base } before { knowledge_base }
it 'ensure 2 knowledge bases are created' do it 'ensure 2 knowledge bases are created' do
expect(KnowledgeBase.count).to eq(2) expect(described_class.count).to eq(2)
end end
it 'filter by activity' do it 'filter by activity' do
expect(KnowledgeBase.active).to contain_exactly(knowledge_base) expect(described_class.active).to contain_exactly(knowledge_base)
end end
it 'skip activity check for editors when filtering by activity' do it 'skip activity check for editors when filtering by activity' do
user = create(:admin_user) user = create(:admin_user)
expect(KnowledgeBase.check_active_unless_editor(user).count).to eq(2) expect(described_class.check_active_unless_editor(user).count).to eq(2)
end end
it 'check activity if user is not editor when filtering by activity' do it 'check activity if user is not editor when filtering by activity' do
user = create(:agent_user) user = create(:agent_user)
expect(KnowledgeBase.check_active_unless_editor(user)).to contain_exactly(knowledge_base) expect(described_class.check_active_unless_editor(user)).to contain_exactly(knowledge_base)
end end
it 'skip activity check for guests when filtering by activity' do it 'skip activity check for guests when filtering by activity' do
expect(KnowledgeBase.check_active_unless_editor(nil)).to contain_exactly(knowledge_base) expect(described_class.check_active_unless_editor(nil)).to contain_exactly(knowledge_base)
end end
end end
end end

View file

@ -6,7 +6,7 @@ RSpec.describe ObjectLookup, type: :model do
subject(:object_lookup) { create(:object_lookup) } subject(:object_lookup) { create(:object_lookup) }
it 'returns its id' do it 'returns its id' do
expect(ObjectLookup.by_name(object_lookup.name)) expect(described_class.by_name(object_lookup.name))
.to eq(object_lookup.id) .to eq(object_lookup.id)
end end
end end
@ -15,24 +15,24 @@ RSpec.describe ObjectLookup, type: :model do
let(:name) { 'FooBar' } let(:name) { 'FooBar' }
it 'creates a new one with that name' do it 'creates a new one with that name' do
expect { ObjectLookup.by_name(name) } expect { described_class.by_name(name) }
.to change(ObjectLookup, :count).by(1) .to change(described_class, :count).by(1)
expect(ObjectLookup.last.name).to eq(name) expect(described_class.last.name).to eq(name)
end end
it 'returns its id' do it 'returns its id' do
expect(ObjectLookup.by_name(name)) expect(described_class.by_name(name))
.to eq(ObjectLookup.last.id) .to eq(described_class.last.id)
end end
context 'for names not in strict CamelCase' do context 'for names not in strict CamelCase' do
let(:name) { 'Foo_Bar' } let(:name) { 'Foo_Bar' }
it 'does not modify the format' do it 'does not modify the format' do
ObjectLookup.by_name(name) described_class.by_name(name)
expect(ObjectLookup.last.name).to eq(name) expect(described_class.last.name).to eq(name)
end end
end end
end end
@ -43,7 +43,7 @@ RSpec.describe ObjectLookup, type: :model do
subject(:object_lookup) { create(:object_lookup) } subject(:object_lookup) { create(:object_lookup) }
it 'returns its name' do it 'returns its name' do
expect(ObjectLookup.by_id(object_lookup.id)) expect(described_class.by_id(object_lookup.id))
.to eq(object_lookup.name) .to eq(object_lookup.name)
end end
end end

View file

@ -53,14 +53,14 @@ RSpec.describe ObjectManager::Attribute, type: :model do
describe 'check name' do describe 'check name' do
it 'rejects ActiveRecord reserved word "attribute"' do it 'rejects ActiveRecord reserved word "attribute"' do
expect do expect do
ObjectManager::Attribute.add attributes_for :object_manager_attribute_text, name: 'attribute' described_class.add attributes_for :object_manager_attribute_text, name: 'attribute'
end.to raise_error 'attribute is a reserved word, please choose a different one' end.to raise_error 'attribute is a reserved word, please choose a different one'
end end
%w[destroy true false integer select drop create alter index table varchar blob date datetime timestamp url icon initials avatar permission validate subscribe unsubscribe translate search _type _doc _id id].each do |reserved_word| %w[destroy true false integer select drop create alter index table varchar blob date datetime timestamp url icon initials avatar permission validate subscribe unsubscribe translate search _type _doc _id id].each do |reserved_word|
it "rejects Zammad reserved word '#{reserved_word}'" do it "rejects Zammad reserved word '#{reserved_word}'" do
expect do expect do
ObjectManager::Attribute.add attributes_for :object_manager_attribute_text, name: reserved_word described_class.add attributes_for :object_manager_attribute_text, name: reserved_word
end.to raise_error "#{reserved_word} is a reserved word, please choose a different one" end.to raise_error "#{reserved_word} is a reserved word, please choose a different one"
end end
end end
@ -68,41 +68,41 @@ RSpec.describe ObjectManager::Attribute, type: :model do
%w[someting_id something_ids].each do |reserved_word| %w[someting_id something_ids].each do |reserved_word|
it "rejects word '#{reserved_word}' which is used for database references" do it "rejects word '#{reserved_word}' which is used for database references" do
expect do expect do
ObjectManager::Attribute.add attributes_for :object_manager_attribute_text, name: reserved_word described_class.add attributes_for :object_manager_attribute_text, name: reserved_word
end.to raise_error "Name can't get used, *_id and *_ids are not allowed" end.to raise_error "Name can't get used, *_id and *_ids are not allowed"
end end
end end
it 'rejects duplicate attribute name of conflicting types' do it 'rejects duplicate attribute name of conflicting types' do
attribute = attributes_for :object_manager_attribute_text attribute = attributes_for :object_manager_attribute_text
ObjectManager::Attribute.add attribute described_class.add attribute
attribute[:data_type] = 'boolean' attribute[:data_type] = 'boolean'
expect do expect do
ObjectManager::Attribute.add attribute described_class.add attribute
end.to raise_error ActiveRecord::RecordInvalid end.to raise_error ActiveRecord::RecordInvalid
end end
it 'accepts duplicate attribute name on the same types (editing an existing attribute)' do it 'accepts duplicate attribute name on the same types (editing an existing attribute)' do
attribute = attributes_for :object_manager_attribute_text attribute = attributes_for :object_manager_attribute_text
ObjectManager::Attribute.add attribute described_class.add attribute
expect do expect do
ObjectManager::Attribute.add attribute described_class.add attribute
end.not_to raise_error end.not_to raise_error
end end
it 'accepts duplicate attribute name on compatible types (editing the type of an existing attribute)' do it 'accepts duplicate attribute name on compatible types (editing the type of an existing attribute)' do
attribute = attributes_for :object_manager_attribute_text attribute = attributes_for :object_manager_attribute_text
ObjectManager::Attribute.add attribute described_class.add attribute
attribute[:data_type] = 'select' attribute[:data_type] = 'select'
attribute[:data_option_new] = { default: '', options: { 'a' => 'a' } } attribute[:data_option_new] = { default: '', options: { 'a' => 'a' } }
expect do expect do
ObjectManager::Attribute.add attribute described_class.add attribute
end.not_to raise_error end.not_to raise_error
end end
it 'accepts valid attribute names' do it 'accepts valid attribute names' do
expect do expect do
ObjectManager::Attribute.add attributes_for :object_manager_attribute_text described_class.add attributes_for :object_manager_attribute_text
end.not_to raise_error end.not_to raise_error
end end
end end

View file

@ -4,13 +4,13 @@ RSpec.describe Permission, type: :model do
describe '.with_parents' do describe '.with_parents' do
context 'when given a simple string (no dots)' do context 'when given a simple string (no dots)' do
it 'returns an array containing only that string' do it 'returns an array containing only that string' do
expect(Permission.with_parents('foo')).to eq(['foo']) expect(described_class.with_parents('foo')).to eq(['foo'])
end end
end end
context 'when given a String permission name (dot-delimited identifier)' do context 'when given a String permission name (dot-delimited identifier)' do
it 'returns an array of String ancestors (desc. from root)' do it 'returns an array of String ancestors (desc. from root)' do
expect(Permission.with_parents('foo.bar.baz')) expect(described_class.with_parents('foo.bar.baz'))
.to eq(%w[foo foo.bar foo.bar.baz]) .to eq(%w[foo foo.bar foo.bar.baz])
end end
end end

View file

@ -138,7 +138,7 @@ RSpec.describe RecentView, type: :model do
it 'wraps RecentView.create' do it 'wraps RecentView.create' do
expect do expect do
described_class.log(viewed_object.class.name, viewed_object.id, admin) described_class.log(viewed_object.class.name, viewed_object.id, admin)
end.to change(RecentView, :count).by(1) end.to change(described_class, :count).by(1)
end end
describe 'access privileges' do describe 'access privileges' do
@ -152,7 +152,7 @@ RSpec.describe RecentView, type: :model do
expect do expect do
described_class.log(viewed_object.class.name, viewed_object.id, agent) described_class.log(viewed_object.class.name, viewed_object.id, agent)
end.not_to change(RecentView, :count) end.not_to change(described_class, :count)
end end
end end
@ -160,19 +160,19 @@ RSpec.describe RecentView, type: :model do
it 'does not create RecentView for non-existent record' do it 'does not create RecentView for non-existent record' do
expect do expect do
described_class.log('User', 99_999_999, admin) described_class.log('User', 99_999_999, admin)
end.not_to change(RecentView, :count) end.not_to change(described_class, :count)
end end
it 'does not create RecentView for instance of non-ObjectLookup class' do it 'does not create RecentView for instance of non-ObjectLookup class' do
expect do expect do
described_class.log('Overview', 1, admin) described_class.log('Overview', 1, admin)
end.not_to change(RecentView, :count) end.not_to change(described_class, :count)
end end
it 'does not create RecentView for instance of non-existent class' do it 'does not create RecentView for instance of non-existent class' do
expect do expect do
described_class.log('NonExistentClass', 1, admin) described_class.log('NonExistentClass', 1, admin)
end.not_to change(RecentView, :count) end.not_to change(described_class, :count)
end end
end end
end end

View file

@ -2,10 +2,9 @@ require 'rails_helper'
RSpec.describe Scheduler do RSpec.describe Scheduler do
before do let(:test_backend_name) { 'SpecSpace::DelayedJobBackend' }
module SpecSpace let(:test_backend_class) do
class DelayedJobBackend Class.new do
def self.start def self.start
# noop # noop
end end
@ -21,10 +20,9 @@ RSpec.describe Scheduler do
end end
end end
end end
end
after do before do
SpecSpace.send(:remove_const, :DelayedJobBackend) stub_const test_backend_name, test_backend_class
end end
describe '.failed_jobs' do describe '.failed_jobs' do

View file

@ -7,7 +7,7 @@ RSpec.describe Setting, type: :model do
context 'when given a valid Setting#name' do context 'when given a valid Setting#name' do
it 'returns #state_current[:value]' do it 'returns #state_current[:value]' do
expect { setting.update(state_current: { value: 'foo' }) } expect { setting.update(state_current: { value: 'foo' }) }
.to change { Setting.get(setting.name) }.to('foo') .to change { described_class.get(setting.name) }.to('foo')
end end
end end
end end
@ -15,7 +15,7 @@ RSpec.describe Setting, type: :model do
describe '.set' do describe '.set' do
context 'when given a valid Setting#name' do context 'when given a valid Setting#name' do
it 'sets #state_current = { value: <arg> }' do it 'sets #state_current = { value: <arg> }' do
expect { Setting.set(setting.name, 'foo') } expect { described_class.set(setting.name, 'foo') }
.to change { setting.reload.state_current }.to({ 'value' => 'foo' }) .to change { setting.reload.state_current }.to({ 'value' => 'foo' })
end end
end end
@ -26,7 +26,7 @@ RSpec.describe Setting, type: :model do
before { Cache.write('foo', 'bar') } before { Cache.write('foo', 'bar') }
it 'resets the cache key' do it 'resets the cache key' do
expect { Setting.set(setting.name, 'baz') } expect { described_class.set(setting.name, 'baz') }
.to change { Cache.get('foo') }.to(nil) .to change { Cache.get('foo') }.to(nil)
end end
end end
@ -36,9 +36,9 @@ RSpec.describe Setting, type: :model do
context 'when given a valid Setting#name' do context 'when given a valid Setting#name' do
it 'sets #state_current = { value: <orig> } (via #state_initial[:value])' do it 'sets #state_current = { value: <orig> } (via #state_initial[:value])' do
setting.update(state_initial: { value: 'foo' }) setting.update(state_initial: { value: 'foo' })
Setting.set(setting.name, 'bar') described_class.set(setting.name, 'bar')
expect { Setting.reset(setting.name) } expect { described_class.reset(setting.name) }
.to change { setting.reload.state_current }.to({ value: 'foo' }) .to change { setting.reload.state_current }.to({ value: 'foo' })
end end
end end

View file

@ -12,9 +12,9 @@ RSpec.describe Tag, type: :model do
context 'when a Tag::Object does not exist for the given class' do context 'when a Tag::Object does not exist for the given class' do
it 'creates it and assigns it to a new Tag' do it 'creates it and assigns it to a new Tag' do
expect { described_class.tag_add(object: 'Foo', item: 'bar', o_id: 1, created_by_id: 1) } expect { described_class.tag_add(object: 'Foo', item: 'bar', o_id: 1, created_by_id: 1) }
.to change(Tag, :count).by(1) .to change(described_class, :count).by(1)
.and change { Tag::Object.exists?(name: 'Foo') }.to(true) .and change { Tag::Object.exists?(name: 'Foo') }.to(true)
.and change { Tag.last&.tag_object&.name }.to('Foo') .and change { described_class.last&.tag_object&.name }.to('Foo')
end end
end end
@ -23,33 +23,33 @@ RSpec.describe Tag, type: :model do
it 'assigns it to a new Tag' do it 'assigns it to a new Tag' do
expect { described_class.tag_add(object: 'Ticket', item: 'foo', o_id: 1, created_by_id: 1) } expect { described_class.tag_add(object: 'Ticket', item: 'foo', o_id: 1, created_by_id: 1) }
.to change(Tag, :count).by(1) .to change(described_class, :count).by(1)
.and not_change(Tag::Object, :count) .and not_change(Tag::Object, :count)
.and change { Tag.last&.tag_object&.name }.to('Ticket') .and change { described_class.last&.tag_object&.name }.to('Ticket')
end end
end end
context 'when a Tag::Item does not exist with the given name' do context 'when a Tag::Item does not exist with the given name' do
it 'creates it and assigns it to a new Tag' do it 'creates it and assigns it to a new Tag' do
expect { described_class.tag_add(object: 'Ticket', item: 'foo', o_id: 1, created_by_id: 1) } expect { described_class.tag_add(object: 'Ticket', item: 'foo', o_id: 1, created_by_id: 1) }
.to change(Tag, :count).by(1) .to change(described_class, :count).by(1)
.and change { Tag::Item.exists?(name: 'foo') }.to(true) .and change { Tag::Item.exists?(name: 'foo') }.to(true)
.and change { Tag.last&.tag_item&.name }.to('foo') .and change { described_class.last&.tag_item&.name }.to('foo')
end end
it 'strips trailing/leading whitespace' do it 'strips trailing/leading whitespace' do
expect { described_class.tag_add(object: 'Ticket', item: ' foo ', o_id: 1, created_by_id: 1) } expect { described_class.tag_add(object: 'Ticket', item: ' foo ', o_id: 1, created_by_id: 1) }
.to change(Tag, :count).by(1) .to change(described_class, :count).by(1)
.and change { Tag::Item.exists?(name: 'foo') }.to(true) .and change { Tag::Item.exists?(name: 'foo') }.to(true)
.and change { Tag.last&.tag_item&.name }.to('foo') .and change { described_class.last&.tag_item&.name }.to('foo')
end end
context 'and the name contains 8-bit Unicode characters' do context 'and the name contains 8-bit Unicode characters' do
it 'creates it and assigns it to a new Tag' do it 'creates it and assigns it to a new Tag' do
expect { described_class.tag_add(object: 'Ticket', item: 'fooöäüß', o_id: 1, created_by_id: 1) } expect { described_class.tag_add(object: 'Ticket', item: 'fooöäüß', o_id: 1, created_by_id: 1) }
.to change(Tag, :count).by(1) .to change(described_class, :count).by(1)
.and change { Tag::Item.exists?(name: 'fooöäüß') }.to(true) .and change { Tag::Item.exists?(name: 'fooöäüß') }.to(true)
.and change { Tag.last&.tag_item&.name }.to('fooöäüß') .and change { described_class.last&.tag_item&.name }.to('fooöäüß')
end end
end end
@ -58,9 +58,9 @@ RSpec.describe Tag, type: :model do
it 'creates it and assigns it to a new Tag' do it 'creates it and assigns it to a new Tag' do
expect { described_class.tag_add(object: 'Ticket', item: 'FOO', o_id: 1, created_by_id: 1) } expect { described_class.tag_add(object: 'Ticket', item: 'FOO', o_id: 1, created_by_id: 1) }
.to change(Tag, :count).by(1) .to change(described_class, :count).by(1)
.and change { Tag::Item.pluck(:name).include?('FOO') }.to(true) # .exists?(name: 'FOO') fails on MySQL .and change { Tag::Item.pluck(:name).include?('FOO') }.to(true) # .exists?(name: 'FOO') fails on MySQL
.and change { Tag.last&.tag_item&.name }.to('FOO') .and change { described_class.last&.tag_item&.name }.to('FOO')
end end
end end
end end
@ -70,16 +70,16 @@ RSpec.describe Tag, type: :model do
it 'assigns it to a new Tag' do it 'assigns it to a new Tag' do
expect { described_class.tag_add(object: 'Ticket', item: 'foo', o_id: 1, created_by_id: 1) } expect { described_class.tag_add(object: 'Ticket', item: 'foo', o_id: 1, created_by_id: 1) }
.to change(Tag, :count).by(1) .to change(described_class, :count).by(1)
.and not_change(Tag::Item, :count) .and not_change(Tag::Item, :count)
.and change { Tag.last&.tag_item&.name }.to('foo') .and change { described_class.last&.tag_item&.name }.to('foo')
end end
it 'strips leading/trailing whitespace' do it 'strips leading/trailing whitespace' do
expect { described_class.tag_add(object: 'Ticket', item: ' foo ', o_id: 1, created_by_id: 1) } expect { described_class.tag_add(object: 'Ticket', item: ' foo ', o_id: 1, created_by_id: 1) }
.to change(Tag, :count).by(1) .to change(described_class, :count).by(1)
.and not_change(Tag::Item, :count) .and not_change(Tag::Item, :count)
.and change { Tag.last&.tag_item&.name }.to('foo') .and change { described_class.last&.tag_item&.name }.to('foo')
end end
end end
@ -89,7 +89,7 @@ RSpec.describe Tag, type: :model do
it 'does not create any records' do it 'does not create any records' do
expect { described_class.tag_add(object: 'Ticket', item: 'foo', o_id: Ticket.first.id, created_by_id: 1) } expect { described_class.tag_add(object: 'Ticket', item: 'foo', o_id: Ticket.first.id, created_by_id: 1) }
.to not_change(Tag, :count) .to not_change(described_class, :count)
.and not_change(Tag::Item, :count) .and not_change(Tag::Item, :count)
end end
end end
@ -107,14 +107,14 @@ RSpec.describe Tag, type: :model do
it 'destroys the Tag' do it 'destroys the Tag' do
expect { described_class.tag_remove(object: 'Ticket', o_id: Ticket.first.id, item: 'foo') } expect { described_class.tag_remove(object: 'Ticket', o_id: Ticket.first.id, item: 'foo') }
.to change(Tag, :count).by(-1) .to change(described_class, :count).by(-1)
end end
end end
context 'when no matching Tag exists' do context 'when no matching Tag exists' do
it 'makes no changes' do it 'makes no changes' do
expect { described_class.tag_remove(object: 'Ticket', o_id: Ticket.first.id, item: 'foo') } expect { described_class.tag_remove(object: 'Ticket', o_id: Ticket.first.id, item: 'foo') }
.not_to change(Tag, :count) .not_to change(described_class, :count)
end end
end end
end end

View file

@ -9,7 +9,7 @@ RSpec.describe Ticket::Priority, type: :model do
describe 'Default state' do describe 'Default state' do
describe 'of whole table:' do describe 'of whole table:' do
it 'has exactly one default record' do it 'has exactly one default record' do
expect(Ticket::Priority.where(default_create: true)).to be_one expect(described_class.where(default_create: true)).to be_one
end end
end end
end end
@ -18,21 +18,21 @@ RSpec.describe Ticket::Priority, type: :model do
describe '#default_create' do describe '#default_create' do
it 'cannot be true for more than one record at a time' do it 'cannot be true for more than one record at a time' do
expect { create(:'ticket/priority', default_create: true) } expect { create(:'ticket/priority', default_create: true) }
.to change { Ticket::Priority.find_by(default_create: true).id } .to change { described_class.find_by(default_create: true).id }
.and change { Ticket::Priority.where(default_create: true).count }.by(0) .and change { described_class.where(default_create: true).count }.by(0)
end end
it 'cannot be false for all records' do it 'cannot be false for all records' do
create(:'ticket/priority', default_create: true) create(:'ticket/priority', default_create: true)
expect { Ticket::Priority.find_by(default_create: true).destroy } expect { described_class.find_by(default_create: true).destroy }
.to change { Ticket::Priority.find_by(default_create: true).id } .to change { described_class.find_by(default_create: true).id }
.and change { Ticket::Priority.where(default_create: true).count }.by(0) .and change { described_class.where(default_create: true).count }.by(0)
end end
it 'is not automatically set to the last-created record' do it 'is not automatically set to the last-created record' do
expect { create(:'ticket/priority') } expect { create(:'ticket/priority') }
.not_to change { Ticket::Priority.find_by(default_create: true).id } .not_to change { described_class.find_by(default_create: true).id }
end end
end end
end end

View file

@ -9,22 +9,22 @@ RSpec.describe Ticket::State, type: :model do
describe 'Default state' do describe 'Default state' do
describe 'of whole table:' do describe 'of whole table:' do
it 'has seven records' do it 'has seven records' do
expect(Ticket::State.pluck(:name)) expect(described_class.pluck(:name))
.to match_array(%w[closed merged new open pending\ close pending\ reminder removed]) .to match_array(%w[closed merged new open pending\ close pending\ reminder removed])
end end
end end
describe 'of "new" state:' do describe 'of "new" state:' do
it 'is the sole #default_create state' do it 'is the sole #default_create state' do
expect(Ticket::State.where(default_create: true)) expect(described_class.where(default_create: true))
.to match_array([Ticket::State.find_by(name: 'new')]) .to match_array([described_class.find_by(name: 'new')])
end end
end end
describe 'of "open" state:' do describe 'of "open" state:' do
it 'is the sole #default_follow_up state' do it 'is the sole #default_follow_up state' do
expect(Ticket::State.where(default_follow_up: true)) expect(described_class.where(default_follow_up: true))
.to match_array([Ticket::State.find_by(name: 'open')]) .to match_array([described_class.find_by(name: 'open')])
end end
end end
end end
@ -34,7 +34,7 @@ RSpec.describe Ticket::State, type: :model do
it 'looks up states by category' do it 'looks up states by category' do
expect(described_class.by_category(:open)) expect(described_class.by_category(:open))
.to be_an(ActiveRecord::Relation) .to be_an(ActiveRecord::Relation)
.and include(instance_of(Ticket::State)) .and include(instance_of(described_class))
end end
context 'with invalid category name' do context 'with invalid category name' do
@ -48,7 +48,7 @@ RSpec.describe Ticket::State, type: :model do
describe 'Attributes:' do describe 'Attributes:' do
describe '#default_create' do describe '#default_create' do
let!(:original_default) { Ticket::State.find_by(default_create: true) } let!(:original_default) { described_class.find_by(default_create: true) }
context 'for newly created record' do context 'for newly created record' do
subject!(:state) { build(:ticket_state, default_create: default_create) } subject!(:state) { build(:ticket_state, default_create: default_create) }
@ -59,7 +59,7 @@ RSpec.describe Ticket::State, type: :model do
it 'unsets previous default' do it 'unsets previous default' do
expect { state.save } expect { state.save }
.to change { original_default.reload.default_create }.to(false) .to change { original_default.reload.default_create }.to(false)
.and not_change { Ticket::State.where(default_create: true).count } .and not_change { described_class.where(default_create: true).count }
end end
end end
@ -68,8 +68,8 @@ RSpec.describe Ticket::State, type: :model do
it 'does not alter existing default' do it 'does not alter existing default' do
expect { state.save } expect { state.save }
.to not_change { Ticket::State.find_by(default_create: true) } .to not_change { described_class.find_by(default_create: true) }
.and not_change { Ticket::State.where(default_create: true).count } .and not_change { described_class.where(default_create: true).count }
end end
end end
end end
@ -83,16 +83,16 @@ RSpec.describe Ticket::State, type: :model do
context 'and updated to false' do context 'and updated to false' do
it 'assigns Ticket::State.first as default' do it 'assigns Ticket::State.first as default' do
expect { state.update(default_create: false) } expect { state.update(default_create: false) }
.to change { Ticket::State.first.default_create }.to(true) .to change { described_class.first.default_create }.to(true)
.and not_change { Ticket::State.where(default_create: true).count } .and not_change { described_class.where(default_create: true).count }
end end
end end
context 'and destroyed' do context 'and destroyed' do
it 'assigns Ticket::State.first as default' do it 'assigns Ticket::State.first as default' do
expect { state.destroy } expect { state.destroy }
.to change { Ticket::State.first.default_create }.to(true) .to change { described_class.first.default_create }.to(true)
.and not_change { Ticket::State.where(default_create: true).count } .and not_change { described_class.where(default_create: true).count }
end end
end end
end end
@ -104,15 +104,15 @@ RSpec.describe Ticket::State, type: :model do
it 'unsets previous default' do it 'unsets previous default' do
expect { state.update(default_create: true) } expect { state.update(default_create: true) }
.to change { original_default.reload.default_create }.to(false) .to change { original_default.reload.default_create }.to(false)
.and not_change { Ticket::State.where(default_create: true).count } .and not_change { described_class.where(default_create: true).count }
end end
end end
context 'and destroyed' do context 'and destroyed' do
it 'does not alter existing default' do it 'does not alter existing default' do
expect { state.destroy } expect { state.destroy }
.to not_change { Ticket::State.find_by(default_create: true) } .to not_change { described_class.find_by(default_create: true) }
.and not_change { Ticket::State.where(default_create: true).count } .and not_change { described_class.where(default_create: true).count }
end end
end end
end end
@ -120,7 +120,7 @@ RSpec.describe Ticket::State, type: :model do
end end
describe '#default_follow_up' do describe '#default_follow_up' do
let!(:original_default) { Ticket::State.find_by(default_follow_up: true) } let!(:original_default) { described_class.find_by(default_follow_up: true) }
context 'for newly created record' do context 'for newly created record' do
subject!(:state) { build(:ticket_state, default_follow_up: default_follow_up) } subject!(:state) { build(:ticket_state, default_follow_up: default_follow_up) }
@ -131,7 +131,7 @@ RSpec.describe Ticket::State, type: :model do
it 'unsets previous default' do it 'unsets previous default' do
expect { state.save } expect { state.save }
.to change { original_default.reload.default_follow_up }.to(false) .to change { original_default.reload.default_follow_up }.to(false)
.and not_change { Ticket::State.where(default_follow_up: true).count } .and not_change { described_class.where(default_follow_up: true).count }
end end
end end
@ -140,8 +140,8 @@ RSpec.describe Ticket::State, type: :model do
it 'does not alter existing default' do it 'does not alter existing default' do
expect { state.save } expect { state.save }
.to not_change { Ticket::State.find_by(default_follow_up: true) } .to not_change { described_class.find_by(default_follow_up: true) }
.and not_change { Ticket::State.where(default_follow_up: true).count } .and not_change { described_class.where(default_follow_up: true).count }
end end
end end
end end
@ -155,16 +155,16 @@ RSpec.describe Ticket::State, type: :model do
context 'and updated to false' do context 'and updated to false' do
it 'assigns Ticket::State.first as default' do it 'assigns Ticket::State.first as default' do
expect { state.update(default_follow_up: false) } expect { state.update(default_follow_up: false) }
.to change { Ticket::State.first.default_follow_up }.to(true) .to change { described_class.first.default_follow_up }.to(true)
.and not_change { Ticket::State.where(default_follow_up: true).count } .and not_change { described_class.where(default_follow_up: true).count }
end end
end end
context 'and destroyed' do context 'and destroyed' do
it 'assigns Ticket::State.first as default' do it 'assigns Ticket::State.first as default' do
expect { state.destroy } expect { state.destroy }
.to change { Ticket::State.first.default_follow_up }.to(true) .to change { described_class.first.default_follow_up }.to(true)
.and not_change { Ticket::State.where(default_follow_up: true).count } .and not_change { described_class.where(default_follow_up: true).count }
end end
end end
end end
@ -176,15 +176,15 @@ RSpec.describe Ticket::State, type: :model do
it 'unsets previous default' do it 'unsets previous default' do
expect { state.update(default_follow_up: true) } expect { state.update(default_follow_up: true) }
.to change { original_default.reload.default_follow_up }.to(false) .to change { original_default.reload.default_follow_up }.to(false)
.and not_change { Ticket::State.where(default_follow_up: true).count } .and not_change { described_class.where(default_follow_up: true).count }
end end
end end
context 'and destroyed' do context 'and destroyed' do
it 'does not alter existing default' do it 'does not alter existing default' do
expect { state.destroy } expect { state.destroy }
.to not_change { Ticket::State.find_by(default_follow_up: true) } .to not_change { described_class.find_by(default_follow_up: true) }
.and not_change { Ticket::State.where(default_follow_up: true).count } .and not_change { described_class.where(default_follow_up: true).count }
end end
end end
end end

View file

@ -11,7 +11,7 @@ RSpec.describe Ticket::TimeAccounting, type: :model do
it 'destroys self' do it 'destroys self' do
expect { time_accounting.ticket_article.destroy } expect { time_accounting.ticket_article.destroy }
.to change(time_accounting, :persisted?).to(false) .to change(time_accounting, :persisted?).to(false)
.and change { Ticket::TimeAccounting.count }.by(-1) .and change(described_class, :count).by(-1)
end end
it 'does not destroy other TimeAccountings for same ticket' do it 'does not destroy other TimeAccountings for same ticket' do
@ -19,7 +19,7 @@ RSpec.describe Ticket::TimeAccounting, type: :model do
create(:'ticket/time_accounting', :for_article, ticket: time_accounting.ticket) create(:'ticket/time_accounting', :for_article, ticket: time_accounting.ticket)
expect { time_accounting.ticket_article.destroy } expect { time_accounting.ticket_article.destroy }
.to change { Ticket::TimeAccounting.count }.by(-1) .to change(described_class, :count).by(-1)
end end
end end
end end

View file

@ -43,7 +43,7 @@ RSpec.describe Ticket, type: :model do
end end
it 'returns a list of unique tickets (i.e., no duplicates)' do it 'returns a list of unique tickets (i.e., no duplicates)' do
expect(Ticket.selectors(condition, limit: 100, access: 'full')) expect(described_class.selectors(condition, limit: 100, access: 'full'))
.to match_array([2, tickets.to_a]) .to match_array([2, tickets.to_a])
end end
end end

View file

@ -6,19 +6,19 @@ RSpec.describe Token, type: :model do
describe '.check' do describe '.check' do
context 'with name and action matching existing token' do context 'with name and action matching existing token' do
it 'returns the tokens user' do it 'returns the tokens user' do
expect(Token.check(action: token.action, name: token.name)).to eq(token.user) expect(described_class.check(action: token.action, name: token.name)).to eq(token.user)
end end
end end
context 'with invalid name' do context 'with invalid name' do
it 'returns nil' do it 'returns nil' do
expect(Token.check(action: token.action, name: '1NV4L1D')).to be(nil) expect(described_class.check(action: token.action, name: '1NV4L1D')).to be(nil)
end end
end end
context 'with invalid action' do context 'with invalid action' do
it 'returns nil' do it 'returns nil' do
expect(Token.check(action: 'PasswordReset_NotExisting', name: token.name)).to be(nil) expect(described_class.check(action: 'PasswordReset_NotExisting', name: token.name)).to be(nil)
end end
end end
@ -30,14 +30,14 @@ RSpec.describe Token, type: :model do
let(:created_at) { 1.month.ago } let(:created_at) { 1.month.ago }
it 'returns the tokens user' do it 'returns the tokens user' do
expect(Token.check(action: token.action, name: token.name)).to eq(token.user) expect(described_class.check(action: token.action, name: token.name)).to eq(token.user)
end end
it 'does not delete the token' do it 'does not delete the token' do
token # create token token # create token
expect { Token.check(action: token.action, name: token.name) } expect { described_class.check(action: token.action, name: token.name) }
.not_to change(Token, :count) .not_to change(described_class, :count)
end end
end end
end end
@ -49,14 +49,14 @@ RSpec.describe Token, type: :model do
let(:created_at) { 1.day.ago + 5 } let(:created_at) { 1.day.ago + 5 }
it 'returns the tokens user' do it 'returns the tokens user' do
expect(Token.check(action: token.action, name: token.name)).to eq(token.user) expect(described_class.check(action: token.action, name: token.name)).to eq(token.user)
end end
it 'does not delete the token' do it 'does not delete the token' do
token # create token token # create token
expect { Token.check(action: token.action, name: token.name) } expect { described_class.check(action: token.action, name: token.name) }
.not_to change(Token, :count) .not_to change(described_class, :count)
end end
end end
@ -64,14 +64,14 @@ RSpec.describe Token, type: :model do
let(:created_at) { 1.day.ago } let(:created_at) { 1.day.ago }
it 'returns nil' do it 'returns nil' do
expect(Token.check(action: token.action, name: token.name)).to be(nil) expect(described_class.check(action: token.action, name: token.name)).to be(nil)
end end
it 'deletes the token' do it 'deletes the token' do
token # create token token # create token
expect { Token.check(action: token.action, name: token.name) } expect { described_class.check(action: token.action, name: token.name) }
.to change(Token, :count).by(-1) .to change(described_class, :count).by(-1)
end end
end end
end end
@ -85,43 +85,43 @@ RSpec.describe Token, type: :model do
context 'with a permission shared by both token.user and token.preferences' do context 'with a permission shared by both token.user and token.preferences' do
it 'returns token.user' do it 'returns token.user' do
expect(Token.check(action: token.action, name: token.name, permission: 'ticket.agent')).to eq(agent) expect(described_class.check(action: token.action, name: token.name, permission: 'ticket.agent')).to eq(agent)
end end
end end
context 'with the child of a permission shared by both token.user and token.preferences' do context 'with the child of a permission shared by both token.user and token.preferences' do
it 'returns token.user' do it 'returns token.user' do
expect(Token.check(action: token.action, name: token.name, permission: 'ticket.agent.foo')).to eq(agent) expect(described_class.check(action: token.action, name: token.name, permission: 'ticket.agent.foo')).to eq(agent)
end end
end end
context 'with the parent of a permission shared by both token.user and token.preferences' do context 'with the parent of a permission shared by both token.user and token.preferences' do
it 'returns nil' do it 'returns nil' do
expect(Token.check(action: token.action, name: token.name, permission: 'ticket')).to be(nil) expect(described_class.check(action: token.action, name: token.name, permission: 'ticket')).to be(nil)
end end
end end
context 'with a permission in token.preferences, but not on token.user' do context 'with a permission in token.preferences, but not on token.user' do
it 'returns nil' do it 'returns nil' do
expect(Token.check(action: token.action, name: token.name, permission: 'admin')).to be(nil) expect(described_class.check(action: token.action, name: token.name, permission: 'admin')).to be(nil)
end end
end end
context 'with a permission not in token.preferences, but on token.user' do context 'with a permission not in token.preferences, but on token.user' do
it 'returns nil' do it 'returns nil' do
expect(Token.check(action: token.action, name: token.name, permission: 'cti.agent')).to be(nil) expect(described_class.check(action: token.action, name: token.name, permission: 'cti.agent')).to be(nil)
end end
end end
context 'with non-existent permission' do context 'with non-existent permission' do
it 'returns nil' do it 'returns nil' do
expect(Token.check(action: token.action, name: token.name, permission: 'foo')).to be(nil) expect(described_class.check(action: token.action, name: token.name, permission: 'foo')).to be(nil)
end end
end end
context 'with multiple permissions, where at least one is shared by both token.user and token.preferences' do context 'with multiple permissions, where at least one is shared by both token.user and token.preferences' do
it 'returns token.user' do it 'returns token.user' do
expect(Token.check(action: token.action, name: token.name, permission: %w[foo ticket.agent])).to eq(agent) expect(described_class.check(action: token.action, name: token.name, permission: %w[foo ticket.agent])).to eq(agent)
end end
end end
end end
@ -130,7 +130,7 @@ RSpec.describe Token, type: :model do
describe 'Attributes:' do describe 'Attributes:' do
describe '#persistent' do describe '#persistent' do
context 'when not set on creation' do context 'when not set on creation' do
subject(:token) { Token.create(action: 'foo', user_id: User.first.id) } subject(:token) { described_class.create(action: 'foo', user_id: User.first.id) }
it 'defaults to nil' do it 'defaults to nil' do
expect(token.persistent).to be(nil) expect(token.persistent).to be(nil)

View file

@ -8,7 +8,7 @@ RSpec.describe Trigger, type: :model do
describe 'Send-email triggers' do describe 'Send-email triggers' do
before do before do
Trigger.destroy_all # Default DB state includes three sample triggers described_class.destroy_all # Default DB state includes three sample triggers
trigger # create subject trigger trigger # create subject trigger
end end

View file

@ -6,7 +6,7 @@ RSpec.describe TypeLookup, type: :model do
subject(:type_lookup) { create(:type_lookup) } subject(:type_lookup) { create(:type_lookup) }
it 'returns its id' do it 'returns its id' do
expect(TypeLookup.by_name(type_lookup.name)) expect(described_class.by_name(type_lookup.name))
.to eq(type_lookup.id) .to eq(type_lookup.id)
end end
end end
@ -15,24 +15,24 @@ RSpec.describe TypeLookup, type: :model do
let(:name) { 'FooBar' } let(:name) { 'FooBar' }
it 'creates a new one with that name' do it 'creates a new one with that name' do
expect { TypeLookup.by_name(name) } expect { described_class.by_name(name) }
.to change(TypeLookup, :count).by(1) .to change(described_class, :count).by(1)
expect(TypeLookup.last.name).to eq(name) expect(described_class.last.name).to eq(name)
end end
it 'returns its id' do it 'returns its id' do
expect(TypeLookup.by_name(name)) expect(described_class.by_name(name))
.to eq(TypeLookup.last.id) .to eq(described_class.last.id)
end end
context 'for names not in strict CamelCase' do context 'for names not in strict CamelCase' do
let(:name) { 'Foo_Bar' } let(:name) { 'Foo_Bar' }
it 'does not modify the format' do it 'does not modify the format' do
TypeLookup.by_name(name) described_class.by_name(name)
expect(TypeLookup.last.name).to eq(name) expect(described_class.last.name).to eq(name)
end end
end end
end end
@ -43,7 +43,7 @@ RSpec.describe TypeLookup, type: :model do
subject(:type_lookup) { create(:type_lookup) } subject(:type_lookup) { create(:type_lookup) }
it 'returns its name' do it 'returns its name' do
expect(TypeLookup.by_id(type_lookup.id)) expect(described_class.by_id(type_lookup.id))
.to eq(type_lookup.name) .to eq(type_lookup.name)
end end
end end

View file

@ -2,7 +2,7 @@ require 'rails_helper'
RSpec.describe UserDevice, type: :model do RSpec.describe UserDevice, type: :model do
describe '.add' do describe '.add' do
let(:existing_record) { UserDevice.add(user_agent, ip, agent.id, fingerprint, type) } let(:existing_record) { described_class.add(user_agent, ip, agent.id, fingerprint, type) }
let(:ip) { '91.115.248.231' } let(:ip) { '91.115.248.231' }
let(:agent) { create(:agent_user) } let(:agent) { create(:agent_user) }
@ -15,7 +15,7 @@ RSpec.describe UserDevice, type: :model do
context 'when called with same parameters as existing record' do context 'when called with same parameters as existing record' do
it 'returns the original record' do it 'returns the original record' do
expect(UserDevice.add(user_agent, ip, agent.id, fingerprint, type)) expect(described_class.add(user_agent, ip, agent.id, fingerprint, type))
.to eq(existing_record) .to eq(existing_record)
end end
end end
@ -24,8 +24,8 @@ RSpec.describe UserDevice, type: :model do
let(:other_ip) { '176.198.137.254' } let(:other_ip) { '176.198.137.254' }
it 'returns a new record' do it 'returns a new record' do
expect(UserDevice.add(user_agent, other_ip, agent.id, fingerprint, type)) expect(described_class.add(user_agent, other_ip, agent.id, fingerprint, type))
.to be_a(UserDevice) .to be_a(described_class)
.and not_eq(existing_record) .and not_eq(existing_record)
end end
end end
@ -34,8 +34,8 @@ RSpec.describe UserDevice, type: :model do
let(:other_ip) { 'foo' } let(:other_ip) { 'foo' }
it 'returns a new record' do it 'returns a new record' do
expect(UserDevice.add(user_agent, other_ip, agent.id, fingerprint, type)) expect(described_class.add(user_agent, other_ip, agent.id, fingerprint, type))
.to be_a(UserDevice) .to be_a(described_class)
.and not_eq(existing_record) .and not_eq(existing_record)
end end
end end
@ -44,8 +44,8 @@ RSpec.describe UserDevice, type: :model do
let(:other_fingerprint) { 'fingerprintABCD' } let(:other_fingerprint) { 'fingerprintABCD' }
it 'returns a new record' do it 'returns a new record' do
expect(UserDevice.add(user_agent, ip, agent.id, other_fingerprint, type)) expect(described_class.add(user_agent, ip, agent.id, other_fingerprint, type))
.to be_a(UserDevice) .to be_a(described_class)
.and not_eq(existing_record) .and not_eq(existing_record)
end end
end end
@ -112,7 +112,7 @@ RSpec.describe UserDevice, type: :model do
context 'when called with same parameters as existing record' do context 'when called with same parameters as existing record' do
it 'returns the original record' do it 'returns the original record' do
expect(UserDevice.add(user_agent, ip, agent.id, fingerprint, type)) expect(described_class.add(user_agent, ip, agent.id, fingerprint, type))
.to eq(existing_record) .to eq(existing_record)
end end
end end
@ -121,8 +121,8 @@ RSpec.describe UserDevice, type: :model do
let(:other_ip) { '176.198.137.254' } let(:other_ip) { '176.198.137.254' }
it 'returns a new record' do it 'returns a new record' do
expect(UserDevice.add(user_agent, other_ip, agent.id, fingerprint, type)) expect(described_class.add(user_agent, other_ip, agent.id, fingerprint, type))
.to be_a(UserDevice) .to be_a(described_class)
.and not_eq(existing_record) .and not_eq(existing_record)
end end
end end
@ -131,7 +131,7 @@ RSpec.describe UserDevice, type: :model do
let(:other_type) { 'token_auth' } let(:other_type) { 'token_auth' }
it 'returns the original record' do it 'returns the original record' do
expect(UserDevice.add(user_agent, ip, agent.id, fingerprint, other_type)) expect(described_class.add(user_agent, ip, agent.id, fingerprint, other_type))
.to eq(existing_record) .to eq(existing_record)
end end
end end
@ -140,8 +140,8 @@ RSpec.describe UserDevice, type: :model do
let(:other_user_agent) { '' } let(:other_user_agent) { '' }
it 'returns a new record' do it 'returns a new record' do
expect(UserDevice.add(other_user_agent, ip, agent.id, fingerprint, type)) expect(described_class.add(other_user_agent, ip, agent.id, fingerprint, type))
.to be_a(UserDevice) .to be_a(described_class)
.and not_eq(existing_record) .and not_eq(existing_record)
end end
end end
@ -151,7 +151,7 @@ RSpec.describe UserDevice, type: :model do
let(:other_user_agent) { nil } let(:other_user_agent) { nil }
it 'returns the original record' do it 'returns the original record' do
expect(UserDevice.add(other_user_agent, ip, agent.id, fingerprint, type)) expect(described_class.add(other_user_agent, ip, agent.id, fingerprint, type))
.to eq(existing_record) .to eq(existing_record)
end end
end end
@ -161,8 +161,8 @@ RSpec.describe UserDevice, type: :model do
let(:other_ip) { '176.198.137.254' } let(:other_ip) { '176.198.137.254' }
it 'returns a new record' do it 'returns a new record' do
expect(UserDevice.add(user_agent, other_ip, agent.id, fingerprint, type)) expect(described_class.add(user_agent, other_ip, agent.id, fingerprint, type))
.to be_a(UserDevice) .to be_a(described_class)
.and not_eq(existing_record) .and not_eq(existing_record)
end end
end end
@ -174,14 +174,14 @@ RSpec.describe UserDevice, type: :model do
let(:type) { 'session' } let(:type) { 'session' }
it 'raises an error' do it 'raises an error' do
expect { UserDevice.add(user_agent, ip, agent.id, fingerprint, type) } expect { described_class.add(user_agent, ip, agent.id, fingerprint, type) }
.to raise_error(Exceptions::UnprocessableEntity) .to raise_error(Exceptions::UnprocessableEntity)
end end
end end
end end
describe '.action' do describe '.action' do
let(:user_device) { UserDevice.add(user_agent, ip, agent.id, fingerprint, type) } let(:user_device) { described_class.add(user_agent, ip, agent.id, fingerprint, type) }
let(:user_agent) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36' } let(:user_agent) { 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36' }
let(:ip) { '91.115.248.231' } let(:ip) { '91.115.248.231' }
let(:agent) { create(:agent_user) } let(:agent) { create(:agent_user) }
@ -200,7 +200,7 @@ RSpec.describe UserDevice, type: :model do
it 'returns a new user_device' do it 'returns a new user_device' do
expect(described_class.action(user_device.id, user_agent, other_ip, agent.id, type)) expect(described_class.action(user_device.id, user_agent, other_ip, agent.id, type))
.to be_a(UserDevice) .to be_a(described_class)
.and not_eq(user_device) .and not_eq(user_device)
end end
end end

View file

@ -177,11 +177,11 @@ RSpec.describe User, type: :model do
describe '.identify' do describe '.identify' do
it 'returns users by given login' do it 'returns users by given login' do
expect(User.identify(user.login)).to eq(user) expect(described_class.identify(user.login)).to eq(user)
end end
it 'returns users by given email' do it 'returns users by given email' do
expect(User.identify(user.email)).to eq(user) expect(described_class.identify(user.email)).to eq(user)
end end
end end
end end
@ -716,7 +716,7 @@ RSpec.describe User, type: :model do
describe '#out_of_office_replacement_id' do describe '#out_of_office_replacement_id' do
it 'cannot be set to invalid user ID' do it 'cannot be set to invalid user ID' do
expect { agent.update(out_of_office_replacement_id: User.pluck(:id).max.next) } expect { agent.update(out_of_office_replacement_id: described_class.pluck(:id).max.next) }
.to raise_error(ActiveRecord::InvalidForeignKey) .to raise_error(ActiveRecord::InvalidForeignKey)
end end
@ -980,7 +980,7 @@ RSpec.describe User, type: :model do
describe 'System-wide agent limit checks:' do describe 'System-wide agent limit checks:' do
let(:agent_role) { Role.lookup(name: 'Agent') } let(:agent_role) { Role.lookup(name: 'Agent') }
let(:admin_role) { Role.lookup(name: 'Admin') } let(:admin_role) { Role.lookup(name: 'Admin') }
let(:current_agents) { User.with_permissions('ticket.agent') } let(:current_agents) { described_class.with_permissions('ticket.agent') }
describe '#validate_agent_limit_by_role' do describe '#validate_agent_limit_by_role' do
context 'for Integer value of system_agent_limit' do context 'for Integer value of system_agent_limit' do