Articles tagged with: tests

Testing Cookies in Rails 2.3

Posted by Andreas on Monday, March 30, 2009 at 15:37 (CEST)

While moving some applications to Rails 2.3 recently, I stumbled across some problems with testing cookies. E.g. this blog uses cookies to remember your name, email address and web url if you leave a comment. This way, you don’t need to re-enter these information the next time you leave a comment. These cookies are set by the controller action that creates new comments (in CommentsController#create):

1 cookies['blog_visitor_name'] = { :value => @comment.name, :expires => 1.year.from_now }

This is the extended form of setting a cookie (a hash is used to not only set the cookies value but also the expiration time. There are several more hash options available which are described in the ActionController#cookies documentation. The basic form (which only sets a simple session cookie that is valid until the visitor closes the browser) uses a simple string:

Read more »
• Tags: , ,
CommentsPermalink

Flash not accessible in tests (TypeError: can't convert String into Integer)

Posted by Andreas on Friday, September 21, 2007 at 09:09 (CEST)

This morning I faced a strange problem when trying to write RSpec tests for a user login action. Trying to setting the flash before doing a request, resulted in an unexpected Exception:

TypeError in ‘SessionController logging in with correct credentials should redirect to the url_after_login url if given’
can’t convert String into Integer
…/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/functional.rb:80:in `flash’
./spec/controllers/session_controller_spec.rb:52:
./script/spec:4:

Read more »
• Tags: , ,
CommentsPermalink