2011-05-31 23:07:20 +02:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2007-03-30 04:36:52 +00:00
|
|
|
|
2009-06-02 21:22:50 +02:00
|
|
|
class ContextTest < ActiveSupport::TestCase
|
2009-01-23 14:15:02 -05:00
|
|
|
fixtures :contexts, :todos, :recurring_todos, :users, :preferences
|
2007-03-30 04:36:52 +00:00
|
|
|
|
|
|
|
|
def setup
|
|
|
|
|
@agenda = contexts(:agenda)
|
|
|
|
|
@email = contexts(:email)
|
|
|
|
|
@library = contexts(:library)
|
|
|
|
|
end
|
|
|
|
|
|
2012-04-17 16:47:37 +02:00
|
|
|
def test_uses_acts_as_list
|
|
|
|
|
# only check that acts_as_list is present in the model
|
|
|
|
|
assert @agenda.respond_to?(:move_to_bottom)
|
|
|
|
|
end
|
|
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def test_validate_presence_of_name
|
|
|
|
|
@agenda.name = ""
|
|
|
|
|
assert !@agenda.save
|
|
|
|
|
assert_equal 1, @agenda.errors.count
|
2012-04-17 16:47:37 +02:00
|
|
|
assert_equal "context must have a name", @agenda.errors[:name][0]
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_validate_name_is_less_than_256
|
2012-04-17 16:47:37 +02:00
|
|
|
@agenda.name = generate_random_string(256)
|
2007-03-30 04:36:52 +00:00
|
|
|
assert !@agenda.save
|
|
|
|
|
assert_equal 1, @agenda.errors.count
|
2012-04-17 16:47:37 +02:00
|
|
|
assert_equal "context name must be less than 256 characters", @agenda.errors[:name][0]
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_validate_name_is_unique
|
|
|
|
|
newcontext = Context.new
|
|
|
|
|
newcontext.name = contexts(:agenda).name
|
|
|
|
|
newcontext.user_id = contexts(:agenda).user_id
|
|
|
|
|
assert !newcontext.save
|
|
|
|
|
assert_equal 1, newcontext.errors.count
|
2012-04-17 16:47:37 +02:00
|
|
|
assert_equal "already exists", newcontext.errors[:name][0]
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
2012-04-17 16:47:37 +02:00
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
def test_delete_context_deletes_todos_within_it
|
2008-10-14 22:49:17 +02:00
|
|
|
assert_equal 7, @agenda.todos.count
|
2007-03-30 04:36:52 +00:00
|
|
|
agenda_todo_ids = @agenda.todos.collect{|t| t.id }
|
|
|
|
|
@agenda.destroy
|
|
|
|
|
agenda_todo_ids.each do |todo_id|
|
|
|
|
|
assert !Todo.exists?(todo_id)
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-04-17 16:47:37 +02:00
|
|
|
|
2007-04-06 03:30:20 +00:00
|
|
|
def test_to_param_returns_id
|
|
|
|
|
assert_equal '1', @agenda.to_param
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_title_reader_returns_name
|
|
|
|
|
assert_equal @agenda.name, @agenda.title
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_hidden_attr_reader
|
|
|
|
|
assert !@agenda.hidden?
|
|
|
|
|
@agenda.hide = true
|
|
|
|
|
@agenda.save!
|
|
|
|
|
@agenda.reload
|
|
|
|
|
assert_equal true, @agenda.hidden?
|
|
|
|
|
end
|
|
|
|
|
|
2007-05-25 19:01:08 +00:00
|
|
|
def test_null_object
|
|
|
|
|
c = Context.null_object
|
|
|
|
|
assert c.nil?
|
|
|
|
|
assert_nil c.id
|
|
|
|
|
assert_equal '', c.name
|
|
|
|
|
end
|
|
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|