//
archives

Ruby on Rails

This tag is associated with 10 posts

Cucumber and Factory Girl testing when having Single Table Inheritance

To get familiar with Single Table Inheritance, please, refer to this article Let’s assume, we have a web site requiring authentication and we have a User class that allows every user to log in, created with the gems Clearance and Suspenders such as described here, with a user name field added. Now, let’s have 2 … Continue reading

Factory Girl associations with MongoMapper

If you have an association (an Article belonging to a User) and you write something like that in Cucumber: Given the following article exists: | title | user | | My article | email: writer1@example.com | then the Factory Girl steps will handle this association for you, creating both an Article and a User for … Continue reading

Association testing in rspec with MongoMapper

As far as I know, MongoMapper is currently not able to handle association tests for rspec/shoulda, such as most common belongs_to, has_many, has_one. I think they are working on it, but it’s not there yet. I wrote a hack to work with MongoMapper, so far it’s able to handle my simple belongs_to association, and my … Continue reading

How to load test Ruby on Rails Applications with JMeter

RoR version 2.3.5, JMeter version 2.4 There are a few specifics using JMeter with RoR applications. 1.Handling forms We have to take into account that forms are submitted using authenticity_token which is generated randomly with every form. The solution is to catch the authenticity token from the form page using a regular expression extractor, save … Continue reading

How to implement “show more” and “show less” using a hidden counter when rendering a collection

While rendering a collection, I wanted to hide some items with higher indexes (and show them when clicking on “Show more”). But there is no way to tell the index when rendering :collection => @items. Then I came across this posting: Render partial with collection has hidden counter Now, when rendering <ul> <%= render :partial … Continue reading

How to insert a jpeg image into pdf with rfpdf and Image Science

I was using a 2006 version of rfpdf with tcpdf support (I don’t remember where I got it). It was the only working version I was able to find. Once I tried to insert images into a pdf document, I discovered that it doesn’t work with jpg. The function GetImageSize was called but didn’t exist. … Continue reading

Capistrano deployment problem with git and windows

I had a problem deploying with Capistrano from a git repository (both local and remote depositories equally didn’t work) while on a Windows machine. The git version was probably 1.5 and Capistrano versions used were 2.4.* and 2.5.* My capistrano settings were the following (besides the usual stuff): set :deploy_via, :copy set :copy_dir, “C:/caches/myapp” I … Continue reading

Assigning a Ruby expression to a Javascript variable.

I came across a problem: before directly assigning a ruby expression to a javascript variable, it’s a good idea to escape it: var my_javascript_var = ‘<%= escape_javascript(my_ruby_expression) %>’; The reason to do that is your ruby expression might contain special symbols ( for example some innocent quotes), making your life excruciatingly painful when all of … Continue reading

How to implement user authentication with restful_authentication and email activation

A good step-by-step guide how to install user authentication system with email activation can be found here There are still a few issues when using those wonderful plugins. 1. Emailing activation code using a gmail account doesn’t work explicitly with the current Rails version 2.2.2. In order to make it work, place the following class … Continue reading

How to write a tabular form builder

I wanted to create a form using old good tables. Like this one: This table consists of 3 columns: label, field and comment (optional). Some of the cells span for 2 columns. Also, the third row has several elements in it. If I directly embed code into HTML, my view will result in the following … Continue reading

ip tracing