Testing a mailer attachment from a carrierwave uploaderSending email with attachment using Rails 4 and Carrierwaverspec showing error messageNoExistingObject exception when using Sequel::Model.plugin timestamps and touchActiveJob cannot schedule jobs in the future, although Sidekiq is set as queue adapterrspec error michael hartl lesson 3sensu mailer handler using mail gem rubyRails server quits right when it startsrails generate devise:install error 1Gitlab CE not sending emailRuby on Rails with React getting NoMethodErrorRails: ForbiddenAttributesError for dynamic simple form

The Planck constant for mathematicians

I asked for a graduate student position from a professor. He replied "welcome". What does that mean?

Has SHA256 been broken by Treadwell Stanton DuPont?

Can I disable a battery powered device by reversing half of its batteries?

Resume: How to quantify my contributions as a software engineer?

Are there any non-WEB re-implementation of TeX Core in recent years?

Do all humans have an identical nucleotide sequence for certain proteins, e.g haemoglobin?

What was the relationship between Einstein and Minkowski?

Maintenance tips to prolong engine lifespan for short trips

Job offer without any details but asking me to withdraw other applications - is it normal?

How seriously should I take a CBP interview where I was told I have a red flag and could only stay for 30 days?

How can I discourage sharing internal API keys within a company?

Where does the expression "triple-A" come from?

Selecting 2 column in an Inner join

Napkin Folding Problem / Rumpled Ruble Problem

Why would "an mule" be used instead of "a mule"?

Relocation error, error code (127) after last updates

A shy person in a queue

Gas pipes - why does gas burn "outwards?"

Why is Kirchoff's loop rule true in a DC circuit?

How are chord ratios developed exactly?

Glue or not to glue boots

Does an oscilloscope subtract voltages as phasors?

Does my opponent need to prove his creature has morph?



Testing a mailer attachment from a carrierwave uploader


Sending email with attachment using Rails 4 and Carrierwaverspec showing error messageNoExistingObject exception when using Sequel::Model.plugin timestamps and touchActiveJob cannot schedule jobs in the future, although Sidekiq is set as queue adapterrspec error michael hartl lesson 3sensu mailer handler using mail gem rubyRails server quits right when it startsrails generate devise:install error 1Gitlab CE not sending emailRuby on Rails with React getting NoMethodErrorRails: ForbiddenAttributesError for dynamic simple form






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I do not understand how I can write a spec that would stub my model carrierwave uploader so I can actually test it in a mailer spec



class Message
mount_uploader :attachment, ::AttachmentUploader
end

