Skip to content

Instantly share code, notes, and snippets.

@roidrage
Created September 26, 2008 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roidrage/13203 to your computer and use it in GitHub Desktop.
Save roidrage/13203 to your computer and use it in GitHub Desktop.
Code of the day
def test_permalinks
# note that this test assumes you haven't changed the `extra_word` argument of Post.to_permalink
# from the default 'again'... if you have, change the equality assertions below appropriately
p = Post.new
p.title = 'test post'
p.body_raw = "this is my post content and it's a test"
assert p.save
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'this_is_my_post_content' : 'test_post'), p.permalink
# cleaning HTML...
p = Post.new
p.title = 'testing <b>post</b>'
p.body_raw = "here's a strange <a href=\"test.html\">permalink</a> because it has a link"
assert p.save
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'heres_a_strange_permalink_because' : 'testing_post'), p.permalink
# duplicates?
p = Post.new
p.title = 'tested post'
p.body_raw = "here's my test permalink"
assert p.save
n = Post.new
n.title = 'tested post'
n.body_raw = "here's my test permalink"
assert n.save
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'heres_my_test_permalink' : 'tested_post'), p.permalink
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'heres_my_test_permalink_again' : 'tested_post_again'), n.permalink
# HTML + duplicates?
p = Post.new
p.title = 'tester <b>post</b>'
p.body_raw = "here's another strange <a href=\"test.html\">permalink</a> because it has a link"
assert p.save
n = Post.new
n.title = 'tester <b>post</b>'
n.body_raw = "here's another strange <a href=\"test.html\">permalink</a> because it has a link"
assert n.save
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'heres_another_strange_permalink_because' : 'tester_post'), p.permalink
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'heres_another_strange_permalink_because_it' : 'tester_post_again'), n.permalink
# short content + duplicates + duplicates
p = Post.new
p.title = 'one more test'
p.body_raw = 'hi'
assert p.save
n = Post.new
n.title = 'one more test'
n.body_raw = 'hi'
assert n.save
a = Post.new
a.title = 'one more test'
a.body_raw = 'hi'
a.save
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'hi' : 'one_more_test'), p.permalink
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'hi_again' : 'one_more_test_again'), n.permalink
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'hi_again_again' : 'one_more_test_again_again'), a.permalink
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment