Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # in specs/models/post_spec.rb
  2. require 'spec_helper'
  3.  
  4. describe Post do
  5.   it {
  6.     should belong_to :user
  7.     should validate_presence_of :title
  8.   }
  9.  
  10.   # class method spec
  11.   describe '.find_by_url_param' do
  12.     it 'should find a Post by converting a URL param to a post title' do
  13.       post = Post.create(:title => 'My New Post')
  14.       Post.find_by_url_param('my-new-post').should == post
  15.     end
  16.   end
  17.  
  18.   # instance method spec
  19.   describe '#url_param' do
  20.     it 'should convert the post title to a param for URLs' do
  21.       Post.create(:title => 'Another Post').url_param.should == 'another-post'
  22.     end
  23.   end
  24. end