tricknotes / ember-cli-rails

Unify your EmberCLI and Rails Workflows
http://thoughtbot.github.io/ember-cli-rails/
MIT License
713 stars 205 forks source link

Running rspec api tests only - ember seems to intefere #485

Open rmcsharry opened 8 years ago

rmcsharry commented 8 years ago

Which operating system and version is the project developed on? OSX El Capitan

Which version of [ruby][ruby] is the project developed on? 2.3.1

Which version of [npm][npm] is the project developed on? 3.10.6

Which version of [ember-cli][ember-cli] is the project developed on? 2.7

What is the [rails][rails] version? 5.0.0.1

What is the [ember-cli-rails][gem] version (from Gemfile)? 0.8.0

What is the [ember-cli-rails-addon][addon] version (from package.json)? 0.8.0

Is your application server [multi-threaded][](such as puma and unicorn) or is it multi-process (such as thin and webrick)? puma

What are the contents of config/initializers/ember.rb?

EmberCli.configure do |c|
  c.app :trekclient, path: "trekclient"
end

What are the contents of the Rails' view that renders the Ember application? It's empty

How are the EmberCLI-related routes defined?

mount_ember_app :trekclient, to: "/"

How is the application deployed? It's not, this is locally in development

I am not sure if this is an issue, but if I just want (for now) to write api tests only such as model and controller and route tests, I get the impression that ember-cli-rails is in the way?

Example output when running 'rspec spec'

NotesController routing routes to #edit Failure/Error: expect(:get => "/notes/1/edit").to route_to("notes#edit", :id => "1")

   The recognized options <{"ember_app"=>:trekclient, "controller"=>"ember_cli/ember", "action"=>"index", "rest"=>"notes/1/edit"}> did not match <{"id"=>"1", "controller"=>"notes", "action"=>"edit"}>, difference:.
   --- expected
   +++ actual
   @@ -1 +1 @@
   -{"id"=>"1", "controller"=>"notes", "action"=>"edit"}
   +{"ember_app"=>:trekclient, "controller"=>"ember_cli/ember", "action"=>"index", "rest"=>"notes/1/edit"}
 # ./spec/routing/notes_routing_spec.rb:19:in `block (3 levels) in <top (required)>'

I am a bit confused about how I can fix that?

seanpdoyle commented 8 years ago

@rmcsharry thanks for opening this issue -- could you please read the CONTRIBUTING document and update the format of your issue to populate the issue template?

Could you share the pertinent portion of your config/routes.rb file?

EmberCli routes requests to the Ember application by declaring a catch-all route, constrained to format: :html requests.

How are you mounting your Ember application?

Where are you mounting it? Is it before the notes#edit route declaration?

If you're declaring notes#edit after the call to mount_ember_application, try declaring mount_ember_application as far down in your routes file as possible.

rmcsharry commented 8 years ago

@seanpdoyle You are correct, I was mounting the ember app too early in the routes file.

Solved by "declaring mount_ember_application as far down in your routes file as possible."

Thanks!

rmcsharry commented 8 years ago

@seanpdoyle I think there is something basic I am missing here about how ember-cli-rails affects routing. Perhaps you can shed some light?

After I moved the mount_ember route root "/" to below my rails routes, rspec worked fine...but the ember routes no longer work...?

This breaks rspec, ember routes work, rails json routes work:

Rails.application.routes.draw do
  mount_ember_app :trekclient, to: "/"

  resources :employees
  resources :addresses
  resources :trails
  resources :notes
  resources :comments
  resources :assignments

end

This fixes rspec, none of the ember routes work:

Rails.application.routes.draw do
  resources :employees
  resources :addresses
  resources :trails
  resources :notes
  resources :comments
  resources :assignments
  mount_ember_app :trekclient, to: "/"
end
seanpdoyle commented 7 years ago

I think there is something basic I am missing here about how ember-cli-rails affects routing. Perhaps you can shed some light?

@rmcsharry in your application's case, mount_ember_app effectively mounts the Ember application to /(*rest), with a format: :html constraint.

but the ember routes no longer work...?

Could you elaborate a bit more on the issues you're having when your mount_ember_app is at the bottom of your routes file?