responders 0.6.0 → 0.6.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.
@@ -1,3 +1,9 @@
1
+ == 0.6
2
+
3
+ * :js now sets the flash.now by default, instead of flash
4
+ * Renamed responders_install generator to responders:install
5
+ * Added a fix for Rails 3.0.0.beta3
6
+
1
7
  == 0.5
2
8
 
3
9
  * Added Railtie and better Rails 3 support
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.0.beta3"
4
+ gem "mocha"
5
+
6
+ if RUBY_VERSION < "1.9"
7
+ gem "ruby-debug"
8
+ else
9
+ gem "test-unit"
10
+ end
@@ -58,7 +58,7 @@ responder. This can be done in an initializer for example:
58
58
 
59
59
  Or, for your convenience, just do:
60
60
 
61
- rails generate responders_install
61
+ rails generate responders:install
62
62
 
63
63
  == Controller method
64
64
 
data/Rakefile CHANGED
@@ -10,7 +10,6 @@ task :default => :test
10
10
 
11
11
  desc 'Test Responders'
12
12
  Rake::TestTask.new(:test) do |t|
13
- t.libs << 'lib'
14
13
  t.libs << 'test'
15
14
  t.pattern = 'test/**/*_test.rb'
16
15
  t.verbose = true
@@ -0,0 +1,33 @@
1
+ module Responders
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ def self.source_root
5
+ @_source_root ||= File.expand_path("..", __FILE__)
6
+ end
7
+
8
+ desc "Creates an initializer with default responder configuration and copy locale file"
9
+
10
+ def create_responder_file
11
+ create_file "lib/application_responder.rb", <<-RUBY
12
+ class ApplicationResponder < ActionController::Responder
13
+ include Responders::FlashResponder
14
+ include Responders::HttpCacheResponder
15
+ end
16
+ RUBY
17
+ end
18
+
19
+ def update_application_controller
20
+ prepend_file "app/controllers/application_controller.rb", %{require "application_responder"\n\n}
21
+ inject_into_class "app/controllers/application_controller.rb", "ApplicationController", <<-RUBY
22
+ self.responder = ApplicationResponder
23
+ respond_to :html
24
+
25
+ RUBY
26
+ end
27
+
28
+ def copy_locale
29
+ copy_file "../../responders/locales/en.yml", "config/locales/responders.en.yml"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -5,7 +5,6 @@ module Responders
5
5
  autoload :HttpCacheResponder, 'responders/http_cache_responder'
6
6
 
7
7
  require 'responders/controller_method'
8
- ActionController::Base.extend Responders::ControllerMethod
9
8
 
10
9
  class Railtie < ::Rails::Railtie
11
10
  config.responders = ActiveSupport::OrderedOptions.new
@@ -32,4 +32,15 @@ module Responders
32
32
  end
33
33
  end
34
34
  end
35
- end
35
+ end
36
+
37
+ # Fix for Rails <= 3.0.0.beta3
38
+ require "action_controller/metal/responder"
39
+
40
+ class ActionController::Responder
41
+ def default_action
42
+ @action ||= ACTIONS_FOR_VERBS[request.request_method_symbol]
43
+ end
44
+ end
45
+
46
+ ActionController::Base.extend Responders::ControllerMethod
@@ -95,7 +95,7 @@ module Responders
95
95
 
96
96
  def to_js
97
97
  set_flash_message! if set_flash_message?
98
- to_format
98
+ defined?(super) ? super : to_format
99
99
  end
100
100
 
101
101
  protected
@@ -23,22 +23,22 @@ module Responders
23
23
 
24
24
  def do_http_cache!
25
25
  timestamp = resources.flatten.map do |resource|
26
- (resource.updated_at || Time.now).utc if resource.respond_to?(:updated_at)
26
+ next unless resource.respond_to?(:updated_at)
27
+ resource.updated_at.utc
27
28
  end.compact.max
28
29
 
29
- controller.response.last_modified = timestamp if timestamp
30
+ controller.response.last_modified ||= timestamp if timestamp
30
31
 
31
32
  head :not_modified if fresh = request.fresh?(controller.response)
32
33
  fresh
33
34
  end
34
35
 
35
36
  def do_http_cache?
36
- get? && @http_cache != false && ActionController::Base.perform_caching &&
37
- !new_record? && controller.response.last_modified.nil?
37
+ get? && @http_cache != false && ActionController::Base.perform_caching && persisted? && resourceful?
38
38
  end
39
39
 
40
- def new_record?
41
- resource.respond_to?(:new_record?) && resource.new_record?
40
+ def persisted?
41
+ resource.respond_to?(:persisted?) ? resource.persisted? : true
42
42
  end
43
43
  end
44
44
  end
@@ -2,9 +2,9 @@ en:
2
2
  flash:
3
3
  actions:
4
4
  create:
5
- notice: '{{resource_name}} was successfully created.'
5
+ notice: '%{resource_name} was successfully created.'
6
6
  update:
7
- notice: '{{resource_name}} was successfully updated.'
7
+ notice: '%{resource_name} was successfully updated.'
8
8
  destroy:
