Index: permalink_fu/test/permalink_fu_test.rb =================================================================== --- permalink_fu/test/permalink_fu_test.rb (revision 22) +++ permalink_fu/test/permalink_fu_test.rb (working copy) @@ -6,7 +6,7 @@ attr_accessor :title attr_accessor :permalink - def self.after_validation(&block) + def self.before_validation(&block) @@validation = block end @@ -18,6 +18,24 @@ has_permalink :title end +class MockModelExtra + extend PermalinkFu + attr_accessor :title + attr_accessor :extra + attr_accessor :permalink + + def self.before_validation(&block) + @@validation = block + end + + def validate + @@validation.call self + permalink + end + + has_permalink [:title, :extra] +end + class PermalinkFuTest < Test::Unit::TestCase @@samples = { 'This IS a Tripped out title!!.!1 (well/ not really)' => 'this-is-a-tripped-out-title-1-well-not-really', @@ -25,6 +43,8 @@ 'āčēģīķļņū' => 'acegiklnu' } + @@extra = { 'some-)()()-ExtRa!/// .data==?> to \/\/test' => 'some-extra-data-to-test' } + def test_should_escape_permalinks @@samples.each do |from, to| assert_equal to, PermalinkFu.escape(from) @@ -38,4 +58,14 @@ assert_equal to, @m.validate end end -end \ No newline at end of file + + def test_multiple_attribute_permalink + @m = MockModelExtra.new + @@samples.each do |from, to| + @@extra.each do |from_extra, to_extra| + @m.title = from; @m.extra = from_extra; @m.permalink = nil + assert_equal "#{to}-#{to_extra}", @m.validate + end + end + end +end Index: permalink_fu/lib/permalink_fu.rb =================================================================== --- permalink_fu/lib/permalink_fu.rb (revision 22) +++ permalink_fu/lib/permalink_fu.rb (working copy) @@ -14,11 +14,13 @@ end end - def has_permalink(attr_name, permalink_field = nil) + def has_permalink(attr_names = [], permalink_field = nil) permalink_field ||= 'permalink' - before_validation { |record| record.send("#{permalink_field}=", PermalinkFu.escape(record.send(attr_name).to_s)) if record.send(permalink_field).to_s.empty? } + before_validation { |record| record.send("#{permalink_field}=", Array(attr_names).collect { |attr_name| PermalinkFu.escape(record.send(attr_name).to_s) }.join('-')) if record.send(permalink_field).to_s.empty? } + + #before_validation { |record| record.send("#{permalink_field}=", PermalinkFu.escape(record.send(attr_name).to_s)) if record.send(permalink_field).to_s.empty? } end end PermalinkFu.translation_to = 'ascii//ignore//translit' -PermalinkFu.translation_from = 'utf-8' \ No newline at end of file +PermalinkFu.translation_from = 'utf-8'