cacheable_flash 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -5
  3. data/CHANGELOG +5 -0
  4. data/LICENSE +23 -23
  5. data/README.rdoc +21 -5
  6. data/init.rb +6 -6
  7. data/install.rb +18 -18
  8. data/lib/cacheable_flash.rb +7 -5
  9. data/lib/cacheable_flash/config.rb +3 -1
  10. data/lib/cacheable_flash/engine.rb +10 -7
  11. data/lib/cacheable_flash/middleware.rb +6 -22
  12. data/lib/cacheable_flash/railtie.rb +10 -10
  13. data/lib/cacheable_flash/rspec_matchers.rb +6 -6
  14. data/lib/cacheable_flash/test_helpers.rb +1 -1
  15. data/lib/cacheable_flash/version.rb +3 -3
  16. data/lib/generators/cacheable_flash/install/install_generator.rb +24 -23
  17. data/lib/tasks/cacheable-flash_tasks.rake +4 -4
  18. data/spec/cacheable_flash/cacheable_flash_spec.rb +17 -12
  19. data/spec/cacheable_flash/install_spec.rb +68 -68
  20. data/spec/controllers/controller_test_using_test_unit_spec.rb +28 -0
  21. data/spec/dummy/Rakefile +7 -7
  22. data/spec/dummy/app/assets/javascripts/application.js +15 -15
  23. data/spec/dummy/app/assets/stylesheets/application.css +13 -13
  24. data/spec/dummy/app/controllers/application_controller.rb +3 -3
  25. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  26. data/spec/dummy/app/views/layouts/application.html.erb +14 -14
  27. data/spec/dummy/config.ru +4 -4
  28. data/spec/dummy/config/application.rb +62 -62
  29. data/spec/dummy/config/boot.rb +9 -9
  30. data/spec/dummy/config/database.yml +25 -25
  31. data/spec/dummy/config/environment.rb +5 -5
  32. data/spec/dummy/config/environments/development.rb +39 -39
  33. data/spec/dummy/config/environments/production.rb +67 -67
  34. data/spec/dummy/config/environments/test.rb +39 -39
  35. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  36. data/spec/dummy/config/initializers/inflections.rb +15 -15
  37. data/spec/dummy/config/initializers/mime_types.rb +5 -5
  38. data/spec/dummy/config/initializers/secret_token.rb +7 -7
  39. data/spec/dummy/config/initializers/session_store.rb +8 -8
  40. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  41. data/spec/dummy/config/locales/en.yml +5 -5
  42. data/spec/dummy/public/404.html +26 -26
  43. data/spec/dummy/public/422.html +26 -26
  44. data/spec/dummy/public/500.html +25 -25
  45. data/spec/dummy/script/rails +6 -6
  46. data/spec/js_unit/cookie_test.html +60 -60
  47. data/spec/js_unit/flash_test.html +112 -112
  48. data/tasks/cacheable_flash_tasks.rake +3 -3
  49. data/vendor/assets/javascripts/{flash.js → flash.js.erb} +2 -2
  50. data/vendor/assets/javascripts/jquery.cookie.js +47 -47
  51. metadata +29 -49
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bdb098987853b71c911ad84e070ca44e3c3dee1
4
+ data.tar.gz: 167e3d10c1679c57f12d1a7f8127509301092e65
5
+ SHA512:
6
+ metadata.gz: 3bdf569f5354470eba7634a09c55dfe35d8f43362a1d2ef9949d290b6855bf781023df8555560ee8131851115d4a9150a572df528c56d245439f883b5f338493
7
+ data.tar.gz: b5a1f3892cefd5b90b3c450b27090e34b9d38fc33486ddd18fcc5cc48968aa2bdaf8c3f5dd050f86e672b46a3546c2826e2875c30dd583549af793c1e59890bf
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.3.3 - SEP.13.2013
2
+ * Maintenance release with lots of minor changes and fixes.
3
+ * Main gem should be API compatible.
4
+ * Small changes to test helpers which will require updating tests using them.
5
+
1
6
  0.3.2 - AUG.23.2012
