-
Notifications
You must be signed in to change notification settings - Fork 434
/
notification.rb
121 lines (99 loc) · 3.56 KB
/
notification.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
FactoryBot.define do
factory :notification do
event_type { 'Event::RequestStatechange' }
event_payload { { fake: 'payload' } }
subscription_receiver_role { 'owner' }
title { Faker::Lorem.sentence }
delivered { false }
transient do
originator { nil } # User login
recipient_group { nil } # Group title
role { nil } # Role title
end
after(:build) do |notification, evaluator|
notification.event_payload['who'] ||= evaluator.originator unless evaluator.originator.nil?
notification.event_payload['group'] ||= evaluator.recipient_group unless evaluator.recipient_group.nil?
notification.event_payload['role'] ||= evaluator.role unless evaluator.role.nil?
notification.event_payload['project'] ||= notification.notifiable.to_s if notification.notifiable.is_a?(Project)
end
trait :stale do
created_at { 13.months.ago }
end
trait :request_state_change do
event_type { 'Event::RequestStatechange' }
notifiable factory: [:bs_request_with_submit_action]
bs_request_oldstate { :new }
end
trait :request_created do
event_type { 'Event::RequestCreate' }
notifiable factory: [:bs_request_with_submit_action]
end
trait :review_wanted do
event_type { 'Event::ReviewWanted' }
notifiable factory: [:bs_request_with_submit_action]
end
trait :comment_for_project do
event_type { 'Event::CommentForProject' }
notifiable factory: [:comment_project]
end
trait :comment_for_package do
event_type { 'Event::CommentForPackage' }
notifiable factory: [:comment_package]
end
trait :comment_for_request do
event_type { 'Event::CommentForRequest' }
notifiable factory: [:comment_request]
end
trait :relationship_create_for_project do
event_type { 'Event::RelationshipCreate' }
notifiable factory: [:project]
end
trait :relationship_delete_for_project do
event_type { 'Event::RelationshipDelete' }
notifiable factory: [:project]
end
trait :relationship_create_for_package do
event_type { 'Event::RelationshipCreate' }
notifiable factory: [:package]
end
trait :relationship_delete_for_package do
event_type { 'Event::RelationshipDelete' }
notifiable factory: [:package]
end
trait :build_failure do
event_type { 'Event::BuildFail' }
notifiable factory: [:package]
end
trait :create_report do
event_type { 'Event::CreateReport' }
notifiable factory: [:report]
transient do
reason { nil }
end
after(:build) do |notification, evaluator|
notification.event_payload['reportable_type'] ||= notification.notifiable.reportable.class.to_s
notification.event_payload['reason'] ||= evaluator.reason
end
end
trait :cleared_decision do
event_type { 'Event::ClearedDecision' }
notifiable { association(:decision_cleared) }
after(:build) do |notification|
notification.event_payload['reportable_type'] ||= notification.notifiable.reports.first.reportable.class.to_s
end
end
trait :favored_decision do
event_type { 'Event::FavoredDecision' }
notifiable { association(:decision_favored) }
after(:build) do |notification|
notification.event_payload['reportable_type'] ||= notification.notifiable.reports.first.reportable.class.to_s
end
end
end
factory :rss_notification, parent: :notification do
rss { true }
end
factory :web_notification, parent: :notification do
web { true }
end
end