diff --git a/Gemfile.lock b/Gemfile.lock index bce39abb3..96e7408e3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -456,7 +456,7 @@ GEM rubocop-rails (2.3.2) rack (>= 1.1) rubocop (>= 0.72.0) - rubocop-rspec (1.33.0) + rubocop-rspec (1.35.0) rubocop (>= 0.60.0) ruby-progressbar (1.10.1) ruby-saml (1.10.2) diff --git a/spec/jobs/search_index_job_spec.rb b/spec/jobs/search_index_job_spec.rb index 2d037fb64..ee7c1463b 100644 --- a/spec/jobs/search_index_job_spec.rb +++ b/spec/jobs/search_index_job_spec.rb @@ -19,6 +19,6 @@ RSpec.describe SearchIndexJob, type: :job do it 'retries on exception' do expect(::User).to receive(:lookup).and_raise(RuntimeError) described_class.perform_now('User', 1) - expect(SearchIndexJob).to have_been_enqueued + expect(described_class).to have_been_enqueued end end diff --git a/spec/jobs/ticket_online_notification_seen_job_spec.rb b/spec/jobs/ticket_online_notification_seen_job_spec.rb index 1c9eb90ac..e6e1124be 100644 --- a/spec/jobs/ticket_online_notification_seen_job_spec.rb +++ b/spec/jobs/ticket_online_notification_seen_job_spec.rb @@ -17,7 +17,7 @@ RSpec.describe TicketOnlineNotificationSeenJob, type: :job do ticket.save! 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 end diff --git a/spec/jobs/ticket_user_ticket_counter_job_spec.rb b/spec/jobs/ticket_user_ticket_counter_job_spec.rb index 36d7db75a..094e0a0f7 100644 --- a/spec/jobs/ticket_user_ticket_counter_job_spec.rb +++ b/spec/jobs/ticket_user_ticket_counter_job_spec.rb @@ -30,7 +30,7 @@ RSpec.describe TicketUserTicketCounterJob, type: :job do end it 'checks if customer ticket count has been updated in preferences' do - TicketUserTicketCounterJob.perform_now( + described_class.perform_now( customer.id, customer.id, ) diff --git a/spec/lib/search_index_backend_spec.rb b/spec/lib/search_index_backend_spec.rb index 0524597fc..2b12e60ba 100644 --- a/spec/lib/search_index_backend_spec.rb +++ b/spec/lib/search_index_backend_spec.rb @@ -110,7 +110,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do context 'ticket' 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 described_class.add('Ticket', ticket) diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb index abbce6972..9d1293370 100644 --- a/spec/models/calendar_spec.rb +++ b/spec/models/calendar_spec.rb @@ -5,14 +5,14 @@ RSpec.describe Calendar, type: :model do describe 'attributes' 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 subject(:calendar) { build(:calendar, default: true) } it 'stays true and sets all other calendars to default: false' do 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 @@ -23,14 +23,14 @@ RSpec.describe Calendar, type: :model 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.where(default: true) - [calendar]).to be_empty + expect(described_class.where(default: true) - [calendar]).to be_empty end end context 'when set to false on update' do it 'sets default: true on earliest-created calendar' do - expect { Calendar.first.update(default: false) } - .not_to change { Calendar.first.default } + expect { described_class.first.update(default: false) } + .not_to change { described_class.first.default } end end @@ -38,7 +38,7 @@ RSpec.describe Calendar, type: :model do subject!(:calendar) { create(:calendar, default: false) } 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) end end diff --git a/spec/models/channel/email_parser_spec.rb b/spec/models/channel/email_parser_spec.rb index 733505af9..eae580e7c 100644 --- a/spec/models/channel/email_parser_spec.rb +++ b/spec/models/channel/email_parser_spec.rb @@ -40,7 +40,7 @@ RSpec.describe Channel::EmailParser, type: :model do describe 'auto-creating new users' do context 'with one unrecognized email address' 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} RAW end @@ -48,7 +48,7 @@ RSpec.describe Channel::EmailParser, type: :model do context 'with a large number of unrecognized recipient addresses' 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 To: #{Array.new(20) { 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 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 } From: customer@example.com @@ -79,7 +79,7 @@ RSpec.describe Channel::EmailParser, type: :model do RAW it 'updates the customer’s #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') .and change { customer.reload.lastname }.from('').to('Smith') end @@ -98,19 +98,19 @@ RSpec.describe Channel::EmailParser, type: :model do RAW 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) .and change(Ticket::Article, :count).by_at_least(1) end 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') end 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') end @@ -119,13 +119,13 @@ RSpec.describe Channel::EmailParser, type: :model do let!(:agent) { create(:agent_user, email: 'foo@bar.com') } 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') end 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') end @@ -135,13 +135,13 @@ RSpec.describe Channel::EmailParser, type: :model do let!(:customer) { create(:customer_user, email: 'foo@bar.com') } 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') end 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') end @@ -149,7 +149,7 @@ RSpec.describe Channel::EmailParser, type: :model do context 'when from address is unrecognized' 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') 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 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) 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) } 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) 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')) } 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) .to include('send-auto-response' => false, 'is-auto-response' => true) end 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) end 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) end 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') end end @@ -1047,18 +1047,18 @@ RSpec.describe Channel::EmailParser, type: :model 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 - article = Channel::EmailParser.new.process({}, raw_mail).second + article = described_class.new.process({}, raw_mail).second expect(article.preferences) .to include('send-auto-response' => false, 'is-auto-response' => true) end 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) end 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') 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) } 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) .to include('send-auto-response' => false, 'is-auto-response' => true) end 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) end 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') end end @@ -1088,12 +1088,12 @@ RSpec.describe Channel::EmailParser, type: :model do 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 - expect { Channel::EmailParser.new.process({}, raw_mail) } + expect { described_class.new.process({}, raw_mail) } .to change { ticket.articles.count }.by(1) end 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') end end @@ -1173,7 +1173,7 @@ RSpec.describe Channel::EmailParser, type: :model do shared_examples '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[:content_type]).to eq('text/plain') expect(reply[:subject]).to eq(expected_subject) @@ -1233,7 +1233,7 @@ RSpec.describe Channel::EmailParser, type: :model do shared_examples '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[:content_type]).to eq('text/plain') expect(reply[:subject]).to eq(expected_subject) diff --git a/spec/models/history_spec.rb b/spec/models/history_spec.rb index 8550666b9..0f60f3189 100644 --- a/spec/models/history_spec.rb +++ b/spec/models/history_spec.rb @@ -11,7 +11,7 @@ RSpec.describe History, type: :model do let!(:object) { create(:'cti/log') } 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 end end @@ -23,7 +23,7 @@ RSpec.describe History, type: :model do before { object.update(email: 'foo@example.com') } 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 expect(list).to match_array( @@ -58,9 +58,9 @@ RSpec.describe History, type: :model do end 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 - History.where( + described_class.where( o_id: object.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') } 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 expect(list).to match_array( @@ -145,12 +145,12 @@ RSpec.describe History, type: :model do end 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 - History.where( + described_class.where( o_id: object.id, history_object_id: History::Object.lookup(name: object.class.name).id - ) + History.where( + ) + described_class.where( o_id: related_object.id, history_object_id: History::Object.lookup(name: related_object.class.name).id ) diff --git a/spec/models/import_job_spec.rb b/spec/models/import_job_spec.rb index a99d029a4..f1a7cf8c6 100644 --- a/spec/models/import_job_spec.rb +++ b/spec/models/import_job_spec.rb @@ -3,39 +3,35 @@ require 'rails_helper' RSpec.describe ImportJob do before do - module Import - class Test < Import::Base - def start - @import_job.result = { state: 'Done' } - end - end - end - - module Import - class NoRescheduleMethod - - def initialize(import_job) - @import_job = import_job - end - - def start - @import_job.result = { state: 'Done' } - end - - def reschedule?(_delayed_job) - 'invalid_but_checkable_result' - end - end - end - end - - after do - Import.send(:remove_const, :Test) - Import.send(:remove_const, :NoRescheduleMethod) + stub_const test_backend_name, test_backend_class + stub_const test_backend_noreschedule_name, test_backend_noreschedule_class end let(:test_backend_name) { 'Import::Test' } - let(:test_backend_class) { test_backend_name.constantize } + let(:test_backend_class) do + Class.new(Import::Base) do + def start + @import_job.result = { state: 'Done' } + end + end + end + + let(:test_backend_noreschedule_name) { 'Import::NoRescheduleMethod' } + let(:test_backend_noreschedule_class) do + Class.new do + def initialize(import_job) + @import_job = import_job + end + + def start + @import_job.result = { state: 'Done' } + end + + def reschedule?(_delayed_job) + 'invalid_but_checkable_result' + end + end + end describe '#dry_run' do diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb index 4b8f2baa8..fb7db89ab 100644 --- a/spec/models/job_spec.rb +++ b/spec/models/job_spec.rb @@ -37,7 +37,7 @@ RSpec.describe Job, type: :model do end 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) .and not_change { nonexecutable_jobs.map(&:reload).map(&:last_run_at).all?(&:nil?) } end diff --git a/spec/models/knowledge_base_spec.rb b/spec/models/knowledge_base_spec.rb index 84c07d422..080b46dbf 100644 --- a/spec/models/knowledge_base_spec.rb +++ b/spec/models/knowledge_base_spec.rb @@ -6,7 +6,7 @@ RSpec.describe KnowledgeBase, type: :model do subject(:knowledge_base) { create(:knowledge_base) } # 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' @@ -40,25 +40,25 @@ RSpec.describe KnowledgeBase, type: :model do before { knowledge_base } it 'ensure 2 knowledge bases are created' do - expect(KnowledgeBase.count).to eq(2) + expect(described_class.count).to eq(2) end it 'filter by activity' do - expect(KnowledgeBase.active).to contain_exactly(knowledge_base) + expect(described_class.active).to contain_exactly(knowledge_base) end it 'skip activity check for editors when filtering by activity' do 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 it 'check activity if user is not editor when filtering by activity' do 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 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 diff --git a/spec/models/object_lookup_spec.rb b/spec/models/object_lookup_spec.rb index 790f184ae..d77d23c8c 100644 --- a/spec/models/object_lookup_spec.rb +++ b/spec/models/object_lookup_spec.rb @@ -6,7 +6,7 @@ RSpec.describe ObjectLookup, type: :model do subject(:object_lookup) { create(:object_lookup) } 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) end end @@ -15,24 +15,24 @@ RSpec.describe ObjectLookup, type: :model do let(:name) { 'FooBar' } it 'creates a new one with that name' do - expect { ObjectLookup.by_name(name) } - .to change(ObjectLookup, :count).by(1) + expect { described_class.by_name(name) } + .to change(described_class, :count).by(1) - expect(ObjectLookup.last.name).to eq(name) + expect(described_class.last.name).to eq(name) end it 'returns its id' do - expect(ObjectLookup.by_name(name)) - .to eq(ObjectLookup.last.id) + expect(described_class.by_name(name)) + .to eq(described_class.last.id) end context 'for names not in strict CamelCase' do let(:name) { 'Foo_Bar' } 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 @@ -43,7 +43,7 @@ RSpec.describe ObjectLookup, type: :model do subject(:object_lookup) { create(:object_lookup) } 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) end end diff --git a/spec/models/object_manager/attribute_spec.rb b/spec/models/object_manager/attribute_spec.rb index a6c41b29d..523b6da4c 100644 --- a/spec/models/object_manager/attribute_spec.rb +++ b/spec/models/object_manager/attribute_spec.rb @@ -53,14 +53,14 @@ RSpec.describe ObjectManager::Attribute, type: :model do describe 'check name' do it 'rejects ActiveRecord reserved word "attribute"' 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 %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 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 end @@ -68,41 +68,41 @@ RSpec.describe ObjectManager::Attribute, type: :model do %w[someting_id something_ids].each do |reserved_word| it "rejects word '#{reserved_word}' which is used for database references" 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 end it 'rejects duplicate attribute name of conflicting types' do attribute = attributes_for :object_manager_attribute_text - ObjectManager::Attribute.add attribute + described_class.add attribute attribute[:data_type] = 'boolean' expect do - ObjectManager::Attribute.add attribute + described_class.add attribute end.to raise_error ActiveRecord::RecordInvalid end it 'accepts duplicate attribute name on the same types (editing an existing attribute)' do attribute = attributes_for :object_manager_attribute_text - ObjectManager::Attribute.add attribute + described_class.add attribute expect do - ObjectManager::Attribute.add attribute + described_class.add attribute end.not_to raise_error end it 'accepts duplicate attribute name on compatible types (editing the type of an existing attribute)' do attribute = attributes_for :object_manager_attribute_text - ObjectManager::Attribute.add attribute + described_class.add attribute attribute[:data_type] = 'select' attribute[:data_option_new] = { default: '', options: { 'a' => 'a' } } expect do - ObjectManager::Attribute.add attribute + described_class.add attribute end.not_to raise_error end it 'accepts valid attribute names' 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 end diff --git a/spec/models/permission_spec.rb b/spec/models/permission_spec.rb index af15f6bc9..68b79c0c3 100644 --- a/spec/models/permission_spec.rb +++ b/spec/models/permission_spec.rb @@ -4,13 +4,13 @@ RSpec.describe Permission, type: :model do describe '.with_parents' do context 'when given a simple string (no dots)' 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 context 'when given a String permission name (dot-delimited identifier)' 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]) end end diff --git a/spec/models/recent_view_spec.rb b/spec/models/recent_view_spec.rb index d287d49e5..322bc0ce3 100644 --- a/spec/models/recent_view_spec.rb +++ b/spec/models/recent_view_spec.rb @@ -138,7 +138,7 @@ RSpec.describe RecentView, type: :model do it 'wraps RecentView.create' do expect do 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 describe 'access privileges' do @@ -152,7 +152,7 @@ RSpec.describe RecentView, type: :model do expect do 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 @@ -160,19 +160,19 @@ RSpec.describe RecentView, type: :model do it 'does not create RecentView for non-existent record' do expect do described_class.log('User', 99_999_999, admin) - end.not_to change(RecentView, :count) + end.not_to change(described_class, :count) end it 'does not create RecentView for instance of non-ObjectLookup class' do expect do described_class.log('Overview', 1, admin) - end.not_to change(RecentView, :count) + end.not_to change(described_class, :count) end it 'does not create RecentView for instance of non-existent class' do expect do described_class.log('NonExistentClass', 1, admin) - end.not_to change(RecentView, :count) + end.not_to change(described_class, :count) end end end diff --git a/spec/models/scheduler_spec.rb b/spec/models/scheduler_spec.rb index 0f11afc74..e0b9a03ef 100644 --- a/spec/models/scheduler_spec.rb +++ b/spec/models/scheduler_spec.rb @@ -2,29 +2,27 @@ require 'rails_helper' RSpec.describe Scheduler do - before do - module SpecSpace - class DelayedJobBackend + let(:test_backend_name) { 'SpecSpace::DelayedJobBackend' } + let(:test_backend_class) do + Class.new do + def self.start + # noop + end - def self.start - # noop - end + # rubocop:disable Style/TrivialAccessors + def self.reschedule=(reschedule) + @reschedule = reschedule + end + # rubocop:enable Style/TrivialAccessors - # rubocop:disable Style/TrivialAccessors - def self.reschedule=(reschedule) - @reschedule = reschedule - end - # rubocop:enable Style/TrivialAccessors - - def self.reschedule?(_delayed_job) - @reschedule || false - end + def self.reschedule?(_delayed_job) + @reschedule || false end end end - after do - SpecSpace.send(:remove_const, :DelayedJobBackend) + before do + stub_const test_backend_name, test_backend_class end describe '.failed_jobs' do diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index e29130847..34eff28c8 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Setting, type: :model do context 'when given a valid Setting#name' do it 'returns #state_current[:value]' do 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 @@ -15,7 +15,7 @@ RSpec.describe Setting, type: :model do describe '.set' do context 'when given a valid Setting#name' do it 'sets #state_current = { value: }' do - expect { Setting.set(setting.name, 'foo') } + expect { described_class.set(setting.name, 'foo') } .to change { setting.reload.state_current }.to({ 'value' => 'foo' }) end end @@ -26,7 +26,7 @@ RSpec.describe Setting, type: :model do before { Cache.write('foo', 'bar') } 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) end end @@ -36,9 +36,9 @@ RSpec.describe Setting, type: :model do context 'when given a valid Setting#name' do it 'sets #state_current = { value: } (via #state_initial[:value])' do 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' }) end end diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index c960c9142..ae089aef6 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -12,9 +12,9 @@ RSpec.describe Tag, type: :model 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 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.last&.tag_object&.name }.to('Foo') + .and change { described_class.last&.tag_object&.name }.to('Foo') end end @@ -23,33 +23,33 @@ RSpec.describe Tag, type: :model 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) } - .to change(Tag, :count).by(1) + .to change(described_class, :count).by(1) .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 context 'when a Tag::Item does not exist with the given name' 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) } - .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.last&.tag_item&.name }.to('foo') + .and change { described_class.last&.tag_item&.name }.to('foo') end it 'strips trailing/leading whitespace' do 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.last&.tag_item&.name }.to('foo') + .and change { described_class.last&.tag_item&.name }.to('foo') end context 'and the name contains 8-bit Unicode characters' 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) } - .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.last&.tag_item&.name }.to('fooöäüß') + .and change { described_class.last&.tag_item&.name }.to('fooöäüß') end end @@ -58,9 +58,9 @@ RSpec.describe Tag, type: :model 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) } - .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.last&.tag_item&.name }.to('FOO') + .and change { described_class.last&.tag_item&.name }.to('FOO') end end end @@ -70,16 +70,16 @@ RSpec.describe Tag, type: :model 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) } - .to change(Tag, :count).by(1) + .to change(described_class, :count).by(1) .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 it 'strips leading/trailing whitespace' do 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 change { Tag.last&.tag_item&.name }.to('foo') + .and change { described_class.last&.tag_item&.name }.to('foo') end end @@ -89,7 +89,7 @@ RSpec.describe Tag, type: :model 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) } - .to not_change(Tag, :count) + .to not_change(described_class, :count) .and not_change(Tag::Item, :count) end end @@ -107,14 +107,14 @@ RSpec.describe Tag, type: :model do it 'destroys the Tag' do 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 context 'when no matching Tag exists' do it 'makes no changes' do 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 diff --git a/spec/models/ticket/priority_spec.rb b/spec/models/ticket/priority_spec.rb index c775a4f18..a26b89dfb 100644 --- a/spec/models/ticket/priority_spec.rb +++ b/spec/models/ticket/priority_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Ticket::Priority, type: :model do describe 'Default state' do describe 'of whole table:' 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 @@ -18,21 +18,21 @@ RSpec.describe Ticket::Priority, type: :model do describe '#default_create' do it 'cannot be true for more than one record at a time' do expect { create(:'ticket/priority', default_create: true) } - .to change { Ticket::Priority.find_by(default_create: true).id } - .and change { Ticket::Priority.where(default_create: true).count }.by(0) + .to change { described_class.find_by(default_create: true).id } + .and change { described_class.where(default_create: true).count }.by(0) end it 'cannot be false for all records' do create(:'ticket/priority', default_create: true) - expect { Ticket::Priority.find_by(default_create: true).destroy } - .to change { Ticket::Priority.find_by(default_create: true).id } - .and change { Ticket::Priority.where(default_create: true).count }.by(0) + expect { described_class.find_by(default_create: true).destroy } + .to change { described_class.find_by(default_create: true).id } + .and change { described_class.where(default_create: true).count }.by(0) end it 'is not automatically set to the last-created record' do 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 diff --git a/spec/models/ticket/state_spec.rb b/spec/models/ticket/state_spec.rb index e07f08639..48369554b 100644 --- a/spec/models/ticket/state_spec.rb +++ b/spec/models/ticket/state_spec.rb @@ -9,22 +9,22 @@ RSpec.describe Ticket::State, type: :model do describe 'Default state' do describe 'of whole table:' 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]) end end describe 'of "new" state:' do it 'is the sole #default_create state' do - expect(Ticket::State.where(default_create: true)) - .to match_array([Ticket::State.find_by(name: 'new')]) + expect(described_class.where(default_create: true)) + .to match_array([described_class.find_by(name: 'new')]) end end describe 'of "open" state:' do it 'is the sole #default_follow_up state' do - expect(Ticket::State.where(default_follow_up: true)) - .to match_array([Ticket::State.find_by(name: 'open')]) + expect(described_class.where(default_follow_up: true)) + .to match_array([described_class.find_by(name: 'open')]) end end end @@ -34,7 +34,7 @@ RSpec.describe Ticket::State, type: :model do it 'looks up states by category' do expect(described_class.by_category(:open)) .to be_an(ActiveRecord::Relation) - .and include(instance_of(Ticket::State)) + .and include(instance_of(described_class)) end context 'with invalid category name' do @@ -48,7 +48,7 @@ RSpec.describe Ticket::State, type: :model do describe 'Attributes:' 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 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 expect { state.save } .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 @@ -68,8 +68,8 @@ RSpec.describe Ticket::State, type: :model do it 'does not alter existing default' do expect { state.save } - .to not_change { Ticket::State.find_by(default_create: true) } - .and not_change { Ticket::State.where(default_create: true).count } + .to not_change { described_class.find_by(default_create: true) } + .and not_change { described_class.where(default_create: true).count } end end end @@ -83,16 +83,16 @@ RSpec.describe Ticket::State, type: :model do context 'and updated to false' do it 'assigns Ticket::State.first as default' do expect { state.update(default_create: false) } - .to change { Ticket::State.first.default_create }.to(true) - .and not_change { Ticket::State.where(default_create: true).count } + .to change { described_class.first.default_create }.to(true) + .and not_change { described_class.where(default_create: true).count } end end context 'and destroyed' do it 'assigns Ticket::State.first as default' do expect { state.destroy } - .to change { Ticket::State.first.default_create }.to(true) - .and not_change { Ticket::State.where(default_create: true).count } + .to change { described_class.first.default_create }.to(true) + .and not_change { described_class.where(default_create: true).count } end end end @@ -104,15 +104,15 @@ RSpec.describe Ticket::State, type: :model do it 'unsets previous default' do expect { state.update(default_create: true) } .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 context 'and destroyed' do it 'does not alter existing default' do expect { state.destroy } - .to not_change { Ticket::State.find_by(default_create: true) } - .and not_change { Ticket::State.where(default_create: true).count } + .to not_change { described_class.find_by(default_create: true) } + .and not_change { described_class.where(default_create: true).count } end end end @@ -120,7 +120,7 @@ RSpec.describe Ticket::State, type: :model do end 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 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 expect { state.save } .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 @@ -140,8 +140,8 @@ RSpec.describe Ticket::State, type: :model do it 'does not alter existing default' do expect { state.save } - .to not_change { Ticket::State.find_by(default_follow_up: true) } - .and not_change { Ticket::State.where(default_follow_up: true).count } + .to not_change { described_class.find_by(default_follow_up: true) } + .and not_change { described_class.where(default_follow_up: true).count } end end end @@ -155,16 +155,16 @@ RSpec.describe Ticket::State, type: :model do context 'and updated to false' do it 'assigns Ticket::State.first as default' do expect { state.update(default_follow_up: false) } - .to change { Ticket::State.first.default_follow_up }.to(true) - .and not_change { Ticket::State.where(default_follow_up: true).count } + .to change { described_class.first.default_follow_up }.to(true) + .and not_change { described_class.where(default_follow_up: true).count } end end context 'and destroyed' do it 'assigns Ticket::State.first as default' do expect { state.destroy } - .to change { Ticket::State.first.default_follow_up }.to(true) - .and not_change { Ticket::State.where(default_follow_up: true).count } + .to change { described_class.first.default_follow_up }.to(true) + .and not_change { described_class.where(default_follow_up: true).count } end end end @@ -176,15 +176,15 @@ RSpec.describe Ticket::State, type: :model do it 'unsets previous default' do expect { state.update(default_follow_up: true) } .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 context 'and destroyed' do it 'does not alter existing default' do expect { state.destroy } - .to not_change { Ticket::State.find_by(default_follow_up: true) } - .and not_change { Ticket::State.where(default_follow_up: true).count } + .to not_change { described_class.find_by(default_follow_up: true) } + .and not_change { described_class.where(default_follow_up: true).count } end end end diff --git a/spec/models/ticket/time_accounting_spec.rb b/spec/models/ticket/time_accounting_spec.rb index 6ef6f4954..ea339387d 100644 --- a/spec/models/ticket/time_accounting_spec.rb +++ b/spec/models/ticket/time_accounting_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Ticket::TimeAccounting, type: :model do it 'destroys self' do expect { time_accounting.ticket_article.destroy } .to change(time_accounting, :persisted?).to(false) - .and change { Ticket::TimeAccounting.count }.by(-1) + .and change(described_class, :count).by(-1) end 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) expect { time_accounting.ticket_article.destroy } - .to change { Ticket::TimeAccounting.count }.by(-1) + .to change(described_class, :count).by(-1) end end end diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index c4bf17126..0944d79d1 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -43,7 +43,7 @@ RSpec.describe Ticket, type: :model do end 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]) end end diff --git a/spec/models/token_spec.rb b/spec/models/token_spec.rb index c12d0590c..cba373674 100644 --- a/spec/models/token_spec.rb +++ b/spec/models/token_spec.rb @@ -6,19 +6,19 @@ RSpec.describe Token, type: :model do describe '.check' do context 'with name and action matching existing token' do it 'returns the token’s 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 context 'with invalid name' 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 context 'with invalid action' 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 @@ -30,14 +30,14 @@ RSpec.describe Token, type: :model do let(:created_at) { 1.month.ago } it 'returns the token’s 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 it 'does not delete the token' do token # create token - expect { Token.check(action: token.action, name: token.name) } - .not_to change(Token, :count) + expect { described_class.check(action: token.action, name: token.name) } + .not_to change(described_class, :count) end end end @@ -49,14 +49,14 @@ RSpec.describe Token, type: :model do let(:created_at) { 1.day.ago + 5 } it 'returns the token’s 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 it 'does not delete the token' do token # create token - expect { Token.check(action: token.action, name: token.name) } - .not_to change(Token, :count) + expect { described_class.check(action: token.action, name: token.name) } + .not_to change(described_class, :count) end end @@ -64,14 +64,14 @@ RSpec.describe Token, type: :model do let(:created_at) { 1.day.ago } 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 it 'deletes the token' do token # create token - expect { Token.check(action: token.action, name: token.name) } - .to change(Token, :count).by(-1) + expect { described_class.check(action: token.action, name: token.name) } + .to change(described_class, :count).by(-1) 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 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 context 'with the child of a permission shared by both token.user and token.preferences' 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 context 'with the parent of a permission shared by both token.user and token.preferences' 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 context 'with a permission in token.preferences, but not on token.user' 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 context 'with a permission not in token.preferences, but on token.user' 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 context 'with non-existent permission' 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 context 'with multiple permissions, where at least one is shared by both token.user and token.preferences' 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 @@ -130,7 +130,7 @@ RSpec.describe Token, type: :model do describe 'Attributes:' do describe '#persistent' 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 expect(token.persistent).to be(nil) diff --git a/spec/models/trigger_spec.rb b/spec/models/trigger_spec.rb index 75d2146c4..d47a2edb4 100644 --- a/spec/models/trigger_spec.rb +++ b/spec/models/trigger_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Trigger, type: :model do describe 'Send-email triggers' 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 end diff --git a/spec/models/type_lookup_spec.rb b/spec/models/type_lookup_spec.rb index 0edb45c07..bcc2b71f9 100644 --- a/spec/models/type_lookup_spec.rb +++ b/spec/models/type_lookup_spec.rb @@ -6,7 +6,7 @@ RSpec.describe TypeLookup, type: :model do subject(:type_lookup) { create(:type_lookup) } 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) end end @@ -15,24 +15,24 @@ RSpec.describe TypeLookup, type: :model do let(:name) { 'FooBar' } it 'creates a new one with that name' do - expect { TypeLookup.by_name(name) } - .to change(TypeLookup, :count).by(1) + expect { described_class.by_name(name) } + .to change(described_class, :count).by(1) - expect(TypeLookup.last.name).to eq(name) + expect(described_class.last.name).to eq(name) end it 'returns its id' do - expect(TypeLookup.by_name(name)) - .to eq(TypeLookup.last.id) + expect(described_class.by_name(name)) + .to eq(described_class.last.id) end context 'for names not in strict CamelCase' do let(:name) { 'Foo_Bar' } 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 @@ -43,7 +43,7 @@ RSpec.describe TypeLookup, type: :model do subject(:type_lookup) { create(:type_lookup) } 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) end end diff --git a/spec/models/user_device_spec.rb b/spec/models/user_device_spec.rb index ffb12b6c6..2f27e3223 100644 --- a/spec/models/user_device_spec.rb +++ b/spec/models/user_device_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' RSpec.describe UserDevice, type: :model 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(:agent) { create(:agent_user) } @@ -15,7 +15,7 @@ RSpec.describe UserDevice, type: :model do context 'when called with same parameters as existing 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) end end @@ -24,8 +24,8 @@ RSpec.describe UserDevice, type: :model do let(:other_ip) { '176.198.137.254' } it 'returns a new record' do - expect(UserDevice.add(user_agent, other_ip, agent.id, fingerprint, type)) - .to be_a(UserDevice) + expect(described_class.add(user_agent, other_ip, agent.id, fingerprint, type)) + .to be_a(described_class) .and not_eq(existing_record) end end @@ -34,8 +34,8 @@ RSpec.describe UserDevice, type: :model do let(:other_ip) { 'foo' } it 'returns a new record' do - expect(UserDevice.add(user_agent, other_ip, agent.id, fingerprint, type)) - .to be_a(UserDevice) + expect(described_class.add(user_agent, other_ip, agent.id, fingerprint, type)) + .to be_a(described_class) .and not_eq(existing_record) end end @@ -44,8 +44,8 @@ RSpec.describe UserDevice, type: :model do let(:other_fingerprint) { 'fingerprintABCD' } it 'returns a new record' do - expect(UserDevice.add(user_agent, ip, agent.id, other_fingerprint, type)) - .to be_a(UserDevice) + expect(described_class.add(user_agent, ip, agent.id, other_fingerprint, type)) + .to be_a(described_class) .and not_eq(existing_record) end end @@ -112,7 +112,7 @@ RSpec.describe UserDevice, type: :model do context 'when called with same parameters as existing 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) end end @@ -121,8 +121,8 @@ RSpec.describe UserDevice, type: :model do let(:other_ip) { '176.198.137.254' } it 'returns a new record' do - expect(UserDevice.add(user_agent, other_ip, agent.id, fingerprint, type)) - .to be_a(UserDevice) + expect(described_class.add(user_agent, other_ip, agent.id, fingerprint, type)) + .to be_a(described_class) .and not_eq(existing_record) end end @@ -131,7 +131,7 @@ RSpec.describe UserDevice, type: :model do let(:other_type) { 'token_auth' } 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) end end @@ -140,8 +140,8 @@ RSpec.describe UserDevice, type: :model do let(:other_user_agent) { '' } it 'returns a new record' do - expect(UserDevice.add(other_user_agent, ip, agent.id, fingerprint, type)) - .to be_a(UserDevice) + expect(described_class.add(other_user_agent, ip, agent.id, fingerprint, type)) + .to be_a(described_class) .and not_eq(existing_record) end end @@ -151,7 +151,7 @@ RSpec.describe UserDevice, type: :model do let(:other_user_agent) { nil } 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) end end @@ -161,8 +161,8 @@ RSpec.describe UserDevice, type: :model do let(:other_ip) { '176.198.137.254' } it 'returns a new record' do - expect(UserDevice.add(user_agent, other_ip, agent.id, fingerprint, type)) - .to be_a(UserDevice) + expect(described_class.add(user_agent, other_ip, agent.id, fingerprint, type)) + .to be_a(described_class) .and not_eq(existing_record) end end @@ -174,14 +174,14 @@ RSpec.describe UserDevice, type: :model do let(:type) { 'session' } 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) end end end 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(:ip) { '91.115.248.231' } let(:agent) { create(:agent_user) } @@ -200,7 +200,7 @@ RSpec.describe UserDevice, type: :model do it 'returns a new user_device' do 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) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 36e6adf4a..143490d4a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -177,11 +177,11 @@ RSpec.describe User, type: :model do describe '.identify' 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 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 @@ -716,7 +716,7 @@ RSpec.describe User, type: :model do describe '#out_of_office_replacement_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) end @@ -980,7 +980,7 @@ RSpec.describe User, type: :model do describe 'System-wide agent limit checks:' do let(:agent_role) { Role.lookup(name: 'Agent') } 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 context 'for Integer value of system_agent_limit' do