world_bank_fetcher 0.0.14 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,19 +15,14 @@ module WorldBankFetcher
15
15
  all_data = fetch_everything query
16
16
  if all_data
17
17
  data = (@job_type == :country) ? CountryParser.filter(all_data) : IndicatorDataParser.filter(all_data)
18
- @checksum = checksum data
19
- {:results => data, :checksum => @checksum}
18
+ data
20
19
  else
21
20
  nil
22
21
  end
23
22
  end
24
23
 
25
24
  private
26
-
27
- def checksum(data)
28
- Digest::MD5.hexdigest Marshal.dump(data)
29
- end
30
-
25
+
31
26
  def build_query(options)
32
27
  options[:indicator] ? indicator_query(options[:indicator]) : countries_query
33
28
  end
@@ -1,3 +1,3 @@
1
1
  module WorldBankFetcher
2
- VERSION = "0.0.14"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/job_spec.rb CHANGED
@@ -2,11 +2,7 @@ require 'helper'
2
2
 
3
3
  module WorldBankFetcher
4
4
  describe Job do
5
- before do
6
- CountryParser.stub!(:filter) do |arg|
7
- arg
8
- end
9
-
5
+ before do
10
6
  IndicatorDataParser.stub!(:filter) do |arg|
11
7
  arg
12
8
  end
@@ -14,13 +10,15 @@ module WorldBankFetcher
14
10
 
15
11
  let(:indicator_string) { 'SP.POP.TOTL' }
16
12
 
17
- context 'initialize' do
13
+ describe 'initialize' do
18
14
  it "should accept hash w/ indicator to specify job type in intializer" do
15
+ country_parser_filters_nothing!
19
16
  WorldBank::Data.should_receive(:country).with('all').and_return(stubbed_query)
20
17
  Job.new(:indicator => indicator_string)
21
18
  end
22
19
 
23
20
  it "should accept countries to indicate all countries in initializer hash" do
21
+ country_parser_filters_nothing!
24
22
  WorldBank::Country.should_receive(:all).and_return(stubbed_query)
25
23
  Job.new(:countries => true)
26
24
  end
@@ -56,43 +54,26 @@ module WorldBankFetcher
56
54
  end
57
55
 
58
56
  it "should return nil if query shceduler returns nil" do
59
- WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
57
+ country_parser_filters_nothing!
60
58
  QueryScheduler.any_instance.should_receive(:execute!).and_return(nil)
61
59
  job = Job.new(:indicator => indicator_string)
62
60
  job.fetch.should be_nil
63
61
  end
64
62
 
65
63
  it "should not return nil if query shceduler returns non nil value" do
66
- WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
64
+ country_parser_filters_nothing!
67
65
  QueryScheduler.any_instance.should_receive(:execute!).and_return(:something)
68
66
  job = Job.new(:indicator => indicator_string)
69
67
  job.fetch.should_not be_nil
70
68
  end
71
69
 
72
- it "returns a hash if there are no errors" do
73
- WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
70
+ it "filters return value from Query Scheduler through IndicatorDataParser" do
74
71
  QueryScheduler.any_instance.should_receive(:execute!).and_return(:something)
75
-
72
+ IndicatorDataParser.should_receive(:filter).with(:something).and_return(:something_else)
76
73
  job = Job.new(:indicator => indicator_string)
77
- job.fetch.should be_an_instance_of(Hash)
78
- end
79
-
80
- context 'checksum' do
81
- it "should return unique checksums given unique results" do
82
- job = Job.new(:indicator => indicator_string)
83
- d1 = [:blah, :blog, :dj]
84
- d2 = [:bjad, :awe, :asdf]
85
- job.send(:checksum, d1).should_not eq(job.send(:checksum, d2))
86
- end
87
-
88
- it "should receive same checksum if scheduler returns identical results" do
89
- job = Job.new(:indicator => indicator_string)
90
- d1 = [:blah, :blog, :dj]
91
- job.send(:checksum, d1).should eq(job.send(:checksum, d1))
92
- end
93
-
74
+ job.fetch.should eq(:something_else)
94
75
  end
95
- end
76
+ end
96
77
 
97
78
  private
98
79
  def stubbed_query
@@ -100,5 +81,11 @@ module WorldBankFetcher
100
81
  dummy_query.stub(:indicator)
101
82
  dummy_query
102
83
  end
84
+
85
+ def country_parser_filters_nothing!
86
+ CountryParser.stub!(:filter) do |arg|
87
+ arg
88
+ end
89
+ end
103
90
  end
104
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: world_bank_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-16 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: 1038126396308871092
88
+ hash: 438441967872334920
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  segments:
96
96
  - 0
97
- hash: 1038126396308871092
97
+ hash: 438441967872334920
98
98
  requirements: []
99
99
  rubyforge_project:
100
100
  rubygems_version: 1.8.24