Commit bf562cb92819cb57c797e4701042af0f24f0cf1e
- Diff rendering mode:
- inline
- side by side
.gitignore
(1 / 0)
|   | |||
| 1 | 1 | *~ | |
| 2 | 2 | *.yml | |
| 3 | 3 | untracked/ | |
| 4 | coverage/ |
Rakefile
(22 / 0)
|   | |||
| 1 | # -*- ruby -*- | ||
| 2 | require 'rake' | ||
| 3 | require 'rake/testtask' | ||
| 4 | require 'rcov/rcovtask' | ||
| 5 | task :default => ["test"] | ||
| 6 | |||
| 7 | task :test do | ||
| 8 | Rake::TestTask.new do |t| | ||
| 9 | t.libs << "tests" | ||
| 10 | t.test_files = FileList['tests/*.rb'] | ||
| 11 | t.verbose = true | ||
| 12 | end | ||
| 13 | end | ||
| 14 | |||
| 15 | task :rcov do | ||
| 16 | Rcov::RcovTask.new do |t| | ||
| 17 | t.test_files = FileList['tests/*.rb'] | ||
| 18 | t.verbose = true | ||
| 19 | t.rcov_opts << "--test-unit-only" | ||
| 20 | t.rcov_opts << "-x \"/site_ruby/\"" | ||
| 21 | end | ||
| 22 | end |
coefficient.rb
(4 / 5)
|   | |||
| 50 | 50 | end | |
| 51 | 51 | ||
| 52 | 52 | def html(text) | |
| 53 | return text.gsub(/&(?!(amp|lt|gt|#39|quot);)/, "&"). | ||
| 53 | return escape_amp(text). | ||
| 54 | 54 | gsub("<", "<"). | |
| 55 | 55 | gsub(">", ">"). | |
| 56 | 56 | gsub("'", "'"). | |
| … | … | ||
| 94 | 94 | end | |
| 95 | 95 | ||
| 96 | 96 | def convert_time_to_est(time) | |
| 97 | date_time = DateTime.parse(time) | ||
| 98 | new_time = date_time.new_offset(Rational(-1,6)) | ||
| 97 | new_time = DateTime.parse(time).new_offset(Rational(-1,6)) | ||
| 99 | 98 | return new_time.strftime("%A, %B %e %Y at %l:%M %P") | |
| 100 | 99 | end | |
| 101 | 100 | ||
| … | … | ||
| 181 | 181 | metadata[site]['new_since'] = metadata[site]['last_id'] | |
| 182 | 182 | next | |
| 183 | 183 | end | |
| 184 | metadata[site]['last_update'] = DateTime.parse(first['created_at']).new_offset(Rational(-1,6)).strftime("%A, %B %e %Y at %l:%M %P") | ||
| 185 | metadata[site]['last_request'] = Time.now.strftime("%A, %B %e %Y at %l:%M %P") | ||
| 184 | metadata[site]['last_update'] = convert_time_to_est(first['created_at']) | ||
| 185 | metadata[site]['last_request'] = convert_time_to_est(Time.now.to_s) | ||
| 186 | 186 | metadata[site]['new_since'] = metadata[site]['last_id'] | |
| 187 | 187 | metadata[site]['last_id'] = first['id'] | |
| 188 | 188 | end |
tests/unit.rb
(41 / 0)
|   | |||
| 133 | 133 | identicaify("Conan\'s #Tonight_Show: \"In the year 3000 #Facebook, #Twitter, and #YouTube merge to form the largest time-wasting site ever: #YouTwitFace.\"") | |
| 134 | 134 | end | |
| 135 | 135 | end | |
| 136 | |||
| 137 | context "html" do | ||
| 138 | should "correctly encode <, >, ', \", and &" do | ||
| 139 | assert_equal "<", html("<") | ||
| 140 | assert_equal ">", html(">") | ||
| 141 | assert_equal """, html("\"") | ||
| 142 | assert_equal "&", html("&") | ||
| 143 | assert_equal "'", html("'") | ||
| 144 | |||
| 145 | assert_equal "<;>", html("<;>") | ||
| 146 | assert_equal ">;<", html(">;<") | ||
| 147 | |||
| 148 | assert_equal "&", html("&") | ||
| 149 | assert_equal "<", html("<") | ||
| 150 | assert_equal ">", html(">") | ||
| 151 | assert_equal "'", html("'") | ||
| 152 | assert_equal """, html("\"") | ||
| 153 | |||
| 154 | assert_equal "&", html("&") | ||
| 155 | assert_equal "&foo", html("&foo") | ||
| 156 | assert_equal "&foo;", html("&foo;") | ||
| 157 | assert_equal "foo&", html("foo&") | ||
| 158 | end | ||
| 159 | end | ||
| 160 | |||
| 161 | context "parse_text" do | ||
| 162 | should "not linkify hashtags from twitter" do | ||
| 163 | assert_equal "I like #pie", parse_text("twitter", "I like #pie") | ||
| 164 | end | ||
| 165 | should "linkify hashtags from identica" do | ||
| 166 | assert_equal "I like #<a href=\"http://identi.ca/tag/pie\">pie</a>", | ||
| 167 | parse_text("identica", "I like #pie") | ||
| 168 | end | ||
| 169 | end | ||
| 170 | |||
| 171 | context "handling time" do | ||
| 172 | should "be in the right time zone" do | ||
| 173 | assert_equal "Tuesday, June 9 2009 at 5:39 pm", | ||
| 174 | convert_time_to_est("Tue Jun 09 21:39:31 +0000 2009") | ||
| 175 | end | ||
| 176 | end | ||
| 136 | 177 | end |

