Generating permalink from string in Ruby

May 14
2007 18:27 (Ruby on Rails) · Русский (11,078 views)

If you are creating Ruby on Rails application like a blog, you most probably want to generate URLs using post titles. It’s good practice, because search engines like keywords in URL, and it looks more human-readable. Just compare: http://example.com/posts/10 and http://example.com/posts/generating-permalinks-from-string (yeah, it’s long, but self-descriptive). Anyways, this is small post about converting a title to a permalink.

Read the rest of entry »

Useful helpers for RSpec mocks

May 05
2007 02:38 (Development, RSpec, Ruby on Rails) · Русский (10,376 views)

RSpec has great feature — mock objects (mocks). In a few words: mock object imitates behavior of the object, which used by the tested methods. And simple example immediately:

describe UserHelper
  it 'should generate correct link to user profile in user_link' do
    @user = mock('User')
    @user.stub!(:id, 10)
    @user.stub!(:new_record?, false)
    @user.stub!(:preferred_name, 'Dmytro S.')
    @user.stub!(:full_name, 'Dmytro Shteflyuk')
    user_link(@user).should == link_to('Dmytro S.', user_url(:id => 10), :title => 'Dmytro Shteflyuk')
  end
end

Read the rest of entry »

Testing mailers with RSpec

Apr 19
2007 07:42 (Development, RSpec, Ruby on Rails) · Русский (8,347 views)

Unfortunately, RSpec does not provide helpers for testing mailers like TestUnit. But it is easy to add them to your application, and here you could find code snippet for testing mailers.

Read the rest of entry »

5 Things why I love RSpec

Mar 19
2007 09:31 (Development, RSpec, Ruby on Rails) · Русский (8,245 views)

RSpec provides a framework for writing what can be called executable specifications of program behavior. In this short post I want to explain why I use this framework in place of classic TestUnit library.

Read the rest of entry »

Create your fixtures easily

Jan 20
2007 23:09 (Development, RSpec, Ruby on Rails) · Русский (9,374 views)

Every time I’m creating fixtures for Rails application I’m being angry because any more or less considerable project needs tons of them. Most complicated thing is to track all relationships, validations, and to keep fixtures up to date. A few days ago Yurii Rashkovskii has released small utility — Fixturease. What if I would tell you that now you can create your fixtures using your models?

Read the rest of entry »

 
Copyright © 2005 - 2008, Dmytro Shteflyuk