Posts Tagged ‘testing’

Chrome’s Autofill and honeypot fields

Ai developers typically add a hidden “honeypot” field to forms to avoid spam bots. Spam bots usually fill out all of the fields on a form, including the honeypot field. When the honeypot field is filled out and the form is submitted, the form information is not captured.

While doing some cross-browser form testing for several sites I noticed that in the Chrome browser form information wasn’t always being captured.

Upon further investigation I learned that Chrome’s Autofill feature is causing this problem. Chrome’s Autofill fills out the honeypot field and makes the form think that it has been filled out by a spam bot. Since this may result in a significant amount of legitimate form submissions not reaching their intended target, it is important to test all forms with Chrome’s Autofill in mind. Developers need to provide a solution that successfully curbs malicious spam bots without preventing legitimate form submissions.

Technology

Tip: Reloading ActiveRecord Instances

When writing unit tests in Rails, I’ll often make a change to an ActiveRecord instance, requiring a reload for the next assertion to pass (oversimplified):

context "A new group" do
setup do
@group = Factory(:group)
end
context "with an added entry" do
setup do
@entry = Factory(:entry, :title => "WEB", :group => @group)
@group.reload
end
should "add an entry to the group"
assert @group.entries.include?(@entry)
end
end
end



Instead of calling #reload on all the affected objects, I’ve found it useful to include a simple helper method that, when called, reloads any in-scope ActiveRecord instances:

class Test::Unit::TestCase
private
def reload_activerecord_instances
self.instance_variables.each do |ivar|
if ivar.is_a?(ActiveRecord::Base) && ivar.respond_to?(:reload)
ivar.reload
end
end
end
end



This has proven especially helpful when I’m handling several ActiveRecord objects and need to update them all at once. Cleaner, less repetitive code.

Technology