Permalink
Browse files

Add test for News, and convert dates automatically.

  • Loading branch information...
1 parent 23f019b commit 3b383a4bcb6f725c9ea6c39b7d4b973f11e9361f @marcandre marcandre committed Feb 26, 2010
Showing with 27 additions and 5 deletions.
  1. +1 −1 VERSION
  2. +7 −4 googleajax.gemspec
  3. +4 −0 lib/googleajax/filters.rb
  4. +1 −0 lib/googleajax/search.rb
  5. +14 −0 spec/googleajax_common.rb
View
@@ -1 +1 @@
-1.0.0
+1.0.1
View
@@ -5,20 +5,22 @@
Gem::Specification.new do |s|
s.name = %q{googleajax}
- s.version = "1.0.0"
+ s.version = "1.0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["geemus(Wesley Beary)", "Marc-Andre Lafortune"]
- s.date = %q{2009-12-24}
+ s.date = %q{2010-02-26}
s.email = %q{me@geemus.com}
s.extra_rdoc_files = [
"README.txt"
]
s.files = [
- "History.txt",
+ ".gitignore",
+ "History.txt",
"README.txt",
"Rakefile",
"VERSION",
+ "googleajax.gemspec",
"lib/googleajax.rb",
"lib/googleajax/api.rb",
"lib/googleajax/as_hash.rb",
@@ -52,7 +54,8 @@ Gem::Specification.new do |s|
"spec/googleajax_basic_spec.rb",
"spec/googleajax_common.rb",
"spec/googleajax_spec.rb",
- "spec/spec_helper.rb"
+ "spec/spec_helper.rb",
+ "spec/temp_spec.rb"
]
if s.respond_to? :specification_version then
@@ -44,6 +44,7 @@ module ConvertValues
TRUE_OR_FALSE = /^true|(false)$/i
INTEGER = /^\d+$/
FLOAT = /^\d+\.\d+$/
+ TIME = /^[A-Z][a-z]{2}, \d\d [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d \S*$/ # Very strict date format
def initialize(h)
h.each do |key, value|
# Won't use Integer.try_convert for 1.8.6 & 7 compatibility
@@ -54,6 +55,9 @@ def initialize(h)
h[key] = value.to_f
when TRUE_OR_FALSE
h[key] = Regexp.last_match[1].nil?
+ when TIME
+ require 'time'
+ h[key] = Time.parse(value)
end
end
super(h)
View
@@ -34,6 +34,7 @@ def self.local(query, latitude, longitude, args = {})
# :call-seq:
# news(query, args = {})
# Arguments: http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_news
+ # Contrary to the doc, scoring=d is not an acceptable parameter (nor is scoring=date)
##
# :call-seq:
View
@@ -17,6 +17,20 @@
end
end
+ describe ".news" do
+ before :each do
+ GoogleAjax.referer = "http://example.com"
+ end
+
+ it "returns fresh news" do
+ one_day = 24 * 60 * 60
+ yesterday = Time.now - one_day
+ results = GoogleAjax::Search.news("", :topic => :h)[:results]
+ results.size.should >= 4
+ results.all?{|r| r[:published_date].should >= yesterday}
+ end
+ end
+
{
:blogs => 100_000,
:books => 10_000,

0 comments on commit 3b383a4

Please sign in to comment.