Ants Pants
2011-Dec-19 17:00 UTC
[rspec-users] 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20111219/03e2655c/attachment.html>
Pat Maddox
2011-Dec-19 19:45 UTC
[rspec-users] Problem with RSpec, Rails or Me? (I know the answer is me!!)
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
Ants Pants
2011-Dec-19 20:32 UTC
[rspec-users] Problem with RSpec, Rails or Me? (I know the answer is me!!)
On 19 December 2011 20:45, Pat Maddox <patmaddox at me.com> wrote:> 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 > _______________________________________________ > rspec-users mailing list > rspec-users at 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20111219/99553462/attachment-0001.html>
Ants Pants
2011-Dec-20 10:07 UTC
[rspec-users] Problem with RSpec, Rails or Me? (I know the answer is me!!)
On 19 December 2011 21:32, Ants Pants <antsmailinglist at gmail.com> wrote:> > > On 19 December 2011 20:45, Pat Maddox <patmaddox at me.com> wrote: > >> 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 >> _______________________________________________ >> rspec-users mailing list >> rspec-users at 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 > > >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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20111220/35aa47a2/attachment.html>