Fix EmailAddress dependency issue in Ticket factory

This commit is contained in:
Ryan Lue 2019-02-04 07:56:18 +01:00 committed by Martin Edenhofer
parent 85d6d78eea
commit 9f33ca5c0a
10 changed files with 49 additions and 48 deletions

View file

@ -2,7 +2,7 @@ FactoryBot.define do
factory :email_address do factory :email_address do
sequence(:email) { |n| "zammad#{n}@localhost.com" } sequence(:email) { |n| "zammad#{n}@localhost.com" }
sequence(:realname) { |n| "zammad#{n}" } sequence(:realname) { |n| "zammad#{n}" }
channel_id 1 channel { create(:email_channel) }
created_by_id 1 created_by_id 1
updated_by_id 1 updated_by_id 1
end end

View file

@ -1,14 +1,8 @@
FactoryBot.define do FactoryBot.define do
sequence :test_group_name do |n|
"TestGroup#{n}"
end
end
FactoryBot.define do
factory :group do factory :group do
name { generate(:test_group_name) } sequence(:name) { |n| "Group #{n}" }
created_by_id 1 email_address
updated_by_id 1 created_by_id { 1 }
updated_by_id { 1 }
end end
end end

View file

@ -1,12 +1,12 @@
FactoryBot.define do FactoryBot.define do
factory :ticket do factory :ticket do
title 'Test Ticket' title { 'Test Ticket' }
group { Group.lookup(name: 'Users') } group
customer { FactoryBot.create(:customer_user) } customer
state { Ticket::State.lookup(name: 'new') } state { Ticket::State.lookup(name: 'new') }
priority { Ticket::Priority.lookup(name: '2 normal') } priority { Ticket::Priority.lookup(name: '2 normal') }
updated_by_id 1 updated_by_id { 1 }
created_by_id 1 created_by_id { 1 }
factory :twitter_ticket do factory :twitter_ticket do
transient do transient do

View file

@ -16,17 +16,17 @@ FactoryBot.define do
login_failed 0 login_failed 0
updated_by_id 1 updated_by_id 1
created_by_id 1 created_by_id 1
end
factory :customer_user, parent: :user do factory :customer_user, aliases: %i[customer] do
role_ids { Role.signup_role_ids.sort } role_ids { Role.signup_role_ids.sort }
end end
factory :agent_user, parent: :user do factory :agent_user, aliases: %i[agent] do
roles { Role.where(name: 'Agent') } roles { Role.where(name: 'Agent') }
end end
factory :admin_user, parent: :user do factory :admin_user, aliases: %i[admin] do
roles { Role.where(name: %w[Admin Agent]) } roles { Role.where(name: %w[Admin Agent]) }
end end
end
end end

View file

@ -5,7 +5,6 @@ RSpec.describe Trigger do
describe 'sms' do describe 'sms' do
it 'sends interpolated, html-free SMS' do it 'sends interpolated, html-free SMS' do
customer = create(:customer_user)
agent = create(:agent_user) agent = create(:agent_user)
another_agent = create(:admin_user, mobile: '+37061010000') another_agent = create(:admin_user, mobile: '+37061010000')
Group.lookup(id: 1).users << another_agent 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 Observer::Transaction.commit
triggered_article = Ticket::Article.last triggered_article = Ticket::Article.last

View file

@ -2,11 +2,12 @@ require 'rails_helper'
RSpec.describe 'Search', type: :request, searchindex: true do RSpec.describe 'Search', type: :request, searchindex: true do
let(:group) { create(:group) }
let!(:admin_user) do let!(:admin_user) do
create(:admin_user, groups: Group.all) create(:admin_user, groups: [Group.lookup(name: 'Users'), group])
end end
let!(:agent_user) do 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 end
let!(:customer_user) do let!(:customer_user) do
create(:customer_user) create(:customer_user)
@ -33,13 +34,13 @@ RSpec.describe 'Search', type: :request, searchindex: true do
create(:customer_user, organization: organization1) create(:customer_user, organization: organization1)
end end
let!(:ticket1) do let!(:ticket1) do
create(:ticket, title: 'test 1234-1', customer: customer_user) create(:ticket, title: 'test 1234-1', customer: customer_user, group: group)
end end
let!(:ticket2) do let!(:ticket2) do
create(:ticket, title: 'test 1234-2', customer: customer_user2) create(:ticket, title: 'test 1234-2', customer: customer_user2, group: group)
end end
let!(:ticket3) do let!(:ticket3) do
create(:ticket, title: 'test 1234-2', customer: customer_user3) create(:ticket, title: 'test 1234-2', customer: customer_user3, group: group)
end end
let!(:article1) do let!(:article1) do
create(:ticket_article, ticket_id: ticket1.id) create(:ticket_article, ticket_id: ticket1.id)

View file

@ -2,14 +2,16 @@ require 'rails_helper'
RSpec.describe 'Ticket Article Attachments', type: :request do RSpec.describe 'Ticket Article Attachments', type: :request do
let(:group) { create(:group) }
let(:agent_user) do let(:agent_user) do
create(:agent_user, groups: Group.all) create(:agent_user, groups: [Group.lookup(name: 'Users'), group])
end end
describe 'request handling' do describe 'request handling' do
it 'does test attachment urls' do it 'does test attachment urls' do
ticket1 = create(:ticket) ticket1 = create(:ticket, group: group)
article1 = create(:ticket_article, ticket_id: ticket1.id) article1 = create(:ticket_article, ticket_id: ticket1.id)
store1 = Store.add( store1 = Store.add(
@ -34,7 +36,7 @@ RSpec.describe 'Ticket Article Attachments', type: :request do
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
expect(@response.body).to match(/401: Unauthorized/) expect(@response.body).to match(/401: Unauthorized/)
ticket2 = create(:ticket) ticket2 = create(:ticket, group: group)
ticket1.merge_to( ticket1.merge_to(
ticket_id: ticket2.id, ticket_id: ticket2.id,
user_id: 1, user_id: 1,

View file

@ -5,8 +5,10 @@ RSpec.describe 'Ticket Article', type: :request do
let(:admin_user) do let(:admin_user) do
create(:admin_user) create(:admin_user)
end end
let(:group) { create(:group) }
let(:agent_user) do let(:agent_user) do
create(:agent_user, groups: Group.all) create(:agent_user, groups: [Group.lookup(name: 'Users'), group])
end end
let(:customer_user) do let(:customer_user) do
create(:customer_user) create(:customer_user)
@ -307,7 +309,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
end end
it 'does ticket split with html - check attachments' do it 'does ticket split with html - check attachments' do
ticket = create(:ticket) ticket = create(:ticket, group: group)
article = create( article = create(
:ticket_article, :ticket_article,
ticket_id: ticket.id, ticket_id: ticket.id,
@ -401,6 +403,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
it 'does ticket split with plain - check attachments' do it 'does ticket split with plain - check attachments' do
ticket = create( ticket = create(
:ticket, :ticket,
group: group,
updated_by_id: agent_user.id, updated_by_id: agent_user.id,
created_by_id: agent_user.id, created_by_id: agent_user.id,
) )

View file

@ -2105,9 +2105,9 @@ RSpec.describe 'Ticket', type: :request do
end end
describe 'stats' do describe 'stats' do
let(:ticket1) { 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) } let(:ticket2) { create(:ticket, customer: customer, organization: organization, group: ticket_group) }
let(:ticket3) { create(:ticket, customer: customer, organization: organization) } let(:ticket3) { create(:ticket, customer: customer, organization: organization, group: ticket_group) }
let(:customer) { create(:customer_user, organization: organization) } let(:customer) { create(:customer_user, organization: organization) }
let(:organization) { create(:organization, shared: false) } let(:organization) { create(:organization, shared: false) }

View file

@ -4,25 +4,27 @@ RSpec.describe 'Ticket Create', type: :system do
context 'when applying ticket templates' do context 'when applying ticket templates' do
# Regression test for issue #2424 - Unavailable ticket template attributes get applied # Regression test for issue #2424 - Unavailable ticket template attributes get applied
scenario 'unavailable attributes do not get applied', authenticated: false do 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 = { 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: { template = create :template, options: {
'title' => 'Template Title', 'title' => 'Template Title',
'group_id' => '1', 'group_id' => unpermitted_group.id,
'owner_id' => '2', 'owner_id' => '2',
} }
# apply the ticket template and confirm that the group_id dropdown does not appear
login( login(
username: user.email, username: user.email,
password: 'test', password: 'test',
) )
visit 'ticket/create' 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 find('#form-template select[name="id"]').find(:option, template.name).select_option
click '.sidebar-content .js-apply' click '.sidebar-content .js-apply'
expect(page).not_to have_selector 'select[name="group_id"]' expect(page).not_to have_selector 'select[name="group_id"]'