public
Description: Some [hopefully] useful extensions to Ruby’s String class. It is made up of three libraries: ActsAsUrl [permalink solution with better character translation], Unidecoder [Unicode to Ascii transliteration], and StringExtensions [miscellaneous helper methods for the String class].
Clone URL: git://github.com/rsl/stringex.git
Search Repo:
added initialize_urls class method
rsl (author)
Tue May 27 06:04:30 -0700 2008
commit  2510128bfc11041cd0847ac1b9510d193433291f
tree    c3314016395c5eb61dfb9aac871cb429496c5140
parent  6763179313c427b6bf390278f0d859187ba91eaf
...
34
35
36
 
 
 
 
 
 
 
 
 
 
37
38
39
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
0
@@ -34,6 +34,16 @@ module LuckySneaks
0
         self.scope_for_url = options[:scope]
0
         self.url_attribute = options[:url_attribute] || "url"
0
       end
0
+
0
+ # Initialize the url fields for the records that need it. Designed for people who add
0
+ # <tt>acts_as_url</tt> support once there's already development/production data they'd
0
+ # like to keep around.
0
+ def initialize_urls
0
+ find(:all, :conditions => {:url => nil}).each do |instance|
0
+ instance.send :ensure_unique_url
0
+ instance.save
0
+ end
0
+ end
0
     end
0
       
0
   private
...
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
0
@@ -92,4 +92,18 @@ class ActsAsUrlTest < Test::Unit::TestCase
0
     @moc.update_attributes :title => "New and Improved"
0
     assert_not_equal @original_url, @moc.url
0
   end
0
+
0
+ def test_should_mass_initialize_urls
0
+ @doc_1 = Document.create!(:title => "Initial")
0
+ @doc_2 = Document.create!(:title => "Subsequent")
0
+ @doc_1.update_attribute :url, nil
0
+ @doc_2.update_attribute :url, nil
0
+ assert_nil @doc_1.url
0
+ assert_nil @doc_2.url
0
+ Document.initialize_urls
0
+ @doc_1.reload
0
+ @doc_2.reload
0
+ assert_equal "initial", @doc_1.url
0
+ assert_equal "subsequent", @doc_2.url
0
+ end
0
 end

Comments

    No one has commented yet.