datacatalog 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,36 +1,36 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
- include DataCatalog
3
-
4
- describe DataCatalog do
5
-
6
- describe "module accessors" do
7
- it "should access the API Key" do
8
- DataCatalog.api_key = "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
9
- DataCatalog.api_key.should == "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
10
- end
11
-
12
- it "should access the base URI" do
13
- DataCatalog.base_uri = 'http://somehost.com'
14
- DataCatalog.base_uri.should == 'http://somehost.com'
15
- end
16
- end
17
-
18
- describe ".with_key" do
19
- it "should set the API key within the block" do
20
- regular_key = '4159179f32ff8fefd2c6d48b7e675e7736bf1357'
21
- DataCatalog.api_key = regular_key
22
- temporary_key = '0000123400001234000012340000123400001234'
23
- DataCatalog.with_key(temporary_key) do
24
- DataCatalog.api_key.should == temporary_key
25
- end
26
- DataCatalog.api_key.should == regular_key
27
- end
28
-
29
- it "should return the last value in the block" do
30
- DataCatalog.with_key("0000444400004444") do
31
- 42
32
- end.should == 42
33
- end
34
- end
35
-
36
- end
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe DataCatalog do
5
+
6
+ describe "module accessors" do
7
+ it "should access the API Key" do
8
+ DataCatalog.api_key = "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
9
+ DataCatalog.api_key.should == "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
10
+ end
11
+
12
+ it "should access the base URI" do
13
+ DataCatalog.base_uri = 'http://somehost.com'
14
+ DataCatalog.base_uri.should == 'http://somehost.com'
15
+ end
16
+ end
17
+
18
+ describe ".with_key" do
19
+ it "should set the API key within the block" do
20
+ regular_key = '4159179f32ff8fefd2c6d48b7e675e7736bf1357'
21
+ DataCatalog.api_key = regular_key
22
+ temporary_key = '0000123400001234000012340000123400001234'
23
+ DataCatalog.with_key(temporary_key) do
24
+ DataCatalog.api_key.should == temporary_key
25
+ end
26
+ DataCatalog.api_key.should == regular_key
27
+ end
28
+
29
+ it "should return the last value in the block" do
30
+ DataCatalog.with_key("0000444400004444") do
31
+ 42
32
+ end.should == 42
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,124 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Organization do
5
+
6
+ def create_3_organizations
7
+ @organization_names = ["Federal Communications Commission", "Federal Election Commission", "Department of State"]
8
+ @organization_names.each do |name|
9
+ Organization.create(:name => name)
10
+ end
11
+ end
12
+
13
+ before do
14
+ setup_api
15
+ clean_slate
16
+ end
17
+
18
+ describe ".all" do
19
+
20
+ before do
21
+ create_3_organizations
22
+ end
23
+
24
+ it "should return an enumeration of Organizations" do
25
+ @organizations = Organization.all
26
+ @organizations.each do |o|
27
+ o.should be_an_instance_of(Organization)
28
+ end
29
+ end
30
+
31
+ it "should return an enumeration with organization name set" do
32
+ @organizations = Organization.all
33
+ @organizations.map(&:name).sort.should == @organization_names.sort
34
+ end
35
+
36
+ it "should return the matching organizations when options are passed in" do
37
+ @organizations = Organization.all(:name => "Federal Communications Commission")
38
+ @organizations.map(&:name).should == ["Federal Communications Commission"]
39
+ end
40
+
41
+ end # describe ".all"
42
+
43
+ describe ".first" do
44
+
45
+ before do
46
+ create_3_organizations
47
+ end
48
+
49
+ it "should return the matching organization when options are passed in" do
50
+ @organization = Organization.first(:name => "Federal Communications Commission")
51
+ @organization.name.should == "Federal Communications Commission"
52
+ end
53
+
54
+ end # describe ".first"
55
+
56
+ describe ".get" do
57
+
58
+ before do
59
+ @organization = Organization.create(:name => "Federal Election Commission")
60
+ end
61
+
62
+ it "should return an organization" do
63
+ organization = Organization.get(@organization.id)
64
+ organization.should be_an_instance_of(Organization)
65
+ organization.name.should == "Federal Election Commission"
66
+ end
67
+
68
+ it "should raise NotFound if no source exists" do
69
+ executing do
70
+ Organization.get(mangle(@organization.id))
71
+ end.should raise_error(NotFound)
72
+ end
73
+
74
+ end # describe ".get"
75
+
76
+ describe ".create" do
77
+
78
+ it "should create a new organization when valid params are passed in" do
79
+ @organization = Organization.create(:name => "Federal Communications Commission")
80
+ @organization.should be_an_instance_of(Organization)
81
+ @organization.name.should == "Federal Communications Commission"
82
+ end
83
+
84
+ it "should raise BadRequest when a bad URL is passed in" do
85
+ executing do
86
+ Organization.create(:name => "Bad Org", :url => "htt:p//jlkj!3")
87
+ end.should raise_error(BadRequest)
88
+ end
89
+
90
+ end # describe ".create"
91
+
92
+ describe ".update" do
93
+
94
+ before do
95
+ @organization = Organization.create(:name => "Federal Election Commission")
96
+ end
97
+
98
+ it "should update an existing organization from valid params" do
99
+ organization = Organization.update(@organization.id, { :url => "http://fec.gov/" })
100
+ organization.should be_an_instance_of(Organization)
101
+ organization.url.should == "http://fec.gov/"
102
+ end
103
+
104
+ end # describe ".update"
105
+
106
+ describe ".destroy" do
107
+
108
+ before do
109
+ @organization = Organization.create(:name => "Federal Election Commission")
110
+ end
111
+
112
+ it "should destroy an existing organization" do
113
+ Organization.destroy(@organization.id).should be_true
114
+ end
115
+
116
+ it "should raise NotFound when attempting to destroy non-existing organization" do
117
+ executing do
118
+ Organization.destroy(mangle(@organization.id))
119
+ end.should raise_error(NotFound)
120
+ end
121
+
122
+ end # describe ".destroy"
123
+
124
+ end
data/spec/source_spec.rb CHANGED
@@ -1,162 +1,162 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
- include DataCatalog
3
-
4
- module SourceHelpers
5
- def create_source(params={})
6
- valid_params = {
7
- :title => "Some FCC Data",
8
- :url => "http://fcc.gov/somedata.csv"
9
- }
10
- Source.create(valid_params.merge(params))
11
- end
12
-
13
- def create_3_sources
14
- %w(FCC NASA DOE).each do |name|
15
- Source.create({
16
- :title => "#{name} Data",
17
- :url => "http://#{name.downcase}.gov/data.xml"
18
- })
19
- end
20
- end
21
- end
22
-
23
- describe Source do
24
- include SourceHelpers
25
-
26
- before do
27
- setup_api
28
- clean_slate
29
- end
30
-
31
- describe ".all" do
32
- before do
33
- create_3_sources
34
- @sources = Source.all
35
- end
36
-
37
- it "should return an enumeration of sources" do
38
- @sources.each do |source|
39
- source.should be_an_instance_of(Source)
40
- end
41
- end
42
-
43
- it "should return correct titles" do
44
- expected = ["FCC Data", "NASA Data", "DOE Data"]
45
- @sources.map(&:title).sort.should == expected.sort
46
- end
47
- end
48
-
49
- describe ".all with conditions" do
50
- before do
51
- create_3_sources
52
- @sources = Source.all(:title => "NASA Data")
53
- end
54
-
55
- it "should return an enumeration of sources" do
56
- @sources.each do |source|
57
- source.should be_an_instance_of(Source)
58
- end
59
- end
60
-
61
- it "should return correct titles" do
62
- expected = ["NASA Data"]
63
- @sources.map(&:title).sort.should == expected.sort
64
- end
65
- end
66
-
67
- describe ".create" do
68
- it "should create a new source from basic params" do
69
- source = create_source
70
- source.should be_an_instance_of(Source)
71
- source.url.should == "http://fcc.gov/somedata.csv"
72
- end
73
-
74
- it "should create a new source from custom params" do
75
- source = create_source({ :custom => {
76
- "0" => {
77
- :label => "License",
78
- :description => "License",
79
- :type => "string",
80
- :value => "Public Domain"
81
- }
82
- }})
83
- source.should be_an_instance_of(Source)
84
- source.url.should == "http://fcc.gov/somedata.csv"
85
- source.custom.should == {
86
- "0" => {
87
- "label" => "License",
88
- "description" => "License",
89
- "type" => "string",
90
- "value" => "Public Domain"
91
- }
92
- }
93
- end
94
- end
95
-
96
- describe ".first" do
97
- before do
98
- create_3_sources
99
- end
100
-
101
- it "should return a source" do
102
- source = Source.first(:title => "NASA Data")
103
- source.should be_an_instance_of(Source)
104
- source.title.should == "NASA Data"
105
- end
106
-
107
- it "should return nil if nothing found" do
108
- source = Source.first(:title => "UFO Data")
109
- source.should be_nil
110
- end
111
- end
112
-
113
- describe ".get" do
114
- before do
115
- @source = create_source
116
- end
117
-
118
- it "should return a source" do
119
- source = Source.get(@source.id)
120
- source.should be_an_instance_of(Source)
121
- source.title.should == "Some FCC Data"
122
- end
123
-
124
- it "should raise NotFound if no source exists" do
125
- executing do
126
- Source.get(mangle(@source.id))
127
- end.should raise_error(NotFound)
128
- end
129
- end
130
-
131
- describe ".update" do
132
- before do
133
- @source = create_source
134
- end
135
-
136
- it "should update an existing source from valid params" do
137
- source = Source.update(@source.id, {
138
- :url => "http://fec.gov/newdata.csv"
139
- })
140
- source.should be_an_instance_of(Source)
141
- source.url.should == "http://fec.gov/newdata.csv"
142
- end
143
- end
144
-
145
- describe ".destroy" do
146
- before do
147
- @source = create_source
148
- end
149
-
150
- it "should destroy an existing source" do
151
- result = Source.destroy(@source.id)
152
- result.should be_true
153
- end
154
-
155
- it "should raise NotFound when attempting to destroy non-existing source" do
156
- executing do
157
- Source.destroy(mangle(@source.id))
158
- end.should raise_error(NotFound)
159
- end
160
- end
161
-
162
- end
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ module SourceHelpers
5
+ def create_source(params={})
6
+ valid_params = {
7
+ :title => "Some FCC Data",
8
+ :url => "http://fcc.gov/somedata.csv"
9
+ }
10
+ Source.create(valid_params.merge(params))
11
+ end
12
+
13
+ def create_3_sources
14
+ %w(FCC NASA DOE).each do |name|
15
+ Source.create({
16
+ :title => "#{name} Data",
17
+ :url => "http://#{name.downcase}.gov/data.xml"
18
+ })
19
+ end
20
+ end
21
+ end
22
+
23
+ describe Source do
24
+ include SourceHelpers
25
+
26
+ before do
27
+ setup_api
28
+ clean_slate
29
+ end
30
+
31
+ describe ".all" do
32
+ before do
33
+ create_3_sources
34
+ @sources = Source.all
35
+ end
36
+
37
+ it "should return an enumeration of sources" do
38
+ @sources.each do |source|
39
+ source.should be_an_instance_of(Source)
40
+ end
41
+ end
42
+
43
+ it "should return correct titles" do
44
+ expected = ["FCC Data", "NASA Data", "DOE Data"]
45
+ @sources.map(&:title).sort.should == expected.sort
46
+ end
47
+ end
48
+
49
+ describe ".all with conditions" do
50
+ before do
51
+ create_3_sources
52
+ @sources = Source.all(:title => "NASA Data")
53
+ end
54
+
55
+ it "should return an enumeration of sources" do
56
+ @sources.each do |source|
57
+ source.should be_an_instance_of(Source)
58
+ end
59
+ end
60
+
61
+ it "should return correct titles" do
62
+ expected = ["NASA Data"]
63
+ @sources.map(&:title).sort.should == expected.sort
64
+ end
65
+ end
66
+
67
+ describe ".create" do
68
+ it "should create a new source from basic params" do
69
+ source = create_source
70
+ source.should be_an_instance_of(Source)
71
+ source.url.should == "http://fcc.gov/somedata.csv"
72
+ end
73
+
74
+ it "should create a new source from custom params" do
75
+ source = create_source({ :custom => {
76
+ "0" => {
77
+ :label => "License",
78
+ :description => "License",
79
+ :type => "string",
80
+ :value => "Public Domain"
81
+ }
82
+ }})
83
+ source.should be_an_instance_of(Source)
84
+ source.url.should == "http://fcc.gov/somedata.csv"
85
+ source.custom.should == {
86
+ "0" => {
87
+ "label" => "License",
88
+ "description" => "License",
89
+ "type" => "string",
90
+ "value" => "Public Domain"
91
+ }
92
+ }
93
+ end
94
+ end
95
+
96
+ describe ".first" do
97
+ before do
98
+ create_3_sources
99
+ end
100
+
101
+ it "should return a source" do
102
+ source = Source.first(:title => "NASA Data")
103
+ source.should be_an_instance_of(Source)
104
+ source.title.should == "NASA Data"
105
+ end
106
+
107
+ it "should return nil if nothing found" do
108
+ source = Source.first(:title => "UFO Data")
109
+ source.should be_nil
110
+ end
111
+ end
112
+
113
+ describe ".get" do
114
+ before do
115
+ @source = create_source
116
+ end
117
+
118
+ it "should return a source" do
119
+ source = Source.get(@source.id)
120
+ source.should be_an_instance_of(Source)
121
+ source.title.should == "Some FCC Data"
122
+ end
123
+
124
+ it "should raise NotFound if no source exists" do
125
+ executing do
126
+ Source.get(mangle(@source.id))
127
+ end.should raise_error(NotFound)
128
+ end
129
+ end
130
+
131
+ describe ".update" do
132
+ before do
133
+ @source = create_source
134
+ end
135
+
136
+ it "should update an existing source from valid params" do
137
+ source = Source.update(@source.id, {
138
+ :url => "http://fec.gov/newdata.csv"
139
+ })
140
+ source.should be_an_instance_of(Source)
141
+ source.url.should == "http://fec.gov/newdata.csv"
142
+ end
143
+ end
144
+
145
+ describe ".destroy" do
146
+ before do
147
+ @source = create_source
148
+ end
149
+
150
+ it "should destroy an existing source" do
151
+ result = Source.destroy(@source.id)
152
+ result.should be_true
153
+ end
154
+
155
+ it "should raise NotFound when attempting to destroy non-existing source" do
156
+ executing do
157
+ Source.destroy(mangle(@source.id))
158
+ end.should raise_error(NotFound)
159
+ end
160
+ end
161
+
162
+ end