Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 92 lines (65 sloc) 2.332 kB
bb5c42c @nakajima Updated README
authored
1 # ACTS-AS-FU
2
3 Now you have no excuse for not test-driving your ActiveRecord
4 extending plugins.
5
6 ### Usage
7
8 In your spec_helper.rb (pretty sure this works with `Test::Unit`
9 too, I'll leave you to figure it out though)
10
11 require 'rubygems'
12 require 'acts_as_fu'
13 require 'spec'
14
15 Spec::Runner.configure do |config|
16 config.include ActsAsFu
17 end
18
19 Then in your specs:
20
21 describe "acts_as_gilmore_girls" do
22 before(:each) do
23 build_model :nerds do
24 text :omg_omg_bio
25 string :name
26 string :favorite_scene
27
28 validates_presence_of :favorite_scene
29
30 def awesome?(show_name)
31 show_name == "Gilmore Girls"
32 end
33 end
34 end
35
36 it "should require favorite scene" do
37 nerd = Nerd.new :favorite_scene => nil
38 nerd.should_not be_valid
39 nerd.errors.on(:favorite_scene).should_not be_nil
40 end
41
42 it "should think gilmore girls is awesome"
43 nerd = Nerd.new
44 nerd.awesome?("Gilmore Girls").should be_true
45 end
46
47 it "has other stuff" do
48 # ETC!
49 end
50 end
51
52 The `build_model` method allows you to build an ActiveRecord model on
53 the fly. It takes a block where you can specify columns and methods.
54
55 #### Single Table Inheritance
56
57 If you want to create a model that's a subclass of another, you can
58 use the `:superclass` option:
59
60 build_model(:assets) do
61 string :type
62 string :name
63 named_scope :pictures, :conditions => { :type => "Picture" }
64 end
65
66 build_model(:pictures, :superclass => Asset)
67
68 The `Picture` model will then be a subclass of the `Asset` model.
69
70 #### Custom database configuration
71
72 If the in-memory sqlite3 database doesn't suit your needs, you can
73 specify an alternative configuration with the `ActsAsFu.connect!` method:
74
75 ActsAsFu.connect! \
76 :adapter => 'mysql',
77 :database => 'some-db',
78 :username => 'some-user',
79 :password => 'some-password',
80 :socket => '/path/to/mysql.sock'
81
82 ### Install
83
84 $ gem install nakajima-acts_as_fu --source=http://gems.github.com
85
86 TODO
87
88 Provide the ability to create **multiple** connections (thanks to Pivotal for the idea):
89
90 ActsAsFu.connections[:sqlite3] # or something
91
92 (c) Copyright 2008-2009 Pat Nakajima. All Rights Reserved.
Something went wrong with that request. Please try again.