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:
1 2 3 4 5 6 7 8 9 10
| 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 »
When I worked on Best Tech Videos with Alexey Kovyrin, we faced a problem of filtering videos by category with selecting posts categories in the same query. It was easy to solve the problem, but there is one query optimization trick exists.
Read the rest of entry »
Yesterday in mailing list of russian RoR group we have discussed following problem. MySQL database has unique index and model has validates_uniqueness_of constraint. Do we need to handle MySQL server exceptions or RoR’s validation will be enough?
Read the rest of entry »