Skip to content

Commit

Permalink
Add support for actionpack 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenCocoon committed Sep 13, 2011
1 parent 94657de commit 97eda92
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
9 changes: 4 additions & 5 deletions Appraisals
Expand Up @@ -3,8 +3,7 @@ appraise "3.0" do
gem "actionpack", "~> 3.0"
end

# Not yet supported
# appraise "3.1.0.rc4" do
# gem "i18n", "~> 0.6.0"
# gem "actionpack", "~> 3.1.0.rc4"
# end
appraise "3.1.0" do
gem "i18n", "~> 0.6.0"
gem "actionpack", "~> 3.1.0"
end
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -26,7 +26,7 @@ tracker](https://github.com/ZenCocoon/routing_filter_locale_unless_api/issues).

## Requirements

actionpack ~> 3.0.9
actionpack >= 3.0.9
i18n >= 0.5.0
routing-filter ~> 0.2.3

Expand Down
Expand Up @@ -71,8 +71,8 @@ def around_generate(*args, &block)

format = params[:format] # save the current format
locale = params.delete(:locale) # extract the passed :locale option
locale = I18n.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false)
locale = nil unless valid_locale?(locale) # reset to no locale when locale is not valid
locale = I18n.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false)

args << params

Expand Down Expand Up @@ -107,7 +107,7 @@ def default_locale?(locale)
#
# @return [Boolean]
def root_path?(path)
path == '/'
(path.is_a?(Array) ? path.first : path) == '/'
end

# Returns true if it should prepend the locale
Expand Down
2 changes: 1 addition & 1 deletion routing_filter_locale_unless_api.gemspec
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.rdoc_options = "--charset=UTF-8"
s.require_path = "lib"

s.add_dependency "actionpack", "~> 3.0.9"
s.add_dependency "actionpack", ">= 3.0.9"
s.add_dependency "i18n", ">= 0.5.0"
s.add_dependency "routing-filter", "~> 0.2.3"

Expand Down
Expand Up @@ -58,45 +58,45 @@ module RoutingFilterLocaleUnlessAPI::Filter

context "prepends the segments /:locale to the generated path" do
it 'if the current locale is not the default locale' do
routes.generate(params).should == '/fr/products/1'
generated_routes_with(params).should == '/fr/products/1'
end

it 'if the current locale is the default locale' do
I18n.locale = 'en'
routes.generate(params).should == '/en/products/1'
generated_routes_with(params).should == '/en/products/1'
end

it 'if the current locale is not the default locale and with root url' do
routes.generate(root).should == '/fr'
generated_routes_with(root).should == '/fr'
end

it 'if the format XLS is not considered as api' do
routes.generate(params.merge(:format => 'xls')).should == '/fr/products/1.xls'
generated_routes_with(params.merge(:format => 'xls')).should == '/fr/products/1.xls'
end
end

context "does not prepend the segments /:locale to the generated path" do
it 'if the current locale is the default locale and with root url' do
I18n.locale = 'en'
routes.generate(root).should == '/'
generated_routes_with(root).should == '/'
end

it 'if the format XML is considered as api' do
routes.generate(params.merge(:format => 'xml')).should == '/products/1.xml'
generated_routes_with(params.merge(:format => 'xml')).should == '/products/1.xml'
end

it 'if the format JSON is considered as api' do
routes.generate(params.merge(:format => 'json')).should == '/products/1.json'
generated_routes_with(params.merge(:format => 'json')).should == '/products/1.json'
end

it 'if the format XLS is considered as api' do
RoutingFilter::LocaleUnlessApi.api_formats = %w( xml json xls )
routes.generate(params.merge(:format => 'xls')).should == '/products/1.xls'
generated_routes_with(params.merge(:format => 'xls')).should == '/products/1.xls'
end
end

it 'should work with format as symbol' do
routes.generate(params.merge(:format => :xml)).should == '/products/1.xml'
generated_routes_with(params.merge(:format => :xml)).should == '/products/1.xml'
end
end

Expand All @@ -105,41 +105,48 @@ module RoutingFilterLocaleUnlessAPI::Filter

context "prepends the segments /:locale to the generated path" do
it 'if the given locale is not the default locale' do
routes.generate(params).should == '/fr/products/1'
generated_routes_with(params).should == '/fr/products/1'
end

it 'if the given locale is the default locale' do
routes.generate(params.merge(:locale => 'en')).should == '/en/products/1'
generated_routes_with(params.merge(:locale => 'en')).should == '/en/products/1'
end

it 'if the given locale is not the default locale and with root url' do
routes.generate(root.merge(:locale => 'fr')).should == '/fr'
generated_routes_with(root.merge(:locale => 'fr')).should == '/fr'
end

it 'if a given locale and the format XLS is not considered as api' do
routes.generate(params.merge(:format => 'xls')).should == '/fr/products/1.xls'
generated_routes_with(params.merge(:format => 'xls')).should == '/fr/products/1.xls'
end
end

context "does not prepend the segments /:locale to the generated path" do
it 'if a given locale is the default locale and with the root url' do
routes.generate(root.merge(:locale => 'en')).should == '/'
generated_routes_with(root.merge(:locale => 'en')).should == '/'
end

it 'if a given locale and the format XML is considered as api' do
routes.generate(params.merge(:format => 'xml')).should == '/products/1.xml'
generated_routes_with(params.merge(:format => 'xml')).should == '/products/1.xml'
end

it 'if a given locale and the format JSON is considered as api' do
routes.generate(params.merge(:format => 'json')).should == '/products/1.json'
generated_routes_with(params.merge(:format => 'json')).should == '/products/1.json'
end

it 'if a given locale and the format XLS is considered as api' do
RoutingFilter::LocaleUnlessApi.api_formats = %w( xml json xls )
routes.generate(params.merge(:format => 'xls')).should == '/products/1.xls'
generated_routes_with(params.merge(:format => 'xls')).should == '/products/1.xls'
end
end
end
end

private

def generated_routes_with(params)
url = routes.generate(params)
url.is_a?(Array) ? url.first : url
end
end
end

0 comments on commit 97eda92

Please sign in to comment.