Forum: Ruby on Rails Testing if a controller renders a JS Template

A00673345921ae8c2e5570d1bd48b2e2?d=identicon&s=25 J. mp (lerias)
on 2013-07-26 01:11
(Received via mailing list)
I have this controller:

class UsersController < ApplicationController
  def enable_password_change
    respond_to do |format|
      format.js {
        render :layout => false
      }
    end
  endend

And the following test:

test "should render js to show the change password form" do
  sign_in_user
  request_javascript
  get :enable_password_change
  assert_template :enable_password_change
  assert_response :okend

And the helper method to set the request headers:

def request_javascript
  @request.headers["Accepts"] = "text/javascript,
application/javascript, application/ecmascript,
application/x-ecmascript"end

However my test reports:

Finished tests in 0.942294s, 7.4287 tests/s, 15.9186 assertions/s.
1)
Error:UsersControllerTest#test_should_render_js_to_show_the_change_password_for:ActionController::UnknownFormat:
ActionController::UnknownFormat
app/controllers/users_controller.rb:9:in `enable_password_change'
test/controllers/users_controller_test.rb:14:in `block in
<class:UsersControllerTest>'

7 tests, 15 assertions, 0 failures, 1 errors, 0 skips

What am I doing wrong here?

P.S. Also posted on
http://stackoverflow.com/questions/17870266/testin...
A00673345921ae8c2e5570d1bd48b2e2?d=identicon&s=25 J. mp (lerias)
on 2013-08-02 00:49
(Received via mailing list)
I found the the xml_http_request or alias xhr for that

test "should render js to show the change password form" do
   sign_in_user

   xhr :get, :enable_password_change

   assert_template :enable_password_change
   assert_response :ok
   assert assigns(:merchant_user)end



http://jpereira.eu
5251fb12ad96bacd1f57e579b28b30fe?d=identicon&s=25 unknown (Guest)
on 2013-08-02 10:50
(Received via mailing list)
Joao,

I am not sure you getting testing right! everytime you find something
like
this that looks hard to test, maybe you should rethink your tests.

I Would for example on controller testing, which is functional, be more
worried to test, if the function did what it was supposed to and on the
features/request tests check if my applications is working correctly
with
js.

I am not sure for this example but just a little tip from what I have
seen
in testing before!

all the best,

Andre
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.