Skip to content

Commit c3411a5

Browse files
author
travis
committed
Added testing for Setup Issue Show process
1 parent ae7e65f commit c3411a5

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

lib/pathname_redmine_version.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Pathname
2+
def redmine_version
3+
self.basename.to_s[0..4]
4+
end
5+
end

lib/setup_issue_show.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
require 'redmine'
22
require 'fileutils'
3+
require 'pathname_redmine_version'
34

45
class SetupIssueShow
5-
attr_reader :issues_directoy, :current_version
6+
attr_accessor :issues_directory
7+
attr_accessor :current_version
68

79
def initialize
810
@issues_directory = Pathname.new( Redmine::Plugin.registered_plugins[:redmine_spent_time_in_issue_description].directory ).join("app","views","issues")
@@ -15,7 +17,9 @@ def show_file
1517
version = file.to_s[0..4]
1618
version == @current_version || version < @current_version
1719
end
18-
@issues_directory.join file
20+
21+
show_file = @issues_directory.join file unless file.nil?
22+
1923
end
2024

2125
def replace

test/unit/setup_issue_show_test.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require File.expand_path('../../test_helper', __FILE__)
2+
3+
class SetupIssueShowTest < ActiveSupport::TestCase
4+
5+
def setup
6+
@SetupIssueShow = SetupIssueShow.new
7+
end
8+
9+
def test_start
10+
assert_equal 'test', 'test'
11+
end
12+
13+
def test_version_detection
14+
assert_equal @SetupIssueShow.current_version.class, String
15+
assert_not_nil @SetupIssueShow.current_version[/\d+\.\d+\.\d+/]
16+
end
17+
18+
def test_show_file
19+
assert_equal @SetupIssueShow.show_file.class, Pathname
20+
end
21+
22+
def test_correct_file_found
23+
24+
@SetupIssueShow.current_version="2.3.1"
25+
assert_equal "2.3.1", @SetupIssueShow.show_file.redmine_version, "Did not find the exact match."
26+
27+
@SetupIssueShow.current_version="2.3.2"
28+
assert_equal "2.3.1", @SetupIssueShow.show_file.redmine_version, "Did not find the most recent match."
29+
30+
@SetupIssueShow.current_version="0.0.0"
31+
assert_nil @SetupIssueShow.show_file
32+
33+
end
34+
35+
end

0 commit comments

Comments
 (0)