frodsan / qunit-rails

[unmantained] QUnit JavaScript Testing on Rails
The Unlicense
51 stars 26 forks source link

Update routes to not remount if previously mounted #16

Closed alkrauss48 closed 10 years ago

alkrauss48 commented 10 years ago

I have been having issues using qunit while simultaneously using wildcard routes. My app utilizes a necessary route like:

  get '/*path' => 'high_voltage/pages#show',  id: 'index'

which overrides the default qunit route since that seems to get mounted after this wildcard route. I can prevent this from happening by manually mounting it in my routes like so:

mount Qunit::Rails::Engine => '/qunit'

but then it gets remounted in the gem, and the entire rails application complains when I do anything (run tests, list routes, run zeus, etc.) because there are 2 named routes with the same name.

So this little fix will not remount the engine if it was previously mounted in the routes.rb in the rails app, which will allow the engine to get mounted prior to any wildcard routes.

elsurudo commented 10 years ago

I had the same problem, and this PR fixed it. Thanks @alkrauss48 !

andruby commented 10 years ago

I'd like to see this too :+1: . I use a catch all route so Ember can use the location api for its own routes.

frodsan commented 10 years ago

This is included in v0.0.6.

elsurudo commented 10 years ago

Hi @frodsan,

I was on that branch of @alkrauss48 and things were fine. I just upgraded to your 0.0.6, and I get the following error:

ArgumentError: Invalid route name, already in use: 'q_unit_rails' 
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: 
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

I have the following at the bottom of my routes.rb:

mount QUnit::Rails::Engine => '/qunit' if Rails.env.development? || Rails.env.test?
match '*unmatched_route', to: 'main#index', via: :get

Is there now a better, supported way to do this?

EDIT, Nevermind, had to name the route something different is all:

mount QUnit::Rails::Engine => '/qunit', as: 'qunit' if Rails.env.development? || Rails.env.test?
frodsan commented 10 years ago

Thanks for the report, I think it's because this change: https://github.com/frodsan/qunit-rails/commit/f23146090e19f60d0f50e27e8c6749c5a9127714. I will revert it. Sorry for the trouble.

elsurudo commented 10 years ago

QUnit is better than Qunit as a namespace, IMO, so you made the right call (back-compat-breaking or not :P)

frodsan commented 10 years ago

I like the change you did in your app. I will backport it.

frodsan commented 10 years ago

@elsurudo Could you use this branch https://github.com/frodsan/qunit-rails/tree/fix_routes and remove the as: "qunit" parameter please? Let me know if that works :smile:

elsurudo commented 10 years ago

Yup, that worked!

frodsan commented 10 years ago

Thanks, I release 0.0.7 with that fix, please upgrade.

elsurudo commented 10 years ago

What a quick release cycle :P

Thanks!

On Jan 20, 2014, at 8:42 PM, Francesco Rodríguez notifications@github.com wrote:

Thanks, I release 0.0.7 with that fix, please upgrade.

— Reply to this email directly or view it on GitHub.