Permalink
Browse files

Merge remote branch 'origin/master'

  • Loading branch information...
2 parents c3b7471 + c7e6777 commit f09d8f3e68ca7cf35a7905b00f85b84c3839c803 @wycats wycats committed May 17, 2010
@@ -693,6 +693,11 @@ def match(*args)
super
end
+ def root(options={})
+ options[:on] ||= :collection if @scope[:scope_level] == :resources
+ super(options)
+ end
+
protected
def parent_resource #:nodoc:
@scope[:scope_level_resource]
@@ -13,6 +13,9 @@ module Helpers #:nodoc:
# unchanged if can't be converted into a valid number.
module NumberHelper
+ DEFAULT_CURRENCY_VALUES = { :format => "%u%n", :unit => "$", :separator => ".", :delimiter => ",",
+ :precision => 2, :significant => false, :strip_insignificant_zeros => false }
+
# Raised when argument +number+ param given to the helpers is invalid and
# the option :raise is set to +true+.
class InvalidNumberError < StandardError
@@ -104,9 +107,9 @@ def number_to_currency(number, options = {})
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
currency = I18n.translate(:'number.currency.format', :locale => options[:locale], :default => {})
- defaults = defaults.merge(currency)
- options = options.reverse_merge(defaults)
+ defaults = DEFAULT_CURRENCY_VALUES.merge(defaults).merge!(currency)
+ options = defaults.merge!(options)
unit = options.delete(:unit)
format = options.delete(:format)
@@ -186,6 +186,8 @@ def self.matches?(request)
end
resources :products, :constraints => { :id => /\d{4}/ } do
+ root :to => "products#root"
+ get :favorite, :on => :collection
resources :images
end
@@ -963,7 +965,9 @@ def test_resource_constraints
get '/products/1'
assert_equal 'pass', @response.headers['X-Cascade']
get '/products'
- assert_equal 'products#index', @response.body
+ assert_equal 'products#root', @response.body
+ get '/products/favorite'
+ assert_equal 'products#favorite', @response.body
get '/products/0001'
assert_equal 'products#show', @response.body
@@ -981,6 +985,12 @@ def test_resource_constraints
end
end
+ def test_root_works_in_the_resources_scope
+ get '/products'
+ assert_equal 'products#root', @response.body
+ assert_equal '/products', products_root_path
+ end
+
def test_module_scope
with_test_routes do
get '/token'
@@ -45,6 +45,12 @@ def test_number_to_currency
assert_equal("&$ - 10.00", number_to_currency(10, :locale => 'ts'))
end
+ def test_number_to_currency_with_clean_i18n_settings
+ clean_i18n do
+ assert_equal("$10.00", number_to_currency(10))
+ end
+ end
+
def test_number_with_precision
#Delimiter was set to ""
assert_equal("10000", number_with_precision(10000, :locale => 'ts'))
@@ -92,4 +98,15 @@ def test_number_to_human_with_custom_translation_scope
#Significant was set to true with precision 2, with custom translated units
assert_equal "4.3 cm", number_to_human(0.0432, :locale => 'ts', :units => :custom_units_for_number_to_human)
end
+
+ private
+ def clean_i18n
+ load_path = I18n.load_path.dup
+ I18n.load_path.clear
+ I18n.reload!
+ yield
+ ensure
+ I18n.load_path = load_path
+ I18n.reload!
+ end
end

0 comments on commit f09d8f3

Please sign in to comment.