Skip to content

Instantly share code, notes, and snippets.

@azisaka
Created May 18, 2010 00:08
Show Gist options
  • Save azisaka/404412 to your computer and use it in GitHub Desktop.
Save azisaka/404412 to your computer and use it in GitHub Desktop.
class Page
include Mongoid::Document
field :title
field :body
field :permalink
validates_presence_of :title, :body
before_validation :generate_permalink
attr_accessible :title, :body
protected
def generate_permalink
self.permalink = title.to_permalink
end
end
require 'spec_helper'
describe Page do
describe "permalink"
it "must derivate from title" do
subject.title = subject.body = "Testing the Permalink"
subject.save!
subject.permalink.should == "testing-the-permalink"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment