Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create activerecord style validations outside of activerecord?
    primarykey
    data
    text
    <p>I am working on a testing framework for the software that my company writes. Our product is web based and After I run a RESTful request I want to process the results. I want to be able to have activerecord type validations in each command class so that after it is run the results are automatically tested against all the "validations". However, I am not sure how to do this. My code looks like this (simplified to show the important parts).</p> <pre><code>class CodesecureCommand def execute result = RestClient.post("http://#{codesecure.host_name_port}#{path}", post_data) return parse(result) #parse simple returns a Hpricot document end end class RunScan &lt; CodesecureCommand #What I have now #I have to override the execute function so that it calls the local success method #to see if it failed or not. def execute() result = super() if success(result) return true else end end def success(result) result.search('div.transaction-message') do |message| if message.innerHTML.scan(/Configure abuse setting for domain users successfully\./).length == 1 return true end end end #What I would like is to be able to call execute (without having to override it). #then after it runs it calls back to this class to check #if the regex matches the command was successful and returns true test_success /regex/ #if test_success fails then these are called #the idea being that I can use the regex to identify errors that happened then #report them to the user identify_error /regex/, "message" identify_error /regex/, "message" end end </code></pre> <p>What I want is that after the execute method is called the test_success and identify_error are automatically called like the validations in activerecord. Can anybody tell me how to do this? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload