Permalink
Browse files

Support for Babosa 0.2.0.

  • Loading branch information...
1 parent ea1cc85 commit e086d10bd1cff842679fb657f1cce90d8977488b @norman committed Aug 27, 2010
Showing with 40 additions and 8 deletions.
  1. +1 −1 extras/bench.rb
  2. +1 −1 friendly_id.gemspec
  3. +8 −1 lib/friendly_id/configuration.rb
  4. +2 −4 lib/friendly_id/slug_string.rb
  5. +28 −1 test/friendly_id_test.rb
View
@@ -37,4 +37,4 @@
summary 'Total'
-end
+end
View
@@ -22,6 +22,6 @@ spec = Gem::Specification.new do |s|
"Rakefile", "rails/init.rb", "generators/**/*.*", "test/**/*.*",
"extras/**/*.*" ]
- s.add_dependency "babosa", ">= 0.1.0"
+ s.add_dependency "babosa", "~> 0.2.0"
end
@@ -130,6 +130,13 @@ def #{method}?
alias :use_slugs? :use_slug?
+ def babosa_options
+ {
+ :to_ascii => strip_non_ascii?,
+ :transliterate => approximate_ascii?,
+ :transliterations => ascii_approximation_options,
+ :max_length => max_length
+ }
+ end
end
-
end
@@ -1,14 +1,12 @@
# encoding: utf-8
module FriendlyId
- class SlugString < Babosa::SlugString
+ class SlugString < Babosa::Identifier
# Normalize the string for a given {FriendlyId::Configuration}.
# @param config [FriendlyId::Configuration]
# @return String
def normalize_for!(config)
- approximate_ascii!(config.ascii_approximation_options) if config.approximate_ascii?
- to_ascii! if config.strip_non_ascii?
- normalize!
+ normalize!(config.babosa_options)
end
# Validate that the slug string is not blank or reserved, and truncate
View
@@ -1,7 +1,34 @@
+# encoding: utf-8
require File.expand_path('../test_helper', __FILE__)
module FriendlyId
module Test
+
+ class SlugStringTest < ::Test::Unit::TestCase
+ test "should not transliterate by default" do
+ s = SlugString.new("über")
+ assert_equal "über", s.normalize_for!(Configuration.new(nil, :name))
+ end
+
+ test "should transliterate if specified" do
+ s = SlugString.new("über")
+ options = {:approximate_ascii => true}
+ assert_equal "uber", s.normalize_for!(Configuration.new(nil, :name, options))
+ end
+
+ test "should strip non-ascii if specified" do
+ s = SlugString.new("über")
+ options = {:strip_non_ascii => true}
+ assert_equal "ber", s.normalize_for!(Configuration.new(nil, :name, options))
+ end
+
+ test "should use transliterations if given" do
+ s = SlugString.new("über")
+ options = {:approximate_ascii => true, :ascii_approximation_options => :german}
+ assert_equal "ueber", s.normalize_for!(Configuration.new(nil, :name, options))
+ end
+ end
+
class FriendlyIdTest < ::Test::Unit::TestCase
test "should parse a friendly_id name and sequence" do
assert_equal ["test", 2], "test--2".parse_friendly_id
@@ -48,4 +75,4 @@ class FriendlyIdTest < ::Test::Unit::TestCase
end
end
end
-end
+end

0 comments on commit e086d10

Please sign in to comment.