Functional testing of Active Scaffold powered controllers?

148 views
Skip to first unread message

Andrey Novikov

unread,
Dec 10, 2012, 1:59:50 AM12/10/12
to actives...@googlegroups.com
I'm now learning how to test rails applications and trying to write tests for one of my little apps. It's almost completely done with Active Scaffold.

I'm now trying to make autogenerated functional tests pass (that ones, that was generated by `rails g active_scaffold` command), but they're not passing.

Does anyone do functional testing of AS-powered controllers, and if so, how are you doing that?

What my `rake` complaints about:

  1) Failure:
test_should_create_address(AddressesControllerTest) [/home/envek/simple_catalog/test/functional/addresses_controller_test.rb:21]:
"Address.count" didn't change by 1.
<3> expected but was
<2>.

  2) Failure:
test_should_destroy_address(AddressesControllerTest) [/home/envek/simple_catalog/test/functional/addresses_controller_test.rb:44]:
"Address.count" didn't change by -1.
<1> expected but was
<2>.

  3) Failure:
test_should_get_edit(AddressesControllerTest) [/home/envek/simple_catalog/test/functional/addresses_controller_test.rb:35]:
Expected response to be a <:success>, but was <302>

  4) Failure:
test_should_get_index(AddressesControllerTest) [/home/envek/simple_catalog/test/functional/addresses_controller_test.rb:10]:
Expected response to be a <:success>, but was <302>

  5) Failure:
test_should_get_new(AddressesControllerTest) [/home/envek/simple_catalog/test/functional/addresses_controller_test.rb:16]:
Expected response to be a <:success>, but was <302>

  6) Failure:
test_should_show_address(AddressesControllerTest) [/home/envek/simple_catalog/test/functional/addresses_controller_test.rb:30]:
Expected response to be a <:success>, but was <302>

  7) Failure:
test_should_update_address(AddressesControllerTest) [/home/envek/simple_catalog/test/functional/addresses_controller_test.rb:40]:
Expected response to be a redirect to <http://test.host/addresses/368308524> but was a redirect to <http://test.host/users/sign_in>

Thanks for patience.

Rafael Maus

unread,
Dec 10, 2012, 4:49:23 AM12/10/12
to actives...@googlegroups.com


2012/12/10 Andrey Novikov <en...@envek.name>

--
You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" group.
To view this discussion on the web visit https://groups.google.com/d/msg/activescaffold/-/YzEKh_KWN0oJ.
To post to this group, send email to actives...@googlegroups.com.
To unsubscribe from this group, send email to activescaffol...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/activescaffold?hl=en.
Sorry to use this thread, but how do i unsubscribe fom this list?
thanks

Sergio Cambra

unread,
Dec 10, 2012, 4:51:30 AM12/10/12
to actives...@googlegroups.com
On Lunes, 10 de diciembre de 2012 07:49:23 Rafael Maus escribió:
> > To unsubscribe from this group, send email to
> > activescaffol...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/activescaffold?hl=en.
>
> Sorry to use this thread, but how do i unsubscribe fom this list?
> thanks

It's at bottom of mails

Andrey Novikov

unread,
Dec 10, 2012, 10:44:09 PM12/10/12
to actives...@googlegroups.com
I've solved it.

First, I'm using Devise and, according to Devise docs, I should add to test/test_helper.rb something like:

class ActionController::TestCase
  include Devise::TestHelpers

  def sign_in_user
    @request.env["devise.mapping"] = Devise.mappings[:user]
    sign_in users(:first_user)
  end

end

And add add_user call in test/functional/addresses_controller_test.rb in setup macro:

setup |do|
  sign_in_user
  @user = users(:first_user)
end

Second, next things different between default rails scaffolds and Active Scaffold:
  • You should pass record hash in post request instead of model_name
  • create and update actions redirects to index
  • Active Scaffold do not assign instance variables such as @model_names (as generated tests asserts for)
Moreover, if you have disabled some actions (e.g. show, test for them should be removed or asserting for raising ActionView::Template::Error)

After that changes, I've get these tests passed. Thanks and sorry for inconvenience.
Reply all
Reply to author
Forward
0 new messages