2014-05-16 18:03:13 -04:00
|
|
|
require 'test_helper'
|
2014-01-27 16:42:54 +01:00
|
|
|
|
|
|
|
|
module RecurringTodos
|
|
|
|
|
|
|
|
|
|
class DailyRecurringTodosBuilderTest < ActiveSupport::TestCase
|
|
|
|
|
fixtures :users
|
|
|
|
|
|
|
|
|
|
def setup
|
|
|
|
|
@admin = users(:admin_user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_pattern_is_daily
|
|
|
|
|
object = RecurringTodosBuilder.new(@admin, { 'recurring_period' => 'daily', 'daily_selector' => 'daily_every_x_day' })
|
|
|
|
|
assert object.builder.is_a? DailyRecurringTodosBuilder
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_filter_non_daily_attributes
|
|
|
|
|
attributes = {
|
|
|
|
|
'recurring_period' => 'daily',
|
2015-02-10 16:25:27 +01:00
|
|
|
'description' => 'a recurring todo', # generic
|
2014-01-27 16:42:54 +01:00
|
|
|
'daily_selector' => 'daily_every_x_day', # daily specific
|
|
|
|
|
'bla_bla' => 'go away' # irrelevant for daily
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = RecurringTodosBuilder.new(@admin, attributes).attributes
|
|
|
|
|
|
2014-02-09 21:48:52 +01:00
|
|
|
assert_nil result.get('bla_bla'), "bla_bla should be filtered"
|
|
|
|
|
assert_nil result.get(:bla_bla), "bla_bla should be filtered"
|
|
|
|
|
assert_equal false, result.get(:only_work_days), "daily attributes should be preserved"
|
2015-02-10 16:25:27 +01:00
|
|
|
assert_equal "a recurring todo", result.get(:description), "description should be preserved"
|
2014-01-27 16:42:54 +01:00
|
|
|
end
|
|
|
|
|
|
2014-02-07 22:55:52 +01:00
|
|
|
def test_valid_selector
|
2014-02-09 21:48:52 +01:00
|
|
|
attributes = Tracks::AttributeHandler.new(@admin, {
|
2014-02-07 22:55:52 +01:00
|
|
|
'recurring_period' => 'daily'
|
2014-02-09 21:48:52 +01:00
|
|
|
})
|
2014-02-07 22:55:52 +01:00
|
|
|
|
|
|
|
|
# should not raise
|
|
|
|
|
%w{daily_every_x_day daily_every_work_day}.each do |selector|
|
2014-02-09 21:48:52 +01:00
|
|
|
attributes.set('daily_selector', selector)
|
2014-02-07 22:55:52 +01:00
|
|
|
DailyRecurringTodosBuilder.new(@admin, attributes)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# should raise
|
2014-02-09 21:48:52 +01:00
|
|
|
attributes = Tracks::AttributeHandler.new(@admin, {
|
2014-02-07 22:55:52 +01:00
|
|
|
'recurring_period' => 'daily',
|
|
|
|
|
'daily_selector' => 'wrong value'
|
2014-02-09 21:48:52 +01:00
|
|
|
})
|
2014-02-07 22:55:52 +01:00
|
|
|
|
|
|
|
|
# should raise
|
|
|
|
|
assert_raise(Exception, "should have exception since daily_selector has wrong value"){ DailyRecurringTodosBuilder.new(@admin, attributes) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_mapping_of_attributes
|
2014-02-09 21:48:52 +01:00
|
|
|
attributes = Tracks::AttributeHandler.new(@admin, {
|
2014-02-07 22:55:52 +01:00
|
|
|
'recurring_period' => 'daily',
|
2015-02-10 16:25:27 +01:00
|
|
|
'description' => 'a recurring todo', # generic
|
2014-02-07 22:55:52 +01:00
|
|
|
'daily_selector' => 'daily_every_x_day', # daily specific --> mapped to only_work_days=false
|
|
|
|
|
'daily_every_x_days' => '5' # mapped to every_other1
|
2014-02-09 21:48:52 +01:00
|
|
|
})
|
2014-02-07 22:55:52 +01:00
|
|
|
|
|
|
|
|
pattern = DailyRecurringTodosBuilder.new(@admin, attributes)
|
|
|
|
|
|
2014-02-09 21:48:52 +01:00
|
|
|
assert_equal '5', pattern.mapped_attributes.get(:every_other1), "every_other1 should be set to daily_every_x_days"
|
|
|
|
|
assert_equal false, pattern.mapped_attributes.get(:only_work_days), "only_work_days should be set to false for daily_every_x_day"
|
2014-02-07 22:55:52 +01:00
|
|
|
|
2014-02-09 21:48:52 +01:00
|
|
|
attributes = Tracks::AttributeHandler.new(@admin, {
|
2014-02-07 22:55:52 +01:00
|
|
|
'recurring_period' => 'daily',
|
2015-02-10 16:25:27 +01:00
|
|
|
'description' => 'a recurring todo', # generic
|
2014-02-07 22:55:52 +01:00
|
|
|
'daily_selector' => 'daily_every_work_day', # daily specific --> mapped to only_work_days=true
|
2014-02-09 21:48:52 +01:00
|
|
|
})
|
2014-02-07 22:55:52 +01:00
|
|
|
|
|
|
|
|
pattern = DailyRecurringTodosBuilder.new(@admin, attributes)
|
2014-02-09 21:48:52 +01:00
|
|
|
assert_equal true, pattern.mapped_attributes.get(:only_work_days)
|
2014-02-07 22:55:52 +01:00
|
|
|
end
|
|
|
|
|
|
2014-01-27 16:42:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|