Skip to content

Commit 1fb3a55

Browse files
committed
oops forgot to actually check for slug collisions
1 parent a80f076 commit 1fb3a55

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

app/models/program.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Program
1313
def make_slug
1414
if slug.blank?
1515
all_slugs = Program.where(:author_username => author_username).map(&:slug)
16-
self.slug = Sluggifier.generate(title)
16+
self.slug = Sluggifier.generate(title, all_slugs)
1717
end
1818
end
1919

spec/unit/program_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
3+
describe Program do
4+
let(:prog) { Program.create(author_username: 'tester', title: 'test title')}
5+
it "sets the slug" do
6+
prog.slug.should == 'test-title'
7+
end
8+
9+
it "makes unique slugs" do
10+
first_prog = Program.create(author_username: 'tester',
11+
title: 'test title #2',
12+
slug: 'test-title')
13+
prog.slug.should_not == first_prog.slug
14+
end
15+
end

spec/unit/sluggifier_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
it "makes a slug from a title" do
99
Sluggifier.generate('test a slug').should == 'test-a-slug'
1010
end
11-
1211

1312
context "doesn't allow multiple slugs to be the same" do
1413
let(:all_slugs) { ['test'] }

0 commit comments

Comments
 (0)