Forum: RSpec Problem with RSpec, Rails or Me? (I know the answer is me!!)

Posted by Ants Pants (Guest)
on 2011-12-19 18:26
(Received via mailing list)
This could just be my lack of knowledge of how Rails works but from the
following code in my RSpec test ....

$stderr.puts "BEFORE:
#{@invitation.meeting.event.event_type.event_type_time_units.inspect}"

@invitation.save!

EventTypeTimeUnit.all.each {|rec| $stderr.puts rec.inspect }

$stderr.puts "AFTER REC INSPECT
#{@invitation.meeting.event.event_type.inspect}"
$stderr.puts "AFTER LIST INSPECT
 #{@invitation.meeting.event.event_type.event_type_time_units.inspect}"

................ I get the following output. The thing that is not 
right,
is that there is no data for the association event_type_time_units. The
data is in the DB, the ids, foreign keys are correct but I just can't 
get
the data from the association.

BEFORE: [#<EventTypeTimeUnit id: 1, event_type_id: 1, time_unit_id: 
1,...>,
#<EventTypeTimeUnit id: 2, event_type_id: 1, time_unit_id: 2, ...>,
#<EventTypeTimeUnit id: 3, event_type_id: 1, time_unit_id: 3, ...>]

#<EventTypeTimeUnit id: 1, event_type_id: 1, time_unit_id: 1, ...>
#<EventTypeTimeUnit id: 2, event_type_id: 1, time_unit_id: 2, ...>
#<EventTypeTimeUnit id: 3, event_type_id: 1, time_unit_id: 3, ...>

AFTER REC INSPECT   #<EventType id: 1, event_category_id: 1, ...>

AFTER LIST INSPECT []

Can someone please put me out of my ignorant misery, please.

Thank you.

-ants
Posted by Pat Maddox (Guest)
on 2011-12-19 20:48
(Received via mailing list)
On Dec 19, 2011, at 11:00 AM, Ants Pants wrote:

> This could just be my lack of knowledge of how Rails works but from the 
following code in my RSpec test ....
>
> $stderr.puts "BEFORE: 
#{@invitation.meeting.event.event_type.event_type_time_units.inspect}"

Can you please share your RSpec code that doesn't do what you expect it 
to?

Pat
Posted by Ants Pants (Guest)
on 2011-12-19 22:09
(Received via mailing list)
On 19 December 2011 20:45, Pat Maddox <patmaddox@me.com> wrote:

> Pat
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>

I've added the necessary code. I've shown that before the save! the
event_type.event_type_time_units association returns data (from a 
Factory
build). After the save!, EventTypeTimeUnit.all shows that the data is in
the DB and all keys look okay, I've then whacked in two puts; the first
showing that event_type returns the correct id; and the second puts 
returns
an empty list.

This is simply in an it block with nothing special going on. The code is 
in
the order as it's in the block. Nothing going on in between.

It's not an RSpec problem (I don't think) It's just running in that
environment.

Thanks for taking an interest but to be honest, dont waste any time on 
it,
I'll sort it out. But to me, it's a strange one!!

-ants
Posted by Ants Pants (Guest)
on 2011-12-20 11:25
(Received via mailing list)
On 19 December 2011 21:32, Ants Pants <antsmailinglist@gmail.com> wrote:

>> #{@invitation.meeting.event.event_type.event_type_time_units.inspect}"
>
> It's not an RSpec problem (I don't think) It's just running in that
> environment.
>
> Thanks for taking an interest but to be honest, dont waste any time on it,
> I'll sort it out. But to me, it's a strange one!!
>
> -ants
>
>
>
In the end, I just used #reload to reload the attributes from the DB and 
it
works. Should I have to do this, I don't know, but my test is now 
passing.

-ants
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.