Created
May 18, 2010 00:08
-
-
Save azisaka/404412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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