use new model to handle updating of recurring todos

This commit is contained in:
Reinier Balt 2014-02-03 10:48:21 +01:00
parent 00af159be7
commit c2c67f1640
12 changed files with 166 additions and 104 deletions

View file

@ -68,7 +68,7 @@ module RecurringTodos
assert_equal "", builder.attributes[:tag_list]
end
def test_tags_should_be_saved
def test_tags_should_be_saved_on_create_and_update
attributes = {
'recurring_period' => "daily",
'description' => "test",
@ -91,6 +91,14 @@ module RecurringTodos
assert !builder.tag_list.present?, "tag list should not be present"
assert builder.save, "it should be saved"
assert_equal "", builder.saved_recurring_todo.tag_list, "tag list should be empty"
# tags should be updated
rt = builder.saved_recurring_todo
attributes['tag_list'] = "bar, foo"
updater = RecurringTodosBuilder.new(@admin, attributes)
updater.update(rt)
rt.reload
assert_equal "bar, foo", rt.tag_list
end

View file

@ -102,7 +102,7 @@ module RecurringTodos
end
def test_project_is_optional
builder = RecurringTodosBuilder.new(@admin, {
attributes = {
'recurring_period' => "daily",
'description' => "test",
'context_name' => "my new context",
@ -110,13 +110,42 @@ module RecurringTodos
'recurring_target' => 'show_from_date',
'show_always' => true,
'start_from' => '01/01/01',
'ends_on' => 'no_end_date'})
'ends_on' => 'no_end_date'}
builder = RecurringTodosBuilder.new(@admin, attributes)
assert_nil builder.project, "project should not exist"
builder.save
assert_nil builder.saved_recurring_todo.project
end
def test_builder_can_update_description
attributes = {
'recurring_period' => "daily",
'description' => "test",
'context_name' => "my new context",
'daily_selector' => 'daily_every_work_day',
'recurring_target' => 'show_from_date',
'show_always' => true,
'start_from' => '01/01/01',
'ends_on' => 'no_end_date'}
builder = RecurringTodosBuilder.new(@admin, attributes)
builder.save
rt = builder.saved_recurring_todo
assert_equal "test", rt.description
attributes['description'] = 'updated'
updater = RecurringTodosBuilder.new(@admin, attributes)
updater.update(rt)
rt.reload
assert_equal rt.id, builder.saved_recurring_todo.id
assert_equal "updated", rt.description
end
end
end

View file

@ -30,6 +30,19 @@ module RecurringTodos
assert_equal "a repeating todo", result[:description], "description should be preserved"
end
def test_attributes_to_filter
attributes = {
'recurring_period' => 'weekly',
'description' => 'a repeating todo', # generic
'weekly_return_monday' => 'm', # weekly specific
}
w = WeeklyRecurringTodosBuilder.new(@admin, attributes)
assert_equal 9, w.attributes_to_filter.size
assert w.attributes_to_filter.include?('weekly_selector'), "attributes_to_filter should return static attribute weekly_selector"
assert w.attributes_to_filter.include?('weekly_return_monday'), "attributes_to_filter should return generated weekly_return_xyz"
end
end
end