datacatalog 0.4.16 → 0.4.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,6 @@ describe Organization do
20
20
  end
21
21
 
22
22
  describe ".all" do
23
-
24
23
  before do
25
24
  create_3_organizations
26
25
  end
@@ -39,23 +38,39 @@ describe Organization do
39
38
  orgs = Organization.all(:name => "Federal Communications Commission")
40
39
  orgs.map(&:name).should == ["Federal Communications Commission"]
41
40
  end
41
+ end
42
42
 
43
- end # describe ".all"
43
+ describe ".create" do
44
+ it "should create a new organization when valid params are passed in" do
45
+ org = Organization.create(:name => "Federal Communications Commission", :org_type => "governmental")
46
+ org.should be_an_instance_of(Organization)
47
+ org.name.should == "Federal Communications Commission"
48
+ end
44
49
 
45
- describe ".search" do
50
+ it "should raise BadRequest when a bad URL is passed in" do
51
+ executing do
52
+ Organization.create(:name => "Bad Org", :url => "htt:p//jlkj!3", :org_type => "governmental")
53
+ end.should raise_error(BadRequest)
54
+ end
55
+ end
56
+
57
+ describe ".destroy" do
46
58
  before do
47
- create_3_organizations
59
+ @organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
48
60
  end
49
61
 
50
- it "should return correct search result" do
51
- @organizations = Organization.search("Federal")
52
- @organizations.size.should == 2
53
- @organizations.first.name.should == "Federal Communications Commission"
62
+ it "should destroy an existing organization" do
63
+ Organization.destroy(@organization.id).should be_true
54
64
  end
55
- end # describe organizations
56
65
 
57
- describe ".first" do
66
+ it "should raise NotFound when attempting to destroy non-existing organization" do
67
+ executing do
68
+ Organization.destroy(mangle(@organization.id))
69
+ end.should raise_error(NotFound)
70
+ end
71
+ end
58
72
 
73
+ describe ".first" do
59
74
  before do
60
75
  create_3_organizations
61
76
  end
@@ -64,11 +79,9 @@ describe Organization do
64
79
  org = Organization.first(:name => "Federal Communications Commission")
65
80
  org.name.should == "Federal Communications Commission"
66
81
  end
67
-
68
- end # describe ".first"
82
+ end
69
83
 
70
84
  describe ".get" do
71
-
72
85
  before do
73
86
  @organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
74
87
  end
@@ -84,27 +97,21 @@ describe Organization do
84
97
  Organization.get(mangle(@organization.id))
85
98
  end.should raise_error(NotFound)
86
99
  end
100
+ end
87
101
 
88
- end # describe ".get"
89
-
90
- describe ".create" do
91
-
92
- it "should create a new organization when valid params are passed in" do
93
- org = Organization.create(:name => "Federal Communications Commission", :org_type => "governmental")
94
- org.should be_an_instance_of(Organization)
95
- org.name.should == "Federal Communications Commission"
102
+ describe ".search" do
103
+ before do
104
+ create_3_organizations
96
105
  end
97
106
 
98
- it "should raise BadRequest when a bad URL is passed in" do
99
- executing do
100
- Organization.create(:name => "Bad Org", :url => "htt:p//jlkj!3", :org_type => "governmental")
101
- end.should raise_error(BadRequest)
107
+ it "should return correct search result" do
108
+ @organizations = Organization.search("Federal")
109
+ @organizations.size.should == 2
110
+ @organizations.first.name.should == "Federal Communications Commission"
102
111
  end
103
-
104
- end # describe ".create"
112
+ end
105
113
 
106
114
  describe ".update" do
107
-
108
115
  before do
109
116
  @organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
110
117
  end
@@ -114,25 +121,6 @@ describe Organization do
114
121
  organization.should be_an_instance_of(Organization)
115
122
  organization.url.should == "http://fec.gov/"
116
123
  end
124
+ end
117
125
 
118
- end # describe ".update"
119
-
120
- describe ".destroy" do
121
-
122
- before do
123
- @organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
124
- end
125
-
126
- it "should destroy an existing organization" do
127
- Organization.destroy(@organization.id).should be_true
128
- end
129
-
130
- it "should raise NotFound when attempting to destroy non-existing organization" do
131
- executing do
132
- Organization.destroy(mangle(@organization.id))
133
- end.should raise_error(NotFound)
134
- end
135
-
136
- end # describe ".destroy"
137
-
138
- end
126
+ end
data/spec/rating_spec.rb CHANGED
@@ -27,8 +27,27 @@ describe Rating do
27
27
  end
28
28
  end
29
29
 
30
- describe ".create" do
30
+ describe ".all" do
31
+ before do
32
+ DataCatalog.with_key(@user.primary_api_key) do
33
+ @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
34
+ end
31
35
 
36
+ DataCatalog.with_key(@user2.primary_api_key) do
37
+ @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 3)
38
+ end
39
+ end
40
+
41
+ it "should return a collection of all the source's ratings" do
42
+ ratings = Rating.all(:source_id => @source.id)
43
+
44
+ ratings[0].should be_an_instance_of(Rating)
45
+ ratings[0].value.should == 5
46
+ ratings[1].value.should == 3
47
+ end
48
+ end
49
+
50
+ describe ".create" do
32
51
  it "should create a source rating when valid params are passed in" do
33
52
  DataCatalog.with_key(@user.primary_api_key) do
34
53
  @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
@@ -48,56 +67,53 @@ describe Rating do
48
67
  refreshed_comment.rating_stats.average.should == 1
49
68
  refreshed_comment.rating_stats.total.should == 1
50
69
  end
70
+ end
51
71
 
52
- end # describe ".create"
53
-
54
- describe ".get" do
55
-
72
+ describe ".destroy" do
56
73
  before do
57
74
  DataCatalog.with_key(@user.primary_api_key) do
58
75
  @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
59
76
  end
60
77
  end
61
78
 
62
- it "should return a rating" do
63
- rating = Rating.get(@rating.id)
64
- rating.should be_an_instance_of(Rating)
65
- rating.value.should == 5
79
+ it "should destroy an existing rating as an admin" do
80
+ Rating.destroy(@rating.id).should be_true
66
81
  end
67
82
 
68
- it "should raise NotFound if no rating exists" do
83
+ it "should destroy an existing rating as the user" do
84
+ DataCatalog.with_key(@user.primary_api_key) do
85
+ Rating.destroy(@rating.id).should be_true
86
+ end
87
+ end
88
+
89
+ it "should raise NotFound when attempting to destroy non-existing rating" do
69
90
  executing do
70
- Rating.get(mangle(@rating.id))
91
+ Rating.destroy(mangle(@rating.id))
71
92
  end.should raise_error(NotFound)
72
93
  end
94
+ end
73
95
 
74
- end # describe ".get"
75
-
76
- describe ".all" do
77
-
96
+ describe ".get" do
78
97
  before do
79
98
  DataCatalog.with_key(@user.primary_api_key) do
80
99
  @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
81
100
  end
82
-
83
- DataCatalog.with_key(@user2.primary_api_key) do
84
- @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 3)
85
- end
86
-
87
101
  end
88
102
 
89
- it "should return a collection of all the source's ratings" do
90
- ratings = Rating.all(:source_id => @source.id)
91
-
92
- ratings[0].should be_an_instance_of(Rating)
93
- ratings[0].value.should == 5
94
- ratings[1].value.should == 3
103
+ it "should return a rating" do
104
+ rating = Rating.get(@rating.id)
105
+ rating.should be_an_instance_of(Rating)
106
+ rating.value.should == 5
95
107
  end
96
108
 
97
- end # describe ".all"
109
+ it "should raise NotFound if no rating exists" do
110
+ executing do
111
+ Rating.get(mangle(@rating.id))
112
+ end.should raise_error(NotFound)
113
+ end
114
+ end
98
115
 
