/ Published in: Ruby
                    
                                        
A fairly DRY way to test for required attributes of a model. It's sort of an alternative to fixtures. It breaks the one-assertion-per-test rule that some people favor. Drop in your unit test and edit as necessary.
A better (yet not quite perfect) approach:
http://johnwilger.com/articles/2005/12/07/a-bit-of-dryness-for-unit-tests-in-rails
                A better (yet not quite perfect) approach:
http://johnwilger.com/articles/2005/12/07/a-bit-of-dryness-for-unit-tests-in-rails
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
def test_required_attributes
required_atts = [:first_name, :last_name, :credentials, :title1,
:department, :organization, :street, :city, :state, :zip,
:phone, :email]
required_atts.each do |att|
r = create_registrant(att => nil)
assert r.errors.on(att)
end
end
private
def create_registrant(options = {})
Registrant.create({:meeting_id => 1,
:first_name => \"John\",
:middle_name => \"Q\",
:last_name => \"Doe\",
:credentials => \"PhD\",
:title1 => \"Doc\",
:title2 => \"\",
:title3 => \"\",
:department => \"Cardiology\",
:organization => \"DUHS\",
:street => \"12 Erwin Road\",
:city => \"Durham\",
:state => \"NC\",
:zip => \"27707\",
:phone => \"919-490-1000\",
:fax => \"919-490-1001\",
:email => \"[email protected]\"}.merge(options))
end
Comments
 Subscribe to comments
                    Subscribe to comments
                
                