couchrest_model/spec/fixtures/more/article.rb
Matt Aimonetti 80317f31a5 fixed the uuid count for the latest version of couchdb
also avoided CONSTANTS warnings, cleaned up the attachment specs, added missing fixtures
2009-02-25 00:22:11 -08:00

34 lines
798 B
Ruby

class Article < CouchRest::ExtendedDocument
use_database TEST_SERVER.default_database
unique_id :slug
view_by :date, :descending => true
view_by :user_id, :date
view_by :tags,
:map =>
"function(doc) {
if (doc['couchrest-type'] == 'Article' && doc.tags) {
doc.tags.forEach(function(tag){
emit(tag, 1);
});
}
}",
:reduce =>
"function(keys, values, rereduce) {
return sum(values);
}"
property :date
property :slug, :read_only => true
property :title
property :tags
timestamps!
save_callback :before, :generate_slug_from_title
def generate_slug_from_title
self['slug'] = title.downcase.gsub(/[^a-z0-9]/,'-').squeeze('-').gsub(/^\-|\-$/,'') if new_document?
end
end