cacheable_flash 0.2.10 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +11 -0
- data/README.rdoc +8 -18
- data/cacheable_flash.gemspec +3 -5
- data/lib/cacheable_flash.rb +2 -1
- data/lib/cacheable_flash/config.rb +18 -6
- data/lib/cacheable_flash/cookie_flash.rb +16 -21
- data/lib/cacheable_flash/middleware.rb +8 -7
- data/lib/cacheable_flash/rspec_matchers.rb +21 -10
- data/lib/cacheable_flash/test_helpers.rb +9 -2
- data/lib/cacheable_flash/version.rb +1 -1
- data/spec/cacheable_flash/cacheable_flash_spec.rb +16 -9
- data/spec/dummy/app/controllers/dummy_controller.rb +32 -10
- data/spec/requests/integration_spec.rb +58 -0
- data/spec/spec_helper.rb +11 -10
- metadata +17 -35
- data/spec/dummy/README.rdoc +0 -261
- data/spec/requests/cacheable_flash_sticky_spec.rb +0 -31
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
0.3.0 - AUG.21.2012
|
2
|
+
- Completed integration with stackable_flash (http://github.com/pboling/stackable_flash)
|
3
|
+
- Test::Unit helpers and Rspec Matchers updated to be stackable
|
4
|
+
- Expanded test suite
|
5
|
+
- Cleaned up both Middleware and Around Filter integration points
|
6
|
+
- Rspec Matchers now have pretty failure messages
|
7
|
+
- Removed dependency on facets gem
|
8
|
+
- Allows any data type to be stored in the cookie. Only escapes strings.
|
9
|
+
- Does not convert flash value to string before storing in cookie if value is a number
|
10
|
+
- (v0.2.X converted everything to string)
|
11
|
+
|
1
12
|
0.2.10 - AUG.13.2012
|
2
13
|
- Split test_helpers from rspec_matchers (test_helpers may be useful in TestUnit
|
3
14
|
- When using Middleware: Flash Cookies now stay in the cookie until cleared out by the javascript: closer to guaranteed delivery.
|
data/README.rdoc
CHANGED
@@ -10,14 +10,8 @@ your application.
|
|
10
10
|
|
11
11
|
== Installation as gem
|
12
12
|
|
13
|
-
gem
|
14
|
-
|
15
|
-
add to your Gemfile:
|
16
|
-
gem 'cacheable_flash'
|
17
|
-
|
18
|
-
== Installation as plugin (For old Rails)
|
19
|
-
|
20
|
-
ruby script/plugin install git://github.com/pivotal/cacheable-flash.git
|
13
|
+
gem 'cacheable_flash' # added to your Gemfile
|
14
|
+
$ bundle install
|
21
15
|
|
22
16
|
== Setup
|
23
17
|
|
@@ -149,13 +143,12 @@ Cacheable Flash provides test helpers which includes the flash_cookie method.
|
|
149
143
|
|
150
144
|
== Contributing to cacheable-flash
|
151
145
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
146
|
+
1. Fork it
|
147
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
148
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
149
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
150
|
+
5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
151
|
+
6. Create new Pull Request
|
159
152
|
|
160
153
|
== Copyright
|
161
154
|
|
@@ -163,6 +156,3 @@ Licensed under the MIT License.
|
|
163
156
|
|
164
157
|
- Copyright (c) 2011-2012 Peter H. Boling (http://peterboling.com). See LICENSE for further details.
|
165
158
|
- Copyright (c) 2007-2010 Pivotal Labs
|
166
|
-
|
167
|
-
|
168
|
-
|
data/cacheable_flash.gemspec
CHANGED
@@ -23,15 +23,13 @@ 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
|
-
s.add_runtime_dependency(%q<
|
26
|
+
s.add_runtime_dependency(%q<stackable_flash>, [">= 0.0.4"])
|
27
27
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
28
28
|
s.add_development_dependency(%q<rails>, ["~> 3.1.3"])
|
29
29
|
s.add_development_dependency(%q<jquery-rails>, [">= 0"])
|
30
|
-
s.add_development_dependency(%q<rspec-rails>, [">= 2.
|
30
|
+
s.add_development_dependency(%q<rspec-rails>, [">= 2.11.0"])
|
31
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
32
|
s.add_development_dependency(%q<reek>, [">= 1.2.8"])
|
35
33
|
s.add_development_dependency(%q<roodi>, [">= 2.1.0"])
|
34
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
36
35
|
end
|
37
|
-
|
data/lib/cacheable_flash.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'stackable_flash'
|
2
3
|
|
3
4
|
module CacheableFlash
|
4
5
|
if defined?(Rails) && ::Rails::VERSION::MAJOR == 3
|
5
6
|
require 'cacheable_flash/middleware'
|
6
7
|
require 'cacheable_flash/engine' if ::Rails::VERSION::MINOR >= 1
|
7
8
|
require 'cacheable_flash/railtie'
|
8
|
-
else
|
9
|
+
else
|
9
10
|
# For older rails use generator
|
10
11
|
end
|
11
12
|
|
@@ -1,19 +1,31 @@
|
|
1
|
-
require 'facets/module/mattr' # gives cattr
|
2
|
-
|
3
1
|
module CacheableFlash
|
4
2
|
class Config
|
5
3
|
|
4
|
+
class << self
|
5
|
+
attr_accessor :config
|
6
|
+
end
|
7
|
+
|
6
8
|
DEFAULTS = {
|
7
9
|
# Specify how multiple flashes at the same key (e.g. :notice, :errors) should be handled
|
8
|
-
:append_as => :br, # or :array
|
10
|
+
:append_as => :br, # or :array, :p, :ul, :ol, or a proc or lambda of your own design
|
9
11
|
}
|
10
12
|
|
11
|
-
cattr_reader :config
|
12
|
-
cattr_writer :config
|
13
|
-
|
14
13
|
self.config ||= DEFAULTS
|
15
14
|
def self.configure &block
|
16
15
|
yield @@config
|
16
|
+
StackableFlash::Config.configure do
|
17
|
+
if self.config[:append_as].respond_to?(:call)
|
18
|
+
config[:stack_with_proc] = self.config[:append_as]
|
19
|
+
else
|
20
|
+
config[:stack_with_proc] = case self.config[:append_as]
|
21
|
+
when :br then Proc.new {|arr| arr.join('<br/>') }
|
22
|
+
when :array then Proc.new {|arr| arr }
|
23
|
+
when :p then Proc.new {|arr| arr.map! {|x| "<p>#{x}</p>"}.join }
|
24
|
+
when :ul then Proc.new {|arr| '<ul>' + arr.map! {|x| "<li>#{x}</li>"}.join + '</ul>' }
|
25
|
+
when :ol then Proc.new {|arr| '<ol>' + arr.map! {|x| "<li>#{x}</li>"}.join + '</ol>' }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
17
29
|
end
|
18
30
|
|
19
31
|
def self.[](key)
|
@@ -1,32 +1,27 @@
|
|
1
1
|
module CacheableFlash
|
2
2
|
module CookieFlash
|
3
3
|
def cookie_flash(flash, cookies)
|
4
|
-
|
5
|
-
|
4
|
+
cflash = (JSON.parse(cookies['flash']) if cookies['flash']) || {} rescue {}
|
6
5
|
flash.each do |key, value|
|
7
|
-
|
8
|
-
if
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
# Since v0.3.0 only escaping strings
|
7
|
+
if value.kind_of?(String)
|
8
|
+
value = ERB::Util.html_escape(value) unless value.html_safe?
|
9
|
+
end
|
10
|
+
# This allows any data type to be stored in the cookie; important for using an array as the value with
|
11
|
+
# stackable_flash
|
12
|
+
skey = key.to_s
|
13
|
+
if cflash[skey].kind_of?(Array) # Stackable!!!
|
14
|
+
if value.kind_of?(Array)
|
15
|
+
cflash[skey] += value # Add the values from the other array, which is already a stackable flash
|
16
|
+
else
|
17
|
+
cflash[skey] << value
|
17
18
|
end
|
18
19
|
else
|
19
|
-
|
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
|
20
|
+
cflash[skey] = value
|
27
21
|
end
|
28
22
|
end
|
29
|
-
|
23
|
+
# I have forgotten why the gsub + matters, so NOTE: to future self: document weird shit.
|
24
|
+
cflash.to_json.gsub("+", "%2B")
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
@@ -12,26 +12,27 @@ module CacheableFlash
|
|
12
12
|
# to ensure they are seen and not lost, so we grab them from the rails flash hash, or the request cookies
|
13
13
|
def call(env)
|
14
14
|
status, headers, body = @app.call(env)
|
15
|
-
|
15
|
+
env_flash = env[FLASH_HASH_KEY]
|
16
16
|
|
17
|
-
if
|
17
|
+
if env_flash
|
18
18
|
response = Rack::Response.new(body, status, headers)
|
19
19
|
cookies = env["rack.cookies"] || {}
|
20
|
-
response.set_cookie("flash", { :value => cookie_flash(
|
20
|
+
response.set_cookie("flash", { :value => cookie_flash(env_flash, cookies), :path => "/" })
|
21
21
|
response.finish
|
22
22
|
else
|
23
23
|
request = ActionDispatch::Request.new(env)
|
24
|
-
|
24
|
+
cflash = request.respond_to?(:cookie_jar) ?
|
25
25
|
request.cookie_jar['flash'] :
|
26
26
|
nil
|
27
|
-
if
|
27
|
+
if cflash
|
28
28
|
response = Rack::Response.new(body, status, headers)
|
29
|
-
response.set_cookie("flash", { :value =>
|
29
|
+
response.set_cookie("flash", { :value => cflash, :path => "/" })
|
30
30
|
response.finish
|
31
31
|
else
|
32
|
-
|
32
|
+
response = body
|
33
33
|
end
|
34
34
|
end
|
35
|
+
[status, headers, response]
|
35
36
|
end
|
36
37
|
|
37
38
|
end
|
@@ -3,20 +3,31 @@ require 'cacheable_flash/test_helpers'
|
|
3
3
|
module CacheableFlash
|
4
4
|
module RspecMatchers
|
5
5
|
include CacheableFlash::TestHelpers
|
6
|
-
RSpec::Matchers.define :have_flash_cookie do |flash_status,
|
6
|
+
RSpec::Matchers.define :have_flash_cookie do |flash_status, expecting|
|
7
7
|
define_method :has_flash_cookie? do |response|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
flash = testable_flash(response)[flash_status]
|
9
|
+
if flash.kind_of?(Array)
|
10
|
+
if expecting.kind_of?(Array)
|
11
|
+
flash == expecting
|
12
|
+
else
|
13
|
+
matches = flash.select do |to_check|
|
14
|
+
to_check == expecting
|
15
|
+
end
|
16
|
+
matches.length > 0
|
17
|
+
end
|
18
|
+
else
|
19
|
+
flash == expecting
|
16
20
|
end
|
17
|
-
cook[flash_status] =~ regex
|
18
21
|
end
|
22
|
+
|
19
23
|
match{|response| has_flash_cookie?(response)}
|
24
|
+
|
25
|
+
failure_message_for_should do |actual|
|
26
|
+
"expected that flash cookie :#{expected[0]} #{testable_flash(actual)[expected[0]]} would include #{expected[1].inspect}"
|
27
|
+
end
|
28
|
+
failure_message_for_should_not do |actual|
|
29
|
+
"expected that flash cookie :#{expected[0]} #{testable_flash(actual)[expected[0]]} would not include #{expected[1].inspect}"
|
30
|
+
end
|
20
31
|
end
|
21
32
|
end
|
22
33
|
end
|
@@ -4,8 +4,15 @@ module CacheableFlash
|
|
4
4
|
module TestHelpers
|
5
5
|
|
6
6
|
def flash_cookie
|
7
|
-
return {} unless response.cookies['flash']
|
8
|
-
JSON(
|
7
|
+
return {} unless cooked_flash = response.cookies['flash']
|
8
|
+
JSON(cooked_flash)
|
9
|
+
rescue JSON::ParserError
|
10
|
+
{}
|
11
|
+
end
|
12
|
+
|
13
|
+
def testable_flash(response)
|
14
|
+
return {} unless cooked_flash = response.cookies['flash']
|
15
|
+
JSON(cooked_flash)
|
9
16
|
rescue JSON::ParserError
|
10
17
|
{}
|
11
18
|
end
|
@@ -41,8 +41,8 @@ describe 'CacheableFlash' do
|
|
41
41
|
@controller.write_flash_to_cookie
|
42
42
|
|
43
43
|
expected_flash = {
|
44
|
-
'notice' => "
|
45
|
-
'errors' => "
|
44
|
+
'notice' => "New notice",
|
45
|
+
'errors' => "New errors",
|
46
46
|
}
|
47
47
|
JSON(@controller.cookies['flash']).should == expected_flash
|
48
48
|
end
|
@@ -65,7 +65,7 @@ describe 'CacheableFlash' do
|
|
65
65
|
it "converts flash value to string before storing in cookie if value is a number" do
|
66
66
|
@controller.flash = { 'quantity' => 5 }
|
67
67
|
@controller.write_flash_to_cookie
|
68
|
-
JSON(@controller.cookies['flash']).should == { 'quantity' =>
|
68
|
+
JSON(@controller.cookies['flash']).should == { 'quantity' => 5 }
|
69
69
|
end
|
70
70
|
|
71
71
|
it "does not convert flash value to string before storing in cookie if value is anything other than a number" do
|
@@ -77,12 +77,19 @@ describe 'CacheableFlash' do
|
|
77
77
|
it "encodes plus signs in generated JSON before storing in cookie" do
|
78
78
|
@controller.flash = { 'notice' => 'Life, Love + Liberty' }
|
79
79
|
@controller.write_flash_to_cookie
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
@controller.cookies['flash'].should == "{\"notice\":\"Life, Love %2B Liberty\"}"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "escapes strings when not html safe" do
|
84
|
+
@controller.flash = { 'notice' => '<em>Life, Love + Liberty</em>' } # Not html_safe, so it will be escaped
|
85
|
+
@controller.write_flash_to_cookie
|
86
|
+
@controller.cookies['flash'].should == "{\"notice\":\"<em>Life, Love %2B Liberty</em>\"}"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "does not escape strings that are html_safe" do
|
90
|
+
@controller.flash = { 'notice' => '<em>Life, Love + Liberty</em>'.html_safe } # html_safe so it will not be escaped
|
91
|
+
@controller.write_flash_to_cookie
|
92
|
+
@controller.cookies['flash'].should == "{\"notice\":\"<em>Life, Love %2B Liberty</em>\"}"
|
86
93
|
end
|
87
94
|
|
88
95
|
it "clears the controller.flash hash provided by Rails" do
|
@@ -1,22 +1,44 @@
|
|
1
1
|
class DummyController < ApplicationController
|
2
|
+
|
2
3
|
include CacheableFlash
|
4
|
+
|
3
5
|
def index
|
4
|
-
|
5
|
-
|
6
|
-
'notice' => "This is a Notice"
|
7
|
-
}
|
8
|
-
flash[:errors] = expected_flash['errors']
|
9
|
-
flash[:notice] = expected_flash['notice']
|
6
|
+
flash[:errors] = "This is an Error"
|
7
|
+
flash[:notice] = "This is a Notice"
|
10
8
|
end
|
11
9
|
|
12
10
|
def error
|
13
|
-
|
14
|
-
'errors' => "This is a real Error",
|
15
|
-
}
|
16
|
-
flash[:errors] = expected_flash['errors']
|
11
|
+
flash[:errors] << "Error ##{params[:id]}" # Cold boot the flash!
|
17
12
|
end
|
18
13
|
|
19
14
|
def no_flash
|
20
15
|
# Does not set any flash
|
21
16
|
end
|
17
|
+
|
18
|
+
def multiple_keys
|
19
|
+
flash[:notice] = 'This is a Notice'
|
20
|
+
flash[:errors] = 'This is an Error'
|
21
|
+
render :text => 'Foo'
|
22
|
+
end
|
23
|
+
|
24
|
+
def override
|
25
|
+
flash[:notice] = 'original'
|
26
|
+
flash[:notice] = 'message'
|
27
|
+
render :text => 'Foo'
|
28
|
+
end
|
29
|
+
|
30
|
+
def stack
|
31
|
+
flash[:notice] = 'original'
|
32
|
+
flash[:notice] << 'message'
|
33
|
+
flash[:notice] << 'another'
|
34
|
+
render :text => 'Foo'
|
35
|
+
end
|
36
|
+
|
37
|
+
def cold_boot
|
38
|
+
flash[:notice] << 'original'
|
39
|
+
flash[:notice] << 'message'
|
40
|
+
flash[:notice] << 'another'
|
41
|
+
render :text => 'Foo'
|
42
|
+
end
|
43
|
+
|
22
44
|
end
|
@@ -0,0 +1,58 @@
|
|
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?id=1"
|
25
|
+
response.should have_flash_cookie('errors', "This is an Error")
|
26
|
+
response.should have_flash_cookie('errors', "Error #1")
|
27
|
+
|
28
|
+
get "/dummy/error?id=2"
|
29
|
+
response.should have_flash_cookie('errors', "This is an Error")
|
30
|
+
response.should have_flash_cookie('errors', "Error #1")
|
31
|
+
response.should have_flash_cookie('errors', "Error #2")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Stolen (and converted to a request spec) from stackable_flash:
|
36
|
+
# https://github.com/pboling/stackable_flash/blob/master/spec/controllers/dummy_controller_spec.rb
|
37
|
+
it "should handle multiple keys" do
|
38
|
+
get "/dummy/multiple_keys"
|
39
|
+
response.should have_flash_cookie('notice', 'This is a Notice')
|
40
|
+
response.should have_flash_cookie('errors', 'This is an Error')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should override" do
|
44
|
+
get "/dummy/override"
|
45
|
+
response.should_not have_flash_cookie('notice','original')
|
46
|
+
response.should have_flash_cookie('notice','message')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should stack" do
|
50
|
+
get "/dummy/stack"
|
51
|
+
response.should have_flash_cookie('notice',['original','message','another'])
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should cold boot" do
|
55
|
+
get "/dummy/cold_boot"
|
56
|
+
response.should have_flash_cookie('notice',['original','message','another'])
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,8 @@ require File.expand_path("../dummy/config/environment", __FILE__)
|
|
4
4
|
|
5
5
|
require 'rspec/rails'
|
6
6
|
require "json"
|
7
|
+
require 'cacheable_flash'
|
8
|
+
require 'cacheable_flash/rspec_matchers'
|
7
9
|
|
8
10
|
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
9
11
|
|
@@ -11,17 +13,16 @@ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
|
11
13
|
# in spec/support/ and its subdirectories.
|
12
14
|
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
require 'cacheable_flash/rspec_matchers'
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
18
|
+
config.run_all_when_everything_filtered = true
|
19
|
+
config.filter_run :focus
|
20
20
|
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
21
|
+
# Run specs in random order to surface order dependencies. If you find an
|
22
|
+
# order dependency and want to debug it, you can fix the order by providing
|
23
|
+
# the seed, which is printed after each run.
|
24
|
+
# --seed 1234
|
25
|
+
config.order = 'random'
|
24
26
|
|
25
|
-
RSpec.configure do |config|
|
26
27
|
config.include CacheableFlash::RspecMatchers
|
27
28
|
end
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,13 +13,13 @@ cert_chain: []
|
|
13
13
|
date: 2012-08-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: stackable_flash
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 0.0.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ! '>='
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
30
|
+
version: 0.0.4
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: json
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,7 +83,7 @@ dependencies:
|
|
83
83
|
requirements:
|
84
84
|
- - ! '>='
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: 2.
|
86
|
+
version: 2.11.0
|
87
87
|
type: :development
|
88
88
|
prerelease: false
|
89
89
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
requirements:
|
92
92
|
- - ! '>='
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: 2.
|
94
|
+
version: 2.11.0
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: rdoc
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,29 +109,13 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.12'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
|
-
requirements:
|
116
|
-
- - ! '>='
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: 1.0.24
|
119
|
-
type: :development
|
120
|
-
prerelease: false
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
|
-
requirements:
|
124
|
-
- - ! '>='
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
version: 1.0.24
|
127
|
-
- !ruby/object:Gem::Dependency
|
128
|
-
name: jeweler
|
112
|
+
name: reek
|
129
113
|
requirement: !ruby/object:Gem::Requirement
|
130
114
|
none: false
|
131
115
|
requirements:
|
132
116
|
- - ! '>='
|
133
117
|
- !ruby/object:Gem::Version
|
134
|
-
version: 1.
|
118
|
+
version: 1.2.8
|
135
119
|
type: :development
|
136
120
|
prerelease: false
|
137
121
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -139,15 +123,15 @@ dependencies:
|
|
139
123
|
requirements:
|
140
124
|
- - ! '>='
|
141
125
|
- !ruby/object:Gem::Version
|
142
|
-
version: 1.
|
126
|
+
version: 1.2.8
|
143
127
|
- !ruby/object:Gem::Dependency
|
144
|
-
name:
|
128
|
+
name: roodi
|
145
129
|
requirement: !ruby/object:Gem::Requirement
|
146
130
|
none: false
|
147
131
|
requirements:
|
148
132
|
- - ! '>='
|
149
133
|
- !ruby/object:Gem::Version
|
150
|
-
version: 1.
|
134
|
+
version: 2.1.0
|
151
135
|
type: :development
|
152
136
|
prerelease: false
|
153
137
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -155,15 +139,15 @@ dependencies:
|
|
155
139
|
requirements:
|
156
140
|
- - ! '>='
|
157
141
|
- !ruby/object:Gem::Version
|
158
|
-
version: 1.
|
142
|
+
version: 2.1.0
|
159
143
|
- !ruby/object:Gem::Dependency
|
160
|
-
name:
|
144
|
+
name: rake
|
161
145
|
requirement: !ruby/object:Gem::Requirement
|
162
146
|
none: false
|
163
147
|
requirements:
|
164
148
|
- - ! '>='
|
165
149
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
150
|
+
version: '0'
|
167
151
|
type: :development
|
168
152
|
prerelease: false
|
169
153
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -171,7 +155,7 @@ dependencies:
|
|
171
155
|
requirements:
|
172
156
|
- - ! '>='
|
173
157
|
- !ruby/object:Gem::Version
|
174
|
-
version:
|
158
|
+
version: '0'
|
175
159
|
description: ! 'Allows caching of pages with flash messages by rendering flash
|
176
160
|
|
177
161
|
messages from a cookie using JavaScript, instead of statically in your Rails
|
@@ -212,7 +196,6 @@ files:
|
|
212
196
|
- spec/cacheable_flash/install_spec.rb
|
213
197
|
- spec/cacheable_flash/test_helpers_spec.rb
|
214
198
|
- spec/controllers/dummy_controller_spec.rb
|
215
|
-
- spec/dummy/README.rdoc
|
216
199
|
- spec/dummy/Rakefile
|
217
200
|
- spec/dummy/app/assets/javascripts/application.js
|
218
201
|
- spec/dummy/app/assets/stylesheets/application.css
|
@@ -250,7 +233,7 @@ files:
|
|
250
233
|
- spec/dummy/script/rails
|
251
234
|
- spec/js_unit/cookie_test.html
|
252
235
|
- spec/js_unit/flash_test.html
|
253
|
-
- spec/requests/
|
236
|
+
- spec/requests/integration_spec.rb
|
254
237
|
- spec/spec_helper.rb
|
255
238
|
- tasks/cacheable_flash_tasks.rake
|
256
239
|
- vendor/assets/javascripts/flash.js
|
@@ -286,7 +269,6 @@ test_files:
|
|
286
269
|
- spec/cacheable_flash/install_spec.rb
|
287
270
|
- spec/cacheable_flash/test_helpers_spec.rb
|
288
271
|
- spec/controllers/dummy_controller_spec.rb
|
289
|
-
- spec/dummy/README.rdoc
|
290
272
|
- spec/dummy/Rakefile
|
291
273
|
- spec/dummy/app/assets/javascripts/application.js
|
292
274
|
- spec/dummy/app/assets/stylesheets/application.css
|
@@ -324,5 +306,5 @@ test_files:
|
|
324
306
|
- spec/dummy/script/rails
|
325
307
|
- spec/js_unit/cookie_test.html
|
326
308
|
- spec/js_unit/flash_test.html
|
327
|
-
- spec/requests/
|
309
|
+
- spec/requests/integration_spec.rb
|
328
310
|
- spec/spec_helper.rb
|
data/spec/dummy/README.rdoc
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
== Welcome to Rails
|
2
|
-
|
3
|
-
Rails is a web-application framework that includes everything needed to create
|
4
|
-
database-backed web applications according to the Model-View-Control pattern.
|
5
|
-
|
6
|
-
This pattern splits the view (also called the presentation) into "dumb"
|
7
|
-
templates that are primarily responsible for inserting pre-built data in between
|
8
|
-
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
-
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
-
persist themselves to a database. The controller handles the incoming requests
|
11
|
-
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
-
and directing data to the view.
|
13
|
-
|
14
|
-
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
-
layer entitled Active Record. This layer allows you to present the data from
|
16
|
-
database rows as objects and embellish these data objects with business logic
|
17
|
-
methods. You can read more about Active Record in
|
18
|
-
link:files/vendor/rails/activerecord/README.html.
|
19
|
-
|
20
|
-
The controller and view are handled by the Action Pack, which handles both
|
21
|
-
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
-
are bundled in a single package due to their heavy interdependence. This is
|
23
|
-
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
-
more separate. Each of these packages can be used independently outside of
|
25
|
-
Rails. You can read more about Action Pack in
|
26
|
-
link:files/vendor/rails/actionpack/README.html.
|
27
|
-
|
28
|
-
|
29
|
-
== Getting Started
|
30
|
-
|
31
|
-
1. At the command prompt, create a new Rails application:
|
32
|
-
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
-
|
34
|
-
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
-
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
-
|
37
|
-
3. Go to http://localhost:3000/ and you'll see:
|
38
|
-
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
-
|
40
|
-
4. Follow the guidelines to start developing your application. You can find
|
41
|
-
the following resources handy:
|
42
|
-
|
43
|
-
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
-
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
-
|
46
|
-
|
47
|
-
== Debugging Rails
|
48
|
-
|
49
|
-
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
-
will help you debug it and get it back on the rails.
|
51
|
-
|
52
|
-
First area to check is the application log files. Have "tail -f" commands
|
53
|
-
running on the server.log and development.log. Rails will automatically display
|
54
|
-
debugging and runtime information to these files. Debugging info will also be
|
55
|
-
shown in the browser on requests from 127.0.0.1.
|
56
|
-
|
57
|
-
You can also log your own messages directly into the log file from your code
|
58
|
-
using the Ruby logger class from inside your controllers. Example:
|
59
|
-
|
60
|
-
class WeblogController < ActionController::Base
|
61
|
-
def destroy
|
62
|
-
@weblog = Weblog.find(params[:id])
|
63
|
-
@weblog.destroy
|
64
|
-
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
The result will be a message in your log file along the lines of:
|
69
|
-
|
70
|
-
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
-
|
72
|
-
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
-
|
74
|
-
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
-
several books available online as well:
|
76
|
-
|
77
|
-
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
-
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
-
|
80
|
-
These two books will bring you up to speed on the Ruby language and also on
|
81
|
-
programming in general.
|
82
|
-
|
83
|
-
|
84
|
-
== Debugger
|
85
|
-
|
86
|
-
Debugger support is available through the debugger command when you start your
|
87
|
-
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
-
execution at any point in the code, investigate and change the model, and then,
|
89
|
-
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
-
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
-
|
92
|
-
class WeblogController < ActionController::Base
|
93
|
-
def index
|
94
|
-
@posts = Post.all
|
95
|
-
debugger
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
So the controller will accept the action, run the first line, then present you
|
100
|
-
with a IRB prompt in the server window. Here you can do things like:
|
101
|
-
|
102
|
-
>> @posts.inspect
|
103
|
-
=> "[#<Post:0x14a6be8
|
104
|
-
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
-
#<Post:0x14a6620
|
106
|
-
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
-
>> @posts.first.title = "hello from a debugger"
|
108
|
-
=> "hello from a debugger"
|
109
|
-
|
110
|
-
...and even better, you can examine how your runtime objects actually work:
|
111
|
-
|
112
|
-
>> f = @posts.first
|
113
|
-
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
-
>> f.
|
115
|
-
Display all 152 possibilities? (y or n)
|
116
|
-
|
117
|
-
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
-
|
119
|
-
|
120
|
-
== Console
|
121
|
-
|
122
|
-
The console is a Ruby shell, which allows you to interact with your
|
123
|
-
application's domain model. Here you'll have all parts of the application
|
124
|
-
configured, just like it is when the application is running. You can inspect
|
125
|
-
domain models, change values, and save to the database. Starting the script
|
126
|
-
without arguments will launch it in the development environment.
|
127
|
-
|
128
|
-
To start the console, run <tt>rails console</tt> from the application
|
129
|
-
directory.
|
130
|
-
|
131
|
-
Options:
|
132
|
-
|
133
|
-
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
-
made to the database.
|
135
|
-
* Passing an environment name as an argument will load the corresponding
|
136
|
-
environment. Example: <tt>rails console production</tt>.
|
137
|
-
|
138
|
-
To reload your controllers and models after launching the console run
|
139
|
-
<tt>reload!</tt>
|
140
|
-
|
141
|
-
More information about irb can be found at:
|
142
|
-
link:http://www.rubycentral.org/pickaxe/irb.html
|
143
|
-
|
144
|
-
|
145
|
-
== dbconsole
|
146
|
-
|
147
|
-
You can go to the command line of your database directly through <tt>rails
|
148
|
-
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
-
defined in database.yml. Starting the script without arguments will connect you
|
150
|
-
to the development database. Passing an argument will connect you to a different
|
151
|
-
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
-
PostgreSQL and SQLite 3.
|
153
|
-
|
154
|
-
== Description of Contents
|
155
|
-
|
156
|
-
The default directory structure of a generated Ruby on Rails application:
|
157
|
-
|
158
|
-
|-- app
|
159
|
-
| |-- assets
|
160
|
-
| |-- images
|
161
|
-
| |-- javascripts
|
162
|
-
| `-- stylesheets
|
163
|
-
| |-- controllers
|
164
|
-
| |-- helpers
|
165
|
-
| |-- mailers
|
166
|
-
| |-- models
|
167
|
-
| `-- views
|
168
|
-
| `-- layouts
|
169
|
-
|-- config
|
170
|
-
| |-- environments
|
171
|
-
| |-- initializers
|
172
|
-
| `-- locales
|
173
|
-
|-- db
|
174
|
-
|-- doc
|
175
|
-
|-- lib
|
176
|
-
| `-- tasks
|
177
|
-
|-- log
|
178
|
-
|-- public
|
179
|
-
|-- script
|
180
|
-
|-- test
|
181
|
-
| |-- fixtures
|
182
|
-
| |-- functional
|
183
|
-
| |-- integration
|
184
|
-
| |-- performance
|
185
|
-
| `-- unit
|
186
|
-
|-- tmp
|
187
|
-
| |-- cache
|
188
|
-
| |-- pids
|
189
|
-
| |-- sessions
|
190
|
-
| `-- sockets
|
191
|
-
`-- vendor
|
192
|
-
|-- assets
|
193
|
-
`-- stylesheets
|
194
|
-
`-- plugins
|
195
|
-
|
196
|
-
app
|
197
|
-
Holds all the code that's specific to this particular application.
|
198
|
-
|
199
|
-
app/assets
|
200
|
-
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
-
|
202
|
-
app/controllers
|
203
|
-
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
-
automated URL mapping. All controllers should descend from
|
205
|
-
ApplicationController which itself descends from ActionController::Base.
|
206
|
-
|
207
|
-
app/models
|
208
|
-
Holds models that should be named like post.rb. Models descend from
|
209
|
-
ActiveRecord::Base by default.
|
210
|
-
|
211
|
-
app/views
|
212
|
-
Holds the template files for the view that should be named like
|
213
|
-
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
-
eRuby syntax by default.
|
215
|
-
|
216
|
-
app/views/layouts
|
217
|
-
Holds the template files for layouts to be used with views. This models the
|
218
|
-
common header/footer method of wrapping views. In your views, define a layout
|
219
|
-
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
-
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
-
layout.
|
222
|
-
|
223
|
-
app/helpers
|
224
|
-
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
-
generated for you automatically when using generators for controllers.
|
226
|
-
Helpers can be used to wrap functionality for your views into methods.
|
227
|
-
|
228
|
-
config
|
229
|
-
Configuration files for the Rails environment, the routing map, the database,
|
230
|
-
and other dependencies.
|
231
|
-
|
232
|
-
db
|
233
|
-
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
-
sequence of Migrations for your schema.
|
235
|
-
|
236
|
-
doc
|
237
|
-
This directory is where your application documentation will be stored when
|
238
|
-
generated using <tt>rake doc:app</tt>
|
239
|
-
|
240
|
-
lib
|
241
|
-
Application specific libraries. Basically, any kind of custom code that
|
242
|
-
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
-
the load path.
|
244
|
-
|
245
|
-
public
|
246
|
-
The directory available for the web server. Also contains the dispatchers and the
|
247
|
-
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
-
server.
|
249
|
-
|
250
|
-
script
|
251
|
-
Helper scripts for automation and generation.
|
252
|
-
|
253
|
-
test
|
254
|
-
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
-
command, template test files will be generated for you and placed in this
|
256
|
-
directory.
|
257
|
-
|
258
|
-
vendor
|
259
|
-
External libraries that the application depends on. Also includes the plugins
|
260
|
-
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
-
vendor/rails/. This directory is in the load path.
|
@@ -1,31 +0,0 @@
|
|
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
|