On Mon, Dec 22, 2008 at 8:09 PM, Sarah Allen <li...@ruby-forum.com> wrote:
> I realize this is off-topic for the RSpec forum and cucumber tutorial, > but I'm hoping you'll enlighten me on this point which is, I guess, more > of a Ruby language question... > > Aslak Hellesøy wrote: > >> As you can see from my series of blog posts, I'm > >> new to Ruby and Rails. I thought that ending a method with ! was a > >> naming convention. Reading the humble ruby book it says "Another > >> convention to follow is that if the method modifies its receiver in > >> place (i.e. the method modifies the object that called it), then it > >> should end in an exclamation point" and the Rails doc show examples of > >> create without ! > >> http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001969 but > if > >> I make the change you suggest the test passes. I've updated the > >> tutorial and my code, but I'm confused. > >> > > > > The #create! method is documented here: > > > http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001902 > > > > Essentially, #create will never raise an error no matter what you pass > > it, > > and you actually want exceptions for bad input in your tests (step > > definitions). > > Therefore - use #create! (or #save!). In your app, use the non-bang > > methods. > > My Task model is simply defined (by the generate scaffold script) as: > class Task < ActiveRecord::Base > end > > How is it that I can call Task.create! which is a method of > ActiveRecord::Validations ? > Because ActiveRecord::Base includes the ActiveRecord::Validations module. It's not clear from the RDoc though... >From active_record.rb: ActiveRecord::Base.class_eval do extend ActiveRecord::QueryCache include ActiveRecord::Validations include ActiveRecord::Locking::Optimistic include ActiveRecord::Locking::Pessimistic ...lots more Aslak > Thanks in advance, > Sarah > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users