mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
Start major refactoring of recurring_todos. Started with creating new recurring todos.
All current and new tests pass
This commit is contained in:
parent
8e13059df1
commit
78c07d52b7
26 changed files with 1218 additions and 32 deletions
52
test/models/recurring_todos/weekly_repeat_pattern_test.rb
Normal file
52
test/models/recurring_todos/weekly_repeat_pattern_test.rb
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
require_relative '../../test_helper'
|
||||
|
||||
module RecurringTodos
|
||||
|
||||
class WeeklyRepeatPatternTest < ActiveSupport::TestCase
|
||||
fixtures :users
|
||||
|
||||
def setup
|
||||
@admin = users(:admin_user)
|
||||
end
|
||||
|
||||
def test_mapping_of_attributes
|
||||
attributes = {
|
||||
'recurring_period' => 'weekly',
|
||||
'description' => 'a repeating todo', # generic
|
||||
'weekly_every_x_week' => '5', # mapped to every_other1
|
||||
'weekly_return_monday' => 'm'
|
||||
}
|
||||
|
||||
pattern = WeeklyRepeatPattern.new(@admin, attributes)
|
||||
|
||||
assert_equal '5', pattern.mapped_attributes[:every_other1], "every_other1 should be set to weekly_every_x_week"
|
||||
assert_equal ' m ', pattern.mapped_attributes[:every_day], "weekly_return_<weekday> should be mapped to :every_day in format 'smtwtfs'"
|
||||
end
|
||||
|
||||
def test_map_day
|
||||
attributes = {
|
||||
'recurring_period' => 'weekly',
|
||||
'description' => 'a repeating todo', # generic
|
||||
'weekly_every_x_week' => '5' # mapped to every_other1
|
||||
}
|
||||
|
||||
pattern = WeeklyRepeatPattern.new(@admin, attributes)
|
||||
assert_equal ' ', pattern.mapped_attributes[:every_day], "all days should be empty in :every_day"
|
||||
|
||||
# add all days
|
||||
{ sunday: 's', monday: 'm', tuesday: 't', wednesday: 'w', thursday: 't', friday: 'f', saturday: 's' }.each do |day, short|
|
||||
attributes["weekly_return_#{day}"] = short
|
||||
end
|
||||
|
||||
pattern = WeeklyRepeatPattern.new(@admin, attributes)
|
||||
assert_equal 'smtwtfs', pattern.mapped_attributes[:every_day], "all days should be filled in :every_day"
|
||||
|
||||
# remove wednesday
|
||||
attributes = attributes.except('weekly_return_wednesday')
|
||||
pattern = WeeklyRepeatPattern.new(@admin, attributes)
|
||||
assert_equal 'smt tfs', pattern.mapped_attributes[:every_day], "only wednesday should be empty in :every_day"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue