Skip to content

Commit

Permalink
Fixed missing options for approximate_ascii.
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed May 17, 2010
1 parent 4f9971a commit 9800ce2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/friendly_id/slug_string.rb
Expand Up @@ -191,7 +191,7 @@ def initialize(string)
# @param *args <Symbol>
# @return String
def approximate_ascii!(*args)
@maps = (self.class.approximations + args + [:common]).flatten.uniq
@maps = (self.class.approximations + args.flatten + [:common]).flatten.uniq
@wrapped_string = normalize_utf8(:c).unpack("U*").map { |char| approx_char(char) }.flatten.pack("U*")
end

Expand Down Expand Up @@ -235,7 +235,7 @@ def word_chars!
# @param config [FriendlyId::Configuration]
# @return String
def normalize_for!(config)
approximate_ascii! if config.approximate_ascii?
approximate_ascii!(config.ascii_approximation_options) if config.approximate_ascii?
to_ascii! if config.strip_non_ascii?
normalize!
end
Expand Down
13 changes: 13 additions & 0 deletions lib/friendly_id/test.rb
Expand Up @@ -194,6 +194,19 @@ module Slugged
end
end

test "should approximate ascii if configured" do
klass.friendly_id_config.stubs(:approximate_ascii?).returns(true)
instance = klass.send(create_method, :name => "Cañón")
assert_equal "canon", instance.friendly_id
end

test "should approximate ascii with options if configured" do
klass.friendly_id_config.stubs(:approximate_ascii?).returns(true)
klass.friendly_id_config.stubs(:ascii_approximation_options).returns(:spanish)
instance = klass.send(create_method, :name => "Cañón")
assert_equal "cannon", instance.friendly_id
end

end

# Tests for FriendlyId::Status.
Expand Down

0 comments on commit 9800ce2

Please sign in to comment.