Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Standup 01/12/2009: require & class reloading, acts_as_fu

Abhijit Hiremagalur
Monday, January 12, 2009

Interesting Things

  • Using ‘require’ explicitly interferes with class reloading in Rails

Frederick Cheung discusses this in more detail here. This might be related to the Selenium + class reloading issues some pivots have experienced in recent weeks. The alternative is to rely on Rails automagic loading or ‘require_dependency’.

  • acts_as_fu makes writing database independent tests for models is easier

Props to pivot Pat Nakajima for creating acts_as_fu.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

6 Comments

  1. Pat Nakajima says:

    Hey, glad you like acts_as_fu. Just so you know, it’s not actually database independent. It sets up a sqlite3 database under the covers that requires no configuration. It also allows you to manually specify a different database configuration if you need one.

    January 13, 2009 at 6:03 am

  2. grosser says:

    Setting up such a database by hand is not very problematic, and it keeps your code “real”, so any other developer can understand it without needing to dig into acts_as_fu (which is a very descriptive name btw)

    What i would like in a gem is something simpler: setup_ar_memory_db()
    the rest(migration+class) i would rather do by hand.

    def setup_ar_memory_db
      require 'active_record'
      ActiveRecord::Base.configurations = {"test" => {
        :adapter => "sqlite3",
        :database => ":memory:",
      }.with_indifferent_access}
    
      ActiveRecord::Base.logger = Logger.new("/dev/null")
      ActiveRecord::Base.establish_connection(:test)
    end
    
    setup_ar_memory_db
    
    ActiveRecord::Schema.define(:version => 1) do
      create_table "feeds" do |t|
        t.string "feed_url"
        t.timestamp "feed_updated_at"
        t.text "feed_data"
        t.timestamps
      end
    end
    
    
    class Feed < ActiveRecord::Base
      acts_as_feed
    end
    

    January 13, 2009 at 8:55 am

  3. grosser says:

    ok done: http://github.com/grosser/testing_database

    sudo gem install grosser-testing_database
    
    require 'testing_database'
    TestingDatabase.setup
    ActiveRecord::Schema.define(:version => 1) do
      create_table :users do |t|
        t.string :name
      end
    end
    class User < ActiveRecord::Base
    end
    User.create!(:name=>'EZ')
    

    January 13, 2009 at 9:20 am

  4. Pat Nakajima says:

    Hey grosser,

    You’re right, it’s definitely easy to set this stuff up manually, but after doing it enough times, I wanted a way to only setup the things I care about, and not worry about anything else. That leaves us with this:

    build_model(:users) do
    string :name
    end

    Also, `acts_as_fu` automatically sets and unsets the class constant, meaning you have a pristine version of your ActiveRecord class every time you call `build_model`. That’s pretty nice to have when you’re manipulating the class in your tests.

    It’s certainly concise at the risk of being ambiguous, but it’s worked quite well for me in a wide variety of circumstances.

    Finally, about the name: Many ActiveRecord plugins have names like “acts_as” or “-fu”, and my project is aimed at making those plugins easier to test. Therefore, it can increase your “acts_as”-fu, or if you prefer, it can act as “fu”.

    Also, I just can’t resist a smarmy project name.

    January 13, 2009 at 6:45 pm

  5. grosser says:

    – automatically sets and unsets the class constant
    sounds good!

    how about a public method in acts_as_fu that does “setup_ar_memory_db” so everybody can be happy.

    –> new project name: instant_database :D

    January 15, 2009 at 9:06 am

  6. grosser says:

    oh, that would be ActsAsFu.connect! silly me, did not read the docs :)
    ill give it a try then!

    January 15, 2009 at 9:09 am

Add New Comment Cancel reply

Your email address will not be published.

Abhijit Hiremagalur

Abhijit Hiremagalur
San Francisco

Recent Posts

  • Hash#fetch with confidence
  • Standup 08/05/2010: ‘bundle check’ and Websockets
  • Standup 08/04/2010: Accounting on Rails anybody?
Subscribe to Abhijit's Feed

Author Topics

ruby (3)
bundler (1)
websockets (1)
cucumber (1)
javascript (1)
json (1)
rails (2)
rails3 (1)
rubymine (2)
testing (2)
ey (1)
facebook (1)
imagemagick (1)
jasmine (2)
thor (1)
agile (3)
ajax (1)
css (1)
design (1)
iconv (1)
jquery (1)
utf-8 (2)
character encoding (1)
unicode (1)
acts_as_fu (1)
selenium (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >