Camping on IRB

December 22, 2008 by pedro mota

IRB is a great tool.

What about testing parts of a Camping app in IRB (meaning App::Models module) ? Just require the app, but do not forget to establish the (in case of using it) ActiveRecord connection, that problably is specified in dispatch.rb

Try this, using _Why’s Blog webapp example:

$ cd /path/to/blog/app\n$ irb irb(main):001:0> require 'rubygems' irb(main):002:0> require 'blog' irb(main):003:0> Camping::Models::Base.establish_connection :adapter => 'postgresql', :host => 'trees', :port => 54321, :database => 'beautifull', :username => 'green', :password => 'forest' irb(main):004:0> Blog::Models::Post.find(1)

Answers from lines: * 3 => #< ActiveRecord::Base::ConnectionSpecification:0xb77499a8 @adapter_method=\“postgresql_connection\”, @config={:host=>\“trees\”, :password=>\“forest\”, :port=>54321, :database=>\“beautifull\”, :adapter=>\“postgresql\”, :username=>\“green\”}> * 4 => #< Blog::Models::Post:0xb7736e5c @attributes={\“body\”=>\”… this is the first post on Why’s blog web app for testing Camping functionalities. Its cool. It’s Ruby. Its Lighttpd. Its Postgres (well, at least in my implementation) via Active Record. Camping™ of WhyTheLuckyStiff\”, \“title\”=>\“camping is fine\”, \“id\”=>\“1\”, \“user_id\”=>\“1\”}> is the first row from postgres ‘beautifull’ database ‘blog_posts’ table. Fetched via ActiveRecord, via Blog::Models module, via Blog Camping app

© 2018 | Follow on Twitter | pedro mg & Hugo