Testing a signup confirmation with Rspec/Factory Girl/Rails -


trying create rspec/factory girl test make sure devise's confirmation on signup covered - site has 3 languages (japanese, english, chinese) want make sure nothing breaks signup process.

i have following factories: user.rb << has needed general user mailer tests signup.rb has:

factorygirl.define   factory :signup     token "fwoefurklj102939"     email "abcd@ek12o9d.com"   end end 

the devise user_mailer method want test is:

def confirmation_instructions(user, token, opts={})   @user = user   set_language_user_only   mail to: @user.email,        charset: (@user.language == user::language_ja ? 'iso-2022-jp' : 'utf8') end 

i cannot life of me figure out how token part work in test - advice or ideas?

i have been trying along these lines (to check email being sent) without success:

describe usermailer, type: :mailer    describe "sending email"     after(:all) { actionmailer::base.deliveries.clear }      context "japanese user emails"       subject(:signup) { create(:signup) }       subject(:user) { create(:user) }        subject(:mail)         usermailer.confirmation_instructions(user, token, opts={})       end        "sends email successfully"         expect { mail.deliver }.to change { actionmailer::base.deliveries.size }.by(1)       end     end   end end 

the resulting error undefined local variable or methodtoken'and cannot work out why not coming thesignup` factory. tried changing

subject(:mail)   usermailer.confirmation_instructions(user, token, opts={}) end 

to

subject(:mail)   usermailer.confirmation_instructions(user, signup.token, opts={}) end 

but received error:

failure/error: subject(:signup) { create(:signup) }       nameerror:        uninitialized constant signup 

edit: forgot mention important - actual code works user signups in 3 languages, inexperience testing @ fault.

subject(:mail)   usermailer.confirmation_instructions(user, user.confirmation_token) end 

this varies of course depending on exact implementation user class should generating token:

require 'secure_random'  class user   before_create :generate_confirmation_token!    def generate_confirmation_token!     confirmation_token = securerandom.urlsafe_base64   end end 

creating separate factory unnecessary , won't work since factorygirl try create instance of signup i'm guessing don't have.

factories not fixtures.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -