-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nick Flückiger
authored
May 7, 2021
1 parent
cdecf6b
commit 3823bee
Showing
13 changed files
with
266 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
gem 'slim-rails' | ||
gem 'simplecov', '~> 0.21.2', require: false | ||
gem "factory_bot_rails" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This will guess the User class | ||
FactoryBot.define do | ||
factory :timer_session do | ||
timer_start { Time.zone.now - 1.hour } | ||
timer_end { Time.zone.now } | ||
comments { 'Working on tickets!' } | ||
user { } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
# Load the Redmine helper | ||
require File.expand_path("#{File.dirname(__FILE__)}/../../../test/test_helper") | ||
|
||
require 'simplecov' | ||
require 'factory_bot_rails' | ||
|
||
if Dir.pwd.match(/plugins\/redmine_tracky/) | ||
covdir = 'coverage' | ||
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter | ||
else | ||
covdir = 'plugins/redmine_tracky/coverage' | ||
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([SimpleCov::Formatter::HTMLFormatter]) | ||
end | ||
|
||
SimpleCov.coverage_dir(covdir) | ||
SimpleCov.coverage_dir('coverage/redmine_tracky') | ||
SimpleCov.start 'rails' do | ||
add_filter do |source_file| | ||
# only show files belonging to planner, except init.rb which is not fully testable | ||
source_file.filename.match(/redmine_tracky/).nil? || | ||
!source_file.filename.match(/redmine_tracky\/init.rb/).nil? | ||
!source_file.filename.include?('plugins/redmine_tracky') || !source_file.filename.end_with?('.rb') | ||
end | ||
end | ||
|
||
SimpleCov.minimum_coverage 100 | ||
|
||
# SimpleCov.minimum_coverage 100 | ||
FactoryBot.definition_file_paths = [File.expand_path('../factories', __FILE__)] | ||
FactoryBot.find_definitions | ||
|
||
require File.expand_path("#{File.dirname(__FILE__)}/../../../test/test_helper") | ||
|
||
class ActiveSupport::TestCase | ||
include FactoryBot::Syntax::Methods | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require File.expand_path('../test_helper', __dir__) | ||
|
||
class IssueConnectorTest < ActiveSupport::TestCase | ||
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, | ||
:groups_users, | ||
:trackers, :projects_trackers, | ||
:enabled_modules, | ||
:versions, | ||
:issue_statuses, :issue_categories, :issue_relations, :workflows, | ||
:enumerations, | ||
:issues, :journals, :journal_details, | ||
:watchers, | ||
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, | ||
:time_entries | ||
|
||
setup do | ||
status = IssueStatus.find(1) | ||
role = Role.find(1) | ||
tracker = Tracker.find(1) | ||
user = User.find(2) | ||
@issue = Issue.generate!(:tracker => tracker, :status => status, | ||
:project_id => 1, :author_id => 1) | ||
end | ||
|
||
test 'successful creation' do | ||
timer_session = FactoryBot.create(:timer_session, | ||
user: User.find(2)) | ||
IssueConnector.new([@issue.id.to_s], timer_session).run | ||
assert_equal TimerSessionIssue.count, 1 | ||
assert_equal TimerSessionIssue.first.issue_id, @issue.id | ||
assert_equal TimerSessionIssue.first.timer_session_id, timer_session.id | ||
end | ||
|
||
test 'failure on creation' do | ||
timer_session = FactoryBot.create(:timer_session, | ||
user: User.find(2)) | ||
issue_connector = IssueConnector.new([(@issue.id + 1).to_s], timer_session) | ||
issue_connector.run | ||
assert_equal TimerSessionIssue.count, 0 | ||
assert_equal issue_connector.errors.count, 1 | ||
assert_equal issue_connector.errors, [{ invalid_issue_id: @issue.id + 1 }] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require File.expand_path('../test_helper', __dir__) | ||
|
||
class PermissionManagerTest < ActiveSupport::TestCase | ||
test 'can? - default' do | ||
assert_equal PermissionManager.new.can?(:edit, :timer_sessions), false | ||
end | ||
|
||
test 'cannot? - default' do | ||
assert_equal PermissionManager.new.cannot?(:edit, :timer_sessions), true | ||
end | ||
|
||
test 'forbidden_to_access_operation' do | ||
assert_equal PermissionManager.new.forbidden_to_access_operation, I18n.t('timer_sessions.permissions.not_allowed') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require File.expand_path('../test_helper', __dir__) | ||
|
||
class SessionCreatorTest < ActiveSupport::TestCase | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require File.expand_path('../test_helper', __dir__) | ||
|
||
class SettingsManagerTest < ActiveSupport::TestCase | ||
|
||
test '#rounding_for_displayed_hours - default' do | ||
assert_equal SettingsManager.rounding_for_displayed_hours, 2 | ||
end | ||
|
||
test '#max_hours_recorded_per_day - default' do | ||
assert_equal SettingsManager.max_hours_recorded_per_day, 24 | ||
end | ||
|
||
test '#max_hours_recorded_per_session - default' do | ||
assert_equal SettingsManager.max_hours_recorded_per_session, 24 | ||
end | ||
|
||
test '#visible_hints - default' do | ||
assert_equal SettingsManager.visible_hints, true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require File.expand_path('../test_helper', __dir__) | ||
|
||
class TimeRebalancerTest < ActiveSupport::TestCase | ||
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, | ||
:groups_users, | ||
:trackers, :projects_trackers, | ||
:enabled_modules, | ||
:versions, | ||
:issue_statuses, :issue_categories, :issue_relations, :workflows, | ||
:enumerations, | ||
:issues, :journals, :journal_details, | ||
:watchers, | ||
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, | ||
:time_entries | ||
|
||
setup do | ||
@issue = Issue.find(1) | ||
@timer_session = FactoryBot.create(:timer_session, | ||
user: User.find(2)) | ||
TimerSessionIssue.create!( | ||
issue_id: @issue.id, | ||
timer_session_id: @timer_session.id | ||
) | ||
|
||
TimerSessionTimeEntry.create!( | ||
time_entry_id: TimeEntry.find(1).id, | ||
timer_session_id: @timer_session.id | ||
) | ||
@timer_session.reload | ||
end | ||
|
||
test '#rebalance_entries - issues changed' do | ||
TimeRebalancer.new([Issue.find(2).id], @timer_session).rebalance_entries | ||
@timer_session.reload | ||
assert_equal 1, TimerSessionIssue.count | ||
assert_equal [2], @timer_session.issue_ids | ||
end | ||
|
||
test '#rebalance_entries - issues not changed - times changed' do | ||
@timer_session.update(timer_start: Time.zone.now - 2.hours) | ||
timer_before_change = @timer_session.time_entries.first.hours | ||
TimeRebalancer.new(@timer_session.issue_ids, @timer_session).rebalance_entries | ||
|
||
assert_equal timer_before_change + 1, TimeEntry.find( | ||
@timer_session.time_entries.first.id | ||
).hours | ||
end | ||
|
||
test '#rebalance_entries - issues not changed - comments changed' do | ||
@timer_session.update(comments: "Different comment") | ||
TimeRebalancer.new(@timer_session.issue_ids, @timer_session).rebalance_entries | ||
|
||
assert_equal 'Different comment', TimeEntry.find( | ||
@timer_session.time_entries.first.id | ||
).comments | ||
end | ||
|
||
test '#force_rebalance' do | ||
issue_id = @issue.id | ||
assert_equal 1, TimerSessionTimeEntry.count | ||
assert_equal 1, TimerSessionIssue.count | ||
|
||
TimeRebalancer.new([@issue.id.to_s], @timer_session).force_rebalance | ||
|
||
assert_equal 1, TimerSessionTimeEntry.count | ||
assert_equal 1, TimerSessionIssue.count | ||
assert_equal issue_id, @timer_session.issues.first.id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require File.expand_path('../test_helper', __dir__) | ||
|
||
class TimeSplitterTest < ActiveSupport::TestCase | ||
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, | ||
:groups_users, | ||
:trackers, :projects_trackers, | ||
:enabled_modules, | ||
:versions, | ||
:issue_statuses, :issue_categories, :issue_relations, :workflows, | ||
:enumerations, | ||
:issues, :journals, :journal_details, | ||
:watchers, | ||
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values | ||
setup do | ||
@issue = Issue.find(1) | ||
@timer_session = FactoryBot.create(:timer_session, | ||
user: User.find(2)) | ||
TimerSessionIssue.create!( | ||
issue_id: @issue.id, | ||
timer_session_id: @timer_session.id | ||
) | ||
end | ||
|
||
test 'creates time entry on one issue' do | ||
assert_equal @timer_session.issues.count, 1 | ||
|
||
time_splitter = TimeSplitter.new(@timer_session) | ||
time_splitter.create_time_entries | ||
assert_equal TimerSessionTimeEntry.count, 1 | ||
end | ||
|
||
test 'splits time entries on multiple issues' do | ||
TimerSessionIssue.create!( | ||
issue_id: Issue.find(2).id, | ||
timer_session_id: @timer_session.id | ||
) | ||
assert_equal @timer_session.issues.count, 2 | ||
|
||
time_splitter = TimeSplitter.new(@timer_session) | ||
time_splitter.create_time_entries | ||
assert_equal 2, TimerSessionTimeEntry.count | ||
assert_equal 0.5, TimeEntry.last.hours | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require File.expand_path('../test_helper', __dir__) | ||
|
||
class TimerEntityCleanerTest < ActiveSupport::TestCase | ||
fixtures :projects, :users, :email_addresses, :user_preferences, :members, :member_roles, :roles, | ||
:groups_users, | ||
:trackers, :projects_trackers, | ||
:enabled_modules, | ||
:versions, | ||
:issue_statuses, :issue_categories, :issue_relations, :workflows, | ||
:enumerations, | ||
:issues, :journals, :journal_details, | ||
:watchers, | ||
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, | ||
:time_entries | ||
|
||
setup do | ||
@issue = Issue.find(1) | ||
@timer_session = FactoryBot.create(:timer_session, | ||
user: User.find(2)) | ||
TimerSessionIssue.create!( | ||
issue_id: @issue.id, | ||
timer_session_id: @timer_session.id | ||
) | ||
|
||
TimerSessionTimeEntry.create!( | ||
time_entry_id: TimeEntry.find(1), | ||
timer_session_id: @timer_session.id | ||
) | ||
end | ||
|
||
test 'removes time entries and connections to issue' do | ||
assert_equal 1, TimerSessionTimeEntry.count | ||
assert_equal 1, TimerSessionIssue.count | ||
TimerEntityCleaner.new(@timer_session).run | ||
assert_equal 0, TimerSessionTimeEntry.count | ||
assert_equal 0, TimerSessionIssue.count | ||
end | ||
end |