Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rails 4.2 and Ruby 2.2 #140

Merged
merged 8 commits into from
Dec 31, 2014
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
language: ruby
cache: bundler

rvm:
- 1.9.3
- 2.0.0
- 2.1.5
- 2.0
- 2.1
- 2.2
- jruby-19mode
- ruby-head
- jruby-head
Expand All @@ -12,6 +14,7 @@ gemfile:
- gemfiles/rails32.gemfile
- gemfiles/rails40.gemfile
- gemfiles/rails41.gemfile
- gemfiles/rails42.gemfile

sudo: false

Expand All @@ -25,5 +28,6 @@ branches:

matrix:
allow_failures:
- rvm: jruby-19mode
- rvm: ruby-head
- rvm: jruby-head
6 changes: 4 additions & 2 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ end

appraise "rails40" do
gem "railties", "~> 4.0.5"
gem "minitest", "~> 4.0"
end

appraise "rails41" do
gem "railties", "~> 4.1.1"
gem "minitest", ">= 4.0"
end

appraise "rails42" do
gem "railties", "~> 4.2.0"
end
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Add the compact mode [#125](https://github.com/railsware/js-routes/pull/125)
* Add support for host, protocol, and port configuration [#137](https://github.com/railsware/js-routes/pull/137)
* Routes path specs [#135](https://github.com/railsware/js-routes/pull/135)
* Support Rails 4.2 and Ruby 2.2 [#140](https://github.com/railsware/js-routes/pull/140)

## v0.9.9

Expand Down
5 changes: 1 addition & 4 deletions gemfiles/rails32.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ source "http://rubygems.org"

gem "railties", "~> 3.2.18"
gem "tzinfo"
platforms :ruby do
gem "libv8", "<= 3.16.14.3"
end

gemspec :path=>"../"
gemspec :path => "../"
3 changes: 1 addition & 2 deletions gemfiles/rails40.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
source "http://rubygems.org"

gem "railties", "~> 4.0.5"
gem "minitest", "~> 4.0"

gemspec :path=>"../"
gemspec :path => "../"
3 changes: 1 addition & 2 deletions gemfiles/rails41.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
source "http://rubygems.org"

gem "railties", "~> 4.1.1"
gem "minitest", ">= 4.0"

gemspec :path=>"../"
gemspec :path => "../"
7 changes: 7 additions & 0 deletions gemfiles/rails42.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "railties", "~> 4.2.0"

gemspec :path => "../"
1 change: 0 additions & 1 deletion js-routes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Gem::Specification.new do |s|
s.homepage = %q{http://github.com/railsware/js-routes}
s.licenses = ["MIT"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.6.0}
s.summary = %q{Brings Rails named routes to javascript}

s.add_runtime_dependency(%q<railties>, [">= 3.2"])
Expand Down
13 changes: 10 additions & 3 deletions lib/js_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@ def generate!(file_name = nil)

def js_routes
js_routes = Rails.application.routes.named_routes.routes.sort_by(&:to_s).map do |_, route|
if route.app.respond_to?(:superclass) && route.app.superclass == Rails::Engine && !route.path.anchored
route.app.routes.named_routes.map do |_, engine_route|
# rails engine for rails 4.2 change to route.app.app
rails_engine_route = if route.app.respond_to?(:app) && route.app.app.respond_to?(:superclass)
route.app.app
else
route.app
end
# rails engine route
if rails_engine_route.respond_to?(:superclass) && rails_engine_route.superclass == Rails::Engine && !route.path.anchored
rails_engine_route.routes.named_routes.map do |_, engine_route|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets refactor this part a little bit. Are you sure you need a double check for respond_to?(:superclass)? Lets extract a part of this code a method.

build_route_if_match(engine_route, route)
end
else
Expand Down Expand Up @@ -177,7 +184,7 @@ def generate_base_url_js(route)
# preserve and deprecate previous behavior
unless @options[:url_links] == true
ActiveSupport::Deprecation.warn('js-routes url_links config value must be a boolean. Use default_url_options for specifying a default host.')
raise "invalid URL format in url_links (ex: http[s]://example.com)" if @options[:url_links].match(URI::regexp(%w(http https))).nil?
raise "invalid URL format in url_links (ex: http[s]://example.com)" if @options[:url_links].match(URI::Parser.new.make_regexp(%w(http https))).nil?
return "#{@options[:url_links].inspect}"
else
protocol = route.defaults[:protocol] || @options[:default_url_options][:protocol] || 'http'
Expand Down
4 changes: 4 additions & 0 deletions spec/js_routes/rails_routes_compatibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,15 @@
expect(evaljs("Routes.thing_path(null, 5)")).to eq(routes.thing_path(nil, 5))
end

# Fail for rails 4.2. Reason: https://github.com/rails/rails/issues/12178
it "should treat undefined as non-given optional part" do
pending("This tests is invalid for rails 4.2. Reason: https://github.com/rails/rails/issues/12178") if [4, 2] == [Rails::VERSION::MAJOR, Rails::VERSION::MINOR]
expect(evaljs("Routes.thing_path(5, {optional_id: undefined})")).to eq(routes.thing_path(5, :optional_id => nil))
end

# Fail for rails 4.2. Reason: https://github.com/rails/rails/issues/12178
it "should treat null as non-given optional part" do
pending("This tests is invalid for rails 4.2. Reason: https://github.com/rails/rails/issues/12178") if [4, 2] == [Rails::VERSION::MAJOR, Rails::VERSION::MINOR]
expect(evaljs("Routes.thing_path(5, {optional_id: null})")).to eq(routes.thing_path(5, :optional_id => nil))
end
end
Expand Down