Re: [rspec-users] Problem with mocking a simple has_many relationship

2008-03-18 Thread Nikos Dimitrakopoulos
Ok, last one - for your interest validates_length_of can be used for this purpose. There is an open bug/patch on the rails trac regarding the :within parameter but the :minimum works fine for me. As for the example the method called on @item.images is #size and not #count so -> @item.images.sho

Re: [rspec-users] Problem with mocking a simple has_many relationship

2008-03-18 Thread Nikos Dimitrakopoulos
James Deville wrote: > Doh! I can't believe that I missed that. > > You can also use if self.images.size.zero? > > Just a little more readable. > > James Deville You were writing while i was writing :D nice one, i didn't know the #zero? - way more readable :) -- Posted via http://www.ruby-for

Re: [rspec-users] Problem with mocking a simple has_many relationship

2008-03-18 Thread Nikos Dimitrakopoulos
Ok, i'm really stupid... i was taking a break (i've been on the pc for several hours) and the problem came to me before reading your posts :D Obviously the "if self.images.count" was wyyy too stupid! added the necessary == 0 and everything is fine... Thanks a lot anyway :) -- Posted via htt

Re: [rspec-users] Problem with mocking a simple has_many relationship

2008-03-18 Thread James Deville
Doh! I can't believe that I missed that. You can also use if self.images.size.zero? Just a little more readable. James Deville On Mar 18, 2008, at 4:38 PM, Rafael Mueller wrote: Hi Nikos, On Tue, Mar 18, 2008 at 8:26 PM, Nikos Dimitrakopoulos <[EMAIL PROTECTED] > wrote: the model: class

Re: [rspec-users] Problem with mocking a simple has_many relationship

2008-03-18 Thread James Deville
On Mar 18, 2008, at 4:26 PM, Nikos Dimitrakopoulos wrote: > Hi there all. Sorry if the question sounds silly but i'm rather new at > the 'mocking' stuff... So here is my problem (code helps more than > talking): > > the model: > > class Item < ActiveRecord::Base > ... > has_many :images, :depend

Re: [rspec-users] Problem with mocking a simple has_many relationship

2008-03-18 Thread Rafael Mueller
Hi Nikos, On Tue, Mar 18, 2008 at 8:26 PM, Nikos Dimitrakopoulos <[EMAIL PROTECTED]> wrote: > > the model: > class Item < ActiveRecord::Base > has_many :images, :dependent => :destroy > protected > def validate > errors.add(:images, "cannot be empty") if self.images.count > end > end se

[rspec-users] Problem with mocking a simple has_many relationship

2008-03-18 Thread Nikos Dimitrakopoulos
Hi there all. Sorry if the question sounds silly but i'm rather new at the 'mocking' stuff... So here is my problem (code helps more than talking): the model: class Item < ActiveRecord::Base ... has_many :images, :dependent => :destroy ... protected def validate errors.add(:image