mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-16 12:40:07 -04:00
Use username-yyyymmdd-subject-line slugs.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
class Update < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :subject, use: :slugged
|
||||
friendly_id :user_date_subject, use: :slugged
|
||||
attr_accessible :body, :subject, :user_id
|
||||
belongs_to :user
|
||||
default_scope order("created_at desc")
|
||||
|
||||
def to_param
|
||||
"#{created_at.year}/#{created_at.month}/#{created_at.day}/#{slug}"
|
||||
def user_date_subject
|
||||
# slugs are created before created_at is set
|
||||
time = created_at || Time.now
|
||||
"#{user.username} #{time.strftime("%Y%m%d")} #{subject}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,9 +6,6 @@ Growstuff::Application.routes.draw do
|
||||
resources :members
|
||||
devise_for :users
|
||||
|
||||
match "/updates/:year/:month/:day/:id", :to => "updates#show"
|
||||
match "/updates/:id", :to => "updates#show"
|
||||
|
||||
get "home/index"
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
|
||||
@@ -66,16 +66,6 @@ describe UpdatesController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET show" do
|
||||
it "assigns the requested update as @update fetching with dates" do
|
||||
update = Update.create! valid_attributes
|
||||
date = update.created_at
|
||||
get :show, {:year => date.year, :month => date.month, :day => date.day,
|
||||
:id => update.slug}
|
||||
assigns(:update).should eq(update)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
it "assigns a new update as @update" do
|
||||
get :new, {}
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Update do
|
||||
before(:each) do
|
||||
user = User.create! :username => "test", :password => "password",
|
||||
:email => "test@example.com", :tos_agreement => true
|
||||
user.confirm!
|
||||
@id = user.id
|
||||
end
|
||||
|
||||
it "should be sorted in reverse order" do
|
||||
Update.create! :subject => "first entry", :body => "blah", :user_id => 1
|
||||
Update.create! :subject => "second entry", :body => "blah", :user_id => 1
|
||||
Update.create! :subject => "first entry", :body => "blah", :user_id => @id
|
||||
Update.create! :subject => "second entry", :body => "blah", :user_id => @id
|
||||
Update.first.subject.should == "second entry"
|
||||
end
|
||||
|
||||
it "should have a slug" do
|
||||
update = Update.create! :subject => "slugs are nasty",
|
||||
:body => "They leave slime everywhere", :user_id => 1
|
||||
update.slug.should == "slugs-are-nasty"
|
||||
:body => "They leave slime everywhere", :user_id => @id
|
||||
time = update.created_at
|
||||
datestr = time.strftime("%Y%m%d")
|
||||
datestr.length.should == 8
|
||||
update.slug.should == "test-#{datestr}-slugs-are-nasty"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user