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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
FactoryGirl.define do
sequence(:email) { |n| "person#{n}@example.com" }
sequence(:name) { |n| "Example Public Body #{n}" }
sequence(:short_name) { |n| "Example Body #{n}" }
factory :foi_attachment do
factory :body_text do
content_type 'text/plain'
body { 'hereisthetext' }
end
factory :pdf_attachment do
content_type 'application/pdf'
filename 'interesting.pdf'
body { load_file_fixture('interesting.pdf') }
end
end
factory :incoming_message do
info_request
raw_email
last_parsed { 1.week.ago }
sent_at { 1.week.ago }
after_create do |incoming_message, evaluator|
FactoryGirl.create(:body_text,
:incoming_message => incoming_message,
:url_part_number => 1)
end
factory :plain_incoming_message do
last_parsed { nil }
sent_at { nil }
after_create do |incoming_message, evaluator|
data = load_file_fixture('incoming-request-plain.email')
data.gsub!('EMAIL_FROM', 'Bob Responder <bob@example.com>')
incoming_message.raw_email.data = data
incoming_message.raw_email.save!
end
end
factory :incoming_message_with_attachments do
# foi_attachments_count is declared as an ignored attribute and available in
# attributes on the factory, as well as the callback via the evaluator
ignore do
foi_attachments_count 2
end
# the after(:create) yields two values; the incoming_message instance itself and the
# evaluator, which stores all values from the factory, including ignored
# attributes;
after_create do |incoming_message, evaluator|
evaluator.foi_attachments_count.times do |count|
FactoryGirl.create(:pdf_attachment,
:incoming_message => incoming_message,
:url_part_number => count+2)
end
end
end
end
factory :raw_email
factory :outgoing_message do
factory :initial_request do
ignore do
status 'ready'
message_type 'initial_request'
body 'Some information please'
what_doing 'normal_sort'
end
initialize_with { OutgoingMessage.new({ :status => status,
:message_type => message_type,
:body => body,
:what_doing => what_doing }) }
after_create do |outgoing_message|
outgoing_message.send_message
end
end
end
factory :info_request do
title "Example Title"
public_body
user
after_create do |info_request, evaluator|
FactoryGirl.create(:initial_request, :info_request => info_request)
end
factory :info_request_with_incoming do
after_create do |info_request, evaluator|
incoming_message = FactoryGirl.create(:incoming_message, :info_request => info_request)
info_request.log_event("response", {:incoming_message_id => incoming_message.id})
end
end
factory :info_request_with_plain_incoming do
after_create do |info_request, evaluator|
incoming_message = FactoryGirl.create(:plain_incoming_message, :info_request => info_request)
info_request.log_event("response", {:incoming_message_id => incoming_message.id})
end
end
factory :info_request_with_incoming_attachments do
after_create do |info_request, evaluator|
incoming_message = FactoryGirl.create(:incoming_message_with_attachments, :info_request => info_request)
info_request.log_event("response", {:incoming_message_id => incoming_message.id})
end
end
factory :external_request do
user nil
external_user_name 'External User'
external_url 'http://www.example.org/request/external'
end
end
factory :user do
name 'Example User'
email
salt "-6116981980.392287733335677"
hashed_password '6b7cd45a5f35fd83febc0452a799530398bfb6e8' # jonespassword
email_confirmed true
ban_text ""
factory :admin_user do
name 'Admin User'
admin_level 'super'
end
end
factory :public_body do
name
short_name
request_email 'request@example.com'
last_edit_editor "admin user"
last_edit_comment "Making an edit"
end
factory :track_thing do
association :tracking_user, :factory => :user
factory :search_track do
track_medium 'email_daily'
track_type 'search_query'
track_query 'Example Query'
end
factory :user_track do
association :tracked_user, :factory => :user
track_type 'user_updates'
end
factory :public_body_track do
association :public_body, :factory => :public_body
track_type 'public_body_updates'
end
factory :request_update_track do
association :info_request, :factory => :info_request
track_type 'request_updates'
end
factory :successful_request_track do
track_type 'all_successful_requests'
end
factory :new_request_track do
track_type 'all_new_requests'
end
end
factory :public_body_change_request do
user
source_url 'http://www.example.com'
notes 'Please'
public_body_email 'new@example.com'
factory :add_body_request do
public_body_name 'A New Body'
end
factory :update_body_request do
public_body
end
end
factory :info_request_batch do
title "Example title"
user
body "Some text"
end
end
|