copyright 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/copyright.gemspec +1 -1
- data/lib/copyright_helper.rb +4 -6
- data/test/test_copyright.rb +24 -21
- data/test/test_helper.rb +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/copyright.gemspec
CHANGED
data/lib/copyright_helper.rb
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
# Adds a method for copyright period
|
4
4
|
# @author Takaaki Kato <takaaki.kato@gmail.com>
|
5
5
|
module CopyrightHelper
|
6
|
-
require 'date'
|
7
|
-
|
8
6
|
# Returns copyright period in years
|
9
7
|
# @example When the argument is the year of now
|
10
8
|
# copyright_years(2009) #=> "2009"
|
@@ -13,11 +11,11 @@ module CopyrightHelper
|
|
13
11
|
# @param [#is_a?(Integer)]
|
14
12
|
def copyright_years(since)
|
15
13
|
raise ArgumentError, "Argument should be a number" unless since.is_a?(Integer)
|
16
|
-
raise ArgumentError, "since should not be a future" if since >
|
17
|
-
if since ==
|
14
|
+
raise ArgumentError, "since should not be a future" if since > Time.new.year
|
15
|
+
if since == Time.new.year
|
18
16
|
"#{since}"
|
19
|
-
else
|
20
|
-
"#{since}-#{
|
17
|
+
else
|
18
|
+
"#{since}-#{Time.new.year}"
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
data/test/test_copyright.rb
CHANGED
@@ -1,33 +1,36 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
|
-
require 'test_helper'
|
4
|
+
# require './test_helper.rb'
|
5
|
+
|
6
|
+
require File.join(File.dirname(__FILE__), ["test_helper"])
|
5
7
|
include CopyrightHelper
|
6
8
|
|
7
9
|
class CopyrightYearTest < Test::Unit::TestCase
|
10
|
+
context "#copyright_years()" do
|
11
|
+
setup do
|
12
|
+
@this_year = Time.stubs(:new).returns(Time.local(2010))
|
13
|
+
@this_year.stubs(:year).returns(2010)
|
14
|
+
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
assert_raise(ArgumentError) { copyright_years() }
|
16
|
-
assert_raise(ArgumentError) { copyright_years("123") }
|
17
|
-
assert_nothing_raised { copyright_years(2004) }
|
18
|
-
assert_nothing_raised { copyright_years(2009) }
|
19
|
-
end
|
16
|
+
should "raise when an argument is not a number" do
|
17
|
+
assert_raise(ArgumentError) { copyright_years() }
|
18
|
+
assert_raise(ArgumentError) { copyright_years("123") }
|
19
|
+
assert_nothing_raised { copyright_years(2004) }
|
20
|
+
assert_nothing_raised { copyright_years(2009) }
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
should "returen the number of 'since' when the 'since' is the year of today" do
|
24
|
+
assert_equal("2010", copyright_years(2010))
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
should "return 2009-2010 when the argument is not the year of 'since'" do
|
28
|
+
years = copyright_years(2006)
|
29
|
+
assert_equal("2006-2010", years)
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
should "raise the argument is bigger than the this year" do
|
33
|
+
assert_raise(ArgumentError) {copyright_years(2220)}
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
data/test/test_helper.rb
CHANGED