99
116
  describe ".update" do
100
-
101
117
  before do
102
118
  DataCatalog.with_key(@user.primary_api_key) do
103
119
  @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
@@ -113,33 +129,5 @@ describe Rating do
113
129
  refreshed_rating.value.should == 3
114
130
  refreshed_rating.previous_value.should == 5
115
131
  end
116
-
117
- end # describe ".update"
118
-
119
- describe ".destroy" do
120
-
121
- before do
122
- DataCatalog.with_key(@user.primary_api_key) do
123
- @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
124
- end
125
- end
126
-
127
- it "should destroy an existing rating as an admin" do
128
- Rating.destroy(@rating.id).should be_true
129
- end
130
-
131
- it "should destroy an existing rating as the user" do
132
- DataCatalog.with_key(@user.primary_api_key) do
133
- Rating.destroy(@rating.id).should be_true
134
- end
135
- end
136
-
137
- it "should raise NotFound when attempting to destroy non-existing rating" do
138
- executing do
139
- Rating.destroy(mangle(@rating.id))
140
- end.should raise_error(NotFound)
141
- end
142
-
143
- end # describe ".destroy"
144
-
145
- end
132
+ end
133
+ end
data/spec/report_spec.rb CHANGED
@@ -13,45 +13,6 @@ describe Report do
13
13
  )
14
14
  end
15
15
 
16
- describe ".create" do
17
- it "should create a new report when valid params are passed in" do
18
- DataCatalog.with_key(@john.primary_api_key) do
19
- @report = Report.create(
20
- :text => "Report 1 by John",
21
- :status => "new"
22
- )
23
- end
24
- @report.should be_an_instance_of(Report)
25
- refreshed_report = Report.get(@report.id)
26
- refreshed_report.text.should == "Report 1 by John"
27
- refreshed_report.status.should == "new"
28
- refreshed_report.user_id.should == @john.id
29
- end
30
- end
31
-
32
- describe ".get" do
33
- before do
34
- DataCatalog.with_key(@john.primary_api_key) do
35
- @report = Report.create(
36
- :text => "Report 1 by John",
37
- :status => "new"
38
- )
39
- end
40
- end
41
-
42
- it "should return a report" do
43
- report = Report.get(@report.id)
44
- report.should be_an_instance_of(Report)
45
- report.text.should == "Report 1 by John"
46
- end
47
-
48
- it "should raise NotFound if no report exists" do
49
- executing do
50
- Report.get(mangle(@report.id))
51
- end.should raise_error(NotFound)
52
- end
53
- end
54
-
55
16
  describe ".all" do
56
17
  before do
