On Monday, March 25, 2013 1:56:23 PM UTC+1, [email protected] wrote:
>
> That should have been "there is _no_ `activities_attributes` method to 
> begin with". 
>
> On Mon, Mar 25, 2013 at 7:55 AM, [email protected] <javascript:> 
> <[email protected] <javascript:>> wrote: 
> > Another shot in the dark: 
> > 
> > My guess is that there is `activities_attributes` method to begin with 
> and 
> > Rails generates it for you the first time it is called. By setting 
> > timesheet.activities_attributes = {}, you're assigning a value to a 
> > previously non-existent variable that is not used internally in 
> validations. 
> > 
> > Part of the problem here, IMO, is an overuse of "reuse". You're creating 
> a 
> > valid instance and then changing its state in order to make it invalid. 
> I 
> > think it would be easier to understand if you created an invalid 
> instance, 
> > e.g. 
> > 
>
OK, I got it, - the below is the spec for building a new Timesheet with no 
activity selected/set up for a new Timesheet:

> > describe Timesheet do 
> >   it "is invalid when any of its activities has no tasks" do 
> >     timesheet = Timesheet.new 
> >     timesheet.activities << Activity.new 
> >     expect(timesheet).not_to be_valid 
> >   end 
> > end 
> > 
>
I tested that and it worked either with defining it directly in the spec or 
creating just a separate factory with no activity task.
Now I see the difference with my another spec where I just set to nil all 
the created activities in the timesheet factory:

describe "when no activities present" do
    before  do
      @timesheet.activities.each { |activity| activity.task = nil }      
    end
    it { should_not be_valid }
  end

Thank you all for the time and help.

Best regards

> The second situation is when 'emptying' all the 
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rspec/-/LsiZjEzkTCYJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to