From 9f33ca5c0a8810bee6f1dc1b49719657984ffcce Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Mon, 4 Feb 2019 07:56:18 +0100 Subject: [PATCH] Fix EmailAddress dependency issue in Ticket factory --- spec/factories/email_address.rb | 2 +- spec/factories/group.rb | 14 ++++---------- spec/factories/ticket.rb | 14 +++++++------- spec/factories/user.rb | 18 +++++++++--------- spec/models/trigger/sms_spec.rb | 3 +-- spec/requests/search_spec.rb | 11 ++++++----- .../ticket/article_attachments_spec.rb | 8 +++++--- spec/requests/ticket/article_spec.rb | 7 +++++-- spec/requests/ticket_spec.rb | 6 +++--- spec/system/ticket/create_spec.rb | 14 ++++++++------ 10 files changed, 49 insertions(+), 48 deletions(-) diff --git a/spec/factories/email_address.rb b/spec/factories/email_address.rb index 6173d8350..9ffd6f873 100644 --- a/spec/factories/email_address.rb +++ b/spec/factories/email_address.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :email_address do sequence(:email) { |n| "zammad#{n}@localhost.com" } sequence(:realname) { |n| "zammad#{n}" } - channel_id 1 + channel { create(:email_channel) } created_by_id 1 updated_by_id 1 end diff --git a/spec/factories/group.rb b/spec/factories/group.rb index b2a673ee1..d5a4ab1ed 100644 --- a/spec/factories/group.rb +++ b/spec/factories/group.rb @@ -1,14 +1,8 @@ FactoryBot.define do - sequence :test_group_name do |n| - "TestGroup#{n}" - end -end - -FactoryBot.define do - factory :group do - name { generate(:test_group_name) } - created_by_id 1 - updated_by_id 1 + sequence(:name) { |n| "Group #{n}" } + email_address + created_by_id { 1 } + updated_by_id { 1 } end end diff --git a/spec/factories/ticket.rb b/spec/factories/ticket.rb index 1cdf14155..7c73f92fe 100644 --- a/spec/factories/ticket.rb +++ b/spec/factories/ticket.rb @@ -1,12 +1,12 @@ FactoryBot.define do factory :ticket do - title 'Test Ticket' - group { Group.lookup(name: 'Users') } - customer { FactoryBot.create(:customer_user) } - state { Ticket::State.lookup(name: 'new') } - priority { Ticket::Priority.lookup(name: '2 normal') } - updated_by_id 1 - created_by_id 1 + title { 'Test Ticket' } + group + customer + state { Ticket::State.lookup(name: 'new') } + priority { Ticket::Priority.lookup(name: '2 normal') } + updated_by_id { 1 } + created_by_id { 1 } factory :twitter_ticket do transient do diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 409dc7719..01d6b9583 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -16,17 +16,17 @@ FactoryBot.define do login_failed 0 updated_by_id 1 created_by_id 1 - end - factory :customer_user, parent: :user do - role_ids { Role.signup_role_ids.sort } - end + factory :customer_user, aliases: %i[customer] do + role_ids { Role.signup_role_ids.sort } + end - factory :agent_user, parent: :user do - roles { Role.where(name: 'Agent') } - end + factory :agent_user, aliases: %i[agent] do + roles { Role.where(name: 'Agent') } + end - factory :admin_user, parent: :user do - roles { Role.where(name: %w[Admin Agent]) } + factory :admin_user, aliases: %i[admin] do + roles { Role.where(name: %w[Admin Agent]) } + end end end diff --git a/spec/models/trigger/sms_spec.rb b/spec/models/trigger/sms_spec.rb index c099b08d5..031069da7 100644 --- a/spec/models/trigger/sms_spec.rb +++ b/spec/models/trigger/sms_spec.rb @@ -5,7 +5,6 @@ RSpec.describe Trigger do describe 'sms' do it 'sends interpolated, html-free SMS' do - customer = create(:customer_user) agent = create(:agent_user) another_agent = create(:admin_user, mobile: '+37061010000') Group.lookup(id: 1).users << another_agent @@ -20,7 +19,7 @@ RSpec.describe Trigger do } }) - ticket = create(:ticket, customer: customer, created_by_id: agent.id) + ticket = create(:ticket, group: Group.lookup(id: 1), created_by_id: agent.id) Observer::Transaction.commit triggered_article = Ticket::Article.last diff --git a/spec/requests/search_spec.rb b/spec/requests/search_spec.rb index 32a41a24e..89fce0ef5 100644 --- a/spec/requests/search_spec.rb +++ b/spec/requests/search_spec.rb @@ -2,11 +2,12 @@ require 'rails_helper' RSpec.describe 'Search', type: :request, searchindex: true do + let(:group) { create(:group) } let!(:admin_user) do - create(:admin_user, groups: Group.all) + create(:admin_user, groups: [Group.lookup(name: 'Users'), group]) end let!(:agent_user) do - create(:agent_user, firstname: 'Search 1234', groups: Group.all) + create(:agent_user, firstname: 'Search 1234', groups: [Group.lookup(name: 'Users'), group]) end let!(:customer_user) do create(:customer_user) @@ -33,13 +34,13 @@ RSpec.describe 'Search', type: :request, searchindex: true do create(:customer_user, organization: organization1) end let!(:ticket1) do - create(:ticket, title: 'test 1234-1', customer: customer_user) + create(:ticket, title: 'test 1234-1', customer: customer_user, group: group) end let!(:ticket2) do - create(:ticket, title: 'test 1234-2', customer: customer_user2) + create(:ticket, title: 'test 1234-2', customer: customer_user2, group: group) end let!(:ticket3) do - create(:ticket, title: 'test 1234-2', customer: customer_user3) + create(:ticket, title: 'test 1234-2', customer: customer_user3, group: group) end let!(:article1) do create(:ticket_article, ticket_id: ticket1.id) diff --git a/spec/requests/ticket/article_attachments_spec.rb b/spec/requests/ticket/article_attachments_spec.rb index c908eb2c3..24207ff21 100644 --- a/spec/requests/ticket/article_attachments_spec.rb +++ b/spec/requests/ticket/article_attachments_spec.rb @@ -2,14 +2,16 @@ require 'rails_helper' RSpec.describe 'Ticket Article Attachments', type: :request do + let(:group) { create(:group) } + let(:agent_user) do - create(:agent_user, groups: Group.all) + create(:agent_user, groups: [Group.lookup(name: 'Users'), group]) end describe 'request handling' do it 'does test attachment urls' do - ticket1 = create(:ticket) + ticket1 = create(:ticket, group: group) article1 = create(:ticket_article, ticket_id: ticket1.id) store1 = Store.add( @@ -34,7 +36,7 @@ RSpec.describe 'Ticket Article Attachments', type: :request do expect(response).to have_http_status(401) expect(@response.body).to match(/401: Unauthorized/) - ticket2 = create(:ticket) + ticket2 = create(:ticket, group: group) ticket1.merge_to( ticket_id: ticket2.id, user_id: 1, diff --git a/spec/requests/ticket/article_spec.rb b/spec/requests/ticket/article_spec.rb index 9d45e2684..93a48647f 100644 --- a/spec/requests/ticket/article_spec.rb +++ b/spec/requests/ticket/article_spec.rb @@ -5,8 +5,10 @@ RSpec.describe 'Ticket Article', type: :request do let(:admin_user) do create(:admin_user) end + let(:group) { create(:group) } + let(:agent_user) do - create(:agent_user, groups: Group.all) + create(:agent_user, groups: [Group.lookup(name: 'Users'), group]) end let(:customer_user) do create(:customer_user) @@ -307,7 +309,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO end it 'does ticket split with html - check attachments' do - ticket = create(:ticket) + ticket = create(:ticket, group: group) article = create( :ticket_article, ticket_id: ticket.id, @@ -401,6 +403,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO it 'does ticket split with plain - check attachments' do ticket = create( :ticket, + group: group, updated_by_id: agent_user.id, created_by_id: agent_user.id, ) diff --git a/spec/requests/ticket_spec.rb b/spec/requests/ticket_spec.rb index a9fecc5db..3c9e7f067 100644 --- a/spec/requests/ticket_spec.rb +++ b/spec/requests/ticket_spec.rb @@ -2105,9 +2105,9 @@ RSpec.describe 'Ticket', type: :request do end describe 'stats' do - let(:ticket1) { create(:ticket, customer: customer, organization: organization) } - let(:ticket2) { create(:ticket, customer: customer, organization: organization) } - let(:ticket3) { create(:ticket, customer: customer, organization: organization) } + let(:ticket1) { create(:ticket, customer: customer, organization: organization, group: ticket_group) } + let(:ticket2) { create(:ticket, customer: customer, organization: organization, group: ticket_group) } + let(:ticket3) { create(:ticket, customer: customer, organization: organization, group: ticket_group) } let(:customer) { create(:customer_user, organization: organization) } let(:organization) { create(:organization, shared: false) } diff --git a/spec/system/ticket/create_spec.rb b/spec/system/ticket/create_spec.rb index 3a0490792..5ae806bf0 100644 --- a/spec/system/ticket/create_spec.rb +++ b/spec/system/ticket/create_spec.rb @@ -4,25 +4,27 @@ RSpec.describe 'Ticket Create', type: :system do context 'when applying ticket templates' do # Regression test for issue #2424 - Unavailable ticket template attributes get applied scenario 'unavailable attributes do not get applied', authenticated: false do - # create a new agent with permissions for only group "some group1" - user = create :agent_user + user = create(:agent_user) + permitted_group = create(:group) + unpermitted_group = create(:group) + user.group_names_access_map = { - 'some group1' => 'full', + permitted_group.name => 'full', } - # create a template that sets the group to Users and ticket owner to user id 1 template = create :template, options: { 'title' => 'Template Title', - 'group_id' => '1', + 'group_id' => unpermitted_group.id, 'owner_id' => '2', } - # apply the ticket template and confirm that the group_id dropdown does not appear login( username: user.email, password: 'test', ) visit 'ticket/create' + + # apply the ticket template and confirm that the group_id dropdown does not appear find('#form-template select[name="id"]').find(:option, template.name).select_option click '.sidebar-content .js-apply' expect(page).not_to have_selector 'select[name="group_id"]'