cacheable_flash 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ - ruby-head
8
+ - jruby-head
data/CHANGELOG CHANGED
@@ -1,66 +1,75 @@
1
- 0.2.9 - AUG.08.2012
2
- - More rearranging
3
- - Improved integration test of CacheableFlash & CacheableFlash::TestHelpers
4
- - Updated to latest jquery.cookie
5
-
6
- 0.2.8 - AUG.07.2012
7
- - switch from jeweler to gem-release for bumping and tagging
8
- - bundler update (1.0.24)
9
- - Escape HTML in flash values unless they're html_safe
10
- - Add CacheableFlash rack middleware
11
-
12
- 0.2.7 - JUN.21.2012
13
- - Note: Does not support flash.now feature of the FlashHash in Rails
14
- - Corrected directory names for controllers/layouts
15
-
16
- 0.2.6 - unreleased
17
- - all specs pass with rspec 2.10
18
-
19
- 0.2.5 - MAR.01.2012
20
- - Real integration test!
21
-
22
- 0.2.4 - FEB.27.2012
23
- - Dependency diet! No longer requires all of rails - only railties.
24
-
25
- 0.2.3 - JAN.13.2012
26
- - Fixed problems loading assets: Sprockets::FileNotFound - thanks jlxw
27
- - reflect move back to pivotal's repo in README.
28
- - Updated specs, to running and passing condition!
29
- - Made rails > 3.0 a dependency, since it is (uses ::Rails::Engine and :Rails::Railtie)
30
-
31
- 0.2.2 - SEP.10.2011
32
- - Improved deprecation warnings about using the generator (not needed with asset pipeline)
33
- - Improved README setup instructions
34
-
35
- 0.2.1 - SEP.10.2011
36
- - Fixed bug in generator for those not using asset pipeline, or pre Rails 3.1
37
-
38
- 0.2.0 - SEP.10.2011 [Peter Boling begins gemification process]
39
- - Converted to a gem
40
- - Updated to improved, patched jquery.cookie from https://github.com/pboling/jquery-cookie
41
- - Merged a few other forks of cacheable-flash
42
- - Added Engine to hook into Rails 3.1 asset pipeline
43
- - Added Railtie to improve usability with Rails 3.0
44
- - Added Generator to improve usability with Rails < 3
45
-
46
- Unreleased
47
- - Implicitly adding js files to Rails include defaults (Patch from Michael Erb)
48
-
49
- 0.1.5
50
- - Requiring version >= 1.1.2 of the json gem
51
- - Converted tests into specs
52
-
53
- 0.1.4
54
- - Added TestHelpers
55
- - Added flash_cookie method for tests
56
-
57
- 0.1.3
58
- - Require json in init.rb
59
-
60
- 0.1.2
61
- - Flash on the Rails side is cleared when written to the cookie
62
- - Uses existing cookie flash value
63
- - Using Scriptaculous cookie.js library
64
-
65
- 0.1.1
66
- - Added cookies.js
1
+ 0.2.10 - AUG.13.2012
2
+ - Split test_helpers from rspec_matchers (test_helpers may be useful in TestUnit
3
+ - When using Middleware: Flash Cookies now stay in the cookie until cleared out by the javascript: closer to guaranteed delivery.
4
+ - Improved spec suite
5
+ - Added CacheableFlash::Config class
6
+ - Configuration of :append_as now possible
7
+ - Added facets runtime dependency
8
+ - corrected namespace of CacheableFlash::CookieFlash
9
+
10
+ 0.2.9 - AUG.08.2012
11
+ - More rearranging
12
+ - Improved integration test of CacheableFlash & CacheableFlash::TestHelpers
13
+ - Updated to latest jquery.cookie
14
+
15
+ 0.2.8 - AUG.07.2012
16
+ - switch from jeweler to gem-release for bumping and tagging
17
+ - bundler update (1.0.24)
18
+ - Escape HTML in flash values unless they're html_safe
19
+ - Add CacheableFlash rack middleware
20
+
21
+ 0.2.7 - JUN.21.2012
22
+ - Note: Does not support flash.now feature of the FlashHash in Rails
23
+ - Corrected directory names for controllers/layouts
24
+
25
+ 0.2.6 - unreleased
26
+ - all specs pass with rspec 2.10
27
+
28
+ 0.2.5 - MAR.01.2012
29
+ - Real integration test!
30
+
31
+ 0.2.4 - FEB.27.2012
32
+ - Dependency diet! No longer requires all of rails - only railties.
33
+
34
+ 0.2.3 - JAN.13.2012
35
+ - Fixed problems loading assets: Sprockets::FileNotFound - thanks jlxw
36
+ - reflect move back to pivotal's repo in README.
37
+ - Updated specs, to running and passing condition!
38
+ - Made rails > 3.0 a dependency, since it is (uses ::Rails::Engine and :Rails::Railtie)
39
+
40
+ 0.2.2 - SEP.10.2011
41
+ - Improved deprecation warnings about using the generator (not needed with asset pipeline)
42
+ - Improved README setup instructions
43
+
44
+ 0.2.1 - SEP.10.2011
45
+ - Fixed bug in generator for those not using asset pipeline, or pre Rails 3.1
46
+
47
+ 0.2.0 - SEP.10.2011 [Peter Boling begins gemification process]
48
+ - Converted to a gem
49
+ - Updated to improved, patched jquery.cookie from https://github.com/pboling/jquery-cookie
50
+ - Merged a few other forks of cacheable-flash
51
+ - Added Engine to hook into Rails 3.1 asset pipeline
52
+ - Added Railtie to improve usability with Rails 3.0
53
+ - Added Generator to improve usability with Rails < 3
54
+
55
+ Unreleased
56
+ - Implicitly adding js files to Rails include defaults (Patch from Michael Erb)
57
+
58
+ 0.1.5
59
+ - Requiring version >= 1.1.2 of the json gem
60
+ - Converted tests into specs
61
+
62
+ 0.1.4
63
+ - Added TestHelpers
64
+ - Added flash_cookie method for tests
65
+
66
+ 0.1.3
67
+ - Require json in init.rb
68
+
69
+ 0.1.2
70
+ - Flash on the Rails side is cleared when written to the cookie
71
+ - Uses existing cookie flash value
72
+ - Using Scriptaculous cookie.js library
73
+
74
+ 0.1.1
75
+ - Added cookies.js
data/Gemfile CHANGED
@@ -1,22 +1,3 @@
1
- source "http://rubygems.org"
2
-
3
- gem "json"
4
-
5
- # Development dependencies (everything needed to run rake, tests, features, etc.)
6
- group :development, :test do
7
- # The Dummy application for the specs is a Rails 3.1.3 app.
8
- gem "rails", "~> 3.1.3"
9
-
10
- # jquery-rails is used by the dummy application
11
- gem "jquery-rails"
12
-
13
- # To use debugger
14
- # gem 'ruby-debug19', :require => 'ruby-debug'
15
-
16
- gem "rspec-rails", ">= 2.8.0"
17
- gem "rdoc", ">= 3.12"
18
- gem "bundler", ">= 1.0.24"
19
- gem "jeweler", ">= 1.6.4"
20
- gem "reek", ">= 1.2.8"
21
- gem "roodi", ">= 2.1.0"
22
- end
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = CacheableFlash {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/pivotal/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]
2
2
 
3
3
  == Description
4
4
 
data/Rakefile CHANGED
@@ -1,46 +1,46 @@
1
- # encoding: utf-8
2
- #!/usr/bin/env rake
3
- require "bundler/gem_tasks"
4
- require 'rake'
5
-
6
- require 'rspec/core'
7
- require 'rspec/core/rake_task'
8
- RSpec::Core::RakeTask.new(:spec) do |spec|
9
- spec.pattern = FileList['spec/**/*_spec.rb']
10
- end
11
-
12
- require 'reek/rake/task'
13
- Reek::Rake::Task.new do |t|
14
- t.fail_on_error = true
15
- t.verbose = false
16
- t.source_files = 'lib/**/*.rb'
17
- end
18
-
19
- require 'roodi'
20
- require 'roodi_task'
21
- RoodiTask.new do |t|
22
- t.verbose = false
23
- end
24
-
25
- task :default => :spec
26
-
27
- begin
28
- require 'rdoc/task'
29
- rescue LoadError
30
- require 'rdoc/rdoc'
31
- require 'rake/rdoctask'
32
- RDoc::Task = Rake::RDocTask
33
- end
34
-
35
- RDoc::Task.new(:rdoc) do |rdoc|
36
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
- rdoc.rdoc_dir = 'rdoc'
38
- rdoc.title = "CacheableFlash #{version}"
39
- rdoc.options << '--line-numbers'
40
- rdoc.rdoc_files.include('README*')
41
- rdoc.rdoc_files.include('lib/**/*.rb')
42
- end
43
-
44
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
45
-
46
- Bundler::GemHelper.install_tasks
1
+ # encoding: utf-8
2
+ #!/usr/bin/env rake
3
+ require "bundler/gem_tasks"
4
+ require 'rake'
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ require 'reek/rake/task'
13
+ Reek::Rake::Task.new do |t|
14
+ t.fail_on_error = true
15
+ t.verbose = false
16
+ t.source_files = 'lib/**/*.rb'
17
+ end
18
+
19
+ require 'roodi'
20
+ require 'roodi_task'
21
+ RoodiTask.new do |t|
22
+ t.verbose = false
23
+ end
24
+
25
+ task :default => :spec
26
+
27
+ begin
28
+ require 'rdoc/task'
29
+ rescue LoadError
30
+ require 'rdoc/rdoc'
31
+ require 'rake/rdoctask'
32
+ RDoc::Task = Rake::RDocTask
33
+ end
34
+
35
+ RDoc::Task.new(:rdoc) do |rdoc|
36
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
+ rdoc.rdoc_dir = 'rdoc'
38
+ rdoc.title = "CacheableFlash #{version}"
39
+ rdoc.options << '--line-numbers'
40
+ rdoc.rdoc_files.include('README*')
41
+ rdoc.rdoc_files.include('lib/**/*.rb')
42
+ end
43
+
44
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
45
+
46
+ Bundler::GemHelper.install_tasks
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Peter H. Boling", "Brian Takita"]
10
- s.date = "2012-08-07"
10
+ s.date = "2012-08-13"
11
11
  s.description = "Allows caching of pages with flash messages by rendering flash\nmessages from a cookie using JavaScript, instead of statically in your Rails\nview template. Flash contents are converted to JSON and placed in\na cookie by an after_filter (default) or a Rack Middleware (option)."
12
12
  s.email = "peter.boling@gmail.com"
13
13
  s.extra_rdoc_files = [
@@ -23,40 +23,15 @@ Gem::Specification.new do |s|
23
23
  s.rubygems_version = "1.8.24"
24
24
  s.summary = "Render flash messages from a cookie using JavaScript, instead of in your Rails view template"
25
25
 
26
- if s.respond_to? :specification_version then
27
- s.specification_version = 3
28
-
29
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
30
- s.add_runtime_dependency(%q<json>, [">= 0"])
31
- s.add_development_dependency(%q<rails>, ["~> 3.1.3"])
32
- s.add_development_dependency(%q<jquery-rails>, [">= 0"])
33
- s.add_development_dependency(%q<rspec-rails>, [">= 2.8.0"])
34
- s.add_development_dependency(%q<rdoc>, [">= 3.12"])
35
- s.add_development_dependency(%q<bundler>, [">= 1.0.24"])
36
- s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
37
- s.add_development_dependency(%q<reek>, [">= 1.2.8"])
38
- s.add_development_dependency(%q<roodi>, [">= 2.1.0"])
39
- else
40
- s.add_dependency(%q<json>, [">= 0"])
41
- s.add_dependency(%q<rails>, ["~> 3.1.3"])
42
- s.add_dependency(%q<jquery-rails>, [">= 0"])
43
- s.add_dependency(%q<rspec-rails>, [">= 2.8.0"])
44
- s.add_dependency(%q<rdoc>, [">= 3.12"])
45
- s.add_dependency(%q<bundler>, [">= 1.0.24"])
46
- s.add_dependency(%q<jeweler>, [">= 1.6.4"])
47
- s.add_dependency(%q<reek>, [">= 1.2.8"])
48
- s.add_dependency(%q<roodi>, [">= 2.1.0"])
49
- end
50
- else
51
- s.add_dependency(%q<json>, [">= 0"])
52
- s.add_dependency(%q<rails>, ["~> 3.1.3"])
53
- s.add_dependency(%q<jquery-rails>, [">= 0"])
54
- s.add_dependency(%q<rspec-rails>, [">= 2.8.0"])
55
- s.add_dependency(%q<rdoc>, [">= 3.12"])
56
- s.add_dependency(%q<bundler>, [">= 1.0.24"])
57
- s.add_dependency(%q<jeweler>, [">= 1.6.4"])
58
- s.add_dependency(%q<reek>, [">= 1.2.8"])
59
- s.add_dependency(%q<roodi>, [">= 2.1.0"])
60
- end
26
+ s.add_runtime_dependency(%q<facets>, [">= 0"])
27
+ s.add_runtime_dependency(%q<json>, [">= 0"])
28
+ s.add_development_dependency(%q<rails>, ["~> 3.1.3"])
29
+ s.add_development_dependency(%q<jquery-rails>, [">= 0"])
30
+ s.add_development_dependency(%q<rspec-rails>, [">= 2.8.0"])
31
+ s.add_development_dependency(%q<rdoc>, [">= 3.12"])
32
+ s.add_development_dependency(%q<bundler>, [">= 1.0.24"])
33
+ s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
34
+ s.add_development_dependency(%q<reek>, [">= 1.2.8"])
35
+ s.add_development_dependency(%q<roodi>, [">= 2.1.0"])
61
36
  end
62
37
 
@@ -9,8 +9,9 @@ module CacheableFlash
9
9
  # For older rails use generator
10
10
  end
11
11
 
12
+ require 'cacheable_flash/config'
12
13
  require 'cacheable_flash/cookie_flash'
13
- include CookieFlash
14
+ include CacheableFlash::CookieFlash
14
15
 
15
16
  def self.included(base)
16
17
  #base must define around_filter, as in Rails
@@ -0,0 +1,29 @@
1
+ require 'facets/module/mattr' # gives cattr
2
+
3
+ module CacheableFlash
4
+ class Config
5
+
6
+ DEFAULTS = {
7
+ # Specify how multiple flashes at the same key (e.g. :notice, :errors) should be handled
8
+ :append_as => :br, # or :array
9
+ }
10
+
11
+ cattr_reader :config
12
+ cattr_writer :config
13
+
14
+ self.config ||= DEFAULTS
15
+ def self.configure &block
16
+ yield @@config
17
+ end
18
+
19
+ def self.[](key)
20
+ return nil unless key.respond_to?(:to_sym)
21
+ CacheableFlash::Config.config[key.to_sym]
22
+ end
23
+
24
+ def self.method_missing(name, *args)
25
+ CacheableFlash[name]
26
+ end
27
+
28
+ end
29
+ end
@@ -1,15 +1,32 @@
1
- module CookieFlash
2
- def cookie_flash(flash, cookies)
3
- cookie_flash = (JSON(cookies['flash']) if cookies['flash']) || {} rescue {}
1
+ module CacheableFlash
2
+ module CookieFlash
3
+ def cookie_flash(flash, cookies)
4
+ cookie_flash = (JSON(cookies['flash']) if cookies['flash']) || {} rescue {}
4
5
 
5
- flash.each do |key, value|
6
- value = ERB::Util.html_escape(value) unless value.is_a?(Hash) || value.html_safe?
7
- if cookie_flash[key.to_s].blank?
8
- cookie_flash[key.to_s] = value.kind_of?(Numeric) ? value.to_s : value
9
- else
10
- cookie_flash[key.to_s] << "<br/>#{value}"
6
+ flash.each do |key, value|
7
+ value = ERB::Util.html_escape(value) unless value.is_a?(Hash) || value.html_safe?
8
+ if cookie_flash[key.to_s].blank?
9
+ value_as_string = value.kind_of?(Numeric) ? value.to_s : value
10
+ case CacheableFlash::Config[:append_as]
11
+ when :br then
12
+ cookie_flash[key.to_s] = value_as_string
13
+ when :array then
14
+ cookie_flash[key.to_s] = Array(value_as_string)
15
+ else
16
+ raise "CacheableFlash: #{CacheableFlash::Config.config[:append_as]} is not a valid value for CacheableFlash::Config.config[:append_as]"
17
+ end
18
+ else
19
+ case CacheableFlash::Config[:append_as]
20
+ when :br then
21
+ cookie_flash[key.to_s] << "<br/>#{value}"
22
+ when :array then
23
+ cookie_flash[key.to_s] << "#{value}"
24
+ else
25
+ raise "CacheableFlash: #{CacheableFlash::Config.config[:append_as]} is not a valid value for CacheableFlash::Config.config[:append_as]"
26
+ end
27
+ end
11
28
  end
29
+ cookie_flash.to_json.gsub("+", "%2B")
12
30
  end
13
- cookie_flash.to_json.gsub("+", "%2B")
14
31
  end
15
32
  end
@@ -1,26 +1,38 @@
1
1
  module CacheableFlash
2
2
  class Middleware
3
3
  require 'cacheable_flash/cookie_flash'
4
- include CookieFlash
4
+ include CacheableFlash::CookieFlash
5
5
  FLASH_HASH_KEY = "action_dispatch.request.flash_hash".freeze
6
6
 
7
7
  def initialize(app)
8
8
  @app = app
9
9
  end
10
10
 
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
11
13
  def call(env)
12
14
  status, headers, body = @app.call(env)
13
15
  flash = env[FLASH_HASH_KEY]
14
16
 
15
17
  if flash
16
18
  response = Rack::Response.new(body, status, headers)
17
-
18
19
  cookies = env["rack.cookies"] || {}
19
20
  response.set_cookie("flash", { :value => cookie_flash(flash, cookies), :path => "/" })
20
21
  response.finish
21
22
  else
22
- [status, headers, body]
23
+ request = ActionDispatch::Request.new(env)
24
+ cookie_flash = request.respond_to?(:cookie_jar) ?
25
+ request.cookie_jar['flash'] :
26
+ nil
27
+ if cookie_flash
28
+ response = Rack::Response.new(body, status, headers)
29
+ response.set_cookie("flash", { :value => cookie_flash, :path => "/" })
30
+ response.finish
31
+ else
32
+ [status, headers, body]
33
+ end
23
34
  end
24
35
  end
36
+
25
37
  end
26
38
  end
@@ -0,0 +1,22 @@
1
+ require 'cacheable_flash/test_helpers'
2
+
3
+ module CacheableFlash
4
+ module RspecMatchers
5
+ include CacheableFlash::TestHelpers
6
+ RSpec::Matchers.define :have_flash_cookie do |flash_status, regex|
7
+ define_method :has_flash_cookie? do |response|
8
+ regex = /#{Regexp.escape(regex)}/ if regex.is_a?(String)
9
+
10
+ cook = begin
11
+ response.cookies['flash'] ?
12
+ JSON(response.cookies['flash']) :
13
+ {}
14
+ rescue JSON::ParserError
15
+ {}
16
+ end
17
+ cook[flash_status] =~ regex
18
+ end
19
+ match{|response| has_flash_cookie?(response)}
20
+ end
21
+ end
22
+ end
@@ -1,12 +1,14 @@
1
- require 'json'
2
-
3
- module CacheableFlash
4
- module TestHelpers
5
- def flash_cookie
6
- return {} unless response.cookies['flash']
7
- JSON(response.cookies['flash'])
8
- rescue JSON::ParserError
9
- {}
10
- end
11
- end
12
- end
1
+ require 'json'
2
+
3
+ module CacheableFlash
4
+ module TestHelpers
5
+
6
+ def flash_cookie
7
+ return {} unless response.cookies['flash']
8
+ JSON(response.cookies['flash'])
9
+ rescue JSON::ParserError
10
+ {}
11
+ end
12
+
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module CacheableFlash
2
- VERSION = "0.2.9"
2
+ VERSION = "0.2.10"
3
3
  end
@@ -1,26 +1,23 @@
1
- require 'spec_helper'
2
-
3
- describe DummyController do
4
-
5
- include CacheableFlash::TestHelpers
6
-
7
- render_views
8
-
9
- before(:each) do
10
- @expected_flash = {
11
- 'errors' => "This is an Error",
12
- 'notice' => "This is a Notice"
13
- }
14
- get :index
15
- end
16
-
17
- describe "TestHelpers" do
18
- it "should assign flashes to cookie" do
19
- flash_cookie['errors'].should == @expected_flash['errors']
20
- flash_cookie['notice'].should == @expected_flash['notice']
21
- flash_cookie.should == @expected_flash
22
- end
23
- end
24
-
25
- end
26
-
1
+ require 'spec_helper'
2
+
3
+ describe DummyController do
4
+
5
+ render_views
6
+
7
+ before(:each) do
8
+ @expected_flash = {
9
+ 'errors' => "This is an Error",
10
+ 'notice' => "This is a Notice"
11
+ }
12
+ get :index
13
+ end
14
+
15
+ describe "TestHelpers" do
16
+ it "should assign flashes to cookie" do
17
+ response.should have_flash_cookie('errors', @expected_flash['errors'])
18
+ response.should have_flash_cookie('notice', @expected_flash['notice'])
19
+ end
20
+ end
21
+
22
+ end
23
+
@@ -1,11 +1,22 @@
1
- class DummyController < ApplicationController
2
- include CacheableFlash
3
- def index
4
- expected_flash = {
5
- 'errors' => "This is an Error",
6
- 'notice' => "This is a Notice"
7
- }
8
- flash[:errors] = expected_flash['errors']
9
- flash[:notice] = expected_flash['notice']
10
- end
11
- end
1
+ class DummyController < ApplicationController
2
+ include CacheableFlash
3
+ def index
4
+ expected_flash = {
5
+ 'errors' => "This is an Error",
6
+ 'notice' => "This is a Notice"
7
+ }
8
+ flash[:errors] = expected_flash['errors']
9
+ flash[:notice] = expected_flash['notice']
10
+ end
11
+
12
+ def error
13
+ expected_flash = {
14
+ 'errors' => "This is a real Error",
15
+ }
16
+ flash[:errors] = expected_flash['errors']
17
+ end
18
+
19
+ def no_flash
20
+ # Does not set any flash
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ <p>
2
+ Here I am! Error Action
3
+ </p>
@@ -1,3 +1,3 @@
1
- <p>
2
- Here I am!
3
- </p>
1
+ <p>
2
+ Here I am! Index Action!
3
+ </p>
@@ -0,0 +1,3 @@
1
+ <p>
2
+ Here I am! No Flash Action!
3
+ </p>
@@ -1,4 +1,6 @@
1
- Rails.application.routes.draw do
2
- root :controller => 'dummy', :action => 'index'
3
- mount CacheableFlash::Engine => "/cacheable_flash"
4
- end
1
+ Rails.application.routes.draw do
2
+ root :controller => 'dummy', :action => 'index'
3
+
4
+ # Note: This route will make all actions in every controller accessible via GET requests.
5
+ match ':controller(/:action(/:id(.:format)))'
6
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe DummyController do
4
+
5
+ describe "cookie flash is sticky" do
6
+ it "should not clear after request" do # because they are only cleared out by javascripts
7
+ get "/dummy/index"
8
+ response.should have_flash_cookie('errors', "This is an Error")
9
+ response.should have_flash_cookie('notice', "This is a Notice")
10
+
11
+ get "/dummy/no_flash"
12
+ response.should have_flash_cookie('errors', "This is an Error")
13
+ response.should have_flash_cookie('notice', "This is a Notice")
14
+
15
+ end
16
+ end
17
+
18
+ describe "cookie flash is stackable" do
19
+ it "should not overwrite when new flash added" do # because they are only cleared out by javascripts
20
+ get "/dummy/index"
21
+ response.should have_flash_cookie('errors', "This is an Error")
22
+ response.should have_flash_cookie('notice', "This is a Notice")
23
+
24
+ get "/dummy/error"
25
+ response.should have_flash_cookie('errors', "This is an Error")
26
+ response.should have_flash_cookie('errors', "This is a real Error")
27
+
28
+ end
29
+ end
30
+
31
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,27 +1,27 @@
1
- # Configure Rails Envinronment
2
- ENV["RAILS_ENV"] = "test"
3
- require File.expand_path("../dummy/config/environment", __FILE__)
4
-
5
- require 'rspec/rails'
6
- require "json"
7
-
8
- ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
9
-
10
- # Requires supporting ruby files with custom matchers and macros, etc,
11
- # in spec/support/ and its subdirectories.
12
- Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
13
-
14
- require 'cacheable_flash'
15
- # Instead of loading the installed gem, we load the source code directly, would this work?
16
- #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
- #$LOAD_PATH.unshift(File.dirname(__FILE__))
18
-
19
- require 'cacheable_flash/test_helpers'
20
-
21
- # Requires supporting files with custom matchers and macros, etc,
22
- # in ./support/ and its subdirectories.
23
- #Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
24
-
25
- RSpec.configure do |config|
26
- config.include CacheableFlash::TestHelpers, :type => :controller
27
- end
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+ require File.expand_path("../dummy/config/environment", __FILE__)
4
+
5
+ require 'rspec/rails'
6
+ require "json"
7
+
8
+ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc,
11
+ # in spec/support/ and its subdirectories.
12
+ Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
13
+
14
+ require 'cacheable_flash'
15
+ # Instead of loading the installed gem, we load the source code directly, would this work?
16
+ #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
+ #$LOAD_PATH.unshift(File.dirname(__FILE__))
18
+
19
+ require 'cacheable_flash/rspec_matchers'
20
+
21
+ # Requires supporting files with custom matchers and macros, etc,
22
+ # in ./support/ and its subdirectories.
23
+ #Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
24
+
25
+ RSpec.configure do |config|
26
+ config.include CacheableFlash::RspecMatchers
27
+ end
@@ -1,21 +1,25 @@
1
- // refactoring from https://github.com/leonid-shevtsov/cacheable-flash-jquery
2
- var Flash = new Object();
3
-
4
- Flash.data = {};
5
-
6
- Flash.transferFromCookies = function() {
7
- var data = JSON.parse(unescape($.cookie("flash")));
8
- if(!data) data = {};
9
- Flash.data = data;
10
- $.cookie('flash',null, {path: '/'});
11
- };
12
-
13
- Flash.writeDataTo = function(name, element) {
14
- element = $(element);
15
- var content = "";
16
- if (Flash.data[name]) {
17
- message = Flash.data[name].toString().replace(/\+/g, ' ');
18
- element.html(message);
19
- element.show();
20
- }
21
- };
1
+ // refactoring from https://github.com/leonid-shevtsov/cacheable-flash-jquery
2
+ var Flash = new Object();
3
+
4
+ Flash.data = {};
5
+
6
+ Flash.transferFromCookies = function() {
7
+ var data = JSON.parse(unescape($.cookie("flash")));
8
+ if(!data) data = {};
9
+ Flash.data = data;
10
+ $.cookie('flash',null, {path: '/'});
11
+ };
12
+
13
+ Flash.writeDataTo = function(name, element, callback) {
14
+ element = $(element);
15
+ var content = "";
16
+ if (Flash.data[name]) {
17
+ message = Flash.data[name].toString().replace(/\+/g, ' ');
18
+ element.html(message);
19
+ if (callback && typeof(callback) === 'function') {
20
+ callback(element);
21
+ } else {
22
+ element.show();
23
+ }
24
+ }
25
+ };
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cacheable_flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-07 00:00:00.000000000 Z
13
+ date: 2012-08-13 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: facets
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: json
17
33
  requirement: !ruby/object:Gem::Requirement
@@ -172,25 +188,26 @@ extra_rdoc_files:
172
188
  files:
173
189
  - .document
174
190
  - .gitignore
191
+ - .travis.yml
175
192
  - CHANGELOG
176
193
  - Gemfile
177
194
  - LICENSE
178
195
  - README.rdoc
179
196
  - Rakefile
180
197
  - cacheable_flash.gemspec
181
- - config/routes.rb
182
198
  - init.rb
183
199
  - install.rb
184
200
  - lib/cacheable_flash.rb
201
+ - lib/cacheable_flash/config.rb
185
202
  - lib/cacheable_flash/cookie_flash.rb
186
203
  - lib/cacheable_flash/engine.rb
187
204
  - lib/cacheable_flash/middleware.rb
188
205
  - lib/cacheable_flash/railtie.rb
206
+ - lib/cacheable_flash/rspec_matchers.rb
189
207
  - lib/cacheable_flash/test_helpers.rb
190
208
  - lib/cacheable_flash/version.rb
191
209
  - lib/generators/cacheable_flash/install/install_generator.rb
192
210
  - lib/tasks/cacheable-flash_tasks.rake
193
- - script/rails
194
211
  - spec/cacheable_flash/cacheable_flash_spec.rb
195
212
  - spec/cacheable_flash/install_spec.rb
196
213
  - spec/cacheable_flash/test_helpers_spec.rb
@@ -204,7 +221,9 @@ files:
204
221
  - spec/dummy/app/helpers/application_helper.rb
205
222
  - spec/dummy/app/mailers/.gitkeep
206
223
  - spec/dummy/app/models/.gitkeep
224
+ - spec/dummy/app/views/dummy/error.html.erb
207
225
  - spec/dummy/app/views/dummy/index.html.erb
226
+ - spec/dummy/app/views/dummy/no_flash.html.erb
208
227
  - spec/dummy/app/views/layouts/application.html.erb
209
228
  - spec/dummy/config.ru
210
229
  - spec/dummy/config/application.rb
@@ -231,6 +250,7 @@ files:
231
250
  - spec/dummy/script/rails
232
251
  - spec/js_unit/cookie_test.html
233
252
  - spec/js_unit/flash_test.html
253
+ - spec/requests/cacheable_flash_sticky_spec.rb
234
254
  - spec/spec_helper.rb
235
255
  - tasks/cacheable_flash_tasks.rake
236
256
  - vendor/assets/javascripts/flash.js
@@ -275,7 +295,9 @@ test_files:
275
295
  - spec/dummy/app/helpers/application_helper.rb
276
296
  - spec/dummy/app/mailers/.gitkeep
277
297
  - spec/dummy/app/models/.gitkeep
298
+ - spec/dummy/app/views/dummy/error.html.erb
278
299
  - spec/dummy/app/views/dummy/index.html.erb
300
+ - spec/dummy/app/views/dummy/no_flash.html.erb
279
301
  - spec/dummy/app/views/layouts/application.html.erb
280
302
  - spec/dummy/config.ru
281
303
  - spec/dummy/config/application.rb
@@ -302,4 +324,5 @@ test_files:
302
324
  - spec/dummy/script/rails
303
325
  - spec/js_unit/cookie_test.html
304
326
  - spec/js_unit/flash_test.html
327
+ - spec/requests/cacheable_flash_sticky_spec.rb
305
328
  - spec/spec_helper.rb
data/config/routes.rb DELETED
@@ -1,2 +0,0 @@
1
- CacheableFlash::Engine.routes.draw do
2
- end
data/script/rails DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
- ENGINE_PATH = File.expand_path('../../lib/cacheable_flash/engine', __FILE__)
6
-
7
- require 'rails/all'
8
- require 'rails/engine/commands'