ruby - Rails test password reset failure --- expected +++ actual @@ -1 +1,40 @@ -


i'm new ruby on rails. have failing password_reset_test ( hartls' ruby on rails tutorial 10.48).to date have:

1) compared code source code in github

2) read documentation mini-test reporters here: http://docs.seattlerb.org/minitest/minitest/assertions.html

3) compared problem similar issues found here on stackoverflow: password reset test failing in m.hartl's ruby on rails tutorial (3rd edition), chapter 10 (10.54)

4) inserted byebug see if understand it's going wrong

here failed test

 fail["test_password_reset", usermailertest, 2015-09-12      04:04:59 +0000]  test_password_reset#usermailertest (1442030699.96s)      --- expected     +++ actual     @@ -1 +1,40 @@     -"michael%40example.com"     +"\r     +----==_mimepart_560b45e51fccd_2eb1adb3302011d\r     +content-type: text/plain;\r     + charset=utf-8\r     +content-transfer-encoding: 7bit\     +\r     +\r     +\r     +to reset password click on link below:\r     +\r     +http://example.com/password_resets/wad2d-u4_dqlm4kdlhzrwa/edit?email=michael%40example.com\r     +\r     +this link expire in 2 hours.\r     +\r     +if did not request password reset, please ignore email , password stay is.\r     +\r     +----==_mimepart_560b45e51fccd_2eb1adb3302011d\r     +content-type: text/html;\r     + charset=utf-8\r     +content-transfer-encoding: 7bit\r     +\r             +<a href=\"http://example.com/password_resets/wad2d-u4_dqlm4kdlhzrwa/edit?email=michael%40example.com\">reset password</a>\r     +\r     +</p>this link expire in 2 hours.</p>\r     +\r     +<p>\r     +  if did not request password reset, please ignore email , password stay is.\r     +</p>\r     +\r     +  </body>\r     +</html>\r     +\r     +----==_mimepart_560b45e51fccd_2eb1adb3302011d--\r     +"     test/mailers/user_mailer_test.rb:24:in `block in <class:usermailertest>' 

here user_mailer_test.rb:

class usermailertest < actionmailer::testcase    test "password_reset"     user = users(:michael)     user.reset_token = user.new_token     mail = usermailer.password_reset(user)     assert_equal "password reset", mail.subject     assert_equal [user.email], mail.to     assert_equal ["noreply@example.com"], mail.from     assert_match user.reset_token,        mail.body.encoded     assert_equal cgi::escape(user.email), mail.body.encoded   end 

here user_mailer.rb

class usermailer < applicationmailer   def password_reset(user)     @user = user     mail to: user.email, subject: "password reset"   end 

and models/user.rb

    # sets password reset attributes     def create_reset_digest        self.reset_token = user.new_token        update_attribute(:reset_digest, user.digest(reset_token))        update_attribute(:reset_sent_at, time.zone.now)     end      # sends password reset email.     def send_password_reset_email         usermailer.password_reset(self).deliver_now     end 

up point i've been find out error messages mean. in advance , noobie appreciates time , help!

the last line of password_reset test should be

assert_match cgi::escape(user.email), mail.body.encoded 

instead of assert_equal.

that line supposed looking email address in body, not checking see if email address equal entire body.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -