Permalink
Browse files

Refactoring: Migrate ticket_article_store_empty to RSpec

  • Loading branch information...
Ryan Lue authored and znuny-robo committed Feb 10, 2019
1 parent 63214c9 commit 107fd5e995e51d9c6b3be3a10a0b36d5869d3838
@@ -0,0 +1,12 @@
FactoryBot.define do
factory :activity_stream do
transient do
o { Ticket.first }
end

association :type, factory: :type_lookup
activity_stream_object_id { ObjectLookup.by_name(o.class.name) }
o_id { o.id }
created_by_id { 1 }
end
end
@@ -1,8 +1,15 @@
FactoryBot.define do
factory :history do
transient do
o { Ticket.first }
end

association :history_type, factory: :'history/type'
association :history_object, factory: :'history/object'
o_id { history_object.name.constantize.pluck(:id).sample }
o_id { o.id }
created_by_id { 1 }

history_object_id do
History::Object.lookup(name: o.class.name)&.id || create(:'history/object', name: o.class.name).id
end
end
end
@@ -0,0 +1,14 @@
FactoryBot.define do
factory :'karma/activity_log', aliases: %i[karma_activity_log] do
transient do
o { Ticket.first }
end

o_id { o.id }
object_lookup_id { ObjectLookup.by_name(o.class.name) }
user_id { 1 }
activity_id { Karma::Activity.pluck(:id).sample }
score { 100 }
score_total { 100 }
end
end
@@ -1,7 +1,14 @@
FactoryBot.define do
factory :link do
link_type_id { Link::Type.find_by(name: 'normal').id }
link_object_source_id { Link::Object.find_by(name: 'Ticket').id }
link_object_target_id { Link::Object.find_by(name: 'Ticket').id }
transient do
from { Ticket.first }
to { Ticket.last }
end

link_type_id { Link::Type.find_by(name: 'normal').id }
link_object_source_id { Link::Object.find_by(name: 'Ticket').id }
link_object_target_id { Link::Object.find_by(name: 'Ticket').id }
link_object_source_value { from.id }
link_object_target_value { to.id }
end
end
@@ -1,13 +1,17 @@
FactoryBot.define do
factory :online_notification do
object_lookup_id { ObjectLookup.by_name('Ticket') }
o_id 1
type_lookup_id { TypeLookup.by_name('updated') }
seen false
user_id 1
created_by_id 1
updated_by_id 1
created_at Time.zone.now
updated_at Time.zone.now
transient do
o { Ticket.first }
end

object_lookup_id { ObjectLookup.by_name(o.class.name) }
o_id { o.id }
type_lookup_id { TypeLookup.by_name('updated') }
seen { false }
user_id { 1 }
created_by_id { 1 }
updated_by_id { 1 }
created_at { Time.zone.now }
updated_at { Time.zone.now }
end
end
@@ -1,23 +1,12 @@
FactoryBot.define do
factory :recent_view do
transient do
type { :ticket }
o { Ticket.first }
user_role { :agent }
end

recent_view_object_id { ObjectLookup.by_name(type.to_s.camelcase) }

# select a random record of the given object class
o_id do
random_function = case ActiveRecord::Base.connection_config[:adapter]
when 'mysql2'
'RAND'
when 'postgresql'
'RANDOM'
end

type.to_s.camelcase.constantize.order("#{random_function}()").first.id
end
recent_view_object_id { ObjectLookup.by_name(o.class.name) }
o_id { o.id }

# assign to an existing user, if possible
created_by_id do
@@ -1,7 +1,15 @@
FactoryBot.define do
factory :tag do
tag_object_id { Tag::Object.lookup_by_name_and_create('Ticket').id }
tag_item_id { Tag::Item.lookup_by_name_and_create('blub').id }
created_by_id 1
transient do
o { Ticket.first }
end

tag_item_id { Tag::Item.lookup_by_name_and_create('blub').id }
o_id { o.id }
created_by_id { 1 }

tag_object_id do
Tag::Object.lookup(name: o.class.name)&.id || create(:'tag/object', name: o.class.name).id
end
end
end
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :'tag/object', aliases: %i[tag_object] do
name { (ApplicationModel.descendants.select(&:any?).map(&:name) - Tag::Object.pluck(:name)).sample }
end
end
@@ -1,25 +1,25 @@
FactoryBot.define do
factory :'ticket/article', aliases: %i[ticket_article] do
transient do
type_name 'email'
sender_name 'Customer'
type_name { 'email' }
sender_name { 'Customer' }
end

ticket
from 'factory-customer-1@example.com'
to 'factory-customer-1@example.com'
subject 'factory article'
message_id 'factory@id_com_1'
body 'some message 123'
internal false
sender { Ticket::Article::Sender.find_by(name: sender_name) }
type { Ticket::Article::Type.find_by(name: type_name) }
updated_by_id 1
created_by_id 1
from { 'factory-customer-1@example.com' }
to { 'factory-customer-1@example.com' }
subject { 'factory article' }
message_id { 'factory@id_com_1' }
body { 'some message 123' }
internal { false }
sender { Ticket::Article::Sender.find_by(name: sender_name) }
type { Ticket::Article::Type.find_by(name: type_name) }
updated_by_id { 1 }
created_by_id { 1 }

factory :twitter_article do
transient do
type_name 'twitter status'
type_name { 'twitter status' }
end

association :ticket, factory: :twitter_ticket
@@ -0,0 +1,17 @@
FactoryBot.define do
factory :type_lookup do
name do
# The following line ensures that the name generated by Faker
# does not conflict with any existing names in the DB.
# There's a special syntax for this
# (Faker::Verb.unique.exclude(:past_participle, [], Ticket::StateType.pluck(:name)),
# but it's not available yet in the current release of Faker (1.9.1).
Faker::Verb.unique
.instance_variable_get(:@previous_results)
.dig([:base, []])
.merge(TypeLookup.pluck(:name))

Faker::Verb.unique.base
end
end
end
Oops, something went wrong.

0 comments on commit 107fd5e

Please sign in to comment.