quandl_client 2.7.11 → 2.7.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +7 -7
  2. data/.rspec +1 -1
  3. data/.travis.yml +20 -20
  4. data/.yardopts +2 -2
  5. data/Gemfile +12 -12
  6. data/Guardfile +8 -8
  7. data/LICENSE +7 -7
  8. data/README.md +303 -303
  9. data/Rakefile +31 -31
  10. data/UPGRADE.md +220 -214
  11. data/VERSION +1 -1
  12. data/examples/create.rb +32 -32
  13. data/examples/find.rb +17 -17
  14. data/examples/login.rb +12 -12
  15. data/examples/search.rb +12 -12
  16. data/examples/trims.rb +15 -15
  17. data/lib/quandl/client/base/attributes.rb +15 -15
  18. data/lib/quandl/client/base/model.rb +40 -40
  19. data/lib/quandl/client/base/search.rb +74 -74
  20. data/lib/quandl/client/base/validation.rb +103 -101
  21. data/lib/quandl/client/base.rb +91 -91
  22. data/lib/quandl/client/middleware/parse_json.rb +87 -85
  23. data/lib/quandl/client/middleware.rb +9 -9
  24. data/lib/quandl/client/models/dataset/data.rb +57 -57
  25. data/lib/quandl/client/models/dataset.rb +269 -269
  26. data/lib/quandl/client/models/location.rb +10 -10
  27. data/lib/quandl/client/models/report.rb +14 -14
  28. data/lib/quandl/client/models/scraper.rb +16 -16
  29. data/lib/quandl/client/models/sheet.rb +50 -50
  30. data/lib/quandl/client/models/source.rb +48 -48
  31. data/lib/quandl/client/models/superset.rb +65 -65
  32. data/lib/quandl/client/models/user.rb +7 -7
  33. data/lib/quandl/client/version.rb +14 -14
  34. data/lib/quandl/client.rb +54 -53
  35. data/lib/quandl/her/collection.rb +18 -0
  36. data/lib/quandl/her/remove_method_data.rb +8 -8
  37. data/lib/quandl/pattern/client.rb +8 -8
  38. data/lib/quandl/pattern.rb +37 -37
  39. data/quandl_client.gemspec +33 -33
  40. data/spec/factories/dataset.rb +10 -10
  41. data/spec/factories/sheet.rb +7 -7
  42. data/spec/factories/source.rb +9 -9
  43. data/spec/fixtures/scraper.rb +5 -5
  44. data/spec/lib/quandl/client/dataset/attributes_spec.rb +63 -63
  45. data/spec/lib/quandl/client/dataset/data_spec.rb +92 -92
  46. data/spec/lib/quandl/client/dataset/location_spec.rb +65 -65
  47. data/spec/lib/quandl/client/dataset/persistence_spec.rb +104 -104
  48. data/spec/lib/quandl/client/dataset/search_spec.rb +19 -19
  49. data/spec/lib/quandl/client/dataset/source_spec.rb +47 -47
  50. data/spec/lib/quandl/client/dataset/trim_spec.rb +35 -35
  51. data/spec/lib/quandl/client/dataset/validation_spec.rb +68 -68
  52. data/spec/lib/quandl/client/dataset_spec.rb +57 -57
  53. data/spec/lib/quandl/client/scraper_spec.rb +71 -71
  54. data/spec/lib/quandl/client/sheet_spec.rb +37 -37
  55. data/spec/lib/quandl/client/source_spec.rb +51 -51
  56. data/spec/spec_helper.rb +30 -30
  57. metadata +28 -4
@@ -1,105 +1,105 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
- context "when built" do
6
- subject{ build(:dataset) }
7
- its(:saved?){ should be_false }
8
- its(:valid?){ should be_true }
9
- end
10
-
11
- its(:request_started_at){ should be_nil }
12
- its(:request_finished_at){ should be_nil }
13
- its(:elapsed_request_time){ should be_nil }
14
-
15
- context "when created" do
16
- context "without token" do
17
- before(:all){ Quandl::Client.token = '' }
18
-
19
- let(:dataset){ create(:dataset) }
20
- subject{ dataset }
21
-
22
- its(:saved?){ should be_false }
23
- its(:status){ should eq 401 }
24
-
25
- its(:request_started_at){ should be_a Time }
26
-
27
- after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
28
- end
29
- context "with token" do
30
-
31
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
32
- subject{ dataset }
33
-
34
- its(:saved?){ should be_true }
35
- its(:status){ should eq 201 }
36
-
37
- end
38
- context "with data" do
39
-
40
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2, nils: false) ) }
41
- subject{ dataset }
42
-
43
- its(:saved?){ should be_true }
44
- its(:status){ should eq 201 }
45
-
46
- end
47
- end
48
-
49
- context "when updated" do
50
-
51
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2, nils: false).to_csv ) }
52
- subject{ Dataset.find(dataset.id) }
53
-
54
- it "should include new row" do
55
- new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 1, rand(12), rand(12) ] }
56
- new_data = Quandl::Data.new(new_data).sort_descending
57
- subject.data = new_data
58
- subject.save
59
- updated_dataset = Dataset.find(subject.id)
60
- updated_dataset.data.to_date[0].should eq new_data.to_date[0]
61
- end
62
-
63
- it "should include old rows" do
64
- new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 2, rand(12), rand(12) ] }
65
- new_data = Quandl::Data.new(new_data).sort_descending
66
- subject.data = new_data
67
- subject.save
68
- updated_dataset = Dataset.find(subject.id)
69
- updated_dataset.data.count.should eq 30
70
- end
71
-
72
- end
73
-
74
- context "#destroy" do
75
-
76
- let(:dataset){ create(:dataset, private: false ) }
77
- before(:each){ dataset.destroy }
78
- subject{ dataset }
79
-
80
- its(:status){ should eq 200 }
81
-
82
- its(:request_started_at){ should be_a Time }
83
- its(:request_finished_at){ should be_a Time }
84
- its(:elapsed_request_time){ should be > 0 }
85
-
86
- end
87
-
88
- context "#destroy when user" do
89
-
90
- let(:dataset){ create(:dataset, private: false ) }
91
-
92
- it "should not delete the dataset with a user token" do
93
- id = dataset.id
94
- # behave as a user
95
- Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
96
- user_dataset = Dataset.find(id)
97
- user_dataset.destroy
98
- user_dataset.status.should eq 403
99
- end
100
-
101
- after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
102
-
103
- end
104
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+ context "when built" do
6
+ subject{ build(:dataset) }
7
+ its(:saved?){ should be_false }
8
+ its(:valid?){ should be_true }
9
+ end
10
+
11
+ its(:request_started_at){ should be_nil }
12
+ its(:request_finished_at){ should be_nil }
13
+ its(:elapsed_request_time){ should be_nil }
14
+
15
+ context "when created" do
16
+ context "without token" do
17
+ before(:all){ Quandl::Client.token = '' }
18
+
19
+ let(:dataset){ create(:dataset) }
20
+ subject{ dataset }
21
+
22
+ its(:saved?){ should be_false }
23
+ its(:status){ should eq 401 }
24
+
25
+ its(:request_started_at){ should be_a Time }
26
+
27
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
28
+ end
29
+ context "with token" do
30
+
31
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
32
+ subject{ dataset }
33
+
34
+ its(:saved?){ should be_true }
35
+ its(:status){ should eq 201 }
36
+
37
+ end
38
+ context "with data" do
39
+
40
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2, nils: false) ) }
41
+ subject{ dataset }
42
+
43
+ its(:saved?){ should be_true }
44
+ its(:status){ should eq 201 }
45
+
46
+ end
47
+ end
48
+
49
+ context "when updated" do
50
+
51
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2, nils: false).to_csv ) }
52
+ subject{ Dataset.find(dataset.id) }
53
+
54
+ it "should include new row" do
55
+ new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 1, rand(12), rand(12) ] }
56
+ new_data = Quandl::Data.new(new_data).sort_descending
57
+ subject.data = new_data
58
+ subject.save
59
+ updated_dataset = Dataset.find(subject.id)
60
+ updated_dataset.data.to_date[0].should eq new_data.to_date[0]
61
+ end
62
+
63
+ it "should include old rows" do
64
+ new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 2, rand(12), rand(12) ] }
65
+ new_data = Quandl::Data.new(new_data).sort_descending
66
+ subject.data = new_data
67
+ subject.save
68
+ updated_dataset = Dataset.find(subject.id)
69
+ updated_dataset.data.count.should eq 30
70
+ end
71
+
72
+ end
73
+
74
+ context "#destroy" do
75
+
76
+ let(:dataset){ create(:dataset, private: false ) }
77
+ before(:each){ dataset.destroy }
78
+ subject{ dataset }
79
+
80
+ its(:status){ should eq 200 }
81
+
82
+ its(:request_started_at){ should be_a Time }
83
+ its(:request_finished_at){ should be_a Time }
84
+ its(:elapsed_request_time){ should be > 0 }
85
+
86
+ end
87
+
88
+ context "#destroy when user" do
89
+
90
+ let(:dataset){ create(:dataset, private: false ) }
91
+
92
+ it "should not delete the dataset with a user token" do
93
+ id = dataset.id
94
+ # behave as a user
95
+ Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
96
+ user_dataset = Dataset.find(id)
97
+ user_dataset.destroy
98
+ user_dataset.status.should eq 403
99
+ end
100
+
101
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
102
+
103
+ end
104
+
105
105
  end
@@ -1,20 +1,20 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
-
8
- it "should find the dataset by id" do
9
- Dataset.find(dataset.id).id.should eq dataset.id
10
- end
11
-
12
- it "should find the dataset by full code" do
13
- Dataset.find(dataset.full_code).id.should eq dataset.id
14
- end
15
-
16
- it "should exclude_data" do
17
- Dataset.find(dataset.id).attributes[:data].should be_blank
18
- end
19
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
+
8
+ it "should find the dataset by id" do
9
+ Dataset.find(dataset.id).id.should eq dataset.id
10
+ end
11
+
12
+ it "should find the dataset by full code" do
13
+ Dataset.find(dataset.full_code).id.should eq dataset.id
14
+ end
15
+
16
+ it "should exclude_data" do
17
+ Dataset.find(dataset.id).attributes[:data].should be_blank
18
+ end
19
+
20
20
  end
@@ -1,47 +1,47 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- let(:dataset){ create(:dataset, source_code: nil ) }
7
- subject{ dataset }
8
-
9
- context "admin user" do
10
-
11
- its(:saved?){ should be_true }
12
- its(:source_code){ should be_present }
13
-
14
- describe "#source_code=" do
15
- before(:each){
16
- subject.source_code = 'WHO'
17
- subject.save
18
- }
19
- its(:status){ should be 200 }
20
- its(:source_code){ should eq 'WHO' }
21
- end
22
-
23
- end
24
-
25
- context "normal user" do
26
- # behave as a user
27
- before(:all){ Quandl::Client.token = ENV['QUANDL_TEST_TOKEN'] }
28
-
29
- its(:saved?){ should be_true }
30
- its(:source_code){ should be_present }
31
-
32
- it "should find the source" do
33
- Source.find(dataset.source_code).exists?.should be_true
34
- end
35
-
36
- describe "#source_code=" do
37
- before(:each){
38
- subject.source_code = 'WHO'
39
- subject.save
40
- }
41
- its(:status){ should be 422 }
42
- end
43
-
44
- after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
45
- end
46
-
47
- end
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:dataset){ create(:dataset, source_code: nil ) }
7
+ subject{ dataset }
8
+
9
+ context "admin user" do
10
+
11
+ its(:saved?){ should be_true }
12
+ its(:source_code){ should be_present }
13
+
14
+ describe "#source_code=" do
15
+ before(:each){
16
+ subject.source_code = 'WHO'
17
+ subject.save
18
+ }
19
+ its(:status){ should be 200 }
20
+ its(:source_code){ should eq 'WHO' }
21
+ end
22
+
23
+ end
24
+
25
+ context "normal user" do
26
+ # behave as a user
27
+ before(:all){ Quandl::Client.token = ENV['QUANDL_TEST_TOKEN'] }
28
+
29
+ its(:saved?){ should be_true }
30
+ its(:source_code){ should be_present }
31
+
32
+ it "should find the source" do
33
+ Source.find(dataset.source_code).exists?.should be_true
34
+ end
35
+
36
+ describe "#source_code=" do
37
+ before(:each){
38
+ subject.source_code = 'WHO'
39
+ subject.save
40
+ }
41
+ its(:status){ should be 422 }
42
+ end
43
+
44
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
45
+ end
46
+
47
+ end
@@ -1,36 +1,36 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- subject{ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2) ) }
7
-
8
- describe "#from_date" do
9
- context "before_save" do
10
- it "should be nil" do
11
- subject.from_date.should be_nil
12
- end
13
- end
14
- context "after_save" do
15
- before(:each){ subject.save }
16
- it "should equal the last date" do
17
- subject.from_date.should eq subject.data.to_date[-1][0].to_s
18
- end
19
- end
20
- end
21
-
22
- describe "#to_date" do
23
- context "before_save" do
24
- it "should be nil" do
25
- subject.to_date.should be_nil
26
- end
27
- end
28
- context "after_save" do
29
- before(:each){ subject.save }
30
- it "should equal the first date" do
31
- subject.to_date.should eq subject.data.to_date[0][0].to_s
32
- end
33
- end
34
- end
35
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ subject{ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2) ) }
7
+
8
+ describe "#from_date" do
9
+ context "before_save" do
10
+ it "should be nil" do
11
+ subject.from_date.should be_nil
12
+ end
13
+ end
14
+ context "after_save" do
15
+ before(:each){ subject.save }
16
+ it "should equal the last date" do
17
+ subject.from_date.should eq subject.data.to_date[-1][0].to_s
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#to_date" do
23
+ context "before_save" do
24
+ it "should be nil" do
25
+ subject.to_date.should be_nil
26
+ end
27
+ end
28
+ context "after_save" do
29
+ before(:each){ subject.save }
30
+ it "should equal the first date" do
31
+ subject.to_date.should eq subject.data.to_date[0][0].to_s
32
+ end
33
+ end
34
+ end
35
+
36
36
  end
@@ -1,69 +1,69 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- let(:dataset){ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
- subject{ dataset }
8
-
9
- context "data='1980,10,20\nASDF,10,30'" do
10
- before(:each){
11
- dataset.data = '1980,10,20\nASDF,10,30'
12
- dataset.valid?
13
- }
14
- its(:valid?){ should be_false }
15
- its('errors.messages'){ should eq({ data: ["Invalid date 'ASDF'"] }) }
16
- end
17
-
18
- context "given ambiguous code" do
19
- before(:each){
20
- dataset.source_code = nil
21
- dataset.code = '12345'
22
- dataset.valid?
23
- }
24
- its(:valid?){ should be_false }
25
- its('errors.messages'){ should eq({ data: ["Pure numerical codes like \"12345\" are not allowed unless you include a source code. Do this:\nsource_code: <USERNAME>\ncode: 12345"]}) }
26
- end
27
-
28
- context "mismatch row count" do
29
- before(:each){
30
- dataset.data = [[2012, 1,2],[2011, 1,2,3]]
31
- dataset.valid?
32
- }
33
- its(:valid?){ should be_false }
34
- its('errors.messages'){ should eq({ data:
35
- ["Unexpected number of points in this row:\n2011-12-31,1.0,2.0,3.0\nFound 3 but expected 2 based on precedent from the first row (2012-12-31,1.0,2.0)"]
36
- })}
37
- end
38
-
39
- context "mismatch column_names count" do
40
- before(:each){
41
- dataset.column_names = ['Date','Value']
42
- dataset.data = [[2012, 18,21],[2011, 1,2]]
43
- dataset.valid?
44
- }
45
- its(:valid?){ should be_false }
46
- its('errors.messages'){ should eq({ data:
47
- ["Unexpected number of points in this row:\n2012-12-31,18.0,21.0\nFound 2 but expected 1 based on precedent from the header row (Date,Value)"]
48
- })}
49
- end
50
-
51
- describe "#code" do
52
-
53
- before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
54
-
55
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
56
- let(:invalid_dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", code: dataset.code ) }
57
- subject{ invalid_dataset }
58
-
59
- it "should create the dataset" do
60
- dataset.status.should eq 201
61
- end
62
-
63
- its(:saved?){ should be_false }
64
- its(:status){ should eq 422 }
65
-
66
- end
67
-
68
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:dataset){ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
+ subject{ dataset }
8
+
9
+ context "data='1980,10,20\nASDF,10,30'" do
10
+ before(:each){
11
+ dataset.data = '1980,10,20\nASDF,10,30'
12
+ dataset.valid?
13
+ }
14
+ its(:valid?){ should be_false }
15
+ its('errors.messages'){ should eq({ data: ["Invalid date 'ASDF'"] }) }
16
+ end
17
+
18
+ context "given ambiguous code" do
19
+ before(:each){
20
+ dataset.source_code = nil
21
+ dataset.code = '12345'
22
+ dataset.valid?
23
+ }
24
+ its(:valid?){ should be_false }
25
+ its('errors.messages'){ should eq({ data: ["Pure numerical codes like \"12345\" are not allowed unless you include a source code. Do this:\nsource_code: <USERNAME>\ncode: 12345"]}) }
26
+ end
27
+
28
+ context "mismatch row count" do
29
+ before(:each){
30
+ dataset.data = [[2012, 1,2],[2011, 1,2,3]]
31
+ dataset.valid?
32
+ }
33
+ its(:valid?){ should be_false }
34
+ its('errors.messages'){ should eq({ data:
35
+ ["Unexpected number of points in this row:\n2011-12-31,1.0,2.0,3.0\nFound 3 but expected 2 based on precedent from the first row (2012-12-31,1.0,2.0)"]
36
+ })}
37
+ end
38
+
39
+ context "mismatch column_names count" do
40
+ before(:each){
41
+ dataset.column_names = ['Date','Value']
42
+ dataset.data = [[2012, 18,21],[2011, 1,2]]
43
+ dataset.valid?
44
+ }
45
+ its(:valid?){ should be_false }
46
+ its('errors.messages'){ should eq({ data:
47
+ ["Unexpected number of points in this row:\n2012-12-31,18.0,21.0\nFound 2 but expected 1 based on precedent from the header row (Date,Value)"]
48
+ })}
49
+ end
50
+
51
+ describe "#code" do
52
+
53
+ before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
54
+
55
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
56
+ let(:invalid_dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", code: dataset.code ) }
57
+ subject{ invalid_dataset }
58
+
59
+ it "should create the dataset" do
60
+ dataset.status.should eq 201
61
+ end
62
+
63
+ its(:saved?){ should be_false }
64
+ its(:status){ should eq 422 }
65
+
66
+ end
67
+
68
+
69
69
  end
@@ -1,58 +1,58 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
- let(:dataset){ create(:dataset) }
6
- subject{ dataset }
7
-
8
- describe ".find" do
9
- subject{ Dataset.find(query) }
10
- context "given nil" do
11
- let(:query){ nil }
12
- it{ should be_nil }
13
- end
14
- context "given empty string" do
15
- let(:query){ '' }
16
- it{ should be_nil }
17
- end
18
- context "given non-code value" do
19
- let(:query){ '/' }
20
- it{ should be_nil }
21
- end
22
- end
23
-
24
- describe ".touch_existing(:id)" do
25
- it "should touch the dataset" do
26
- dataset.updated_at
27
- sleep(1)
28
- Dataset.touch_existing(subject.id).should eq true
29
- Dataset.find(subject.id).updated_at.should_not eq dataset.updated_at
30
- end
31
- end
32
-
33
- it "should change url" do
34
- original_url = Quandl::Client::Base.url
35
- Quandl::Client.use('http://url.com/')
36
- Quandl::Client::Dataset.url.should eq 'http://url.com/v2'
37
- Quandl::Client.use('http://url.com/2/')
38
- Quandl::Client::Dataset.url.should eq 'http://url.com/2/v2'
39
- Quandl::Client.use original_url
40
- end
41
-
42
- describe ".query" do
43
- let(:datasets){ Quandl::Client::Dataset.query('oil').all }
44
- subject{ datasets }
45
-
46
- its(:first){ should be_a Quandl::Client::Dataset }
47
-
48
- describe "#metadata" do
49
- subject{ OpenStruct.new(datasets.metadata) }
50
- its(:total_count){ should > 1 }
51
- its(:per_page){ should eq 20 }
52
- its(:sources){ should be_present }
53
- its(:status){ should eq 200 }
54
- its(:current_page){ should eq 1 }
55
- end
56
- end
57
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+ let(:dataset){ create(:dataset) }
6
+ subject{ dataset }
7
+
8
+ describe ".find" do
9
+ subject{ Dataset.find(query) }
10
+ context "given nil" do
11
+ let(:query){ nil }
12
+ it{ should be_nil }
13
+ end
14
+ context "given empty string" do
15
+ let(:query){ '' }
16
+ it{ should be_nil }
17
+ end
18
+ context "given non-code value" do
19
+ let(:query){ '/' }
20
+ it{ should be_nil }
21
+ end
22
+ end
23
+
24
+ describe ".touch_existing(:id)" do
25
+ it "should touch the dataset" do
26
+ dataset.updated_at
27
+ sleep(1)
28
+ Dataset.touch_existing(subject.id).should eq true
29
+ Dataset.find(subject.id).updated_at.should_not eq dataset.updated_at
30
+ end
31
+ end
32
+
33
+ it "should change url" do
34
+ original_url = Quandl::Client::Base.url
35
+ Quandl::Client.use('http://url.com/')
36
+ Quandl::Client::Dataset.url.should eq 'http://url.com/v2'
37
+ Quandl::Client.use('http://url.com/2/')
38
+ Quandl::Client::Dataset.url.should eq 'http://url.com/2/v2'
39
+ Quandl::Client.use original_url
40
+ end
41
+
42
+ describe ".query" do
43
+ let(:datasets){ Quandl::Client::Dataset.query('oil').all }
44
+ subject{ datasets }
45
+
46
+ its(:first){ should be_a Quandl::Client::Dataset }
47
+
48
+ describe "#metadata" do
49
+ subject{ OpenStruct.new(datasets.metadata) }
50
+ its(:total_count){ should > 1 }
51
+ its(:per_page){ should eq 20 }
52
+ its(:sources){ should be_present }
53
+ its(:status){ should eq 200 }
54
+ its(:current_page){ should eq 1 }
55
+ end
56
+ end
57
+
58
58
  end