ruby on rails - Devise.friendly_token returns an equal hash all the time -


i mixed trying understand happens here:
use devise.friendly_token in user factory.

factorygirl.define   factory :user     email "user@example.com"     password "secret"     authentication_token devise.friendly_token   end end 

in tests use factory follows:

require 'spec_helper'  describe sessionscontroller    before     @user = user.gen!     puts "token = #{@user.authentication_token}" # <--- debugging output   end    describe "#create"     context "when sending ..."       "renders json hash ..."         api_sign_in @user         expect(last_response.status).to eq(201)       end     end      context "when sending ..."       "renders json hash ..."         user = user.gen!(email: "invalid@email.com")         puts "token2 = #{user.authentication_token}" # <--- debugging output         api_sign_in user         expect(last_response.status).to eq(422)       end     end   end    describe "#destroy"     context "when sending ..."       "renders json hash ..."         api_sign_out @user         expect(last_response.status).to eq(200)       end     end   end  end 

the debugging output shows token same hash on every call. strange! when test devise.friendly_token in console generates random hash on every execution. that's expect looking @ implementation.

i guess there major design problem ... please me out.

this line:

authentication_token devise.friendly_token 

will call devise.friendly_token once when factory initialized. want

authentication_token { devise.friendly_token } 

which evaluate block every time object created factorygirl.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -