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

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

On Dec 19, 2011, at 11:00 AM, Ants P. 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

On 19 December 2011 20:45, Pat M. [email protected] wrote:

Pat


rspec-users mailing list
[email protected]
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

On 19 December 2011 21:32, Ants P. [email protected] 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