github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

nakajima / acts_as_fu

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 55
    • 5
  • Source
  • Commits
  • Network (5)
  • Issues (2)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

When you need a dash of ActiveRecord and nothing more — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

remove method_missing before aliasing it, to avoid 'warning: discarding 
old method_missing' messages (when running ruby with warnings) 
flavorjones (author)
Mon Sep 28 22:47:48 -0700 2009
commit  a7736250f7e35363ffc47401da9d05d358516470
tree    3f5b9902c85789b466d6643d954610d5bcff11c1
parent  b85c0dafc32f9a1f3cc7c65ffb7dbad1af3fab39
acts_as_fu /
name age
history
message
file .gemified Sat Oct 25 22:24:32 -0700 2008 upped version [nakajima]
file LICENSE Thu Oct 23 17:42:38 -0700 2008 added mit license [nakajima]
file README.md Wed Mar 11 08:10:10 -0700 2009 Updated README [nakajima]
file acts_as_fu.gemspec Thu Jul 09 13:28:14 -0700 2009 Bumped version [nakajima]
directory lib/ Mon Sep 28 22:47:48 -0700 2009 remove method_missing before aliasing it, to av... [flavorjones]
directory spec/ Wed Jul 08 15:45:06 -0700 2009 failing spec for nested classes [flavorjones]
README.md

ACTS-AS-FU

Now you have no excuse for not test-driving your ActiveRecord extending plugins.

Usage

In your spec_helper.rb (pretty sure this works with Test::Unit too, I'll leave you to figure it out though)

require 'rubygems'
require 'acts_as_fu'
require 'spec'

Spec::Runner.configure do |config|
  config.include ActsAsFu
end

Then in your specs:

describe "acts_as_gilmore_girls" do
  before(:each) do
    build_model :nerds do
      text :omg_omg_bio
      string :name
      string :favorite_scene

      validates_presence_of :favorite_scene

      def awesome?(show_name)
        show_name == "Gilmore Girls"
      end      
    end
  end

  it "should require favorite scene" do
    nerd = Nerd.new :favorite_scene => nil
    nerd.should_not be_valid
    nerd.errors.on(:favorite_scene).should_not be_nil
  end

  it "should think gilmore girls is awesome"
    nerd = Nerd.new
    nerd.awesome?("Gilmore Girls").should be_true
  end

  it "has other stuff" do
    # ETC!
  end
end

The build_model method allows you to build an ActiveRecord model on the fly. It takes a block where you can specify columns and methods.

Single Table Inheritance

If you want to create a model that's a subclass of another, you can use the :superclass option:

build_model(:assets) do
  string :type
  string :name
  named_scope :pictures, :conditions => { :type => "Picture" }
end

build_model(:pictures, :superclass => Asset)

The Picture model will then be a subclass of the Asset model.

Custom database configuration

If the in-memory sqlite3 database doesn't suit your needs, you can specify an alternative configuration with the ActsAsFu.connect! method:

ActsAsFu.connect! \
  :adapter => 'mysql',
  :database => 'some-db',
  :username => 'some-user',
  :password => 'some-password',
  :socket => '/path/to/mysql.sock'

Install

$ gem install nakajima-acts_as_fu --source=http://gems.github.com

TODO

Provide the ability to create multiple connections (thanks to Pivotal for the idea):

ActsAsFu.connections[:sqlite3] # or something

(c) Copyright 2008-2009 Pat Nakajima. All Rights Reserved.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server