I''ve heard about TDD, read about TDD, and now I''m trying to practice it. However, I''m getting stuck trying to do a simple test in rails 2.2.2. I''ve decided to try writing a simple functional test to test the ''add_item'' action of my cart controller. However, I got as far as this before my test was already not running: test "should add an item to the cart" do end My cart controller uses two ''fake'' models (cart_session, cart_session_line_item) that aren''t activerecords. however i''m getting this error message: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: cart_sessi on_line_items: DELETE FROM "cart_session_line_items" WHERE 1=1 for the life of me, I don''t understand why my test would be hitting the database yet when my test body is blank and why it thinks that cart_session_line_item is an activerecord when it''s not wired up as such. i know TDD is a good thing, and any help would be greatly appreciated! Thanks, Nelson -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 19, 2:11 pm, Nelson Hsu <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''ve heard about TDD, read about TDD, and now I''m trying to practice it. > However, I''m getting stuck trying to do a simple test in rails 2.2.2. > I''ve decided to try writing a simple functional test to test the > ''add_item'' action of my cart controller. > > However, I got as far as this before my test was already not running: > > test "should add an item to the cart" do > > end > > My cart controller uses two ''fake'' models (cart_session, > cart_session_line_item) that aren''t activerecords. however i''m getting > this error message: > > ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: > cart_sessi > on_line_items: DELETE FROM "cart_session_line_items" WHERE 1=1 > > for the life of me, I don''t understand why my test would be hitting the > database yet when my test body is blank and why it thinks that > cart_session_line_item is an activerecord when it''s not wired up as > such. >Are you sure your models are not inheriting from ActiveRecord::Base? Even if you''re not calling any methods on them yet, the sheer act of deriving from ActiveRecord::Base will necessitate the presence of those tables.> i know TDD is a good thing, and any help would be greatly appreciated! > > Thanks, > NelsonTDD is a good thing! Let''s see if we can''t get this working for you. Jeff purpleworkshops.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeff Cohen wrote:> > Are you sure your models are not inheriting from ActiveRecord::Base? > > Even if you''re not calling any methods on them yet, the sheer act of > deriving from ActiveRecord::Base will necessitate the presence of > those tables.Thanks for the response! I just double checked the two models and neither of them derive from ActiveRecord::Base. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nelson Hsu wrote:>> Are you sure your models are not inheriting from ActiveRecord::Base? >> >> Even if you''re not calling any methods on them yet, the sheer act of >> deriving from ActiveRecord::Base will necessitate the presence of >> those tables. > > Thanks for the response! I just double checked the two models and > neither of them derive from ActiveRecord::Base.Can you post the source to either class? Also note that inheritance is not equal to derivation. -- Roderick van Domburg http://www.nedforce.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roderick van Domburg wrote:> > Can you post the source to either class?cart_session.rb class CartSession attr :items attr_accessor :building attr_accessor :use_corporate_account end class CartSessionLineItem attr_accessor :sku, :quantity, :sku_id def initialize(sku_id, quantity) @sku_id = sku_id @sku = Sku.find(sku_id) @quantity = quantity end def total sku.skuable.price * quantity end end> Also note that inheritance is not equal to derivation. >OK, I have to admit, I feel dumb here. I always thought inheriting from a class was deriving from it. Is my terminology all messed up? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nelson Hsu wrote:> Thanks for the response! I just double checked the two models and > neither of them derive from ActiveRecord::Base.Use ''script/generate model my_model'' to generate models. They will come complete with empty unit tests, empty data fixtures, etc. Then, learn TDD using the "unit" tests, meaning the tests on the models - not the "functional" tests on the controllers! Anything your users can do to data thru the view and controllers, your unit tests should be able to do to the model objects thru their public methods. Only after you are proficient at the "unit" tests should you try more advanced and indirect testing! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nelson Hsu wrote:> cart_session.rb > > class CartSession > attr :items > attr_accessor :building > attr_accessor :use_corporate_account > end > > class CartSessionLineItem > attr_accessor :sku, :quantity, :sku_id > > def initialize(sku_id, quantity) > @sku_id = sku_id > @sku = Sku.find(sku_id) > @quantity = quantity > end > > def total > sku.skuable.price * quantity > end > > endThat looks right. Is there perhaps a fixture lingering around?>> Also note that inheritance is not equal to derivation. > > OK, I have to admit, I feel dumb here. I always thought inheriting from > a class was deriving from it. Is my terminology all messed up?I take that back and you are right. Must have had my head up in the clouds at that time of writing. :-) -- Roderick van Domburg http://www.nedforce.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tuesday 20 January 2009 03:50 am, Roderick van Domburg wrote:> I take that back and you are right. Must have had my head up in the > clouds at that time of writing. :-)Maybe me too--I''ve been watching this thread waiting for a clue as to what TDD is--my out of the blue guess is Top Down Design, but I''ll do better to ask...? Randy Kramer -- I didn''t have time to write a short letter, so I created a video instead.--with apologies to Cicero, et.al. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Randy Kramer wrote:> On Tuesday 20 January 2009 03:50 am, Roderick van Domburg wrote: >> I take that back and you are right. Must have had my head up in the >> clouds at that time of writing. :-) > > Maybe me too--I''ve been watching this thread waiting for a clue as to > what TDD is--my out of the blue guess is Top Down Design, but I''ll do > better to ask...? > > Randy Kramernot a bad guess, but try Test Driven Design/Development. http://en.wikipedia.org/wiki/Test-driven_development HTH Matt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tuesday 20 January 2009 08:19 am, Matt Harrison wrote:> not a bad guess, but try Test Driven Design/Development. > > http://en.wikipedia.org/wiki/Test-driven_development > > HTHMatt, Yes, thank you! Randy Kramer -- I didn''t have time to write a short letter, so I created a video instead.--with apologies to Cicero, et.al. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well, I figured it out, so I''m going to update my thread and hopefully help someone in the future. The problem was in test_helper.rb on this line: fixtures :all Anyways, thanks for everyone''s responses. And thanks to Phlip''s suggestion about starting out with unit tests. They were much easier to start with, and now I feel more comfortable with tests. Randy Kramer wrote:> On Tuesday 20 January 2009 08:19 am, Matt Harrison wrote: >> not a bad guess, but try Test Driven Design/Development. >> >> http://en.wikipedia.org/wiki/Test-driven_development >> >> HTH > > Matt, > > Yes, thank you! > > Randy Kramer > -- > I didn''t have time to write a short letter, so I created a video > instead.--with apologies to Cicero, et.al.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Oops... I forgot the actual fix. The fix was to comment out: fixtures :all -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---