Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow not forcing downcase of to url

  • Loading branch information...
commit 44d5dade04e5f11925126a93679690154bee1787 1 parent 11ff73b
Russell Norris authored
7 lib/stringex/acts_as_url.rb
View
@@ -28,11 +28,12 @@ module ActsAsUrlClassMethods # :doc:
# <tt>:adapter</tt>:: If specified, will indicate what ORM adapter to use. Default functionality
# is to use the first available adapter. This should work for most cases
# unless you are using multiple ORMs in a single project.
- # <tt>:allow_slash</tt>:: If true, allow the generated url to contain slashes. Default is false[y].
- # <tt>:allow_duplicates</tt>:: If true, allow duplicate urls instead of appending numbers to
+ # <tt>:allow_slash</tt>:: If true, allows the generated url to contain slashes. Default is false[y].
+ # <tt>:allow_duplicates</tt>:: If true, allows duplicate urls instead of appending numbers to
# differentiate between urls. Default is false[y]. See note on <tt>:scope</tt>.
# <tt>:duplicate_count_separator</tt>:: String to use when forcing unique urls from non-unique strings.
# Default is "-".
+ # <tt>:force_downcase</tt>:: If false, allows generated url to contain uppercased letters. Default is false.
# <tt>:exclude_list</tt>:: List of complete strings that should not be transformed by <tt>acts_as_url</tt>.
# Default is empty.
# <tt>:only_when_blank</tt>:: If true, the url generation will only happen when <tt>:url_attribute</tt> is
@@ -41,7 +42,7 @@ module ActsAsUrlClassMethods # :doc:
# <strong>Note:</strong> this will automatically act as if <tt>:allow_duplicates</tt>
# is set to true.
# <tt>:sync_url</tt>:: If set to true, the url field will be updated when changes are made to the
- # attribute it is based on. Default is false[y].
+ # attribute it is based on. Default is false.
# <tt>:url_attribute</tt>:: The name of the attribute to use for storing the generated url string.
# Default is <tt>:url</tt>.
# <tt>:limit</tt>:: The maximum size a generated url should be. <strong>Note:</strong> this does not
2  lib/stringex/configuration/acts_as_url.rb
View
@@ -10,7 +10,7 @@ def initialize(options = {})
end
def string_extensions_settings
- [:allow_slash, :exclude, :limit].inject(Hash.new){|m, x| m[x] = settings.send(x); m}
+ [:allow_slash, :exclude, :force_downcase, :limit].inject(Hash.new){|m, x| m[x] = settings.send(x); m}
end
def self.settings
3  lib/stringex/configuration/string_extensions.rb
View
@@ -9,7 +9,8 @@ def self.default_settings
@default_settings ||= {
:allow_slash => false,
:exclude => [],
- :limit => nil
+ :limit => nil,
+ :force_downcase => true
}
end
end
4 lib/stringex/string_extensions.rb
View
@@ -224,7 +224,9 @@ def to_html(lite_mode = false)
# but can be called manually in order to generate an URI-friendly version of any string.
def to_url(options = {})
return self if options[:exclude] && options[:exclude].include?(self)
- remove_formatting(options).downcase.replace_whitespace("-").collapse("-").limit(options[:limit])
+ dummy = remove_formatting(options).replace_whitespace("-").collapse("-").limit(options[:limit])
+ dummy.downcase! unless options[:force_downcase] == false
+ dummy
end
end
9 test/acts_as_url_integration_test.rb
View
@@ -237,4 +237,13 @@ def test_should_allow_excluding_specific_values_from_being_run_through_to_url
@doc_2 = Document.create!(:title => "But I'm a creep")
assert_equal "but-im-a-creep", @doc_2.url
end
+
+ def test_should_allow_not_forcing_downcasing
+ Document.class_eval do
+ acts_as_url :title, :force_downcase => false
+ end
+
+ @doc = Document.create!(:title => "I have CAPS!")
+ assert_equal "I-have-CAPS", @doc.url
+ end
end
4 test/string_extensions_test.rb
View
@@ -103,6 +103,10 @@ def test_to_url_with_excludes
assert_equal "So Fucking Special", "So Fucking Special".to_url(:exclude => "So Fucking Special")
end
+ def test_to_url_with_not_forcing_downcase
+ assert_equal "I-have-CAPS", "I have CAPS".to_url(:force_downcase => false)
+ end
+
def test_remove_formatting
{
"<p>This has 100% too much <em>formatting</em></p>" =>
Please sign in to comment.
Something went wrong with that request. Please try again.