datacatalog 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +2 -2
- data/LICENSE.md +11 -11
- data/README.md +34 -34
- data/VERSION +1 -1
- data/datacatalog.gemspec +5 -2
- data/lib/base.rb +85 -77
- data/lib/datacatalog.rb +8 -8
- data/lib/main.rb +41 -41
- data/lib/resources/organization.rb +31 -0
- data/sandbox_api.yml.example +2 -2
- data/spec/about_spec.rb +42 -21
- data/spec/api_key_spec.rb +145 -145
- data/spec/base_spec.rb +129 -129
- data/spec/datacatalog_spec.rb +36 -36
- data/spec/organization_spec.rb +124 -0
- data/spec/source_spec.rb +162 -162
- data/spec/spec.opts +3 -4
- data/spec/spec_helper.rb +15 -25
- data/spec/user_spec.rb +279 -278
- metadata +5 -2
data/CHANGES.md
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
### 0.1.0 / 2009-08-15
|
2
|
-
* Initial version
|
1
|
+
### 0.1.0 / 2009-08-15
|
2
|
+
* Initial version
|
data/LICENSE.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
Copyright (c) 2009, Sunlight Foundation.
|
2
|
-
|
3
|
-
All rights reserved.
|
4
|
-
|
5
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
-
|
7
|
-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
-
* Neither the name of Sunlight Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
-
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
|
+
Copyright (c) 2009, Sunlight Foundation.
|
2
|
+
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
+
* Neither the name of Sunlight Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
+
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# Ruby Gem for the National Data Catalog API
|
2
|
-
|
3
|
-
Under heavy development.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
For now, the gem will not be packaged. Instead, install it manually:
|
8
|
-
|
9
|
-
$ git clone git clone git://github.com/sunlightlabs/ruby-datacatalog.git
|
10
|
-
$ cd ruby-datacatalog
|
11
|
-
$ rake check_dependencies
|
12
|
-
$ rake build
|
13
|
-
$ rake install # uses sudo
|
14
|
-
# Or, instead of the line above:
|
15
|
-
$ gem install pkg/datacatalog-0.1.0.gem
|
16
|
-
|
17
|
-
## Usage
|
18
|
-
|
19
|
-
require 'rubygems'
|
20
|
-
require 'datacatalog'
|
21
|
-
|
22
|
-
DataCatalog.api_key = 'c40505247a5e308a24d70a0118f76534b543795b'
|
23
|
-
|
24
|
-
## Running Specs
|
25
|
-
|
26
|
-
We're not mocking out any of the web API calls in the specs. Instead, we expect developers who wish to run the specs to download and run a local sandbox instance of the [Data Catalog API](http://github.com/sunlightlabs/datacatalog-api), a Sinatra app:
|
27
|
-
|
28
|
-
git clone git://github.com/sunlightlabs/datacatalog-api.git
|
29
|
-
|
30
|
-
Get the app running like any normal Sinatra app, so you can choose to use thin or Passenger or new hotness like [Unicorn](http://unicorn.bogomips.org/). Some special considerations:
|
31
|
-
|
32
|
-
1. We recommend creating a `sandbox` entry in `datacatalog-api`'s `config.yml`.
|
33
|
-
2. Run `RACK_ENV=sandbox rake db:ensure_admin` in the `datacatalog-api` project to create a super admin for the API instance.
|
34
|
-
3. Back here in `ruby-datacatalog`, use the example file in `spec/` to create your own `spec/sandbox_api.yml` with the API key of the admin and your local URI.
|
1
|
+
# Ruby Gem for the National Data Catalog API
|
2
|
+
|
3
|
+
Under heavy development.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
For now, the gem will not be packaged. Instead, install it manually:
|
8
|
+
|
9
|
+
$ git clone git clone git://github.com/sunlightlabs/ruby-datacatalog.git
|
10
|
+
$ cd ruby-datacatalog
|
11
|
+
$ rake check_dependencies
|
12
|
+
$ rake build
|
13
|
+
$ rake install # uses sudo
|
14
|
+
# Or, instead of the line above:
|
15
|
+
$ gem install pkg/datacatalog-0.1.0.gem
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
require 'rubygems'
|
20
|
+
require 'datacatalog'
|
21
|
+
|
22
|
+
DataCatalog.api_key = 'c40505247a5e308a24d70a0118f76534b543795b'
|
23
|
+
|
24
|
+
## Running Specs
|
25
|
+
|
26
|
+
We're not mocking out any of the web API calls in the specs. Instead, we expect developers who wish to run the specs to download and run a local sandbox instance of the [Data Catalog API](http://github.com/sunlightlabs/datacatalog-api), a Sinatra app:
|
27
|
+
|
28
|
+
git clone git://github.com/sunlightlabs/datacatalog-api.git
|
29
|
+
|
30
|
+
Get the app running like any normal Sinatra app, so you can choose to use thin or Passenger or new hotness like [Unicorn](http://unicorn.bogomips.org/). Some special considerations:
|
31
|
+
|
32
|
+
1. We recommend creating a `sandbox` entry in `datacatalog-api`'s `config.yml`.
|
33
|
+
2. Run `RACK_ENV=sandbox rake db:ensure_admin` in the `datacatalog-api` project to create a super admin for the API instance.
|
34
|
+
3. Back here in `ruby-datacatalog`, use the example file in `spec/` to create your own `spec/sandbox_api.yml` with the API key of the admin and your local URI.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/datacatalog.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datacatalog}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Luigi Montanez", "David James"]
|
12
|
-
s.date = %q{2009-10-
|
12
|
+
s.date = %q{2009-10-22}
|
13
13
|
s.description = %q{A Ruby client library for the National Data Catalog API}
|
14
14
|
s.email = %q{luigi@sunlightfoundation.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/main.rb",
|
30
30
|
"lib/resources/about.rb",
|
31
31
|
"lib/resources/api_key.rb",
|
32
|
+
"lib/resources/organization.rb",
|
32
33
|
"lib/resources/source.rb",
|
33
34
|
"lib/resources/user.rb",
|
34
35
|
"sandbox_api.yml.example",
|
@@ -36,6 +37,7 @@ Gem::Specification.new do |s|
|
|
36
37
|
"spec/api_key_spec.rb",
|
37
38
|
"spec/base_spec.rb",
|
38
39
|
"spec/datacatalog_spec.rb",
|
40
|
+
"spec/organization_spec.rb",
|
39
41
|
"spec/setup_api.rb",
|
40
42
|
"spec/source_spec.rb",
|
41
43
|
"spec/spec.opts",
|
@@ -56,6 +58,7 @@ Gem::Specification.new do |s|
|
|
56
58
|
"spec/api_key_spec.rb",
|
57
59
|
"spec/base_spec.rb",
|
58
60
|
"spec/datacatalog_spec.rb",
|
61
|
+
"spec/organization_spec.rb",
|
59
62
|
"spec/setup_api.rb",
|
60
63
|
"spec/source_spec.rb",
|
61
64
|
"spec/spec_helper.rb",
|
data/lib/base.rb
CHANGED
@@ -1,77 +1,85 @@
|
|
1
|
-
module DataCatalog
|
2
|
-
|
3
|
-
class Base < Mash
|
4
|
-
|
5
|
-
DEFAULT_BASE_URI = 'http://api.nationaldatacatalog.com'
|
6
|
-
|
7
|
-
include HTTParty
|
8
|
-
|
9
|
-
format :json
|
10
|
-
base_uri DEFAULT_BASE_URI
|
11
|
-
|
12
|
-
class << self
|
13
|
-
alias_method :_delete, :delete
|
14
|
-
alias_method :_get, :get
|
15
|
-
alias_method :_post, :post
|
16
|
-
alias_method :_put, :put
|
17
|
-
|
18
|
-
undef_method :delete
|
19
|
-
undef_method :get
|
20
|
-
undef_method :post
|
21
|
-
undef_method :put
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.http_delete(path, options={})
|
25
|
-
check_status(_delete(path, options))
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.http_get(path, options={})
|
29
|
-
check_status(_get(path, options))
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.http_post(path, options={})
|
33
|
-
check_status(_post(path, options))
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.http_put(path, options={})
|
37
|
-
check_status(_put(path, options))
|
38
|
-
end
|
39
|
-
|
40
|
-
# == protected
|
41
|
-
|
42
|
-
def self.check_status(response)
|
43
|
-
case response.code
|
44
|
-
when 400: raise BadRequest, error(response)
|
45
|
-
when 401: raise Unauthorized, error(response)
|
46
|
-
when 403: raise Forbidden, error(response)
|
47
|
-
when 404: raise NotFound, error(response)
|
48
|
-
when 409: raise Conflict, error(response)
|
49
|
-
when 500: raise InternalServerError, error(response)
|
50
|
-
end
|
51
|
-
response
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.error(response)
|
55
|
-
parsed_body = JSON.parse(response.body)
|
56
|
-
if parsed_body.empty?
|
57
|
-
"Response was empty"
|
58
|
-
elsif parsed_body["errors"]
|
59
|
-
parsed_body["errors"].inspect
|
60
|
-
else
|
61
|
-
response.body
|
62
|
-
end
|
63
|
-
rescue JSON::ParserError
|
64
|
-
"Unable to parse: #{response.body.inspect}"
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.many(response)
|
68
|
-
response.map { |item| new(item) }
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.one(response)
|
72
|
-
response.blank? ? nil : new(response)
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
1
|
+
module DataCatalog
|
2
|
+
|
3
|
+
class Base < Mash
|
4
|
+
|
5
|
+
DEFAULT_BASE_URI = 'http://api.nationaldatacatalog.com'
|
6
|
+
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
format :json
|
10
|
+
base_uri DEFAULT_BASE_URI
|
11
|
+
|
12
|
+
class << self
|
13
|
+
alias_method :_delete, :delete
|
14
|
+
alias_method :_get, :get
|
15
|
+
alias_method :_post, :post
|
16
|
+
alias_method :_put, :put
|
17
|
+
|
18
|
+
undef_method :delete
|
19
|
+
undef_method :get
|
20
|
+
undef_method :post
|
21
|
+
undef_method :put
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.http_delete(path, options={})
|
25
|
+
check_status(_delete(path, options))
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.http_get(path, options={})
|
29
|
+
check_status(_get(path, options))
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.http_post(path, options={})
|
33
|
+
check_status(_post(path, options))
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.http_put(path, options={})
|
37
|
+
check_status(_put(path, options))
|
38
|
+
end
|
39
|
+
|
40
|
+
# == protected
|
41
|
+
|
42
|
+
def self.check_status(response)
|
43
|
+
case response.code
|
44
|
+
when 400: raise BadRequest, error(response)
|
45
|
+
when 401: raise Unauthorized, error(response)
|
46
|
+
when 403: raise Forbidden, error(response)
|
47
|
+
when 404: raise NotFound, error(response)
|
48
|
+
when 409: raise Conflict, error(response)
|
49
|
+
when 500: raise InternalServerError, error(response)
|
50
|
+
end
|
51
|
+
response
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.error(response)
|
55
|
+
parsed_body = JSON.parse(response.body)
|
56
|
+
if parsed_body.empty?
|
57
|
+
"Response was empty"
|
58
|
+
elsif parsed_body["errors"]
|
59
|
+
parsed_body["errors"].inspect
|
60
|
+
else
|
61
|
+
response.body
|
62
|
+
end
|
63
|
+
rescue JSON::ParserError
|
64
|
+
"Unable to parse: #{response.body.inspect}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.many(response)
|
68
|
+
response.map { |item| new(item) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.one(response)
|
72
|
+
response.blank? ? nil : new(response)
|
73
|
+
end
|
74
|
+
|
75
|
+
def method_missing(method_name, *args)
|
76
|
+
if method_name.to_s.match(/.*_(on|at)\z/)
|
77
|
+
return Time.parse(super)
|
78
|
+
else
|
79
|
+
super
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/lib/datacatalog.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'activesupport'
|
3
|
-
require 'httparty'
|
4
|
-
require 'mash'
|
5
|
-
|
6
|
-
require File.dirname(__FILE__) + '/main'
|
7
|
-
require File.dirname(__FILE__) + '/base'
|
8
|
-
Dir.glob(File.dirname(__FILE__) + '/resources/*.rb').each { |f| require f }
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activesupport'
|
3
|
+
require 'httparty'
|
4
|
+
require 'mash'
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/main'
|
7
|
+
require File.dirname(__FILE__) + '/base'
|
8
|
+
Dir.glob(File.dirname(__FILE__) + '/resources/*.rb').each { |f| require f }
|
data/lib/main.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
module DataCatalog
|
2
|
-
|
3
|
-
# == Exceptions
|
4
|
-
|
5
|
-
class Error < RuntimeError; end
|
6
|
-
class BadRequest < Error; end # 400
|
7
|
-
class Unauthorized < Error; end # 401
|
8
|
-
class Forbidden < Error; end # 403
|
9
|
-
class NotFound < Error; end # 404
|
10
|
-
class Conflict < Error; end # 409
|
11
|
-
class InternalServerError < Error; end # 500
|
12
|
-
class ApiKeyNotConfigured < Error; end
|
13
|
-
class CannotDeletePrimaryApiKey < Error; end
|
14
|
-
|
15
|
-
# == Accessors
|
16
|
-
|
17
|
-
def self.api_key
|
18
|
-
Base.default_params[:api_key]
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.api_key=(key)
|
22
|
-
Base.default_params :api_key => key
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.base_uri
|
26
|
-
Base.base_uri
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.base_uri=(uri)
|
30
|
-
Base.base_uri(uri.blank? ? Base::DEFAULT_BASE_URI : uri)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.with_key(temp_key)
|
34
|
-
original_key = DataCatalog.api_key
|
35
|
-
DataCatalog.api_key = temp_key
|
36
|
-
result = yield
|
37
|
-
DataCatalog.api_key = original_key
|
38
|
-
result
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
1
|
+
module DataCatalog
|
2
|
+
|
3
|
+
# == Exceptions
|
4
|
+
|
5
|
+
class Error < RuntimeError; end
|
6
|
+
class BadRequest < Error; end # 400
|
7
|
+
class Unauthorized < Error; end # 401
|
8
|
+
class Forbidden < Error; end # 403
|
9
|
+
class NotFound < Error; end # 404
|
10
|
+
class Conflict < Error; end # 409
|
11
|
+
class InternalServerError < Error; end # 500
|
12
|
+
class ApiKeyNotConfigured < Error; end
|
13
|
+
class CannotDeletePrimaryApiKey < Error; end
|
14
|
+
|
15
|
+
# == Accessors
|
16
|
+
|
17
|
+
def self.api_key
|
18
|
+
Base.default_params[:api_key]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.api_key=(key)
|
22
|
+
Base.default_params :api_key => key
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.base_uri
|
26
|
+
Base.base_uri
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.base_uri=(uri)
|
30
|
+
Base.base_uri(uri.blank? ? Base::DEFAULT_BASE_URI : uri)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.with_key(temp_key)
|
34
|
+
original_key = DataCatalog.api_key
|
35
|
+
DataCatalog.api_key = temp_key
|
36
|
+
result = yield
|
37
|
+
DataCatalog.api_key = original_key
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module DataCatalog
|
2
|
+
|
3
|
+
class Organization < Base
|
4
|
+
|
5
|
+
def self.all(conditions={})
|
6
|
+
many(http_get("/organizations", :query => conditions))
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.create(params={})
|
10
|
+
one(http_post("/organizations", :body => params))
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.destroy(organization_id)
|
14
|
+
one(http_delete("/organizations/#{organization_id}"))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.first(conditions={})
|
18
|
+
one(http_get("/organizations", :query => conditions).first)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get(id)
|
22
|
+
one(http_get("/organizations/#{id}"))
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.update(organization_id, params={})
|
26
|
+
one(http_put("/organizations/#{organization_id}", :body => params))
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/sandbox_api.yml.example
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
api_key: d193d1523d49e4caf46297ef94d7a2c995d3b2cb # generate with rake db:ensure_admin on datacatalog-api
|
2
|
-
base_uri: sandbox.dc-api.local
|
1
|
+
api_key: d193d1523d49e4caf46297ef94d7a2c995d3b2cb # generate with rake db:ensure_admin on datacatalog-api
|
2
|
+
base_uri: sandbox.dc-api.local
|
data/spec/about_spec.rb
CHANGED
@@ -1,21 +1,42 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
include DataCatalog
|
3
|
-
|
4
|
-
describe DataCatalog do
|
5
|
-
|
6
|
-
describe ".about" do
|
7
|
-
before do
|
8
|
-
setup_api
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return information about the API" do
|
12
|
-
about = About.get
|
13
|
-
about.should be_an_instance_of(About)
|
14
|
-
about.name.should == "National Data Catalog API"
|
15
|
-
about.project_page.should == {
|
16
|
-
"href" => "http://sunlightlabs.com/projects/datacatalog/"
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
include DataCatalog
|
3
|
+
|
4
|
+
describe DataCatalog do
|
5
|
+
|
6
|
+
describe ".about" do
|
7
|
+
before do
|
8
|
+
setup_api
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return information about the API" do
|
12
|
+
about = About.get
|
13
|
+
about.should be_an_instance_of(About)
|
14
|
+
about.name.should == "National Data Catalog API"
|
15
|
+
about.project_page.should == {
|
16
|
+
"href" => "http://sunlightlabs.com/projects/datacatalog/"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".version_at_least?" do
|
22
|
+
|
23
|
+
it "should return false if below the actual version" do
|
24
|
+
version_mock = mock(Object.new).version { '1.0.0' }
|
25
|
+
mock(About).get { version_mock }
|
26
|
+
About.version_at_least?('1.1.1').should be false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return true if at the actual version" do
|
30
|
+
version_mock = mock(Object.new).version { '1.0.0' }
|
31
|
+
mock(About).get { version_mock }
|
32
|
+
About.version_at_least?('1.0.0').should be true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return true if above the actual version" do
|
36
|
+
version_mock = mock(Object.new).version { '1.0.0' }
|
37
|
+
mock(About).get { version_mock }
|
38
|
+
About.version_at_least?('0.9.9').should be true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|