publish_my_data 0.0.13 → 0.0.14

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.
@@ -9,6 +9,9 @@ module PublishMyData
9
9
 
10
10
  private
11
11
 
12
+ def is_request_html_format?
13
+ (request.format.to_sym || :html) == :html
14
+ end
12
15
  # TODO: deal with javaascript errors - respond with 200
13
16
 
14
17
  def handle_uncaught_error(e)
@@ -30,20 +33,42 @@ module PublishMyData
30
33
  Rails.logger.info e.backtrace.join("\n")
31
34
  respond_to do |format|
32
35
  format.html { render(:template => "publish_my_data/errors/uncaught", :layout => 'publish_my_data/error', :status => 500) and return false }
33
- format.any{ head(:status => 500, :content_type => 'text/plain') and return false }
36
+ format.any{ render(:text => 'Error', :status => 500, :content_type => 'text/plain') and return false }
34
37
  end
35
38
  end
36
39
 
37
40
  end
38
41
 
39
42
  def handle_timeout(e)
43
+ if defined?(Raven)
44
+ Raven.capture_message("query timeout", {
45
+ :extra => {
46
+ 'url' => request.url
47
+ },
48
+ :tags => {
49
+ 'message_type' => 'timeout'
50
+ },
51
+ :level => 'warning'
52
+ })
53
+ end
40
54
  respond_to do |format|
41
55
  format.html { render(:template => "publish_my_data/errors/timeout", :layout => 'publish_my_data/error', :status => 503) and return false }
42
- format.any { head(:status => 503, :content_type => 'text/plain') and return false }
56
+ format.any { render(:text => 'Timeout', :status => 503, :content_type => 'text/plain') and return false }
43
57
  end
44
58
  end
45
59
 
46
60
  def handle_response_too_large(e)
61
+ if defined?(Raven)
62
+ Raven.capture_message("response too large", {
63
+ :extra => {
64
+ 'url' => request.url
65
+ },
66
+ :tags => {
67
+ 'message_type' => 'too_Large'
68
+ },
69
+ :level => 'warning'
70
+ })
71
+ end
47
72
  respond_to do |format|
48
73
  format.html { render(:template => "publish_my_data/errors/response_too_large", :layout => 'publish_my_data/error', :status => 400) and return false }
49
74
  format.any { render(:text => "Response too large.", :status => 400, :content_type => 'text/plain') and return false }
@@ -56,7 +81,7 @@ module PublishMyData
56
81
  Rails.logger.debug(e.backtrace.join("\n"))
57
82
  respond_to do |format|
58
83
  format.html { render(:template => "publish_my_data/errors/not_found", :layout => 'publish_my_data/error', :status => 404) and return false }
59
- format.any { head(:status => 404, :content_type => 'text/plain') and return false }
84
+ format.any { render(:text => "Not Found" ,:status => 404, :content_type => 'text/plain') and return false }
60
85
  end
61
86
  end
62
87
 
@@ -17,7 +17,7 @@ module PublishMyData
17
17
 
18
18
  @types = RdfType.where('?s a ?uri').graph(@dataset.data_graph_uri).resources
19
19
 
20
- if request.format && request.format.html?
20
+ if is_request_html_format?
21
21
  @type_resource_counts = {}
22
22
  @resources_count = 0
23
23
  @types.each do |t|
@@ -67,7 +67,7 @@ module PublishMyData
67
67
  def render_resource_with_uri(uri)
68
68
  resource = Resource.find(uri)
69
69
 
70
- if request.format.html?
70
+ if is_request_html_format?
71
71
  resource.eager_load_predicate_triples!(:labels_only => true)
72
72
  resource.eager_load_object_triples!(:labels_only => true)
73
73
  end
@@ -12,7 +12,7 @@ module PublishMyData
12
12
  @query_text = params[:query]
13
13
 
14
14
  if @query_text.blank?
15
- unless request.format.html? #the html view handles this ok
15
+ unless is_request_html_format? #the html view handles this ok
16
16
  render :text => "no query supplied", :status => 400
17
17
  end
18
18
  else
@@ -10,7 +10,7 @@ module PublishMyData
10
10
 
11
11
  def index
12
12
  # don't bother paginating this for now - there probably wont be that many themes
13
- @themes = Theme.all.resources
13
+ @themes = Theme.all.where("?uri <#{RDF::RDFS.label}> ?label").order("?label").resources
14
14
  respond_with(@themes)
15
15
  end
16
16
 
@@ -38,7 +38,7 @@ module PublishMyData
38
38
  # if there are pagination paramters, then use them
39
39
  if @pagination_params.per_page && @pagination_params.page
40
40
  sparql_query_result = sparql_query.paginate(@pagination_params.page, @pagination_params.per_page)
41
- if request.format.html?
41
+ if is_request_html_format?
42
42
  count = sparql_query.as_pagination_query(@pagination_params.page, @pagination_params.per_page, 1).count
43
43
  @more_pages = (count > @pagination_params.per_page)
44
44
  end
@@ -17,7 +17,7 @@ module PublishMyData
17
17
  end
18
18
 
19
19
  def self.from_request(request)
20
- self.new(per_page: request.params[:per_page], page: request.params[:page], format: request.format.to_sym)
20
+ self.new(per_page: request.params[:per_page], page: request.params[:page], format: (request.format.to_sym || :html))
21
21
  end
22
22
 
23
23
  def ==(other)
@@ -1,3 +1,3 @@
1
1
  module PublishMyData
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
@@ -41,7 +41,7 @@ module PublishMyData
41
41
  context "for a non-existent dataset slug" do
42
42
  it "should return a blank body" do
43
43
  get :show, id: "slug-that-doesnt-exist", use_route: :publish_my_data, :format => format
44
- response.body.should be_blank
44
+ response.body.should == "Not Found"
45
45
  end
46
46
  end
47
47
  end
@@ -72,7 +72,7 @@ module PublishMyData
72
72
  context "for a non-existent dataset slug" do
73
73
  it "should return a blank body" do
74
74
  get :show, id: "slug-that-doesnt-exist", use_route: :publish_my_data, :format => format
75
- response.body.should be_blank
75
+ response.body.should == "Not Found"
76
76
  end
77
77
  end
78
78
 
@@ -83,7 +83,7 @@ module PublishMyData
83
83
  it "should 404 with a blank response" do
84
84
  get :doc, :path => "unicorns/borat", use_route: :publish_my_data
85
85
  response.should be_not_found
86
- response.body.should be_blank
86
+ response.body.should == "Not Found"
87
87
  end
88
88
  end
89
89
 
@@ -66,7 +66,8 @@ module PublishMyData
66
66
 
67
67
  it "should respond with an empty body" do
68
68
  get :show, :id => "theme-that-doesnt-exist", :use_route => :publish_my_data, :format => 'rdf'
69
- response.body.strip.should be_blank
69
+ response.body.strip.should == "Not Found"
70
+
70
71
  end
71
72
  end
72
73
  end