publish_my_data 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +37 -0
  3. data/Rakefile +41 -0
  4. data/app/assets/javascripts/publish_my_data/application.js +15 -0
  5. data/app/assets/javascripts/publish_my_data/resources.js +2 -0
  6. data/app/assets/stylesheets/publish_my_data/application.css +13 -0
  7. data/app/assets/stylesheets/publish_my_data/resources.css +4 -0
  8. data/app/controllers/publish_my_data/application_controller.rb +49 -0
  9. data/app/controllers/publish_my_data/datasets_controller.rb +48 -0
  10. data/app/controllers/publish_my_data/errors_controller.rb +9 -0
  11. data/app/controllers/publish_my_data/home_controller.rb +4 -0
  12. data/app/controllers/publish_my_data/resources_controller.rb +103 -0
  13. data/app/controllers/publish_my_data/sparql_controller.rb +50 -0
  14. data/app/helpers/publish_my_data/application_helper.rb +4 -0
  15. data/app/helpers/publish_my_data/resources_helper.rb +28 -0
  16. data/app/helpers/publish_my_data/sparql_helper.rb +7 -0
  17. data/app/models/publish_my_data/concept_scheme.rb +5 -0
  18. data/app/models/publish_my_data/dataset.rb +61 -0
  19. data/app/models/publish_my_data/ontology.rb +5 -0
  20. data/app/models/publish_my_data/rdf_type.rb +6 -0
  21. data/app/models/publish_my_data/resource.rb +21 -0
  22. data/app/views/layouts/publish_my_data/application.html.erb +14 -0
  23. data/app/views/layouts/publish_my_data/error.html.erb +3 -0
  24. data/app/views/publish_my_data/datasets/index.html.erb +20 -0
  25. data/app/views/publish_my_data/datasets/show.html.erb +18 -0
  26. data/app/views/publish_my_data/datasets/themes.html.erb +3 -0
  27. data/app/views/publish_my_data/errors/not_found.html.erb +1 -0
  28. data/app/views/publish_my_data/resources/_predicates_table.html.erb +22 -0
  29. data/app/views/publish_my_data/resources/_predicates_table_head.html.erb +6 -0
  30. data/app/views/publish_my_data/resources/_resource_formats.html.erb +11 -0
  31. data/app/views/publish_my_data/resources/_uri_and_label.html.erb +3 -0
  32. data/app/views/publish_my_data/resources/index.html.erb +39 -0
  33. data/app/views/publish_my_data/resources/show.html.erb +3 -0
  34. data/app/views/publish_my_data/sparql/_ask_formats.html.erb +3 -0
  35. data/app/views/publish_my_data/sparql/_construct_formats.html.erb +3 -0
  36. data/app/views/publish_my_data/sparql/_describe_formats.html.erb +1 -0
  37. data/app/views/publish_my_data/sparql/_error_message.html.erb +3 -0
  38. data/app/views/publish_my_data/sparql/_form.html.erb +4 -0
  39. data/app/views/publish_my_data/sparql/_formats.html.erb +6 -0
  40. data/app/views/publish_my_data/sparql/_pagination.html.erb +6 -0
  41. data/app/views/publish_my_data/sparql/_results.html.erb +5 -0
  42. data/app/views/publish_my_data/sparql/_results_data.html.erb +4 -0
  43. data/app/views/publish_my_data/sparql/_select_formats.html.erb +3 -0
  44. data/app/views/publish_my_data/sparql/endpoint.html.erb +10 -0
  45. data/config/initializers/tripod.rb +5 -0
  46. data/config/initializers/vocabularies.rb +1 -0
  47. data/config/routes.rb +33 -0
  48. data/lib/publish_my_data.rb +43 -0
  49. data/lib/publish_my_data/engine.rb +9 -0
  50. data/lib/publish_my_data/renderers.rb +44 -0
  51. data/lib/publish_my_data/sparql_query.rb +117 -0
  52. data/lib/publish_my_data/sparql_query_result.rb +49 -0
  53. data/lib/publish_my_data/version.rb +3 -0
  54. data/lib/tasks/publish_my_data_tasks.rake +4 -0
  55. data/spec/controllers/publish_my_data/datasets_controller_spec.rb +190 -0
  56. data/spec/controllers/publish_my_data/resources_controller_spec.rb +399 -0
  57. data/spec/controllers/publish_my_data/sparql_controller_spec.rb +172 -0
  58. data/spec/dummy/README.rdoc +261 -0
  59. data/spec/dummy/Rakefile +7 -0
  60. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  61. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  62. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  63. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  64. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  65. data/spec/dummy/config.ru +4 -0
  66. data/spec/dummy/config/application.rb +68 -0
  67. data/spec/dummy/config/boot.rb +10 -0
  68. data/spec/dummy/config/environment.rb +5 -0
  69. data/spec/dummy/config/environments/development.rb +38 -0
  70. data/spec/dummy/config/environments/production.rb +65 -0
  71. data/spec/dummy/config/environments/test.rb +41 -0
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/spec/dummy/config/initializers/inflections.rb +15 -0
  74. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  75. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  76. data/spec/dummy/config/initializers/session_store.rb +8 -0
  77. data/spec/dummy/config/initializers/wrap_parameters.rb +10 -0
  78. data/spec/dummy/config/locales/en.yml +5 -0
  79. data/spec/dummy/config/routes.rb +4 -0
  80. data/spec/dummy/log/development.log +211 -0
  81. data/spec/dummy/log/test.log +105012 -0
  82. data/spec/dummy/public/404.html +26 -0
  83. data/spec/dummy/public/422.html +26 -0
  84. data/spec/dummy/public/500.html +25 -0
  85. data/spec/dummy/public/favicon.ico +0 -0
  86. data/spec/dummy/script/rails +6 -0
  87. data/spec/factories/dataset_factories.rb +12 -0
  88. data/spec/factories/property_factories.rb +13 -0
  89. data/spec/factories/resource_factories.rb +37 -0
  90. data/spec/features/running_a_sparql_query_spec.rb +324 -0
  91. data/spec/features/uri_dereferencing_flow_spec.rb +61 -0
  92. data/spec/features/uri_dereferencing_spec.rb +89 -0
  93. data/spec/features/viewing_a_def_spec.rb +45 -0
  94. data/spec/features/viewing_a_doc_spec.rb +124 -0
  95. data/spec/features/viewing_resource_not_in_our_domain_spec.rb +31 -0
  96. data/spec/lib/publish_my_data/sparql_query_spec.rb +495 -0
  97. data/spec/models/publish_my_data/dataset_spec.rb +29 -0
  98. data/spec/models/publish_my_data/resource_spec.rb +23 -0
  99. data/spec/renderers/publish_my_data/renderers_spec.rb +79 -0
  100. data/spec/spec_helper.rb +53 -0
  101. metadata +242 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,12 @@
1
+ FactoryGirl.define do
2
+ factory :my_dataset, class: PublishMyData::Dataset do
3
+ initialize_with { new(uri, graph_uri) }
4
+ title 'My Dataset'
5
+ description 'A test dataset'
6
+
7
+ ignore do
8
+ uri { PublishMyData::Dataset.uri_from_slug("my-dataset") }
9
+ graph_uri { PublishMyData::Dataset.metadata_graph_uri("my-dataset") }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ FactoryGirl.define do
2
+ factory :mean_result, class: PublishMyData::Resource do
3
+ initialize_with { new(uri, graph_uri) }
4
+ ignore do
5
+ uri { "http://pmdtest.dev/def/statistics/meanResult" }
6
+ graph_uri { "http://pmdtest.dev/ontology/statistics" }
7
+ end
8
+ after(:build) do |res|
9
+ res.write_predicate(RDF::RDFS.label, 'Mean Result')
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,37 @@
1
+ FactoryGirl.define do
2
+ factory :yuri_unicorn_resource, class: PublishMyData::Resource do
3
+ initialize_with { new(uri, graph_uri) }
4
+ ignore do
5
+ uri { "http://pmdtest.dev/id/unicorns/yuri" }
6
+ graph_uri { "http://pmdtest.dev/graph/unicorns" }
7
+ end
8
+ after(:build) do |res|
9
+ res.write_predicate(RDF::RDFS.label, 'Yuri The Unicorn')
10
+ end
11
+ end
12
+
13
+ factory :boris_unicorn_resource, class: PublishMyData::Resource do
14
+ initialize_with { new(uri, graph_uri) }
15
+ ignore do
16
+ uri { "http://pmdtest.dev/id/unicorns/boris" }
17
+ graph_uri { "http://pmdtest.dev/graph/unicorns" }
18
+ end
19
+ after(:build) do |res|
20
+ res.write_predicate(RDF::RDFS.label, 'Boris The Unicorn')
21
+ res.write_predicate('http://example.com/knows', RDF::URI("http://pmdtest.dev/id/unicorns/yuri")) # knows yuri
22
+ res.write_predicate('http://example.com/resides-in', RDF::URI("http://locations.example.com/foo")) # resides in foo county
23
+ end
24
+ end
25
+
26
+ factory :foreign_resource, class: PublishMyData::Resource do
27
+ initialize_with { new(uri, graph_uri) }
28
+ ignore do
29
+ uri { "http://locations.example.com/foo" }
30
+ graph_uri { "http://pmdtest.dev/geo" }
31
+ end
32
+ after(:build) do |res|
33
+ res.write_predicate(RDF::RDFS.label, 'Foo County')
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,324 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'visiting the sparql endpoint' do
4
+
5
+ ## shared examples
6
+
7
+ shared_examples_for 'a non-html error' do
8
+ it "should 400 with a blank response" do
9
+ page.source.should be_blank
10
+ page.status_code.should == 400
11
+ end
12
+ end
13
+
14
+ shared_examples_for 'a sparql query' do
15
+ it "should show the results in the page" do
16
+ page.should have_content PublishMyData::SparqlQuery.new(@query).execute.to_s
17
+ end
18
+ end
19
+
20
+ shared_examples_for "a json response" do
21
+ it 'should render json' do
22
+ page.source.should == PublishMyData::SparqlQuery.new(@query, :json).execute.to_s
23
+ end
24
+ end
25
+
26
+ shared_examples_for "an xml response" do
27
+ it 'should render xml' do
28
+ page.source.should == PublishMyData::SparqlQuery.new(@query, :xml).execute.to_s
29
+ end
30
+ end
31
+
32
+ shared_examples_for "an rdf response" do
33
+ it 'should render rdf' do
34
+ page.source.should == PublishMyData::SparqlQuery.new(@query, :rdf).execute.to_s
35
+ end
36
+ end
37
+
38
+ shared_examples_for "a csv response" do
39
+ it 'should render csv' do
40
+ page.source.should == PublishMyData::SparqlQuery.new(@query, :csv).execute.to_s
41
+ end
42
+ end
43
+
44
+ shared_examples_for "a text response" do
45
+ it 'should render text' do
46
+ page.source.should == PublishMyData::SparqlQuery.new(@query, :text).execute.to_s
47
+ end
48
+ end
49
+
50
+ shared_examples_for "an n-triples response" do
51
+ it 'should render ntriples' do
52
+ page.source.should == PublishMyData::SparqlQuery.new(@query, :nt).execute.to_s
53
+ end
54
+ end
55
+
56
+ shared_examples_for "a turtle response" do
57
+ it 'should render turtle' do
58
+ page.source.should == PublishMyData::SparqlQuery.new(@query, :ttl).execute.to_s
59
+ end
60
+ end
61
+
62
+ shared_examples_for 'a construct query' do
63
+ describe 'and clicks N-triples format' do
64
+ before { page.click_link "N-triples" }
65
+
66
+ it_should_behave_like "an n-triples response"
67
+ end
68
+
69
+ describe 'and clicks Turtle format' do
70
+ before { page.click_link "Turtle" }
71
+
72
+ it_should_behave_like "a turtle response"
73
+ end
74
+
75
+ describe 'and clicks rdf/xml format' do
76
+ before { page.click_link "RDF/XML" }
77
+
78
+ it_should_behave_like "an rdf response"
79
+ end
80
+ end
81
+
82
+ ######################
83
+ ## end of shared examples (start of tests!)
84
+
85
+ before do
86
+ @yuri = FactoryGirl.create(:yuri_unicorn_resource)
87
+ @boris = FactoryGirl.create(:boris_unicorn_resource)
88
+ visit '/sparql'
89
+ end
90
+
91
+ describe "and running a sparql construct" do
92
+ before do
93
+ @query = 'construct {?s ?p ?o} where {?s ?p ?o}'
94
+ page.fill_in 'query', with: @query
95
+ find('form input[type="submit"]').click
96
+ end
97
+
98
+ it_should_behave_like 'a sparql query'
99
+
100
+ it_should_behave_like 'a construct query'
101
+ end
102
+
103
+ describe "and runnning a sparql describe" do
104
+ before do
105
+ @query = "Describe <#{@yuri.uri.to_s}>"
106
+ page.fill_in 'query', with: @query
107
+ find('form input[type="submit"]').click
108
+ end
109
+
110
+ it_should_behave_like 'a sparql query'
111
+
112
+ it_should_behave_like 'a construct query'
113
+ end
114
+
115
+ describe "and runnning a sparql ask" do
116
+ before do
117
+ @query = "ASK where {?s ?p ?o}"
118
+ page.fill_in 'query', with: @query
119
+ find('form input[type="submit"]').click
120
+ end
121
+
122
+ describe 'and clicking JSON format' do
123
+ before { page.click_link "JSON" }
124
+
125
+ it_should_behave_like 'a json response'
126
+ end
127
+
128
+ describe 'and clicking XML format' do
129
+ before { page.click_link "XML" }
130
+
131
+ it_should_behave_like 'an xml response'
132
+ end
133
+
134
+ describe 'and clicking Text format' do
135
+ before { page.click_link "Text" }
136
+
137
+ it_should_behave_like 'a text response'
138
+ end
139
+
140
+ end
141
+
142
+ describe "and running a sparql select" do
143
+
144
+ context 'which returns a single page of results' do
145
+
146
+ before do
147
+ @query = 'select * where {?s ?p ?o}'
148
+ page.fill_in 'query', with: @query
149
+ find('form input[type="submit"]').click
150
+ end
151
+
152
+ it_should_behave_like 'a sparql query'
153
+
154
+ describe 'and clicking XML format' do
155
+ before { page.click_link "XML" }
156
+
157
+ it_should_behave_like 'an xml response'
158
+ end
159
+
160
+ describe 'and clicking CSV format' do
161
+ before { page.click_link "CSV" }
162
+
163
+ it_should_behave_like 'a csv response'
164
+ end
165
+
166
+ describe 'and clicking JSON format' do
167
+ before { page.click_link "JSON" }
168
+
169
+ it_should_behave_like 'a json response'
170
+ end
171
+
172
+ describe 'and clicking Text format' do
173
+ before { page.click_link "Text" }
174
+
175
+ it_should_behave_like 'a text response'
176
+ end
177
+
178
+ end
179
+
180
+ context 'which returns multiple pages' do
181
+ before do
182
+
183
+ # make some stuff (more results than the page size.
184
+ (1..30).each do |t|
185
+ uri = "http://resource#{t.to_s}"
186
+ r = PublishMyData::Resource.new(uri, "http://graph")
187
+ r.label = t.to_s
188
+ r.save
189
+ end
190
+
191
+ @query = 'select * where {?s ?p ?o}'
192
+ page.fill_in 'query', with: @query
193
+ find('form input[type="submit"]').click
194
+ end
195
+
196
+ it "should show the next page link" do
197
+ page.should have_link("Next 20 results")
198
+ end
199
+
200
+ context 'and clicking the next page link' do
201
+
202
+ before { page.click_link("Next 20 results") }
203
+
204
+ it "should go to the next page" do
205
+ page.current_url.should include('page=2')
206
+ end
207
+
208
+ it 'should show the previous page link' do
209
+ page.should have_link("Previous 20 results")
210
+ end
211
+
212
+ context 'where there are no more pages' do
213
+ it "should not show the next page link" do
214
+ page.should_not have_link("Next 20 results")
215
+ end
216
+ end
217
+
218
+ context 'and clicking the previous page link' do
219
+ before { page.click_link("Previous 20 results") }
220
+
221
+ it "should go back to the previous page" do
222
+ page.current_url.should include('page=1')
223
+ end
224
+ end
225
+ end
226
+
227
+
228
+ end
229
+
230
+ end
231
+
232
+ describe "and runs an unknown query type" do
233
+
234
+ before do
235
+ @query = 'MUNGE * where {?s ?p ?o}'
236
+ page.fill_in 'query', with: @query
237
+ find('form input[type="submit"]').click
238
+ end
239
+
240
+ it "should show a message" do
241
+ page.should have_content "Unsupported Query Type."
242
+ end
243
+ end
244
+
245
+ describe "and runs a query with a large response" do
246
+ before do
247
+ PublishMyData::SparqlQueryResult.any_instance.should_receive(:length).at_least(:once).and_return(10.megabytes)
248
+ @query = 'CONSTRUCT {?s ?p ?o} where {?s ?p ?o}'
249
+ page.fill_in 'query', with: @query
250
+ find('form input[type="submit"]').click
251
+ end
252
+
253
+ it "should show a message" do
254
+ page.should have_content "The results for this query are too large to return."
255
+ end
256
+ end
257
+
258
+ describe "and running a query with a syntax error" do
259
+ before do
260
+ @query = 'SELECT * where ?s ?p ?o}'
261
+ page.fill_in 'query', with: @query
262
+ find('form input[type="submit"]').click
263
+ end
264
+
265
+ it "should show a synatax error message" do
266
+ page.should have_content(/There was a syntax error in your query/)
267
+ end
268
+ end
269
+
270
+ end
271
+
272
+ describe "calling a sparql query programmatically (non-html)" do
273
+
274
+ context "with a valid query" do
275
+ before do
276
+ @query = 'select * where {?s ?p ?o}'
277
+ end
278
+
279
+ context "for a relevant format" do
280
+ before do
281
+ page.driver.header 'Accept','application/json'
282
+ visit "/sparql?query=#{URI.encode(@query)}"
283
+ end
284
+
285
+ it_should_behave_like "a json response"
286
+ end
287
+
288
+ context "for an invalid format for this query type" do
289
+ before do
290
+ page.driver.header 'Accept','application/n-triples'
291
+ visit "/sparql?query=#{URI.encode(@query)}"
292
+ end
293
+
294
+ it 'should render the default (in this case "text")' do
295
+ page.source.should == PublishMyData::SparqlQuery.new(@query, :text).execute.to_s
296
+ end
297
+
298
+ end
299
+ end
300
+
301
+ context "with an unknown query type" do
302
+ before do
303
+ @query = 'MUNGE * where {?s ?p ?o}'
304
+ page.driver.header 'Accept','text/plain'
305
+ visit "/sparql?query=#{URI.encode(@query)}"
306
+ end
307
+
308
+ it_should_behave_like 'a non-html error'
309
+ end
310
+
311
+ describe "and runs a query with a syntax error" do
312
+ before do
313
+ @query = 'SELECT * where ?s ?p ?o}'
314
+ page.driver.header 'Accept','text/plain'
315
+ visit "/sparql?query=#{URI.encode(@query)}"
316
+ end
317
+
318
+ it_should_behave_like 'a non-html error'
319
+
320
+ end
321
+
322
+
323
+
324
+ end