57
18
  @jane = User.create(
@@ -74,23 +35,19 @@ describe Report do
74
35
  end
75
36
  end
76
37
 
77
- describe ".update" do
78
- before do
38
+ describe ".create" do
39
+ it "should create a new report when valid params are passed in" do
79
40
  DataCatalog.with_key(@john.primary_api_key) do
80
41
  @report = Report.create(
81
42
  :text => "Report 1 by John",
82
43
  :status => "new"
83
44
  )
84
45
  end
85
- end
86
-
87
- it "should update an existing report with valid params" do
88
- DataCatalog.with_key(@john.primary_api_key) do
89
- Report.update(@report.id, :status => "open")
90
- end
46
+ @report.should be_an_instance_of(Report)
91
47
  refreshed_report = Report.get(@report.id)
92
48
  refreshed_report.text.should == "Report 1 by John"
93
- refreshed_report.status.should == "open"
49
+ refreshed_report.status.should == "new"
50
+ refreshed_report.user_id.should == @john.id
94
51
  end
95
52
  end
96
53
 
@@ -121,4 +78,47 @@ describe Report do
121
78
  end
122
79
  end
123
80
 
81
+ describe ".get" do
82
+ before do
83
+ DataCatalog.with_key(@john.primary_api_key) do
84
+ @report = Report.create(
85
+ :text => "Report 1 by John",
86
+ :status => "new"
87
+ )
88
+ end
89
+ end
90
+
91
+ it "should return a report" do
92
+ report = Report.get(@report.id)
93
+ report.should be_an_instance_of(Report)
94
+ report.text.should == "Report 1 by John"
95
+ end
96
+
97
+ it "should raise NotFound if no report exists" do
98
+ executing do
99
+ Report.get(mangle(@report.id))
100
+ end.should raise_error(NotFound)
101
+ end
102
+ end
103
+
104
+ describe ".update" do
105
+ before do
106
+ DataCatalog.with_key(@john.primary_api_key) do
107
+ @report = Report.create(
108
+ :text => "Report 1 by John",
109
+ :status => "new"
110
+ )
111
+ end
112
+ end
113
+
114
+ it "should update an existing report with valid params" do
115
+ DataCatalog.with_key(@john.primary_api_key) do
116
+ Report.update(@report.id, :status => "open")
117
+ end
118
+ refreshed_report = Report.get(@report.id)
119
+ refreshed_report.text.should == "Report 1 by John"
120
+ refreshed_report.status.should == "open"
121
+ end
122
+ end
123
+
124
124
  end
data/spec/source_spec.rb CHANGED
@@ -61,9 +61,7 @@ describe Source do
61
61
  @sources.map(&:title).sort.should == expected.sort
62
62
  end
63
63
 
64
-
65
64
  describe "with cursor" do
66
-
67
65
  it "should raise an error on bad index" do
68
66
  executing do
69
67
  @sources.page(0)
@@ -77,7 +75,6 @@ describe Source do
77
75
  sources.page(1).size.should == 20
78
76
  sources.page(2).size.should == 13
79
77
  end
80
-
81
78
  end
82
79
  end
83
80
 
@@ -99,18 +96,6 @@ describe Source do
99
96
  end
100
97
  end
101
98
 
102
- describe ".search" do
103
- before do
104
- create_3_sources
105
- end
106
-
107
- it "should return correct search result" do
108
- @sources = Source.search("FCC")
109
- @sources.size.should == 1
110
- @sources.first.title.should == "FCC Data"
111
- end
112
- end
113
-
114
99
  describe ".create" do
115
100
  it "should create a new source from basic params" do
116
101
  source = create_source
@@ -140,6 +125,23 @@ describe Source do
140
125
  end
141
126
  end
142
127
 
128
+ describe ".destroy" do
129
+ before do
130
+ @source = create_source
131
+ end
132
+
133
+ it "should destroy an existing source" do
134
+ result = Source.destroy(@source.id)
135
+ result.should be_true
136
+ end
137
+
138
+ it "should raise NotFound when attempting to destroy non-existing source" do
139
+ executing do
140
+ Source.destroy(mangle(@source.id))
141
+ end.should raise_error(NotFound)
142
+ end
143
+ end
144
+
143
145
  describe ".first" do
144
146
  before do
145
147
  create_3_sources
@@ -175,6 +177,18 @@ describe Source do
175
177
  end
176
178
  end
177
179
 
180
+ describe ".search" do
181
+ before do
182
+ create_3_sources
183
+ end
184
+
185
+ it "should return correct search result" do
186
+ @sources = Source.search("FCC")
187
+ @sources.size.should == 1
188
+ @sources.first.title.should == "FCC Data"
189
+ end
190
+ end
191
+
178
192
  describe ".update" do
179
193
  before do
180
194
  @source = create_source
@@ -189,21 +203,4 @@ describe Source do
189
203
  end
190
204
  end
191
205
 
192
- describe ".destroy" do
193
- before do
194
- @source = create_source
195
- end
196
-
197
- it "should destroy an existing source" do
198
- result = Source.destroy(@source.id)
199
- result.should be_true
200
- end
201
-
202
- it "should raise NotFound when attempting to destroy non-existing source" do
203
- executing do
204
- Source.destroy(mangle(@source.id))
205
- end.should raise_error(NotFound)
206
- end
207
- end
208
-
209
206
  end