Skip to content

Commit

Permalink
Adds permalink field to category creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric de Villamil committed Mar 5, 2012
1 parent cd2e895 commit 564c0a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def to_param

protected

before_save :set_defaults
before_save :set_permalink

def set_defaults
self.permalink ||= self.name.to_permalink
def set_permalink
self.permalink = self.name.to_permalink if self.permalink.nil? or self.permalink.empty?
end

validates_presence_of :name
Expand Down
7 changes: 7 additions & 0 deletions app/views/admin/categories/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<%= text_field :category, :keywords, :class => 'large' %>
</div>
</div>
<div class='clearfix'>
<label for="category_permalink"><%= _("Permalink") %></label>
<div class='input'>
<%= text_field :category, :permalink, :class => 'large' %>
<span class='help-block'><%= _("Your category slug. Leave empty if you don't know what to put here") %></span>
</div>
</div>
<div class='clearfix'>
<label for="category_description"><%= _("Description") %></label>
<div class='input'>
Expand Down
13 changes: 13 additions & 0 deletions spec/models/category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
c.articles.size.should == 2
c.published_articles.size.should == 1
end

it "empty permalink should be converted" do
Factory(:blog)
c = Category.create(:name => "test 1")
c.permalink.should == "test-1"
end

it "category with permalink should not have permalink generated" do
Factory(:blog)
c = Category.create(:name => "Test 2", :permalink => "yeah-nice-one")
c.permalink.should == "yeah-nice-one"
end

end

describe Category do
Expand Down

0 comments on commit 564c0a6

Please sign in to comment.