Giter Club home page Giter Club logo

acts_as_fu's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.