diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-03-25 11:03:12 +0000 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-03-25 15:14:49 +0000 |
commit | 9fbca08732650407f697b7d76eee174968e15cdc (patch) | |
tree | 0c60cd57867c9b0d0793f09177a1704a2bb2f780 /spec/factories/incoming_messages.rb | |
parent | 7a108776e4f45b10ef5956326fdd9c66514d1ddd (diff) |
Split factories in to individual files
Factories are loaded automatically from:
- test/factories.rb
- spec/factories.rb
- test/factories/*.rb
- spec/factories/*.rb
Keeping factories per-model helps navigation, especially when they get
more complex with traits and inheritance.
Diffstat (limited to 'spec/factories/incoming_messages.rb')
-rw-r--r-- | spec/factories/incoming_messages.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/factories/incoming_messages.rb b/spec/factories/incoming_messages.rb new file mode 100644 index 000000000..38ad98394 --- /dev/null +++ b/spec/factories/incoming_messages.rb @@ -0,0 +1,46 @@ +FactoryGirl.define do + + 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 + +end |