0
+require File.expand_path(File.dirname(__FILE__) + "/test_helper")
0
+require "acts_as_url_param_base"
0
+class ActsAsUrlParamTest < Test::Unit::TestCase
0
+ def test_should_set_url_name_on_create
0
+ assert !ActsAsUrlParam::Item.create(:name => 'test a url param').url_name.blank?
0
+ def test_should_not_set_url_name_if_already_set
0
+ item = ActsAsUrlParam::Item.create(:name => 'test a url param', :url_name => 'test-this')
0
+ assert_equal('test-this', item.to_param)
0
+ def test_should_make_custom_urls_safe
0
+ ActsAsUrlParam::Item.any_instance.expects(:url_safe)
0
+ ActsAsUrlParam::Item.new(:url_name => 'make me safe')
0
+ def test_should_use_correct_column_to_create_url_name
0
+ assert ActsAsUrlParam::User.create(:name => 'john doe', :login => 'jdog').url_name =~ /jdog/
0
+ def test_should_be_invalid_without_content_to_create_url
0
+ user = ActsAsUrlParam::User.create(:name => 'john doe')
0
+ def test_should_raise_error_without_from_column
0
+ assert_raises ArgumentError do
0
+ acts_as_url_name_model(nil, :from => :no_name)
0
+ def test_should_raise_error_without_url_name_column
0
+ assert_raises ArgumentError do
0
+ acts_as_url_name_model(:no_url_name)
0
+ def test_should_check_if_url_param_available
0
+ ActsAsUrlParam::User.create(:login => 'tester')
0
+ assert !ActsAsUrlParam::User.url_param_available?('tester')
0
+ assert ActsAsUrlParam::User.url_param_available?('goodman')
0
+ def test_should_use_block_to_check_if_url_param_available
0
+ ActsAsUrlParam::Story.create(:title => 'new post')
0
+ assert !ActsAsUrlParam::BlogPost.url_param_available?('new post')
0
+ def test_should_use_block_to_compute_url_name
0
+ post = ActsAsUrlParam::BlogPost.new(:title => 'post')
0
+ assert_equal 'post', post.compute_url_param
0
+ story = ActsAsUrlParam::Story.create(:title => 'new post')
0
+ new_post = ActsAsUrlParam::BlogPost.new(:title => 'new post')
0
+ assert_not_equal new_post.compute_url_param, story.to_param
0
+ def test_should_compute_url_name
0
+ name = 'this is a url param'
0
+ item = ActsAsUrlParam::Item.new(:name => name)
0
+ assert !ActsAsUrlParam::Item.compute_url_param(name).blank?
0
+ assert_equal(item.compute_url_param, ActsAsUrlParam::Item.compute_url_param(name))
0
+ def test_should_update_url_name_on_custom_callback
0
+ author = ActsAsUrlParam::Author.create(:label => 'name of author')
0
+ author_url = author.to_param
0
+ author.update_attributes(:label => 'a new author')
0
+ assert_not_equal(author_url, author.to_param)
0
+ def test_should_not_update_url_name_by_default
0
+ item = ActsAsUrlParam::Item.create(:name => 'this is a url param')
0
+ item_url = item.to_param
0
+ item.update_attributes(:name => 'not updated')
0
+ assert_equal(item_url, item.to_param)
0
+ def test_should_work_with_sti
0
+ item = ActsAsUrlParam::Item.create(:name => 'an item')
0
+ book = ActsAsUrlParam::Book.create(:name => 'an item')
0
+ newspaper = ActsAsUrlParam::Newspaper.create(:name => 'an item')
0
+ assert_not_equal(item.to_param, book.to_param)
0
+ assert_equal(item.to_param, newspaper.to_param)
0
+ newspaper = ActsAsUrlParam::Newspaper.create(:name => 'another item')
0
+ book = ActsAsUrlParam::Book.create(:name => 'another item')
0
+ assert_equal(book.to_param, newspaper.to_param)
0
+ def test_should_use_method_for_url_from_if_exists
0
+ magazine = ActsAsUrlParam::Magazine.create()
0
+ assert !magazine.to_param.blank?
0
+ def acts_as_url_name_model(column = nil, options = {})
0
+ m = Class.new(ActiveRecord::Base)
0
+ acts_as_url_param column, options
0
+ acts_as_url_param options
0
\ No newline at end of file
Comments
No one has commented yet.