ruby on rails - friendly_id and rspec controller tests, finding the correct id -


I have a simple RSPEC controller test for basic crud functions. I recently added Friendly_id for my controller - now all tests are failing

  Describe "Patch Update" before the reference "Where the record is found" (Model) Allow. To obtain (.search) .and_return (example) Allow the end reference "where the record is a root" (for example) (example). ("Root"). And_Reiton (true) End before the end of the reference "where the record is updated" (example). To get (. Save) .and_return (true) Patch: Update, instance.slug Finally "flash notice should set" Flash [: Notice]. Answer: If you do not have Shield_net, answer it as "Redirect to the panel page". Redirect. (Direct_Corporate_page_path) and end end and end   

all of which fail with the following error,

  1) Administrator: Corporate PageAuthorized users Receive Administrator Edit for HTTP Success Failure / Error: Receive: Edit, Id: corporate_page nomethodError: # & lt; Category: 0x007f993a956b88 & gt; Undefined method for 'favorable' 2) Admin :: CorporatePagesController must set a flash notices where the record is found where the record is found, where the record is found to be a root failure / error: patch: update, Instance.slug ActionController :: UrlGenerationError: Match No Routes {: Action => "Update" ,: Admin = & gt; "Admin / corporate_pages"}   

This is the relevant controller,

  def update @corp_page @ path = (@ corp_page.root ?? Admin_corporate_pages_path: admin_corporate_page_path (@ Corp_page.root)) If @ corp_page.update_attributes (param [: corporate_page]) flash [: notice] = 'page update' redirect_to @ path and return and flash [: error] = 'an error occurred': new and Return End And Flash [: Error] = "Record Not Found" Redirect Finally- admin_corporate_pages_path and private def get_corp_page @corp_page = CorporatePage.friendly.find (params [: id])   

M Zhe do not see how could any difference in view as friendly ID: id function anywa y. How can this kind of difference in tests?

There are two things that you have to decide. Firstly, there is no Slug Attribute set in your installation, which results in error number 2 as well. This is also your call is wrong, it should be:

  Patch: update, id: instance.to_param # Let the model decide that   

The reason the column is using is:

  permission (model). To find (: search) .and_return (example)   

Change this:

  Allow (model). Receive_message_chain (: friendly, search) .and_return (example)    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -