world_bank_fetcher 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/world_bank_fetcher/job.rb +2 -7
- data/lib/world_bank_fetcher/version.rb +1 -1
- data/spec/job_spec.rb +17 -32
- metadata +4 -4
@@ -15,19 +15,14 @@ module WorldBankFetcher
|
|
15
15
|
all_data = fetch_everything query
|
16
16
|
if all_data
|
17
17
|
data = CountryParser.filter(all_data)
|
18
|
-
|
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
|
data/spec/job_spec.rb
CHANGED
@@ -1,66 +1,45 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
module WorldBankFetcher
|
4
|
-
describe Job do
|
5
|
-
before do
|
6
|
-
CountryParser.stub!(:filter) do |arg|
|
7
|
-
arg
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
4
|
+
describe Job do
|
11
5
|
let(:indicator_string) { 'SP.POP.TOTL' }
|
12
6
|
|
13
|
-
|
7
|
+
describe 'initialize' do
|
14
8
|
it "should accept hash w/ indicator to specify job type in intializer" do
|
9
|
+
country_parser_filters_nothing!
|
15
10
|
WorldBank::Data.should_receive(:country).with('all').and_return(stubbed_query)
|
16
11
|
Job.new(:indicator => indicator_string)
|
17
12
|
end
|
18
13
|
|
19
14
|
it "should accept countries to indicate all countries in initializer hash" do
|
15
|
+
country_parser_filters_nothing!
|
20
16
|
WorldBank::Country.should_receive(:all).and_return(stubbed_query)
|
21
17
|
Job.new(:countries => true)
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
25
|
-
|
21
|
+
describe 'fetch' do
|
26
22
|
it "should return nil if query shceduler returns nil" do
|
27
|
-
|
23
|
+
country_parser_filters_nothing!
|
28
24
|
QueryScheduler.any_instance.should_receive(:execute!).and_return(nil)
|
29
25
|
job = Job.new(:indicator => indicator_string)
|
30
26
|
job.fetch.should be_nil
|
31
27
|
end
|
32
28
|
|
33
29
|
it "should not return nil if query shceduler returns non nil value" do
|
34
|
-
|
30
|
+
country_parser_filters_nothing!
|
35
31
|
QueryScheduler.any_instance.should_receive(:execute!).and_return(:something)
|
36
32
|
job = Job.new(:indicator => indicator_string)
|
37
33
|
job.fetch.should_not be_nil
|
38
34
|
end
|
39
35
|
|
40
|
-
it "
|
41
|
-
WorldBank::DataQuery.any_instance.stub(:total).and_return(39)
|
36
|
+
it "filters return value from Query Scheduler through CountryParser" do
|
42
37
|
QueryScheduler.any_instance.should_receive(:execute!).and_return(:something)
|
43
|
-
|
38
|
+
CountryParser.should_receive(:filter).with(:something).and_return(:something_else)
|
44
39
|
job = Job.new(:indicator => indicator_string)
|
45
|
-
job.fetch.should
|
40
|
+
job.fetch.should eq(:something_else)
|
46
41
|
end
|
47
|
-
|
48
|
-
context 'checksum' do
|
49
|
-
it "should return unique checksums given unique results" do
|
50
|
-
job = Job.new(:indicator => indicator_string)
|
51
|
-
d1 = [:blah, :blog, :dj]
|
52
|
-
d2 = [:bjad, :awe, :asdf]
|
53
|
-
job.send(:checksum, d1).should_not eq(job.send(:checksum, d2))
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should receive same checksum if scheduler returns identical results" do
|
57
|
-
job = Job.new(:indicator => indicator_string)
|
58
|
-
d1 = [:blah, :blog, :dj]
|
59
|
-
job.send(:checksum, d1).should eq(job.send(:checksum, d1))
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
42
|
+
end
|
64
43
|
|
65
44
|
private
|
66
45
|
def stubbed_query
|
@@ -68,5 +47,11 @@ module WorldBankFetcher
|
|
68
47
|
dummy_query.stub(:indicator)
|
69
48
|
dummy_query
|
70
49
|
end
|
50
|
+
|
51
|
+
def country_parser_filters_nothing!
|
52
|
+
CountryParser.stub!(:filter) do |arg|
|
53
|
+
arg
|
54
|
+
end
|
55
|
+
end
|
71
56
|
end
|
72
57
|
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.
|
4
|
+
version: 0.0.12
|
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-08-
|
12
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
segments:
|
85
85
|
- 0
|
86
|
-
hash: -
|
86
|
+
hash: -4294862042739340307
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
segments:
|
94
94
|
- 0
|
95
|
-
hash: -
|
95
|
+
hash: -4294862042739340307
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
98
|
rubygems_version: 1.8.24
|