GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Random Rails stuff that I've cribbed from other places and improved upon, mostly to bootstrap a new Rails project quickly
Clone URL: git://github.com/willcodeforfoo/foo_tools.git
Some comments on the to_named_fixture option
Tue Mar 18 08:17:51 -0700 2008
commit  0b160afa292eabb283504a6fade152979ca72f44
tree    427804cf08545d1b1641221a2c4573d7220f2578
parent  bac8aaa3fc3ffdbdcdbbae620ffb50e7af7d2f18
...
45
46
47
48
 
 
 
 
 
49
50
51
...
53
54
55
56
 
57
58
59
...
45
46
47
 
48
49
50
51
52
53
54
55
...
57
58
59
 
60
61
62
63
0
@@ -45,7 +45,11 @@ class ActiveRecord::Base
0
     # Write a file that can be loaded with +fixture :some_table+ in tests.
0
     # Uses existing data in the database.
0
     #
0
- # Will be written to +test/fixtures/table_name.yml+. Can be restricted to some number of rows.
0
+ # Will be written to +test/fixtures/table_name.yml+. Can be restricted to
0
+ # some number of rows.
0
+ #
0
+ # If a method named +to_named_fixture+ is available for the models, the
0
+ # fixtures will be named with the result of that method.
0
     def to_fixture(limit=nil)
0
       opts = {}
0
       opts[:limit] = limit if limit
0
@@ -53,7 +57,7 @@ class ActiveRecord::Base
0
       write_file(File.expand_path("test/fixtures/#{table_name}.yml", RAILS_ROOT),
0
           self.find(:all, opts).inject({}) { |hsh, record|
0
               fixture_name = if record.respond_to?(:to_named_fixture)
0
- record.to_named_fixture
0
+ record.to_named_fixture.to_s
0
               else
0
                 "#{table_name.singularize}_#{'%05i' % record.id rescue record.id}"
0
               end

Comments

    No one has commented yet.