publish_my_data 0.0.29 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. data/app/controllers/concerns/publish_my_data/data_download.rb +22 -0
  2. data/app/controllers/concerns/publish_my_data/resource_rendering.rb +40 -0
  3. data/app/controllers/concerns/publish_my_data/sparql_processing.rb +81 -0
  4. data/app/controllers/publish_my_data/datasets_controller.rb +5 -23
  5. data/app/controllers/publish_my_data/information_resources_controller.rb +26 -4
  6. data/app/controllers/publish_my_data/queries_controller.rb +1 -1
  7. data/app/controllers/publish_my_data/resources_controller.rb +5 -9
  8. data/app/controllers/publish_my_data/sparql_controller.rb +1 -1
  9. data/app/controllers/publish_my_data/vocabularies_controller.rb +18 -0
  10. data/app/models/concerns/publish_my_data/all_features.rb +79 -0
  11. data/app/models/concerns/publish_my_data/basic_features.rb +21 -0
  12. data/app/models/concerns/publish_my_data/dataset_powers.rb +130 -0
  13. data/{lib → app/models/concerns}/publish_my_data/defined_by_ontology.rb +5 -0
  14. data/app/models/publish_my_data/concept.rb +2 -2
  15. data/app/models/publish_my_data/concept_scheme.rb +31 -3
  16. data/app/models/publish_my_data/dataset.rb +2 -128
  17. data/app/models/publish_my_data/example_resource.rb +21 -0
  18. data/app/models/publish_my_data/ontology.rb +35 -6
  19. data/app/models/publish_my_data/ontology_class.rb +3 -5
  20. data/app/models/publish_my_data/property.rb +3 -5
  21. data/app/models/publish_my_data/rdf_type.rb +1 -2
  22. data/app/models/publish_my_data/resource.rb +25 -96
  23. data/app/models/publish_my_data/theme.rb +1 -3
  24. data/app/models/publish_my_data/third_party/concept_scheme.rb +30 -0
  25. data/app/models/publish_my_data/third_party/ontology.rb +30 -0
  26. data/app/models/publish_my_data/vocabulary.rb +22 -0
  27. data/app/views/publish_my_data/classes/show.html.erb +3 -0
  28. data/app/views/publish_my_data/concept_schemes/_concepts.html.erb +18 -3
  29. data/app/views/publish_my_data/concept_schemes/show.html.erb +3 -1
  30. data/app/views/publish_my_data/concepts/show.html.erb +3 -3
  31. data/app/views/publish_my_data/datasets/show.html.erb +2 -2
  32. data/app/views/publish_my_data/ontologies/show.html.erb +6 -6
  33. data/app/views/publish_my_data/properties/show.html.erb +3 -3
  34. data/app/views/publish_my_data/resources/_summaries.html.erb +18 -0
  35. data/app/views/publish_my_data/resources/show.html.erb +3 -3
  36. data/config/routes.rb +8 -4
  37. data/lib/publish_my_data.rb +14 -5
  38. data/lib/publish_my_data/engine.rb +3 -0
  39. data/lib/publish_my_data/version.rb +1 -1
  40. data/spec/controllers/publish_my_data/datasets_controller_spec.rb +3 -3
  41. data/spec/controllers/publish_my_data/information_resources_controller_spec.rb +158 -104
  42. data/spec/controllers/publish_my_data/resources_controller_spec.rb +0 -71
  43. data/spec/controllers/publish_my_data/vocabularies_controller_spec.rb +14 -0
  44. data/spec/dummy/config/environments/development.rb +1 -1
  45. data/spec/dummy/config/environments/test.rb +1 -1
  46. data/spec/dummy/log/test.log +208075 -0
  47. data/spec/factories/concept_scheme_factories.rb +17 -13
  48. data/spec/factories/dataset_factories.rb +2 -0
  49. data/spec/factories/example_resource_factories.rb +9 -0
  50. data/spec/factories/ontology_factories.rb +17 -12
  51. data/spec/factories/property_factories.rb +1 -1
  52. data/spec/factories/resource_factories.rb +10 -0
  53. data/spec/features/running_a_sparql_query_spec.rb +2 -2
  54. data/spec/features/viewing_resources_spec.rb +96 -0
  55. data/spec/{renderers → lib}/publish_my_data/renderers_spec.rb +0 -0
  56. data/spec/models/publish_my_data/concept_scheme_spec.rb +20 -0
  57. data/spec/models/publish_my_data/dataset_spec.rb +113 -11
  58. data/spec/models/publish_my_data/example_resource_spec.rb +18 -0
  59. data/spec/models/publish_my_data/ontology_spec.rb +20 -0
  60. data/spec/models/publish_my_data/resource_spec.rb +63 -0
  61. data/spec/models/publish_my_data/third_party_concept_scheme_spec.rb +16 -0
  62. data/spec/models/publish_my_data/third_party_ontology_spec.rb +16 -0
  63. data/spec/spec_helper.rb +2 -1
  64. data/spec/support/all_features.rb +26 -0
  65. data/spec/support/data_download.rb +60 -0
  66. data/spec/support/vocabularies.rb +150 -0
  67. metadata +53 -33
  68. data/app/views/publish_my_data/ontologies/_classes.html.erb +0 -3
  69. data/app/views/publish_my_data/ontologies/_properties.html.erb +0 -3
  70. data/config/initializers/zz_factories.rb +0 -7
  71. data/lib/publish_my_data/concerns.rb +0 -4
  72. data/lib/publish_my_data/concerns/controllers/resource.rb +0 -23
  73. data/lib/publish_my_data/concerns/controllers/sparql.rb +0 -86
  74. data/lib/publish_my_data/concerns/models/resource.rb +0 -14
  75. data/lib/publish_my_data/render_params.rb +0 -7
  76. data/lib/publish_my_data/render_params/concept_render_params.rb +0 -18
  77. data/lib/publish_my_data/render_params/concept_scheme_render_params.rb +0 -31
  78. data/lib/publish_my_data/render_params/dataset_render_params.rb +0 -32
  79. data/lib/publish_my_data/render_params/ontology_class_render_params.rb +0 -18
  80. data/lib/publish_my_data/render_params/ontology_render_params.rb +0 -41
  81. data/lib/publish_my_data/render_params/property_render_params.rb +0 -18
  82. data/lib/publish_my_data/render_params/resource_render_params.rb +0 -17
@@ -3,7 +3,7 @@ module PublishMyData
3
3
  class Theme
4
4
 
5
5
  include Tripod::Resource
6
- include PublishMyData::Concerns::Models::Resource #some common methods for resources.
6
+ include BasicFeatures
7
7
 
8
8
  class << self
9
9
  def theme_graph
@@ -18,9 +18,7 @@ module PublishMyData
18
18
  rdf_type RDF::SITE.Theme
19
19
  graph_uri Theme.theme_graph
20
20
 
21
- field :label, RDF::RDFS.label
22
21
  field :slug, RDF::SKOS.notation
23
- field :comment, RDF::RDFS.comment
24
22
 
25
23
  def datasets_count
26
24
  PublishMyData::SparqlQuery.new(datasets_query_str).count
@@ -0,0 +1,30 @@
1
+ module PublishMyData
2
+ module ThirdParty
3
+ class ConceptScheme < PublishMyData::ConceptScheme
4
+ delegate :comment, :description, :license, :publisher, :contact_email, to: :data_resource
5
+
6
+ # Overrides
7
+ ['to_rdf', 'to_ttl', 'to_nt', 'to_json'].each do |method_name|
8
+ define_method method_name do |opts={}|
9
+ resources = Resource.find_by_sparql("
10
+ SELECT DISTINCT ?uri
11
+ WHERE { GRAPH <#{self.data_graph_uri}> {?uri ?p ?o} }
12
+ ")
13
+ Tripod::ResourceCollection.new(resources).send(method_name)
14
+ end
15
+ end
16
+
17
+ def local?
18
+ false
19
+ end
20
+
21
+ private
22
+
23
+ def data_resource
24
+ @data_resource = PublishMyData::ConceptScheme.new(self.uri, self.data_graph_uri)
25
+ @data_resource.hydrate!
26
+ @data_resource
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module PublishMyData
2
+ module ThirdParty
3
+ class Ontology < PublishMyData::Ontology
4
+ delegate :comment, :description, :license, :publisher, :contact_email, to: :data_resource
5
+
6
+ # Overrides
7
+ ['to_rdf', 'to_ttl', 'to_nt', 'to_json'].each do |method_name|
8
+ define_method method_name do |opts={}|
9
+ resources = Resource.find_by_sparql("
10
+ SELECT DISTINCT ?uri
11
+ WHERE { GRAPH <#{self.data_graph_uri}> {?uri ?p ?o} }
12
+ ")
13
+ Tripod::ResourceCollection.new(resources).send(method_name)
14
+ end
15
+ end
16
+
17
+ def local?
18
+ false
19
+ end
20
+
21
+ private
22
+
23
+ def data_resource
24
+ @data_resource = PublishMyData::Ontology.new(self.uri, self.data_graph_uri)
25
+ @data_resource.hydrate!
26
+ @data_resource
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ # A generic vocabulary class, used to retrieve/differentiate third-party vocabularies (ontologies *and* concept schemes)
2
+ module PublishMyData
3
+ class Vocabulary
4
+ include Tripod::Resource
5
+ include AllFeatures
6
+
7
+ def self.find_by_data_dump(data_dump_uri)
8
+ all.where("?uri <#{RDF::VOID.dataDump}> <#{data_dump_uri}>").first
9
+ end
10
+
11
+ # override
12
+ def slug
13
+ uri_hash(self.uri)
14
+ end
15
+
16
+ private
17
+
18
+ def uri_hash(uri)
19
+ Digest::SHA1.hexdigest(uri)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ <%= render 'publish_my_data/resources/uri_and_label', resource: ontology_class %>
2
+ <%= render 'publish_my_data/resources/predicates_table', resource: ontology_class %>
3
+ <%= render 'publish_my_data/resources/resource_formats', resource: ontology_class %>
@@ -1,3 +1,18 @@
1
- <% concepts.each do |c| %>
2
- <%= render 'publish_my_data/resources/predicates_table', :resource => c, :show_title => true %>
3
- <% end %>
1
+ <table>
2
+ <thead>
3
+ <tr><th><%= pluralize concepts.length, 'concept' %></th></tr>
4
+ </thead>
5
+ <tbody>
6
+ <% concepts.each do |c| %>
7
+ <tr>
8
+ <td class="details">
9
+ <hgroup>
10
+ <h3><%= c.label %><br/></h3>
11
+ <%= link_to c.uri.to_s, c.uri.to_s %>
12
+ </hgroup>
13
+ <section><%= c.comment %></section>
14
+ </td>
15
+ </tr>
16
+ <% end %>
17
+ </tbody>
18
+ </table>
@@ -1,9 +1,11 @@
1
1
  <h1>Concept Scheme: <%= concept_scheme.label || concept_scheme.uri %></h1>
2
2
 
3
+ <%= concept_scheme.description %>
4
+
3
5
  <h2>Overview</h2>
4
6
  <%= render 'publish_my_data/resources/predicates_table', resource: concept_scheme %>
5
7
 
6
8
  <h2>Concepts</h2>
7
- <%= render 'publish_my_data/concept_schemes/concepts', concepts: concepts %>
9
+ <%= render 'publish_my_data/concept_schemes/concepts', concepts: concept_scheme.concepts %>
8
10
 
9
11
  <%= render 'publish_my_data/resources/resource_formats', :resource => concept_scheme, :resource_descriptor => 'concept scheme' %>
@@ -1,3 +1,3 @@
1
- <%= render 'uri_and_label', resource: concept %>
2
- <%= render 'predicates_table', resource: concept %>
3
- <%= render 'resource_formats', resource: concept %>
1
+ <%= render 'publish_my_data/resources/uri_and_label', resource: concept %>
2
+ <%= render 'publish_my_data/resources/predicates_table', resource: concept %>
3
+ <%= render 'publish_my_data/resources/resource_formats', resource: concept %>
@@ -4,9 +4,9 @@
4
4
 
5
5
  <h2> Types in this ds</h2>
6
6
 
7
- <% types.each do |t| %>
7
+ <% dataset.types.each do |t| %>
8
8
  <%= link_to t.label || t.uri, resource_path_from_uri(t.uri) %>
9
- (<%= link_to "#{type_resource_counts[t.uri.to_s]} resources", list_resources_path(dataset: dataset.slug, type_uri: t.uri)%>)
9
+ (<%= link_to "#{dataset.type_count(t)} resources", list_resources_path(dataset: dataset.slug, type_uri: t.uri)%>)
10
10
  <br/>
11
11
  <% end %>
12
12
 
@@ -1,15 +1,15 @@
1
1
  <h1>Ontology <%= ontology.label || ontology.uri %></h1>
2
2
 
3
+ <%= ontology.description %>
4
+
3
5
  <h2>Overview</h2>
4
6
  <%= render 'publish_my_data/resources/predicates_table', resource: ontology %>
5
7
 
6
- <h2>Classes</h2>
7
- <%= render 'publish_my_data/ontologies/classes', :ontology_classes => ontology_classes %>
8
-
9
- <br/>
8
+ <h3>Classes</h3>
9
+ <%= render 'publish_my_data/resources/summaries', :resources => ontology.classes %>
10
10
 
11
- <h2>Properties</h2>
12
- <%= render 'publish_my_data/ontologies/properties', :ontology_properties => ontology_properties %>
11
+ <h3>Properties</h3>
12
+ <%= render 'publish_my_data/resources/summaries', :resources => ontology.properties %>
13
13
 
14
14
  <br/><br/>
15
15
 
@@ -1,3 +1,3 @@
1
- <%= render 'uri_and_label', resource: property %>
2
- <%= render 'predicates_table', resource: property %>
3
- <%= render 'resource_formats', resource: property %>
1
+ <%= render 'publish_my_data/resources/uri_and_label', resource: property %>
2
+ <%= render 'publish_my_data/resources/predicates_table', resource: property %>
3
+ <%= render 'publish_my_data/resources/resource_formats', resource: property %>
@@ -0,0 +1,18 @@
1
+ <table class="resources-summary">
2
+ <thead>
3
+ <tr><th><%= pluralize resources.length, 'resource' %></th></tr>
4
+ </thead>
5
+ <tbody>
6
+ <% resources.each do |r| %>
7
+ <tr>
8
+ <td class="details hardwrap">
9
+ <hgroup>
10
+ <h3><%= resource_uri_or_label(r, r.uri) %></h3>
11
+ <h4 class="click-to-select"><%= r.uri %></h4>
12
+ </hgroup>
13
+ <section><%= r.comment %></section>
14
+ </td>
15
+ </tr>
16
+ <% end %>
17
+ </tbody>
18
+ </table>
@@ -1,3 +1,3 @@
1
- <%= render 'uri_and_label', resource: resource %>
2
- <%= render 'predicates_table', resource: resource %>
3
- <%= render 'resource_formats', resource: resource %>
1
+ <%= render 'publish_my_data/resources/uri_and_label', resource: resource %>
2
+ <%= render 'publish_my_data/resources/predicates_table', resource: resource %>
3
+ <%= render 'publish_my_data/resources/resource_formats', resource: resource %>
data/config/routes.rb CHANGED
@@ -10,8 +10,8 @@ PublishMyData::Engine.routes.draw do
10
10
 
11
11
  # note that the separate .:format and no-format verisons allow extensions like .json on the end of the uri not to be globbed as the *id
12
12
  match "/data/*id/dump" => "datasets#dump", :as => 'dataset_dump'
13
- match "/data/*id.:format" => "information_resources#show"
14
- match "/data/*id" => "information_resources#show", :as => 'dataset'
13
+ match "/data/*id.:format" => "information_resources#data"
14
+ match "/data/*id" => "information_resources#data", :as => 'dataset'
15
15
  match "/data(.:format)" => "datasets#index", :as => 'datasets'
16
16
 
17
17
  # themes
@@ -22,9 +22,13 @@ PublishMyData::Engine.routes.draw do
22
22
  match "/doc/*path.:format" => "resources#doc"
23
23
  match "/doc/*path" => "resources#doc"
24
24
 
25
+ # download paths
26
+ match "/def/*id/dump" => "information_resources#dump"
27
+ match "/vocabularies/:id/dump" => "vocabularies#dump"
28
+
25
29
  # def pages
26
- match "/def/*path.:format" => "resources#definition"
27
- match "/def/*path" => "resources#definition"
30
+ match "/def/*id.:format" => "information_resources#def"
31
+ match "/def/*id" => "information_resources#def"
28
32
 
29
33
  # queries
30
34
  resources :queries, :only => [:show] # add index later
@@ -1,11 +1,20 @@
1
1
  require "publish_my_data/engine"
2
- require "publish_my_data/concerns"
3
2
  require "publish_my_data/renderers"
4
3
  require "publish_my_data/sparql_query"
5
4
  require "publish_my_data/sparql_query_result"
6
- require "publish_my_data/defined_by_ontology"
7
5
  require "publish_my_data/paginator"
8
- require "publish_my_data/render_params"
6
+
7
+ # A bit nasty, but these paths are included by default in Rails 4 so
8
+ # this is only a temporary measure
9
+ #Dir[File.expand_path('../../app/models/concerns/**/*.rb', __FILE__)].each {|f| require f}
10
+
11
+ # load them in the right order so that dataset powers can access all features.
12
+ require File.expand_path('../../app/models/concerns/publish_my_data/all_features.rb', __FILE__)
13
+ require File.expand_path('../../app/models/concerns/publish_my_data/basic_features.rb', __FILE__)
14
+ require File.expand_path('../../app/models/concerns/publish_my_data/dataset_powers.rb', __FILE__)
15
+ require File.expand_path('../../app/models/concerns/publish_my_data/defined_by_ontology.rb', __FILE__)
16
+
17
+ Dir[File.expand_path('../../app/controllers/concerns/**/*.rb', __FILE__)].each {|f| require f}
9
18
 
10
19
 
11
20
  module PublishMyData
@@ -47,7 +56,7 @@ module PublishMyData
47
56
 
48
57
  mattr_accessor :aws_access_key_id
49
58
  mattr_accessor :aws_secret_access_key
50
- mattr_accessor :dataset_downloads_s3_bucket
59
+ mattr_accessor :downloads_s3_bucket
51
60
 
52
61
 
53
62
  # Use +configure+ to override PublishMyData configuration in an app, e.g.:
@@ -62,7 +71,7 @@ module PublishMyData
62
71
  # config.default_html_sparql_per_page = 20
63
72
  #  config.max_resources_per_page = 1000
64
73
  # config.aws_default_host = 's3-eu-west-1.amazonaws.com'
65
- # config.dataset_downloads_s3_bucket = nil # the s3 bucket for dataset dumps. Used for redirecting to the right location for dataset downloads.
74
+ # config.downloads_s3_bucket = nil # the s3 bucket for dataset dumps. Used for redirecting to the right location for dataset downloads.
66
75
  # config.aws_access_key_id = nil # the access key for the s3 bucket
67
76
  # config.aws_secret_access_key = nil # the secret key for the s3 bucket
68
77
  # config.tripod_cache_store = nil #e.g Tripod::CacheStores::MemcachedCacheStore.new('localhost:11211')
@@ -5,5 +5,8 @@ module PublishMyData
5
5
  config.generators do |g|
6
6
  g.test_framework :rspec
7
7
  end
8
+
9
+ config.autoload_paths << "./app/models/concerns"
10
+ config.autoload_paths << "./app/controllers/concerns"
8
11
  end
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module PublishMyData
2
- VERSION = "0.0.29"
2
+ VERSION = "0.0.30"
3
3
  end
@@ -116,7 +116,7 @@ module PublishMyData
116
116
 
117
117
  before do
118
118
  s3 = AWS::S3.new
119
- bucket = s3.buckets[PublishMyData.dataset_downloads_s3_bucket]
119
+ bucket = s3.buckets[PublishMyData.downloads_s3_bucket]
120
120
  bucket.clear! # wipe the bucket
121
121
  end
122
122
 
@@ -129,7 +129,7 @@ module PublishMyData
129
129
  before do
130
130
  # make some downloads.
131
131
  s3 = AWS::S3.new
132
- bucket = s3.buckets[PublishMyData.dataset_downloads_s3_bucket]
132
+ bucket = s3.buckets[PublishMyData.downloads_s3_bucket]
133
133
 
134
134
  @obj1 = bucket.objects.create("dataset_data_my|dataset_201007011200.nt.zip", 'data')
135
135
  @obj2 = bucket.objects.create("dataset_data_my|dataset_201007011201.nt.zip", 'data')
@@ -154,7 +154,7 @@ module PublishMyData
154
154
  before do
155
155
  # make some downloads.
156
156
  s3 = AWS::S3.new
157
- bucket = s3.buckets[PublishMyData.dataset_downloads_s3_bucket]
157
+ bucket = s3.buckets[PublishMyData.downloads_s3_bucket]
158
158
 
159
159
  @obj1 = bucket.objects.create("dataset_data_#{dataset.slug}_201007011159.nt.zip", 'data')
160
160
 
@@ -1,159 +1,213 @@
1
1
  require 'spec_helper'
2
2
 
3
+ shared_examples 'as json' do
4
+ it "should return its json" do
5
+ JSON.parse(response.body).should == JSON.parse(resource.to_json)
6
+ end
7
+
8
+ it "should respond successfully" do
9
+ response.should be_success
10
+ end
11
+ end
12
+
13
+ shared_examples 'as rdf' do
14
+ it "should return its rdf" do
15
+ response.body.should == resource.to_rdf
16
+ end
17
+
18
+ it "should respond successfully" do
19
+ response.should be_success
20
+ end
21
+ end
22
+
23
+ shared_examples 'as ttl' do
24
+ it "should return its ttl" do
25
+ response.body.should == resource.to_ttl
26
+ end
27
+
28
+ it "should respond successfully" do
29
+ response.should be_success
30
+ end
31
+ end
32
+
33
+ shared_examples "as n-triples" do
34
+ it "should return the its n-triples" do
35
+ response.body.should == resource.to_nt
36
+ end
37
+
38
+ it "should respond successfully" do
39
+ response.should be_success
40
+ end
41
+ end
42
+
3
43
  module PublishMyData
4
44
  describe InformationResourcesController do
45
+ # dump an ontology
46
+ it_should_behave_like 'a controller with a dump action' do
47
+ let(:resource) { FactoryGirl.create(:ontology) }
48
+ end
5
49
 
6
- describe "showing an information resource" do
7
- let!(:resource) { FactoryGirl.create(:information_resource) }
50
+ # dump a concept scheme
51
+ it_should_behave_like 'a controller with a dump action' do
52
+ let(:resource) { FactoryGirl.create(:concept_scheme) }
53
+ end
8
54
 
9
- shared_examples_for "resource show" do
55
+ describe '#data' do
56
+ context "given a dataset" do
57
+ let(:resource) { FactoryGirl.create(:my_dataset) }
10
58
 
11
- context "for an existing resource" do
12
- it "should respond successfully" do
13
- get :show, id: "information/resource", use_route: :publish_my_data, :format => format
14
- response.should be_success
59
+ context 'as html' do
60
+ before { get :data, id: resource.slug, use_route: :publish_my_data }
61
+
62
+ it "should render the dataset show template" do
63
+ response.should render_template("publish_my_data/datasets/show")
15
64
  end
16
- end
17
65
 
18
- context "with a non-existent dataset slug" do
19
- it "should respond with not found" do
20
- get :show, id: "non-existent/resource", use_route: :publish_my_data, :format => format
21
- response.should be_not_found
66
+ it "should respond successfully" do
67
+ response.should be_success
22
68
  end
23
69
  end
24
- end
25
70
 
26
- shared_examples_for "resource html format" do
27
- it "should render the resource show template" do
28
- get :show, id: "information/resource", use_route: :publish_my_data, :format => format
29
- response.should render_template("publish_my_data/resources/show")
71
+ context "as rdf" do
72
+ before { get :data, id: resource.slug, use_route: :publish_my_data, :format => 'rdf' }
73
+ include_examples 'as rdf'
30
74
  end
31
- end
32
75
 
33
- shared_examples_for "resource non html format" do
76
+ context "as json" do
77
+ before { get :data, id: resource.slug, use_route: :publish_my_data, :format => 'json' }
78
+ include_examples 'as json'
79
+ end
34
80
 
35
- context "for an existing resource" do
36
- it "should return the resource in that format" do
37
- get :show, id: "information/resource", use_route: :publish_my_data, :format => format
38
- response.body.should == resource.send("to_#{format}")
39
- end
81
+ context "as ttl" do
82
+ before { get :data, id: resource.slug, use_route: :publish_my_data, :format => 'ttl' }
83
+ include_examples 'as ttl'
40
84
  end
41
85
 
42
- context "for a non-existent resource" do
43
- it "should return a blank body" do
44
- get :show, id: "non-existent/resource", use_route: :publish_my_data, :format => format
45
- response.body.should == "Not Found"
46
- end
86
+ context "as n-triples" do
87
+ before { get :data, id: resource.slug, use_route: :publish_my_data, :format => 'nt' }
88
+ include_examples 'as n-triples'
47
89
  end
48
90
  end
49
91
 
50
- context "for html format" do
51
- let(:format){ 'html' }
52
- it_should_behave_like "resource html format"
53
- it_should_behave_like "resource show"
54
- end
92
+ context "given an arbitrary information resource which is not a dataset" do
93
+ let!(:resource) { FactoryGirl.create(:information_resource) }
55
94
 
56
- # try another format.
57
- context "for rdf format" do
58
- let(:format){ 'rdf' }
59
- it_should_behave_like "resource non html format"
60
- it_should_behave_like "resource show"
61
- end
95
+ context 'as html' do
96
+ before { get :data, id: "information/resource", use_route: :publish_my_data }
62
97
 
63
- end
98
+ it "should render the resource show template" do
99
+ response.should render_template("publish_my_data/resources/show")
100
+ end
64
101
 
65
- describe "showing a dataset" do
102
+ it "should respond successfully" do
103
+ response.should be_success
104
+ end
105
+ end
66
106
 
67
- let(:dataset) { FactoryGirl.create(:my_dataset) }
107
+ context "as rdf" do
108
+ before { get :data, id: "information/resource", use_route: :publish_my_data, :format => 'rdf' }
109
+ include_examples 'as rdf'
110
+ end
68
111
 
69
- shared_examples_for "dataset show" do
112
+ context "as json" do
113
+ before { get :data, id: "information/resource", use_route: :publish_my_data, :format => 'json' }
114
+ include_examples 'as json'
115
+ end
70
116
 
71
- context "for an existing dataset" do
72
- it "should respond successfully" do
73
- get :show, id: dataset.slug, use_route: :publish_my_data, :format => format
74
- response.should be_success
75
- end
117
+ context "as ttl" do
118
+ before { get :data, id: "information/resource", use_route: :publish_my_data, :format => 'ttl' }
119
+ include_examples 'as ttl'
76
120
  end
77
121
 
78
- context "with a non-existent dataset slug" do
79
- it "should respond with not found" do
80
- get :show, id: "slug-that-doesnt-exist", use_route: :publish_my_data, :format => format
81
- response.should be_not_found
82
- end
122
+ context "as n-triples" do
123
+ before { get :data, id: "information/resource", use_route: :publish_my_data, :format => 'nt' }
124
+ include_examples 'as n-triples'
83
125
  end
84
126
  end
85
127
 
86
- shared_examples_for "dataset html format" do
87
- it "should render the dataset show template" do
88
- get :show, id: dataset.slug, use_route: :publish_my_data, :format => format
89
- response.should render_template("publish_my_data/datasets/show")
128
+ describe 'given a non-existent identifier' do
129
+ it "should respond with not found" do
130
+ get :data, id: "non-existent/resource", use_route: :publish_my_data
131
+ response.should be_not_found
90
132
  end
91
133
  end
134
+ end
92
135
 
93
- shared_examples_for "dataset non html format" do
136
+ describe "#def" do
137
+ context "when resource is an ontology" do
138
+ let!(:resource) { FactoryGirl.create(:ontology) }
94
139
 
95
- context "for an existing dataset" do
96
- it "should return the dataset dtls in that format" do
97
- get :show, id: dataset.slug, use_route: :publish_my_data, :format => format
98
- response.body.should == dataset.send("to_#{format}")
99
- end
140
+ it "should respond successfully" do
141
+ get :def, :id => "my-topic", use_route: :publish_my_data
142
+ response.should be_success
100
143
  end
101
144
 
102
- context "for a non-existent dataset slug" do
103
- it "should return a blank body" do
104
- get :show, id: "slug-that-doesnt-exist", use_route: :publish_my_data, :format => format
105
- response.body.should == "Not Found"
106
- end
145
+ it "should render the ontologies#show template" do
146
+ get :def, :id => "my-topic", use_route: :publish_my_data
147
+ response.should render_template("publish_my_data/ontologies/show")
107
148
  end
108
- end
109
149
 
110
- context "for html format" do
111
- let(:format){ 'html' }
112
- it_should_behave_like "dataset html format"
113
- it_should_behave_like "dataset show"
114
- end
150
+ context "as rdf" do
151
+ before { get :def, :id => "my-topic", use_route: :publish_my_data, :format => 'rdf' }
152
+ include_examples 'as rdf'
153
+ end
154
+
155
+ context "as json" do
156
+ before { get :def, :id => "my-topic", use_route: :publish_my_data, :format => 'json' }
157
+ include_examples 'as json'
158
+ end
159
+
160
+ context "as ttl" do
161
+ before { get :def, :id => "my-topic", use_route: :publish_my_data, :format => 'ttl' }
162
+ include_examples 'as ttl'
163
+ end
115
164
 
116
- context "for rdf format" do
117
- let(:format){ 'rdf' }
118
- it_should_behave_like "dataset non html format"
119
- it_should_behave_like "dataset show"
165
+ context "as n-triples" do
166
+ before { get :def, :id => "my-topic", use_route: :publish_my_data, :format => 'nt' }
167
+ include_examples 'as n-triples'
168
+ end
120
169
  end
121
170
 
122
- context "for json format" do
123
- let(:format){ 'json' }
171
+ context "when resource is a concept scheme" do
172
+ let!(:resource) { FactoryGirl.create(:concept_scheme) }
124
173
 
125
- # note: we don't use the shared example group here because the JSON format sometimes brings stuff back in different orders!
174
+ it "should respond successfully" do
175
+ get :def, :id => "my-topic", use_route: :publish_my_data
176
+ response.should be_success
177
+ end
126
178
 
127
- context "for an existing dataset" do
128
- it "should return the dataset dtls in that format" do
129
- get :show, id: dataset.slug, use_route: :publish_my_data, :format => format
130
- JSON.parse(response.body).should == JSON.parse(dataset.send("to_#{format}"))
131
- end
179
+ it "should render the concept_schemes#show template" do
180
+ get :def, :id => "my-topic", use_route: :publish_my_data
181
+ response.should render_template("publish_my_data/concept_schemes/show")
132
182
  end
133
183
 
134
- context "for a non-existent dataset slug" do
135
- it "should return a blank body" do
136
- get :show, id: "slug-that-doesnt-exist", use_route: :publish_my_data, :format => format
137
- response.body.should == "Not Found"
138
- end
184
+ context "as rdf" do
185
+ before { get :def, :id => "my-topic", use_route: :publish_my_data, :format => 'rdf' }
186
+ include_examples 'as rdf'
139
187
  end
140
188
 
141
- it_should_behave_like "dataset show"
142
- end
189
+ context "as json" do
190
+ before { get :def, :id => "my-topic", use_route: :publish_my_data, :format => 'json' }
191
+ include_examples 'as json'
192
+ end
143
193
 
144
- context "for ttl format" do
145
- let(:format){ 'ttl' }
146
- it_should_behave_like "dataset non html format"
147
- it_should_behave_like "dataset show"
148
- end
194
+ context "as ttl" do
195
+ before { get :def, :id => "my-topic", use_route: :publish_my_data, :format => 'ttl' }
196
+ include_examples 'as ttl'
197
+ end
149
198
 
150
- context "for ntriples format" do
151
- let(:format){ 'nt' }
152
- it_should_behave_like "dataset non html format"
153
- it_should_behave_like "dataset show"
199
+ context "as n-triples" do
200
+ before { get :def, :id => "my-topic", use_route: :publish_my_data, :format => 'nt' }
201
+ include_examples 'as n-triples'
202
+ end
154
203
  end
155
204
 
205
+ context "when resource doesn't exist" do
206
+ it "should 404" do
207
+ get :def, :id => "statistics/nonExistent", use_route: :publish_my_data
208
+ response.should be_not_found
209
+ end
210
+ end
156
211
  end
157
-
158
212
  end
159
213
  end