2
7
  * Properly handles stacked flash in cookie flash according to config :append_as option [Peter Boling]
3
8
 
data/LICENSE CHANGED
@@ -1,23 +1,23 @@
1
- Copyright (c) 2007-2010 Pivotal Labs
2
- Copyright (c) 2011-2012 Peter H. Boling (http://peterboling.com)
3
-
4
- MIT License
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining
7
- a copy of this software and associated documentation files (the
8
- "Software"), to deal in the Software without restriction, including
9
- without limitation the rights to use, copy, modify, merge, publish,
10
- distribute, sublicense, and/or sell copies of the Software, and to
11
- permit persons to whom the Software is furnished to do so, subject to
12
- the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2007-2010 Pivotal Labs
2
+ Copyright (c) 2011-2012 Peter H. Boling (http://peterboling.com)
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,4 +1,4 @@
1
- = CacheableFlash {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/pivotal/cacheable-flash] {<img src="https://secure.travis-ci.org/pboling/cacheable-flash.png?branch=master" alt="Build Status" />}[http://travis-ci.org/pboling/cacheable-flash]
1
+ = CacheableFlash {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/pivotal/cacheable-flash] {<img src="https://secure.travis-ci.org/pboling/cacheable-flash.png?branch=master" alt="Build Status" />}[http://travis-ci.org/pboling/cacheable-flash] {<img src="http://api.coderwall.com/pboling/endorsecount.png" />}[http://coderwall.com/pboling]
2
2
 
3
3
  == Description
4
4
 
@@ -119,7 +119,7 @@ Cacheable Flash provides test helpers which includes the flash_cookie method.
119
119
 
120
120
  def test_cacheable_flash_action
121
121
  get :index
122
- asset_equal "In index", flash_cookie["notice"]
122
+ assert_equal "In index", flash_cookie["notice"]
123
123
  end
124
124
  end
125
125
 
@@ -150,9 +150,25 @@ Cacheable Flash provides test helpers which includes the flash_cookie method.
150
150
  5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
151
151
  6. Create new Pull Request
152
152
 
153
+ == Versioning
154
+
155
+ This library aims to adhere to {Semantic Versioning 2.0.0}[http://semver.org/].
156
+ Violations of this scheme should be reported as bugs. Specifically,
157
+ if a minor or patch version is released that breaks backward
158
+ compatibility, a new version should be immediately released that
159
+ restores compatibility. Breaking changes to the public API will
160
+ only be introduced with new major versions.
161
+
162
+ As a result of this policy, you can (and should) specify a
163
+ dependency on this gem using the {Pessimistic Version Constraint}[http://docs.rubygems.org/read/chapter/16#page74] with two digits of precision.
164
+
165
+ For example:
166
+
167
+ spec.add_dependency 'cacheable_flash', '~> 4.0'
168
+
153
169
  == Copyright
154
170
 
155
- Licensed under the MIT License.
171
+ Licensed under the MIT License. See LICENSE for further details.
156
172
 
157
- - Copyright (c) 2011-2012 Peter H. Boling (http://peterboling.com). See LICENSE for further details.
158
- - Copyright (c) 2007-2010 Pivotal Labs
173
+ - Copyright (c) 2011-2012 {Peter H. Boling}[http://railsbling.com] {<img src="http://api.coderwall.com/pboling/endorsecount.png" />}[http://coderwall.com/pboling]
174
+ - Copyright (c) 2007-2010 {Pivotal Labs}[https://coderwall.com/team/pivotal-labs]
data/init.rb CHANGED
@@ -1,6 +1,6 @@
1
- require "json"
2
- require "cacheable_flash"
3
- #use Rails::VERSION::STRING for rails < 1 somehow -- or perhaps, who cares??
4
- if ::Rails::VERSION::MAJOR == 2
5
- ActionView::Helpers::AssetTagHelper.register_javascript_include_default('jquery.cookie','flash')
6
- end
1
+ require "json"
2
+ require "cacheable_flash"
3
+ #use Rails::VERSION::STRING for rails < 1 somehow -- or perhaps, who cares??
4
+ if ::Rails::VERSION::MAJOR == 2
5
+ ActionView::Helpers::AssetTagHelper.register_javascript_include_default('jquery.cookie','flash')
6
+ end
data/install.rb CHANGED
@@ -1,18 +1,18 @@
1
- # Only executed when installed as plugin.
2
- # When installed as a gem must use the generator, unless using Rails >= 3.1 and asset pipeline,
3
- # in which case the asset pipeline takes care of everything
4
- require 'fileutils'
5
- include FileUtils
6
-
7
- dir = "#{File.dirname(__FILE__)}/vendor/assets/javascripts"
8
- rails_javascripts_dir = "#{Rails.root}/public/javascripts"
9
-
10
- puts "copying flash.js to #{rails_javascripts_dir}"
11
- cp "#{dir}/flash.js", rails_javascripts_dir
12
-
13
- if File.exists?("#{rails_javascripts_dir}/jquery.cookie.js")
14
- puts "#{rails_javascripts_dir}/jquery.cookie.js already exists"
15
- else
16
- puts "copying jquery.cookie.js to #{rails_javascripts_dir}"
17
- cp "#{dir}/jquery.cookie.js", rails_javascripts_dir
18
- end
1
+ # Only executed when installed as plugin.
2
+ # When installed as a gem must use the generator, unless using Rails >= 3.1 and asset pipeline,
3
+ # in which case the asset pipeline takes care of everything
4
+ require 'fileutils'
5
+ include FileUtils
6
+
7
+ dir = "#{File.dirname(__FILE__)}/vendor/assets/javascripts"
8
+ rails_javascripts_dir = "#{Rails.root}/public/javascripts"
9
+
10
+ puts "copying flash.js to #{rails_javascripts_dir}"
11
+ cp "#{dir}/flash.js", rails_javascripts_dir
12
+
13
+ if File.exists?("#{rails_javascripts_dir}/jquery.cookie.js")
14
+ puts "#{rails_javascripts_dir}/jquery.cookie.js already exists"
15
+ else
16
+ puts "copying jquery.cookie.js to #{rails_javascripts_dir}"
17
+ cp "#{dir}/jquery.cookie.js", rails_javascripts_dir
18
+ end
@@ -2,9 +2,9 @@ require 'json'
2
2
  require 'stackable_flash'
3
3
 
4
4
  module CacheableFlash
5
- if defined?(Rails) && ::Rails::VERSION::MAJOR == 3
5
+ if defined?(Rails) && (::Rails::VERSION::MAJOR >= 3)
6
6
  require 'cacheable_flash/middleware'
7
- require 'cacheable_flash/engine' if ::Rails::VERSION::MINOR >= 1
7
+ require 'cacheable_flash/engine' if (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1) || ::Rails::VERSION::MAJOR > 3
8
8
  require 'cacheable_flash/railtie'
9
9
  else
10
10
  # For older rails use generator
@@ -17,7 +17,7 @@ module CacheableFlash
17
17
  # end
18
18
  StackableFlash.stacking = false
19
19
 
20
- # The configure will override the above default
20
+ # The configure will override the above defaults
21
21
  require 'cacheable_flash/config'
22
22
  require 'cacheable_flash/cookie_flash'
23
23
  include CacheableFlash::CookieFlash
@@ -30,10 +30,12 @@ module CacheableFlash
30
30
  def write_flash_to_cookie
31
31
  yield if block_given?
32
32
 
33
+
33
34
  # Base must define cookies, as in Rails
34
- cookies['flash'] = cookie_flash(flash, cookies)
35
+ domain = CacheableFlash::Config.config[:domain]
36
+ cookies['flash'] = { :value => cookie_flash(flash, cookies), :domain => domain }
35
37
  # Base must define flash, as in Rails
36
- # TODO: Does not support flash.now feature of the FlashHash in Rails,
38
+ # TODO: Does not support flash.now feature of the FlashHash in Rails,
37
39
  # because flashes are only removed from cookies when they are used.
38
40
  flash.clear
39
41
  end
@@ -13,7 +13,9 @@ module CacheableFlash
13
13
  :stacking => false, # or true if you want auto-magically stacking flashes
14
14
  # Specify how multiple flashes at the same key (e.g. :notice, :errors) should be handled
15
15
  # :append_as is ignored if :stacking is false
16
- :append_as => :br # or :array, :p, :ul, :ol, or a proc or lambda of your own design
16
+ :append_as => :br, # or :array, :p, :ul, :ol, or a proc or lambda of your own design
17
+ # if domain is unspecified, defaults to nil and the request domain is used (see middleware.rb)
18
+ :domain => nil
17
19
  }
18
20
 
19
21
  @config ||= DEFAULTS
@@ -1,7 +1,10 @@
1
- module CacheableFlash
2
- class Engine < ::Rails::Engine
3
- if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MAJOR >= 1
4
- isolate_namespace CacheableFlash
5
- end
6
- end
7
- end
1
+ module CacheableFlash
2
+ class Engine < ::Rails::Engine
3
+ # Allow for Rails versions ~> 3.1 and > 3
4
+ if (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1) || ::Rails::VERSION::MAJOR > 3
5
+ isolate_namespace CacheableFlash
6
+ else
7
+ warn 'CacheableFlash namespace not isolated, check that Rails version is >= 3.1'
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,6 @@
1
1
  module CacheableFlash
2
2
  class Middleware
3
+ require 'cacheable_flash/config'
3
4
  require 'cacheable_flash/cookie_flash'
4
5
  include CacheableFlash::CookieFlash
5
6
  FLASH_HASH_KEY = "action_dispatch.request.flash_hash".freeze
@@ -8,34 +9,17 @@ module CacheableFlash
8
9
  @app = app
9
10
  end
10
11
 
11
- # Cookies stick in the flash until rendered (cleared out of the cookie by javascript),
12
- # to ensure they are seen and not lost, so we grab them from the rails flash hash, or the request cookies
13
12
  def call(env)
14
13
  status, headers, body = @app.call(env)
15
14
  env_flash = env[FLASH_HASH_KEY]
16
15
 
17
16
  if env_flash
18
- # There is a flash set from this request, merge it into the cookie flash (which may already be populated)
19
- response = Rack::Response.new(body, status, headers)
20
- cookies = env["rack.cookies"] || {}
21
- response.set_cookie("flash", { :value => cookie_flash(env_flash, cookies), :path => "/" })
22
- response.finish
23
- else
24
- # There is no flash set in this request but there are leftovers from previous requests still in the cookie
25
- request = ActionDispatch::Request.new(env)
26
- cflash = request.respond_to?(:cookie_jar) ?
27
- request.cookie_jar['flash'] :
28
- nil
29
- if cflash
30
- response = Rack::Response.new(body, status, headers)
31
- response.set_cookie("flash", { :value => cflash, :path => "/" })
32
- response.finish
33
- else
34
- response = body
35
- end
17
+ domain = CacheableFlash::Config.config[:domain]
18
+ cookies = Rack::Request.new(env).cookies
19
+ Rack::Utils.set_cookie_header!(headers, "flash", :value => cookie_flash(env_flash, cookies), :path => "/", :domain => "#{domain}")
36
20
  end
37
- [status, headers, response]
38
- end
39
21
 
22
+ [status, headers, body]
23
+ end
40
24
  end
41
25
  end
@@ -1,10 +1,10 @@
1
- # Add cacheable flash JS to defaults for Rails < 3.1 (not needed with asset pipeline)
2
- module CacheableFlash
3
- class Railtie < ::Rails::Railtie
4
- if ::Rails::VERSION::MAJOR == 3
5
- config.before_configuration do
6
- config.action_view.javascript_expansions[:cacheable_flash] = %w(jquery.cookie flash)
7
- end
8
- end
9
- end
10
- end
1
+ module CacheableFlash
2
+ class Railtie < ::Rails::Railtie
3
+ # Add cacheable flash JS to defaults for Rails < 3.1 (not needed with asset pipeline)
4
+ if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 0
5
+ config.before_configuration do
6
+ config.action_view.javascript_expansions[:cacheable_flash] = %w(jquery.cookie flash)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -8,27 +8,27 @@ module CacheableFlash
8
8
  include CacheableFlash::TestHelpers
9
9
  RSpec::Matchers.define :have_flash_cookie do |flash_status, expecting|
10
10
  define_method :has_flash_cookie? do |response|
11
- flash_in_stack(testable_flash(response)[flash_status], expecting)
11
+ flash_in_stack(flash_cookie_for(response)[flash_status], expecting)
12
12
  end
13
13
  match{|response| has_flash_cookie?(response)}
14
14
  failure_message_for_should do |actual|
15
- "expected flash[:#{expected[0]}] to be or include #{expected[1].inspect}, but got #{testable_flash(actual)[expected[0]]}"
15
+ "expected flash[:#{expected[0]}] to be or include #{expected[1].inspect}, but got #{flash_cookie_for(actual)[expected[0]]}"
16
16
  end
17
17
  failure_message_for_should_not do |actual|
18
- "expected flash[:#{expected[0]}] to not be and not include #{expected[1].inspect}, but got #{testable_flash(actual)[expected[0]]}"
18
+ "expected flash[:#{expected[0]}] to not be and not include #{expected[1].inspect}, but got #{flash_cookie_for(actual)[expected[0]]}"
19
19
  end
20
20
  end
21
21
 
22
22
  RSpec::Matchers.define :have_cacheable_flash do |flash_status, expecting|
23
23
  define_method :has_cacheable_flash? do |response|
24
- flash_in_stack(testable_flash(response)[flash_status], expecting)
24
+ flash_in_stack(flash_cookie_for(response)[flash_status], expecting)
25
25
  end
26
26
  match{|response| has_cacheable_flash?(response)}
27
27
  failure_message_for_should do |actual|
28
- "expected flash[:#{expected[0]}] to be or include #{expected[1].inspect}, but got #{testable_flash(actual)[expected[0]]}"
28
+ "expected flash[:#{expected[0]}] to be or include #{expected[1].inspect}, but got #{flash_cookie_for(actual)[expected[0]]}"
29
29
  end
30
30
  failure_message_for_should_not do |actual|
31
- "expected flash[:#{expected[0]}] to not be and not include #{expected[1].inspect}, but got #{testable_flash(actual)[expected[0]]}"
31
+ "expected flash[:#{expected[0]}] to not be and not include #{expected[1].inspect}, but got #{flash_cookie_for(actual)[expected[0]]}"
32
32
  end
33
33
  end
34
34
 
@@ -10,7 +10,7 @@ module CacheableFlash
10
10
  {}
11
11
  end
12
12
 
13
- def testable_flash(response)
13
+ def flash_cookie_for(response)
14
14
  return {} unless cooked_flash = response.cookies['flash']
15
15
  JSON(cooked_flash)
16
16
  rescue JSON::ParserError
@@ -1,3 +1,3 @@
1
- module CacheableFlash
2
- VERSION = "0.3.2"
3
- end
1
+ module CacheableFlash
2
+ VERSION = "0.3.3"
3
+ end
@@ -1,23 +1,24 @@
1
- # encoding: utf-8
2
-
3
- module CacheableFlash
4
- # Copies javascript libraries flash.js and jquery.cookie.js to public/javascripts/ (Rails 3.0.X only, Rails 3.1 has asset pipeline)
5
- #
6
- # @example
7
- # $ rails generate cacheable_flash:install
8
- #
9
- class InstallGenerator < Rails::Generators::Base
10
- source_root File.expand_path('../../../../../vendor/assets/javascripts/', __FILE__)
11
-
12
- # Rails 3.1 has the asset pipeline, no need to copy javascript files anymore
13
- # Rails 3.0 doesn't have an asset pipeline, so we copy in javascript files
14
- desc "Copies some JS files to public/javascripts/"
15
- def copy_files
16
- if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 1
17
- ActiveSupport::Deprecation.warn("Rails 3.1 has the asset pipeline, so you only need to copy javascript files if you aren't using it.")
18
- end
19
- template 'flash.js', 'public/javascripts/flash.js'
20
- template 'jquery.cookie.js', 'public/javascripts/jquery.cookie.js'
21
- end
22
- end
23
- end
1
+ # encoding: utf-8
2
+
3
+ module CacheableFlash
4
+ # Copies javascript libraries flash.js and jquery.cookie.js to public/javascripts/ (Rails 3.0.X only, Rails 3.1 has asset pipeline)
5
+ #
6
+ # @example
7
+ # $ rails generate cacheable_flash:install
8
+ #
9
+ class InstallGenerator < Rails::Generators::Base
10
+ source_root File.expand_path('../../../../../vendor/assets/javascripts/', __FILE__)
11
+
12
+ # Rails 3.1 has the asset pipeline, no need to copy javascript files anymore
13
+ # Rails 3.0 doesn't have an asset pipeline, so we copy in javascript files
14
+ desc "Copies some JS files to public/javascripts/"
15
+ def copy_files
16
+ # Also raise this deprecation in rails 4
17
+ if (::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1) || ::Rails::VERSION::MAJOR > 3
18
+ ActiveSupport::Deprecation.warn("Rails 3.1 has the asset pipeline, so you only need to copy javascript files if you aren't using it.")
19
+ end
20
+ template 'flash.js', 'public/javascripts/flash.js'
21
+ template 'jquery.cookie.js', 'public/javascripts/jquery.cookie.js'
22
+ end
23
+ end
24
+ end
@@ -1,4 +1,4 @@
1
- # desc "Explaining what the task does"
2
- # task :cacheable_flash do
3
- # # Task goes here
4
- # end
1
+ # desc "Explaining what the task does"
2
+ # task :cacheable_flash do
3
+ # # Task goes here
4
+ # end
@@ -11,6 +11,11 @@ describe 'CacheableFlash' do
11
11
  @controller.stub(:cookies).and_return(@cookies)
12
12
  end
13
13
 
14
+ def controller_cookie_flash
15
+ @controller.cookies['flash'][:value]
16
+ end
17
+
18
+
14
19
  describe "#write_flash_to_cookie" do
15
20
  context "when there is not an existing flash cookie" do
16
21
  it "sets the flash cookie with a JSON representation of the Hash" do
@@ -18,10 +23,10 @@ describe 'CacheableFlash' do
18
23
  'errors' => "This is an Error",
19
24
  'notice' => "This is a Notice"
20
25
  }
21
- controller.flash = expected_flash.dup
22
- controller.write_flash_to_cookie
26
+ @controller.flash = expected_flash.dup
27
+ @controller.write_flash_to_cookie
23
28
 
24
- JSON(@controller.cookies['flash']).should == expected_flash
29
+ JSON(controller_cookie_flash).should == expected_flash
25
30
  end
26
31
  end
27
32
 
@@ -44,7 +49,7 @@ describe 'CacheableFlash' do
44
49
  'notice' => "New notice",
45
50
  'errors' => "New errors",
46
51
  }
47
- JSON(@controller.cookies['flash']).should == expected_flash
52
+ JSON(controller_cookie_flash).should == expected_flash
48
53
  end
49
54
  end
50
55
 
@@ -57,7 +62,7 @@ describe 'CacheableFlash' do
57
62
 
58
63
  @controller.write_flash_to_cookie
59
64
 
60
- JSON(@cookies['flash']).should == {}
65
+ JSON(@cookies['flash'][:value]).should == {}
61
66
  end
62
67
  end
63
68
  end
@@ -65,31 +70,31 @@ describe 'CacheableFlash' do
65
70
  it "converts flash value to string before storing in cookie if value is a number" do
66
71
  @controller.flash = { 'quantity' => 5 }
67
72
  @controller.write_flash_to_cookie
68
- JSON(@controller.cookies['flash']).should == { 'quantity' => 5 }
73
+ JSON(controller_cookie_flash).should == { 'quantity' => 5 }
69
74
  end
70
75
 
71
76
  it "does not convert flash value to string before storing in cookie if value is anything other than a number" do
72
77
  @controller.flash = { 'foo' => { 'bar' => 'baz' } }
73
78
  @controller.write_flash_to_cookie
74
- JSON(@controller.cookies['flash']).should == { 'foo' => { 'bar' => 'baz' } }
79
+ JSON(controller_cookie_flash).should == { 'foo' => { 'bar' => 'baz' } }
75
80
  end
76
81
 
77
82
  it "encodes plus signs in generated JSON before storing in cookie" do
78
83
  @controller.flash = { 'notice' => 'Life, Love + Liberty' }
79
84
  @controller.write_flash_to_cookie
80
- @controller.cookies['flash'].should == "{\"notice\":\"Life, Love %2B Liberty\"}"
85
+ controller_cookie_flash.should == "{\"notice\":\"Life, Love %2B Liberty\"}"
81
86
  end
82
87
 
83
88
  it "escapes strings when not html safe" do
84
89
  @controller.flash = { 'notice' => '<em>Life, Love + Liberty</em>' } # Not html_safe, so it will be escaped
85
90
  @controller.write_flash_to_cookie
86
- @controller.cookies['flash'].should == "{\"notice\":\"&lt;em&gt;Life, Love %2B Liberty&lt;/em&gt;\"}"
91
+ controller_cookie_flash.should == "{\"notice\":\"&lt;em&gt;Life, Love %2B Liberty&lt;/em&gt;\"}"
87
92
  end
88
93
 
89
94
  it "does not escape strings that are html_safe" do
90
95
  @controller.flash = { 'notice' => '<em>Life, Love + Liberty</em>'.html_safe } # html_safe so it will not be escaped
91
96
  @controller.write_flash_to_cookie
92
- @controller.cookies['flash'].should == "{\"notice\":\"<em>Life, Love %2B Liberty</em>\"}"
97
+ controller_cookie_flash.should == "{\"notice\":\"<em>Life, Love %2B Liberty</em>\"}"
93
98
  end
94
99
 
95
100
  it "clears the controller.flash hash provided by Rails" do
@@ -106,13 +111,13 @@ describe 'CacheableFlash' do
106
111
  it "escapes HTML if the flash value is not html safe" do
107
112
  @controller.flash = { 'quantity' => "<div>foobar</div>" }
108
113
  @controller.write_flash_to_cookie
109
- JSON(@controller.cookies['flash']).should == { 'quantity' => "&lt;div&gt;foobar&lt;/div&gt;" }
114
+ JSON(controller_cookie_flash).should == { 'quantity' => "&lt;div&gt;foobar&lt;/div&gt;" }
110
115
  end
111
116
 
112
117
  it "does not escape flash HTML if the value is html safe" do
113
118
  @controller.flash = { 'quantity' => '<div>foobar</div>'.html_safe }
114
119
  @controller.write_flash_to_cookie
115
- JSON(@controller.cookies['flash']).should == { 'quantity' => "<div>foobar</div>" }
120
+ JSON(controller_cookie_flash).should == { 'quantity' => "<div>foobar</div>" }
116
121
  end
117
122
  end
118
123