class MessageMailer
def new_message(message
...
attachments[message.attachment.file.filename] = message.attachment.read
end
end


I have tried several stuff, it seems I cannot easily replace my mount_uploader with a stub using Rspec allow, so I resorted to actually sending a real file in there but then it seems in test mode carrierwave does not actually store the file, which results in a




undefined method length' for <CarrierWave::SanitizedFile:0x007fc89c0095d0>




This is coming from the mailer gem :



0: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2011:in `body_lazy'
1: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:1245:in `body='
2: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2124:in `init_with_hash'
3: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:135:in `initialize'
4: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/attachments_list.rb:83:in `new'
5: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/attachments_list.rb:83:in `[]='
[next line is my mailer code that adds the attachment]


Any help / guidelines on how to test mailers with carrierwave mount_uploader would be appreciated



shared_examples 'a mailer action that sends the message attachment' do
before do
attachment = File.new(file_fixture('avatar.png'))
message.attachment = attachment
message.save
end

it 'sends the message attachment' do
expect(mail.attachments.first.present?).to be
end
end









share|improve this question


























  • Found a solution there stackoverflow.com/a/43278547/2832282 to use attachment.read instead, which works, but I would actually prefer a solution where I could mock the file at all

    – Cyril Duchon-Doris
    Mar 28 at 10:07

















0















I do not understand how I can write a spec that would stub my model carrierwave uploader so I can actually test it in a mailer spec



class Message
mount_uploader :attachment, ::AttachmentUploader
end

class MessageMailer
def new_message(message
...
attachments[message.attachment.file.filename] = message.attachment.read
end
end


I have tried several stuff, it seems I cannot easily replace my mount_uploader with a stub using Rspec allow, so I resorted to actually sending a real file in there but then it seems in test mode carrierwave does not actually store the file, which results in a




undefined method length' for <CarrierWave::SanitizedFile:0x007fc89c0095d0>




This is coming from the mailer gem :



0: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2011:in `body_lazy'
1: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:1245:in `body='
2: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2124:in `init_with_hash'
3: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:135:in `initialize'
4: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/attachments_list.rb:83:in `new'
5: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/attachments_list.rb:83:in `[]='
[next line is my mailer code that adds the attachment]


Any help / guidelines on how to test mailers with carrierwave mount_uploader would be appreciated



shared_examples 'a mailer action that sends the message attachment' do
before do
attachment = File.new(file_fixture('avatar.png'))
message.attachment = attachment
message.save
end

it 'sends the message attachment' do
expect(mail.attachments.first.present?).to be
end
end









share|improve this question


























  • Found a solution there stackoverflow.com/a/43278547/2832282 to use attachment.read instead, which works, but I would actually prefer a solution where I could mock the file at all

    – Cyril Duchon-Doris
    Mar 28 at 10:07













0












0








0








I do not understand how I can write a spec that would stub my model carrierwave uploader so I can actually test it in a mailer spec



class Message
mount_uploader :attachment, ::AttachmentUploader
end

class MessageMailer
def new_message(message
...
attachments[message.attachment.file.filename] = message.attachment.read
end
end


I have tried several stuff, it seems I cannot easily replace my mount_uploader with a stub using Rspec allow, so I resorted to actually sending a real file in there but then it seems in test mode carrierwave does not actually store the file, which results in a




undefined method length' for <CarrierWave::SanitizedFile:0x007fc89c0095d0>




This is coming from the mailer gem :



0: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2011:in `body_lazy'
1: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:1245:in `body='
2: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2124:in `init_with_hash'
3: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:135:in `initialize'
4: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/attachments_list.rb:83:in `new'
5: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/attachments_list.rb:83:in `[]='
[next line is my mailer code that adds the attachment]


Any help / guidelines on how to test mailers with carrierwave mount_uploader would be appreciated



shared_examples 'a mailer action that sends the message attachment' do
before do
attachment = File.new(file_fixture('avatar.png'))
message.attachment = attachment
message.save
end

it 'sends the message attachment' do
expect(mail.attachments.first.present?).to be
end
end









share|improve this question
















I do not understand how I can write a spec that would stub my model carrierwave uploader so I can actually test it in a mailer spec



class Message
mount_uploader :attachment, ::AttachmentUploader
end

class MessageMailer
def new_message(message
...
attachments[message.attachment.file.filename] = message.attachment.read
end
end


I have tried several stuff, it seems I cannot easily replace my mount_uploader with a stub using Rspec allow, so I resorted to actually sending a real file in there but then it seems in test mode carrierwave does not actually store the file, which results in a




undefined method length' for <CarrierWave::SanitizedFile:0x007fc89c0095d0>




This is coming from the mailer gem :



0: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2011:in `body_lazy'
1: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:1245:in `body='
2: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2124:in `init_with_hash'
3: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:135:in `initialize'
4: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/attachments_list.rb:83:in `new'
5: /Users/Cyril/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mail-2.7.0/lib/mail/attachments_list.rb:83:in `[]='
[next line is my mailer code that adds the attachment]


Any help / guidelines on how to test mailers with carrierwave mount_uploader would be appreciated



shared_examples 'a mailer action that sends the message attachment' do
before do
attachment = File.new(file_fixture('avatar.png'))
message.attachment = attachment
message.save
end

it 'sends the message attachment' do
expect(mail.attachments.first.present?).to be
end
end






ruby-on-rails email rspec carrierwave email-attachments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 10:08







Cyril Duchon-Doris

















asked Mar 28 at 9:46









Cyril Duchon-DorisCyril Duchon-Doris

5,8454 gold badges27 silver badges78 bronze badges




5,8454 gold badges27 silver badges78 bronze badges















  • Found a solution there stackoverflow.com/a/43278547/2832282 to use attachment.read instead, which works, but I would actually prefer a solution where I could mock the file at all

    – Cyril Duchon-Doris
    Mar 28 at 10:07

















  • Found a solution there stackoverflow.com/a/43278547/2832282 to use attachment.read instead, which works, but I would actually prefer a solution where I could mock the file at all

    – Cyril Duchon-Doris
    Mar 28 at 10:07
















Found a solution there stackoverflow.com/a/43278547/2832282 to use attachment.read instead, which works, but I would actually prefer a solution where I could mock the file at all

– Cyril Duchon-Doris
Mar 28 at 10:07





Found a solution there stackoverflow.com/a/43278547/2832282 to use attachment.read instead, which works, but I would actually prefer a solution where I could mock the file at all

– Cyril Duchon-Doris
Mar 28 at 10:07












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394497%2ftesting-a-mailer-attachment-from-a-carrierwave-uploader%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394497%2ftesting-a-mailer-attachment-from-a-carrierwave-uploader%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현