9
- notice: '{{resource_name}} was successfully destroyed.'
10
- alert: '{{resource_name}} could not be destroyed.'
9
+ notice: '%{resource_name} was successfully destroyed.'
10
+ alert: '%{resource_name} could not be destroyed.'
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "0.6.0".freeze
2
+ VERSION = "0.6.1".freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  ActionController::Base.extend Responders::ControllerMethod
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class Address
4
4
  attr_accessor :errors
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class HttpCacheResponder < ActionController::Responder
4
4
  include Responders::HttpCacheResponder
@@ -17,9 +17,9 @@ 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
20
+ def not_persisted
21
21
  model = Model.new(Time.utc(2009))
22
- model.new_record = true
22
+ model.persisted = false
23
23
  respond_with(model)
24
24
  end
25
25
 
@@ -82,18 +82,6 @@ class HttpCacheResponderTest < ActionController::TestCase
82
82
  assert_equal 200, @response.status
83
83
  end
84
84
 
85
- def test_does_not_set_cache_if_last_modified_already_set_in_response
86
- get :single, :last_modified => true
87
- assert_equal Time.utc(2008).httpdate, @response.headers["Last-Modified"]
88
- assert_equal 200, @response.status
89
- end
90
-
91
- def test_does_not_use_cache_if_last_modified_already_set_in_response
92
- @request.env["HTTP_IF_MODIFIED_SINCE"] = Time.utc(2009, 6).httpdate
93
- get :single, :last_modified => true
94
- assert_equal 200, @response.status
95
- end
96
-
97
85
  def test_collection_chooses_the_latest_timestamp
98
86
  get :collection
99
87
  assert_equal Time.utc(2009).httpdate, @response.headers["Last-Modified"]
@@ -114,7 +102,7 @@ class HttpCacheResponderTest < ActionController::TestCase
114
102
  end
115
103
 
116
104
  def test_does_not_set_cache_for_new_records
117
- get :new_record
105
+ get :not_persisted
118
106
  assert_nil @response.headers["Last-Modified"]
119
107
  assert_equal "<xml />", @response.body
120
108
  assert_equal 200, @response.status
@@ -1,20 +1,7 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
2
3
 
3
- gem 'activesupport', '3.0.0.beta2'
4
- gem 'activemodel', '3.0.0.beta2'
5
- gem 'actionpack', '3.0.0.beta2'
6
- gem 'railties', '3.0.0.beta2'
7
-
8
- begin
9
- gem "test-unit"
10
- rescue LoadError
11
- end
12
-
13
- begin
14
- gem "ruby-debug"
15
- require 'ruby-debug'
16
- rescue LoadError
17
- end
4
+ Bundler.setup
18
5
 
19
6
  require 'test/unit'
20
7
  require 'mocha'
@@ -52,10 +39,10 @@ class ActiveSupport::TestCase
52
39
  end
53
40
 
54
41
  class Model < Struct.new(:updated_at)
55
- attr_writer :new_record
42
+ attr_writer :persisted
56
43
 
57
- def new_record?
58
- @new_record || false
44
+ def persisted?
45
+ defined?(@persisted) ? @persisted : true
59
46
  end
60
47
 
61
48
  def to_xml(*args)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 0
9
- version: 0.6.0
8
+ - 1
9
+ version: 0.6.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jos\xC3\xA9 Valim"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-03 00:00:00 +02:00
17
+ date: 2010-05-24 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -28,13 +28,14 @@ extra_rdoc_files:
28
28
  - README.rdoc
29
29
  files:
30
30
  - CHANGELOG.rdoc
31
+ - Gemfile
31
32
  - MIT-LICENSE
32
33
  - README.rdoc
33
34
  - Rakefile
34
35
  - lib/generators/rails/USAGE
35
36
  - lib/generators/rails/responders_controller_generator.rb
36
37
  - lib/generators/rails/templates/controller.rb
37
- - lib/generators/responders_install_generator.rb
38
+ - lib/generators/responders/install_generator.rb
38
39
  - lib/responders.rb
39
40
  - lib/responders/controller_method.rb
40
41
  - lib/responders/flash_responder.rb
@@ -1,23 +0,0 @@
1
- class RespondersInstallGenerator < Rails::Generators::Base
2
- def self.source_root
3
- @_source_root ||= File.expand_path("..", __FILE__)
4
- end
5
-
6
- desc "Creates an initializer with default responder configuration and copy locale file"
7
-
8
- def create_responder_initializer
9
- create_file "config/initializers/responders.rb", <<-FILE
10
- class ApplicationResponder < ActionController::Responder
11
- include Responders::FlashResponder
12
- include Responders::HttpCacheResponder
13
- end
14
-
15
- ApplicationController.respond_to :html
16
- ApplicationController.responder = ApplicationResponder
17
- FILE
18
- end
19
-
20
- def copy_locale
21
- copy_file "../responders/locales/en.yml", "config/locales/responders.en.yml"
22
- end
23
- end