Currently the posts are filtered by: rails
Reset this filter to see all posts.

Category: Ruby on Rails
Date: 2012-05-04 22:45

Using SimpleCov with FactoryGirl

FactoryGirl is a great replacement for your Ruby-on-rails fixtures. They offer more flexibility for generating stubs and mack-ups for your automated testing.

SimpleCov is the test coverage tool for Ruby 1.9.x (Use RCov for Ruby 1.8.x).

Using both in conjunction requires two extra lines in your test/test_helper.rb file not covered by any documentation. This will prevent you from getting messages like "Factory not registered: " or "uninitialized constant Test::Unit::TestCase::FactoryGirl (NameError)".

My test_helper.rb file looks like:

Code:  Select all
require 'simplecov'
SimpleCov.start 'rails'
 
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
 
# The following two lines of code will reinitialize Factorygirl:
require 'factory_girl'
FactoryGirl.reload
 
class ActiveSupport::TestCase
...
end

back

Category: Ruby on Rails
Date: 2010-08-20 23:06

HTML5 helpers for Rails 2.3.x

Eager on using HTML5 in your Rails projects without upgrading to Rails 3?

For those I've ported the HTML5 FormHelpers and FormTagHelpers from Rails 3 back to Rails 2.3.x. So you can now use:

 

<%= f.email_field(:email) %>

<%= email_field_tag(:user, @user.email) %>

All helpers are Rails 3 compliant so after updating to Rails 3 just remove the plugin.

back

Category: Ruby on Rails
Date: 2010-07-27 15:29

Rails will_paginate with acts_as_ferret

I wanted to use pagination in one of my Rails projects where I was also using the acts_as_ferret plugin. Now normally one would use

@collection=Model.paginate(:page=>params[:page])

in the controller and in the view render with:

<%= will_paginate @collection %>

But with acts_as_ferret the controller will contain:

@collection=Model.find_with_ferret(params[:search], {:page=> params[:page], :per_page=>Model.per_page})

This is not a problem however. Acts_as_ferret is compatible with will_paginate. Your default will_paginate() helper will still be working.

back