mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-06 01:08:50 +01:00
move mapping of form attributes to model attributes from pattern to builder to make
pattern independent of form
This commit is contained in:
parent
1f36c27af8
commit
776a046465
22 changed files with 463 additions and 446 deletions
|
|
@ -24,13 +24,65 @@ module RecurringTodos
|
|||
}
|
||||
|
||||
result = RecurringTodosBuilder.new(@admin, attributes).attributes
|
||||
|
||||
|
||||
assert_nil result['bla_bla'], "bla_bla should be filtered"
|
||||
assert_nil result[:bla_bla], "bla_bla should be filtered"
|
||||
assert_equal '1', result[:every_other2], "yearly attributes should be preserved"
|
||||
assert_equal "a repeating todo", result[:description], "description should be preserved"
|
||||
end
|
||||
|
||||
def test_valid_selector
|
||||
attributes = {
|
||||
'recurring_period' => 'yearly'
|
||||
}
|
||||
|
||||
# should not raise
|
||||
%w{yearly_every_x_day yearly_every_xth_day}.each do |selector|
|
||||
attributes['yearly_selector'] = selector
|
||||
YearlyRecurringTodosBuilder.new(@admin, attributes)
|
||||
end
|
||||
|
||||
# should raise
|
||||
attributes = {
|
||||
'recurring_period' => 'yearly',
|
||||
'yearly_selector' => 'wrong value'
|
||||
}
|
||||
|
||||
# should raise
|
||||
assert_raise(Exception, "should have exception since yearly_selector has wrong value"){ YearlyRecurringTodosBuilder.new(@admin, attributes) }
|
||||
end
|
||||
|
||||
def test_mapping_of_attributes
|
||||
attributes = {
|
||||
'recurring_period' => 'yearly',
|
||||
'description' => 'a repeating todo', # generic
|
||||
'yearly_selector' => 'yearly_every_x_day', # yearly specific
|
||||
'yearly_every_x_day' => '5', # mapped to every_other1
|
||||
'yearly_every_xth_day' => '7', # mapped to every_other3
|
||||
'yearly_day_of_week' => '3', # mapped to every_count
|
||||
'yearly_month_of_year' => '1', # mapped to evert_other2 because yearly_selector is yearly_every_x_day
|
||||
'yearly_month_of_year2' => '2' # ignored because yearly_selector is yearly_every_x_day
|
||||
}
|
||||
|
||||
pattern = YearlyRecurringTodosBuilder.new(@admin, attributes)
|
||||
|
||||
assert_equal '5', pattern.mapped_attributes[:every_other1], "every_other1 should be set to yearly_every_x_day"
|
||||
assert_equal '1', pattern.mapped_attributes[:every_other2], "every_other2 should be set to yearly_month_of_year because selector is yearly_every_x_day"
|
||||
assert_equal '7', pattern.mapped_attributes[:every_other3], "every_other3 should be set to yearly_every_xth_day"
|
||||
assert_equal '3', pattern.mapped_attributes[:every_count], "every_count should be set to yearly_day_of_week"
|
||||
|
||||
attributes = {
|
||||
'recurring_period' => 'yearly',
|
||||
'description' => 'a repeating todo', # generic
|
||||
'yearly_selector' => 'yearly_every_xth_day', # daily specific --> mapped to only_work_days=false
|
||||
'yearly_month_of_year' => '1', # ignored because yearly_selector is yearly_every_xth_day
|
||||
'yearly_month_of_year2' => '2' # mapped to evert_other2 because yearly_selector is yearly_every_xth_day
|
||||
}
|
||||
|
||||
pattern = YearlyRecurringTodosBuilder.new(@admin, attributes)
|
||||
assert_equal '2', pattern.mapped_attributes[:every_other2], "every_other2 should be set to yearly_month_of_year2 because selector is yearly_every_xth_day"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue