publish_my_data 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/publish_my_data/datasets_controller.rb +9 -33
- data/app/controllers/publish_my_data/information_resources_controller.rb +18 -0
- data/app/controllers/publish_my_data/resources_controller.rb +2 -18
- data/app/models/publish_my_data/dataset.rb +10 -5
- data/app/models/publish_my_data/resource.rb +18 -4
- data/app/views/publish_my_data/datasets/index.html.erb +1 -1
- data/app/views/publish_my_data/datasets/show.html.erb +4 -4
- data/config/routes.rb +5 -4
- data/lib/publish_my_data/concerns/controllers/resource.rb +23 -0
- data/lib/publish_my_data/concerns.rb +2 -0
- data/lib/publish_my_data/render_params/concept_render_params.rb +6 -0
- data/lib/publish_my_data/render_params/concept_scheme_render_params.rb +6 -0
- data/lib/publish_my_data/render_params/dataset_render_params.rb +34 -0
- data/lib/publish_my_data/render_params/ontology_class_render_params.rb +6 -0
- data/lib/publish_my_data/render_params/ontology_render_params.rb +6 -0
- data/lib/publish_my_data/render_params/property_render_params.rb +6 -0
- data/lib/publish_my_data/render_params/resource_render_params.rb +6 -0
- data/lib/publish_my_data/render_params/theme_render_params.rb +1 -1
- data/lib/publish_my_data/render_params.rb +1 -0
- data/lib/publish_my_data/version.rb +1 -1
- data/spec/controllers/publish_my_data/datasets_controller_spec.rb +11 -100
- data/spec/controllers/publish_my_data/information_resources_controller_spec.rb +159 -0
- data/spec/dummy/log/test.log +67692 -0
- data/spec/factories/dataset_factories.rb +4 -4
- data/spec/factories/resource_factories.rb +11 -0
- data/spec/models/publish_my_data/dataset_spec.rb +5 -5
- metadata +20 -15
@@ -5,38 +5,6 @@ module PublishMyData
|
|
5
5
|
|
6
6
|
respond_to :html, :ttl, :rdf, :nt, :json, :text
|
7
7
|
|
8
|
-
# /data/:id (where :id is the dataset 'slug')
|
9
|
-
def show
|
10
|
-
|
11
|
-
@dataset = Dataset.find_by_slug(params[:id])
|
12
|
-
|
13
|
-
@dataset.eager_load_object_triples!(:labels_only => true) # for the owner URI label
|
14
|
-
|
15
|
-
@types = RdfType.where('?s a ?uri').graph(@dataset.data_graph_uri).resources
|
16
|
-
|
17
|
-
if is_request_html_format?
|
18
|
-
@type_resource_counts = {}
|
19
|
-
@resources_count = 0
|
20
|
-
@types.each do |t|
|
21
|
-
count_query = "SELECT ?uri WHERE { GRAPH <#{@dataset.data_graph_uri.to_s}> { ?uri a <#{t.uri.to_s}> } }"
|
22
|
-
@type_resource_counts[t.uri.to_s] = SparqlQuery.new(count_query).count
|
23
|
-
@resources_count += @type_resource_counts[t.uri.to_s]
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
respond_with(@dataset)
|
29
|
-
end
|
30
|
-
|
31
|
-
# /data?page=2&per_page=10
|
32
|
-
def index
|
33
|
-
dataset_criteria = Dataset.ordered_datasets_criteria
|
34
|
-
@pagination_params = ResourcePaginationParams.from_request(request)
|
35
|
-
@datasets = Paginator.new(dataset_criteria, @pagination_params).paginate
|
36
|
-
respond_with(@datasets)
|
37
|
-
end
|
38
|
-
|
39
|
-
# /data/:id/dump
|
40
8
|
def dump
|
41
9
|
s3 = AWS::S3.new
|
42
10
|
@dataset = Dataset.find_by_slug(params[:id])
|
@@ -45,7 +13,7 @@ module PublishMyData
|
|
45
13
|
# Note: filenames on s3 take the format: "dataset_data_<slug>_time.nt.zip"
|
46
14
|
# Only look for ones that were made on the same day as the the modified date, to restrict the results
|
47
15
|
# (v. small possibility of errors for changes aroung midnight, but unlikely people will be changing datasets then anyway!)
|
48
|
-
prefix = "dataset_data_#{@dataset.slug}_#{@dataset.modified.strftime("%Y%m%d")}"
|
16
|
+
prefix = "dataset_data_#{@dataset.slug.gsub('/', '|')}_#{@dataset.modified.strftime("%Y%m%d")}"
|
49
17
|
downloads = s3.buckets[PublishMyData.dataset_downloads_s3_bucket].objects.with_prefix(prefix).to_a
|
50
18
|
|
51
19
|
# filter the downloads to only include ones with a timestamp equal to or after the dataset modified date.
|
@@ -66,5 +34,13 @@ module PublishMyData
|
|
66
34
|
end
|
67
35
|
end
|
68
36
|
|
37
|
+
# /data?page=2&per_page=10
|
38
|
+
def index
|
39
|
+
dataset_criteria = Dataset.ordered_datasets_criteria
|
40
|
+
@pagination_params = ResourcePaginationParams.from_request(request)
|
41
|
+
@datasets = Paginator.new(dataset_criteria, @pagination_params).paginate
|
42
|
+
respond_with(@datasets)
|
43
|
+
end
|
44
|
+
|
69
45
|
end
|
70
46
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_dependency "publish_my_data/application_controller"
|
2
|
+
|
3
|
+
module PublishMyData
|
4
|
+
class InformationResourcesController < ApplicationController
|
5
|
+
|
6
|
+
respond_to :html, :ttl, :rdf, :nt, :json, :text
|
7
|
+
|
8
|
+
include PublishMyData::Concerns::Controllers::Resource
|
9
|
+
|
10
|
+
def show
|
11
|
+
the_uri = "http://#{PublishMyData.local_domain}/data/#{params[:id]}"
|
12
|
+
puts the_uri
|
13
|
+
render_resource_with_uri(the_uri)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -3,6 +3,8 @@ require_dependency "publish_my_data/application_controller"
|
|
3
3
|
module PublishMyData
|
4
4
|
class ResourcesController < ApplicationController
|
5
5
|
|
6
|
+
include PublishMyData::Concerns::Controllers::Resource
|
7
|
+
|
6
8
|
respond_to :html, :ttl, :rdf, :nt, :json, :text
|
7
9
|
|
8
10
|
# /resources
|
@@ -66,24 +68,6 @@ module PublishMyData
|
|
66
68
|
|
67
69
|
private
|
68
70
|
|
69
|
-
def render_resource_with_uri(uri)
|
70
|
-
resource = Resource.find(uri)
|
71
|
-
|
72
|
-
if is_request_html_format?
|
73
|
-
resource.eager_load_predicate_triples!(:labels_only => true)
|
74
|
-
resource.eager_load_object_triples!(:labels_only => true)
|
75
|
-
end
|
76
|
-
|
77
|
-
# result = RubyProf.stop
|
78
|
-
# File.open "#{Rails.root}/tmp/profile-graph.html", 'w' do |file|
|
79
|
-
# RubyProf::CallStackPrinter.new(result).print(file)
|
80
|
-
# end
|
81
|
-
|
82
|
-
respond_with(resource) do |format|
|
83
|
-
format.html { render resource.render_params(request) }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
71
|
# TODO: move the filter management into an object
|
88
72
|
def add_type_filter(criteria)
|
89
73
|
unless params[:type_uri].blank?
|
@@ -61,6 +61,10 @@ module PublishMyData
|
|
61
61
|
|
62
62
|
class << self
|
63
63
|
|
64
|
+
def uri_from_data_graph_uri(data_graph_uri)
|
65
|
+
data_graph_uri.to_s.gsub("graph/", "data/")
|
66
|
+
end
|
67
|
+
|
64
68
|
# this is the graph that dataset metadata goes in.
|
65
69
|
def metadata_graph_uri(slug)
|
66
70
|
"#{data_graph_uri(slug)}/metadata"
|
@@ -71,6 +75,10 @@ module PublishMyData
|
|
71
75
|
"http://#{PublishMyData.local_domain}/graph/#{slug}"
|
72
76
|
end
|
73
77
|
|
78
|
+
def uri_from_data_graph_uri(data_graph_uri)
|
79
|
+
data_graph_uri.to_s.sub("/graph/", "/data/")
|
80
|
+
end
|
81
|
+
|
74
82
|
def find_by_slug(slug)
|
75
83
|
Dataset.find(uri_from_slug(slug))
|
76
84
|
end
|
@@ -80,11 +88,8 @@ module PublishMyData
|
|
80
88
|
end
|
81
89
|
|
82
90
|
def slug_from_uri(uri)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
def slug_from_data_graph_uri(data_graph_uri)
|
87
|
-
data_graph_uri.to_s.split("/").last
|
91
|
+
root_uri = uri_from_slug('')
|
92
|
+
uri.to_s.gsub(root_uri, '')
|
88
93
|
end
|
89
94
|
|
90
95
|
def ordered_datasets_criteria
|
@@ -16,14 +16,18 @@ module PublishMyData
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def dataset
|
19
|
-
|
20
|
-
Dataset.find_by_slug(slug) rescue nil
|
19
|
+
Dataset.find(Dataset.uri_from_data_graph_uri(self.graph_uri)) rescue nil
|
21
20
|
end
|
22
21
|
|
23
22
|
# this calls render_params on the right type of RenderParams object.
|
24
23
|
# (strategy pattern-ish).
|
25
24
|
def render_params(request)
|
26
|
-
|
25
|
+
is_html = (request.format.to_sym || :html) == :html
|
26
|
+
render_params_class.new(self).
|
27
|
+
render_params(
|
28
|
+
pagination_params: ResourcePaginationParams.from_request(request),
|
29
|
+
is_html: is_html
|
30
|
+
)
|
27
31
|
end
|
28
32
|
|
29
33
|
# Don't worry that these as_xxx methods look like they'll do an extra lookup.
|
@@ -36,6 +40,10 @@ module PublishMyData
|
|
36
40
|
r
|
37
41
|
end
|
38
42
|
|
43
|
+
def as_dataset
|
44
|
+
as_resource_of_class(Dataset)
|
45
|
+
end
|
46
|
+
|
39
47
|
def as_ontology
|
40
48
|
as_resource_of_class(Ontology)
|
41
49
|
end
|
@@ -56,6 +64,10 @@ module PublishMyData
|
|
56
64
|
as_resource_of_class(OntologyClass)
|
57
65
|
end
|
58
66
|
|
67
|
+
def is_dataset?
|
68
|
+
read_type_predicate.include?(RDF::PMD_DS.Dataset)
|
69
|
+
end
|
70
|
+
|
59
71
|
def is_ontology?
|
60
72
|
read_type_predicate.include?(RDF::OWL.Ontology)
|
61
73
|
end
|
@@ -83,7 +95,9 @@ module PublishMyData
|
|
83
95
|
end
|
84
96
|
|
85
97
|
def render_params_class
|
86
|
-
if self.
|
98
|
+
if self.is_dataset?
|
99
|
+
DatasetRenderParams
|
100
|
+
elsif self.is_ontology?
|
87
101
|
OntologyRenderParams
|
88
102
|
elsif self.is_class?
|
89
103
|
OntologyClassRenderParams
|
@@ -1,12 +1,12 @@
|
|
1
|
-
<h1>Dataset: <%=
|
1
|
+
<h1>Dataset: <%= dataset.title %></h1>
|
2
2
|
|
3
|
-
<%=
|
3
|
+
<%= dataset.description %>
|
4
4
|
|
5
5
|
<h2> Types in this ds</h2>
|
6
6
|
|
7
|
-
<%
|
7
|
+
<% types.each do |t| %>
|
8
8
|
<%= link_to t.label || t.uri, resource_path_from_uri(t.uri) %>
|
9
|
-
(<%= link_to "#{
|
9
|
+
(<%= link_to "#{type_resource_counts[t.uri.to_s]} resources", list_resources_path(dataset: dataset.slug, type_uri: t.uri)%>)
|
10
10
|
<br/>
|
11
11
|
<% end %>
|
12
12
|
|
data/config/routes.rb
CHANGED
@@ -7,11 +7,12 @@ PublishMyData::Engine.routes.draw do
|
|
7
7
|
match "/resources(.:format)" => "resources#index", :as => 'list_resources' # +filters on thh query string
|
8
8
|
|
9
9
|
# datasets
|
10
|
-
match "/data/:id(.:format)" => "datasets#show", :as => 'dataset'
|
11
|
-
match "/data/:id/dump" => "datasets#dump", :as => 'dataset_dump'
|
12
|
-
match "/data(.:format)" => "datasets#index", :as => 'datasets'
|
13
10
|
|
14
|
-
|
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
|
+
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'
|
15
|
+
match "/data(.:format)" => "datasets#index", :as => 'datasets'
|
15
16
|
|
16
17
|
# themes
|
17
18
|
resources :themes, :only => [:index, :show]
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
module Concerns
|
3
|
+
module Controllers
|
4
|
+
module Resource
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def render_resource_with_uri(uri)
|
12
|
+
resource = PublishMyData::Resource.find(uri)
|
13
|
+
|
14
|
+
respond_with(resource) do |format|
|
15
|
+
format.html { render resource.render_params(request) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -7,6 +7,12 @@ module PublishMyData
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def render_params(opts={})
|
10
|
+
|
11
|
+
if opts[:is_html]
|
12
|
+
@concept.eager_load_predicate_triples!(:labels_only => true)
|
13
|
+
@concept.eager_load_object_triples!(:labels_only => true)
|
14
|
+
end
|
15
|
+
|
10
16
|
{template: 'publish_my_data/concepts/show', locals: {concept: @concept}}
|
11
17
|
end
|
12
18
|
|
@@ -7,6 +7,12 @@ module PublishMyData
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def render_params(opts={})
|
10
|
+
|
11
|
+
if opts[:is_html]
|
12
|
+
@concept_scheme.eager_load_predicate_triples!(:labels_only => true)
|
13
|
+
@concept_scheme.eager_load_object_triples!(:labels_only => true)
|
14
|
+
end
|
15
|
+
|
10
16
|
{template: 'publish_my_data/concept_schemes/show', locals: {concept_scheme: @concept_scheme}}
|
11
17
|
end
|
12
18
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
class DatasetRenderParams
|
3
|
+
|
4
|
+
def initialize(resource)
|
5
|
+
@resource = resource
|
6
|
+
@dataset = resource.as_dataset
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_params(opts={})
|
10
|
+
|
11
|
+
if opts[:is_html]
|
12
|
+
@types = RdfType.where('?s a ?uri').graph(@dataset.data_graph_uri).resources
|
13
|
+
@dataset.eager_load_object_triples!(:labels_only => true) # for the owner URI label
|
14
|
+
@type_resource_counts = {}
|
15
|
+
@resources_count = 0
|
16
|
+
@types.each do |t|
|
17
|
+
count_query = "SELECT ?uri WHERE { GRAPH <#{@dataset.data_graph_uri.to_s}> { ?uri a <#{t.uri.to_s}> } }"
|
18
|
+
@type_resource_counts[t.uri.to_s] = SparqlQuery.new(count_query).count
|
19
|
+
@resources_count += @type_resource_counts[t.uri.to_s]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
{
|
24
|
+
template: 'publish_my_data/datasets/show', locals: {
|
25
|
+
dataset: @dataset,
|
26
|
+
types: @types,
|
27
|
+
type_resource_counts: @type_resource_counts,
|
28
|
+
resources_count: @resources_count
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -7,6 +7,12 @@ module PublishMyData
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def render_params(opts={})
|
10
|
+
|
11
|
+
if opts[:is_html]
|
12
|
+
@ontology_class.eager_load_predicate_triples!(:labels_only => true)
|
13
|
+
@ontology_class.eager_load_object_triples!(:labels_only => true)
|
14
|
+
end
|
15
|
+
|
10
16
|
{template: 'publish_my_data/classes/show', locals: {ontology_class: @ontology_class}}
|
11
17
|
end
|
12
18
|
|
@@ -7,6 +7,12 @@ module PublishMyData
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def render_params(opts={})
|
10
|
+
|
11
|
+
if opts[:is_html]
|
12
|
+
@ontology.eager_load_predicate_triples!(:labels_only => true)
|
13
|
+
@ontology.eager_load_object_triples!(:labels_only => true)
|
14
|
+
end
|
15
|
+
|
10
16
|
{template: 'publish_my_data/ontologies/show', locals: {ontology: @ontology}}
|
11
17
|
end
|
12
18
|
|
@@ -7,6 +7,12 @@ module PublishMyData
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def render_params(opts={})
|
10
|
+
|
11
|
+
if opts[:is_html]
|
12
|
+
@resource.eager_load_predicate_triples!(:labels_only => true)
|
13
|
+
@resource.eager_load_object_triples!(:labels_only => true)
|
14
|
+
end
|
15
|
+
|
10
16
|
{template: 'publish_my_data/properties/show', locals: {property: @property}}
|
11
17
|
end
|
12
18
|
|
@@ -6,6 +6,12 @@ module PublishMyData
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def render_params(opts={})
|
9
|
+
|
10
|
+
if opts[:is_html]
|
11
|
+
@resource.eager_load_predicate_triples!(:labels_only => true)
|
12
|
+
@resource.eager_load_object_triples!(:labels_only => true)
|
13
|
+
end
|
14
|
+
|
9
15
|
{template: 'publish_my_data/resources/show', locals: {resource: @resource}}
|
10
16
|
end
|
11
17
|
|
@@ -7,7 +7,7 @@ module PublishMyData
|
|
7
7
|
end
|
8
8
|
|
9
9
|
# e.g. opts[:pagination_params] => ResourcePaginationParams.new
|
10
|
-
def render_params(opts)
|
10
|
+
def render_params(opts={})
|
11
11
|
datasets = Paginator.new(@theme.datasets_criteria, opts[:pagination_params]).paginate
|
12
12
|
{
|
13
13
|
template: 'publish_my_data/themes/show',
|
@@ -3,96 +3,6 @@ require 'spec_helper'
|
|
3
3
|
module PublishMyData
|
4
4
|
describe DatasetsController do
|
5
5
|
|
6
|
-
describe "#show" do
|
7
|
-
|
8
|
-
let(:dataset) { FactoryGirl.create(:my_dataset) }
|
9
|
-
|
10
|
-
shared_examples_for "dataset show" do
|
11
|
-
|
12
|
-
context "for an existing dataset" do
|
13
|
-
it "should respond successfully" do
|
14
|
-
get :show, id: dataset.slug, use_route: :publish_my_data, :format => format
|
15
|
-
response.should be_success
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should set the types variable" do
|
19
|
-
get :show, id: dataset.slug, use_route: :publish_my_data, :format => format
|
20
|
-
assigns['types'].class.should == Tripod::ResourceCollection
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "with a non-existent dataset slug" do
|
25
|
-
it "should respond with not found" do
|
26
|
-
get :show, id: "slug-that-doesnt-exist", use_route: :publish_my_data, :format => format
|
27
|
-
response.should be_not_found
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
shared_examples_for "a non html format" do
|
33
|
-
|
34
|
-
context "for an existing dataset" do
|
35
|
-
it "should return the dataset dtls in that format" do
|
36
|
-
get :show, id: dataset.slug, use_route: :publish_my_data, :format => format
|
37
|
-
response.body.should == dataset.send("to_#{format}")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "for a non-existent dataset slug" do
|
42
|
-
it "should return a blank body" do
|
43
|
-
get :show, id: "slug-that-doesnt-exist", use_route: :publish_my_data, :format => format
|
44
|
-
response.body.should == "Not Found"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "for rdf format" do
|
50
|
-
let(:format){ 'html' }
|
51
|
-
it_should_behave_like "dataset show"
|
52
|
-
end
|
53
|
-
|
54
|
-
context "for rdf format" do
|
55
|
-
let(:format){ 'rdf' }
|
56
|
-
it_should_behave_like "a non html format"
|
57
|
-
it_should_behave_like "dataset show"
|
58
|
-
end
|
59
|
-
|
60
|
-
context "for json format" do
|
61
|
-
let(:format){ 'json' }
|
62
|
-
|
63
|
-
# note: we don't use the shared example group here because the JSON format sometimes brings stuff back in different orders!
|
64
|
-
|
65
|
-
context "for an existing dataset" do
|
66
|
-
it "should return the dataset dtls in that format" do
|
67
|
-
get :show, id: dataset.slug, use_route: :publish_my_data, :format => format
|
68
|
-
JSON.parse(response.body).should == JSON.parse(dataset.send("to_#{format}"))
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "for a non-existent dataset slug" do
|
73
|
-
it "should return a blank body" do
|
74
|
-
get :show, id: "slug-that-doesnt-exist", use_route: :publish_my_data, :format => format
|
75
|
-
response.body.should == "Not Found"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it_should_behave_like "dataset show"
|
80
|
-
end
|
81
|
-
|
82
|
-
context "for ttl format" do
|
83
|
-
let(:format){ 'ttl' }
|
84
|
-
it_should_behave_like "a non html format"
|
85
|
-
it_should_behave_like "dataset show"
|
86
|
-
end
|
87
|
-
|
88
|
-
context "for ntriples format" do
|
89
|
-
let(:format){ 'nt' }
|
90
|
-
it_should_behave_like "a non html format"
|
91
|
-
it_should_behave_like "dataset show"
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
6
|
describe "#index" do
|
97
7
|
|
98
8
|
# make some datasets
|
@@ -200,7 +110,7 @@ module PublishMyData
|
|
200
110
|
bucket.clear! # wipe the bucket
|
201
111
|
end
|
202
112
|
|
203
|
-
context "
|
113
|
+
context "and a dataset with the slug exists" do
|
204
114
|
|
205
115
|
let(:dataset) { FactoryGirl.create(:my_dataset) }
|
206
116
|
|
@@ -211,18 +121,19 @@ module PublishMyData
|
|
211
121
|
s3 = AWS::S3.new
|
212
122
|
bucket = s3.buckets[PublishMyData.dataset_downloads_s3_bucket]
|
213
123
|
|
214
|
-
@obj1 = bucket.objects.create("
|
215
|
-
@obj2 = bucket.objects.create("
|
216
|
-
@obj3 = bucket.objects.create("
|
124
|
+
@obj1 = bucket.objects.create("dataset_data_my|dataset_201007011200.nt.zip", 'data')
|
125
|
+
@obj2 = bucket.objects.create("dataset_data_my|dataset_201007011201.nt.zip", 'data')
|
126
|
+
@obj3 = bucket.objects.create("dataset_data_my|dataset_201007011202.nt.zip", 'data')
|
217
127
|
# this one's on another day:
|
218
|
-
@obj4 = bucket.objects.create("
|
128
|
+
@obj4 = bucket.objects.create("dataset_data_my|dataset_201007021202.nt.zip", 'data')
|
219
129
|
|
220
130
|
# make them public readable
|
221
131
|
[@obj1, @obj2, @obj3].each { |o| o.acl = :public_read }
|
222
132
|
end
|
223
133
|
|
224
134
|
it "should redirect to the latest download that exists for that dataset" do
|
225
|
-
get
|
135
|
+
get :dump, :id => dataset.slug, :use_route => :publish_my_data
|
136
|
+
puts assigns[:dataset].inspect
|
226
137
|
response.should be_redirect
|
227
138
|
response.should redirect_to(@obj3.public_url.to_s)
|
228
139
|
end
|
@@ -243,7 +154,7 @@ module PublishMyData
|
|
243
154
|
end
|
244
155
|
|
245
156
|
it "should 404" do
|
246
|
-
get
|
157
|
+
get :dump, :id => dataset.slug, :use_route => :publish_my_data
|
247
158
|
response.should be_not_found
|
248
159
|
end
|
249
160
|
|
@@ -251,7 +162,7 @@ module PublishMyData
|
|
251
162
|
|
252
163
|
context "when a download doesn't exist on s3" do
|
253
164
|
it "should 404" do
|
254
|
-
get
|
165
|
+
get :dump, :id => dataset.slug, :use_route => :publish_my_data
|
255
166
|
response.should be_not_found
|
256
167
|
end
|
257
168
|
end
|
@@ -260,12 +171,12 @@ module PublishMyData
|
|
260
171
|
|
261
172
|
context "when a dataset with that slug doesn't exist" do
|
262
173
|
it "should 404" do
|
263
|
-
get
|
174
|
+
get :dump, :id => "i-dont-exist", :use_route => :publish_my_data
|
264
175
|
response.should be_not_found
|
265
176
|
end
|
266
177
|
end
|
267
178
|
|
268
|
-
end
|
269
179
|
|
180
|
+
end
|
270
181
|
end
|
271
182
|
end
|