responders 0.4 → 0.4.1

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.
@@ -88,7 +88,7 @@ module Responders
88
88
  def to_html
89
89
  super
90
90
 
91
- unless !respond_to?(:"to_#{format}") || get? || @flash == false
91
+ if set_i18n_flash?
92
92
  if has_errors?
93
93
  controller.flash[:alert] ||= @alert if @alert
94
94
  status = Responders::FlashResponder.flash_keys.last
@@ -107,6 +107,10 @@ module Responders
107
107
 
108
108
  protected
109
109
 
110
+ def set_i18n_flash? #:nodoc:
111
+ !get? && @flash != false
112
+ end
113
+
110
114
  def mount_i18n_options(status) #:nodoc:
111
115
  resource_name = if resource.class.respond_to?(:human_name)
112
116
  resource.class.human_name
@@ -15,9 +15,9 @@ module Responders
15
15
  end
16
16
 
17
17
  def to_format
18
- if get? && @http_cache != false && controller.response.last_modified.nil?
18
+ if do_http_cache?
19
19
  timestamp = resources.flatten.map do |resource|
20
- resource.updated_at.utc if resource.respond_to?(:updated_at)
20
+ (resource.updated_at || Time.now).utc if resource.respond_to?(:updated_at)
21
21
  end.compact.max
22
22
 
23
23
  controller.response.last_modified = timestamp if timestamp
@@ -29,5 +29,15 @@ module Responders
29
29
 
30
30
  super
31
31
  end
32
+
33
+ protected
34
+
35
+ def do_http_cache?
36
+ get? && @http_cache != false && !new_record? && controller.response.last_modified.nil?
37
+ end
38
+
39
+ def new_record?
40
+ resource.respond_to?(:new_record?) && resource.new_record?
41
+ end
32
42
  end
33
43
  end
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "0.4".freeze
3
- end
2
+ VERSION = "0.4.1".freeze
3
+ end
@@ -17,6 +17,12 @@ class HttpCacheController < ApplicationController
17
17
  respond_with [Model.new(Time.utc(2009)), Model.new(Time.utc(2008))]
18
18
  end
19
19
 
20
+ def new_record
21
+ model = Model.new(Time.utc(2009))
22
+ model.new_record = true
23
+ respond_with(model)
24
+ end
25
+
20
26
  def empty
21
27
  respond_with []
22
28
  end
@@ -101,4 +107,16 @@ class HttpCacheResponderTest < ActionController::TestCase
101
107
  assert_match /xml/, @response.body
102
108
  assert_equal 200, @response.status
103
109
  end
110
+
111
+ def test_it_does_not_set_body_etag
112
+ get :collection
113
+ assert_nil @response.headers["ETag"]
114
+ end
115
+
116
+ def test_does_not_set_cache_for_new_records
117
+ get :new_record
118
+ assert_nil @response.headers["Last-Modified"]
119
+ assert_equal "<xml />", @response.body
120
+ assert_equal 200, @response.status
121
+ end
104
122
  end
@@ -43,6 +43,12 @@ ActionController::Routing::Routes.draw do |map|
43
43
  end
44
44
 
45
45
  class Model < Struct.new(:updated_at)
46
+ attr_writer :new_record
47
+
48
+ def new_record?
49
+ @new_record || false
50
+ end
51
+
46
52
  def to_xml(*args)
47
53
  "<xml />"
48
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: responders
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.4"
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jos\xC3\xA9 Valim"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-22 00:00:00 +01:00
12
+ date: 2009-12-24 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15