cacheable_flash 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/CHANGES +42 -36
- data/Gemfile +20 -17
- data/Gemfile.lock +121 -82
- data/LICENSE.txt +21 -21
- data/README.rdoc +158 -159
- data/Rakefile +54 -54
- data/VERSION +1 -1
- data/cacheable_flash.gemspec +15 -18
- data/init.rb +6 -6
- data/install.rb +18 -18
- data/lib/cacheable_flash.rb +39 -38
- data/lib/cacheable_flash/rails/engine.rb +8 -13
- data/lib/cacheable_flash/rails/railtie.rb +14 -14
- data/lib/generators/cacheable_flash/install/install_generator.rb +23 -23
- data/spec/cacheable_flash/cacheable_flash_spec.rb +105 -101
- data/spec/cacheable_flash/install_spec.rb +68 -68
- data/spec/cacheable_flash/test_helpers_spec.rb +37 -36
- data/spec/js_unit/cookie_test.html +60 -60
- data/spec/js_unit/flash_test.html +112 -112
- data/spec/spec_helper.rb +20 -20
- data/spec/support/test_helpers.rb +10 -10
- data/tasks/cacheable_flash_tasks.rake +3 -3
- data/vendor/assets/javascripts/flash.js +21 -21
- data/vendor/assets/javascripts/jquery.cookie.js +91 -91
- metadata +26 -37
@@ -1,68 +1,68 @@
|
|
1
|
-
#This should only be tested for older rails when the generator is used, so commenting out for now.
|
2
|
-
|
3
|
-
#require 'spec_helper'
|
4
|
-
#
|
5
|
-
#describe "install.rb" do
|
6
|
-
# include FileUtils
|
7
|
-
#
|
8
|
-
# before do
|
9
|
-
# @rails_root = "#{Dir.tmpdir}/cachable_flash_#{Time.now.to_f}"
|
10
|
-
# Object.send(:remove_const, :RAILS_ROOT) if Object.const_defined?(:RAILS_ROOT)
|
11
|
-
# Object.const_set(:RAILS_ROOT, @rails_root)
|
12
|
-
#
|
13
|
-
# @stdout = StringIO.new("")
|
14
|
-
# $stdout = @stdout
|
15
|
-
#
|
16
|
-
# @js_dir = "#{@rails_root}/public/javascripts"
|
17
|
-
# FileUtils.mkdir_p(@js_dir)
|
18
|
-
# @install_path = "#{File.dirname(__FILE__)}/../../install.rb"
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# after do
|
22
|
-
# $stdout = STDOUT
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# describe "when project does not have json.js" do
|
26
|
-
# it "installs javascript files including json.js" do
|
27
|
-
# File.exists?("#{@js_dir}/flash.js").should be_false
|
28
|
-
# File.exists?("#{@js_dir}/json.js").should be_false
|
29
|
-
# File.exists?("#{@js_dir}/cookie.js").should be_false
|
30
|
-
# load(@install_path)
|
31
|
-
# File.exists?("#{@js_dir}/flash.js").should be_true
|
32
|
-
# File.exists?("#{@js_dir}/json.js").should be_true
|
33
|
-
# File.exists?("#{@js_dir}/cookie.js").should be_true
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# describe "when project has json.js" do
|
38
|
-
# it "does not overwrite the existing json.js and installs other javascript files" do
|
39
|
-
# File.open("#{@js_dir}/json.js", "w") do |f|
|
40
|
-
# f.write "Original json.js"
|
41
|
-
# end
|
42
|
-
# File.exists?("#{@js_dir}/json.js").should be_true
|
43
|
-
# File.exists?("#{@js_dir}/flash.js").should be_false
|
44
|
-
# File.exists?("#{@js_dir}/cookie.js").should be_false
|
45
|
-
# load(@install_path)
|
46
|
-
# File.exists?("#{@js_dir}/flash.js").should be_true
|
47
|
-
# File.exists?("#{@js_dir}/cookie.js").should be_true
|
48
|
-
# File.exists?("#{@js_dir}/json.js").should be_true
|
49
|
-
# File.read("#{@js_dir}/json.js").should == "Original json.js"
|
50
|
-
# end
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# describe "when project has cookie.js" do
|
54
|
-
# it "does not overwrite the existing cookie.js" do
|
55
|
-
# File.open("#{@js_dir}/cookie.js", "w") do |f|
|
56
|
-
# f.write "Original cookie.js"
|
57
|
-
# end
|
58
|
-
# File.exists?("#{@js_dir}/json.js").should be_false
|
59
|
-
# File.exists?("#{@js_dir}/flash.js").should be_false
|
60
|
-
# File.exists?("#{@js_dir}/cookie.js").should be_true
|
61
|
-
# load(@install_path)
|
62
|
-
# File.exists?("#{@js_dir}/flash.js").should be_true
|
63
|
-
# File.exists?("#{@js_dir}/json.js").should be_true
|
64
|
-
# File.exists?("#{@js_dir}/cookie.js").should be_true
|
65
|
-
# File.read("#{@js_dir}/cookie.js").should == "Original cookie.js"
|
66
|
-
# end
|
67
|
-
# end
|
68
|
-
#end
|
1
|
+
#This should only be tested for older rails when the generator is used, so commenting out for now.
|
2
|
+
|
3
|
+
#require 'spec_helper'
|
4
|
+
#
|
5
|
+
#describe "install.rb" do
|
6
|
+
# include FileUtils
|
7
|
+
#
|
8
|
+
# before do
|
9
|
+
# @rails_root = "#{Dir.tmpdir}/cachable_flash_#{Time.now.to_f}"
|
10
|
+
# Object.send(:remove_const, :RAILS_ROOT) if Object.const_defined?(:RAILS_ROOT)
|
11
|
+
# Object.const_set(:RAILS_ROOT, @rails_root)
|
12
|
+
#
|
13
|
+
# @stdout = StringIO.new("")
|
14
|
+
# $stdout = @stdout
|
15
|
+
#
|
16
|
+
# @js_dir = "#{@rails_root}/public/javascripts"
|
17
|
+
# FileUtils.mkdir_p(@js_dir)
|
18
|
+
# @install_path = "#{File.dirname(__FILE__)}/../../install.rb"
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# after do
|
22
|
+
# $stdout = STDOUT
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# describe "when project does not have json.js" do
|
26
|
+
# it "installs javascript files including json.js" do
|
27
|
+
# File.exists?("#{@js_dir}/flash.js").should be_false
|
28
|
+
# File.exists?("#{@js_dir}/json.js").should be_false
|
29
|
+
# File.exists?("#{@js_dir}/cookie.js").should be_false
|
30
|
+
# load(@install_path)
|
31
|
+
# File.exists?("#{@js_dir}/flash.js").should be_true
|
32
|
+
# File.exists?("#{@js_dir}/json.js").should be_true
|
33
|
+
# File.exists?("#{@js_dir}/cookie.js").should be_true
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# describe "when project has json.js" do
|
38
|
+
# it "does not overwrite the existing json.js and installs other javascript files" do
|
39
|
+
# File.open("#{@js_dir}/json.js", "w") do |f|
|
40
|
+
# f.write "Original json.js"
|
41
|
+
# end
|
42
|
+
# File.exists?("#{@js_dir}/json.js").should be_true
|
43
|
+
# File.exists?("#{@js_dir}/flash.js").should be_false
|
44
|
+
# File.exists?("#{@js_dir}/cookie.js").should be_false
|
45
|
+
# load(@install_path)
|
46
|
+
# File.exists?("#{@js_dir}/flash.js").should be_true
|
47
|
+
# File.exists?("#{@js_dir}/cookie.js").should be_true
|
48
|
+
# File.exists?("#{@js_dir}/json.js").should be_true
|
49
|
+
# File.read("#{@js_dir}/json.js").should == "Original json.js"
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# describe "when project has cookie.js" do
|
54
|
+
# it "does not overwrite the existing cookie.js" do
|
55
|
+
# File.open("#{@js_dir}/cookie.js", "w") do |f|
|
56
|
+
# f.write "Original cookie.js"
|
57
|
+
# end
|
58
|
+
# File.exists?("#{@js_dir}/json.js").should be_false
|
59
|
+
# File.exists?("#{@js_dir}/flash.js").should be_false
|
60
|
+
# File.exists?("#{@js_dir}/cookie.js").should be_true
|
61
|
+
# load(@install_path)
|
62
|
+
# File.exists?("#{@js_dir}/flash.js").should be_true
|
63
|
+
# File.exists?("#{@js_dir}/json.js").should be_true
|
64
|
+
# File.exists?("#{@js_dir}/cookie.js").should be_true
|
65
|
+
# File.read("#{@js_dir}/cookie.js").should == "Original cookie.js"
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
#end
|
@@ -1,36 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
@
|
11
|
-
|
12
|
-
controller.send(:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
'
|
25
|
-
|
26
|
-
|
27
|
-
flash['
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
1
|
+
# TODO: Does not work with latest rails, and switching from ActionController to ActionDispatch didn't fix it.
|
2
|
+
#require 'spec_helper'
|
3
|
+
#
|
4
|
+
#module CacheableFlash
|
5
|
+
# describe TestHelpers do
|
6
|
+
# attr_reader :controller, :request, :response, :flash, :cookies
|
7
|
+
# include TestHelpers
|
8
|
+
# before do
|
9
|
+
# @controller = ActionController::Base.new
|
10
|
+
# @request = ActionDispatch::TestRequest.new
|
11
|
+
# @response = ActionDispatch::TestResponse.new
|
12
|
+
# controller.send(:initialize_template_class, response)
|
13
|
+
# controller.send(:assign_shortcuts, request, response)
|
14
|
+
#
|
15
|
+
# @flash = controller.send(:flash)
|
16
|
+
# class << controller
|
17
|
+
# include CacheableFlash
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# describe "#flash_cookie" do
|
22
|
+
# it "returns the flash hash send as a cookie" do
|
23
|
+
# expected_flash = {
|
24
|
+
# 'errors' => "This is an Error",
|
25
|
+
# 'notice' => "This is a Notice"
|
26
|
+
# }
|
27
|
+
# flash['errors'] = expected_flash['errors']
|
28
|
+
# flash['notice'] = expected_flash['notice']
|
29
|
+
#
|
30
|
+
# controller.write_flash_to_cookie
|
31
|
+
# @cookies = response.cookies # simulate setting the cookie instance variable in rails tests
|
32
|
+
#
|
33
|
+
# flash_cookie.should == expected_flash
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#end
|
@@ -1,60 +1,60 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml">
|
4
|
-
<head>
|
5
|
-
<!-- You will need to change this to point to your jsUnitCore.js -->
|
6
|
-
<script src="http://localhost:3000/jsunit/app/jsUnitCore.js" type="text/javascript"></script>
|
7
|
-
|
8
|
-
<script src="../../javascripts/jquery.js" type="text/javascript"></script>
|
9
|
-
<script src="../../javascripts/cookie.js" type="text/javascript"></script>
|
10
|
-
|
11
|
-
<script language="javascript" type="text/javascript">
|
12
|
-
var content;
|
13
|
-
function setUp() {
|
14
|
-
content = $('#content');
|
15
|
-
Cookie.eraseAll();
|
16
|
-
}
|
17
|
-
|
18
|
-
function tearDown() {
|
19
|
-
Cookie.eraseAll();
|
20
|
-
}
|
21
|
-
|
22
|
-
function test_read() {
|
23
|
-
var expires = new Date();
|
24
|
-
expires.setYear(expires.getFullYear() + 1);
|
25
|
-
document.cookie = "foobar=baz; path=/; expires=" + expires.toGMTString();
|
26
|
-
|
27
|
-
assertEquals('baz', Cookie.get('foobar'));
|
28
|
-
}
|
29
|
-
|
30
|
-
function test_write() {
|
31
|
-
Cookie.set('foobar', 'baz');
|
32
|
-
assertEquals("baz", Cookie.get('foobar'));
|
33
|
-
}
|
34
|
-
|
35
|
-
function test_expire() {
|
36
|
-
Cookie.set('foobar', 'baz');
|
37
|
-
Cookie.erase('foobar');
|
38
|
-
assertNull(Cookie.get('foobar'));
|
39
|
-
}
|
40
|
-
|
41
|
-
function test_expireAll() {
|
42
|
-
Cookie.set('foobar', 'baz');
|
43
|
-
Cookie.set('another', 'cookie');
|
44
|
-
|
45
|
-
Cookie.eraseAll();
|
46
|
-
|
47
|
-
assertNull(Cookie.get('foobar'));
|
48
|
-
assertNull(Cookie.get('another'));
|
49
|
-
}
|
50
|
-
|
51
|
-
</script>
|
52
|
-
|
53
|
-
</head>
|
54
|
-
|
55
|
-
<body>
|
56
|
-
<div id="fixture">
|
57
|
-
<div id="content"></div>
|
58
|
-
</div>
|
59
|
-
</body>
|
60
|
-
</html>
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
4
|
+
<head>
|
5
|
+
<!-- You will need to change this to point to your jsUnitCore.js -->
|
6
|
+
<script src="http://localhost:3000/jsunit/app/jsUnitCore.js" type="text/javascript"></script>
|
7
|
+
|
8
|
+
<script src="../../javascripts/jquery.js" type="text/javascript"></script>
|
9
|
+
<script src="../../javascripts/cookie.js" type="text/javascript"></script>
|
10
|
+
|
11
|
+
<script language="javascript" type="text/javascript">
|
12
|
+
var content;
|
13
|
+
function setUp() {
|
14
|
+
content = $('#content');
|
15
|
+
Cookie.eraseAll();
|
16
|
+
}
|
17
|
+
|
18
|
+
function tearDown() {
|
19
|
+
Cookie.eraseAll();
|
20
|
+
}
|
21
|
+
|
22
|
+
function test_read() {
|
23
|
+
var expires = new Date();
|
24
|
+
expires.setYear(expires.getFullYear() + 1);
|
25
|
+
document.cookie = "foobar=baz; path=/; expires=" + expires.toGMTString();
|
26
|
+
|
27
|
+
assertEquals('baz', Cookie.get('foobar'));
|
28
|
+
}
|
29
|
+
|
30
|
+
function test_write() {
|
31
|
+
Cookie.set('foobar', 'baz');
|
32
|
+
assertEquals("baz", Cookie.get('foobar'));
|
33
|
+
}
|
34
|
+
|
35
|
+
function test_expire() {
|
36
|
+
Cookie.set('foobar', 'baz');
|
37
|
+
Cookie.erase('foobar');
|
38
|
+
assertNull(Cookie.get('foobar'));
|
39
|
+
}
|
40
|
+
|
41
|
+
function test_expireAll() {
|
42
|
+
Cookie.set('foobar', 'baz');
|
43
|
+
Cookie.set('another', 'cookie');
|
44
|
+
|
45
|
+
Cookie.eraseAll();
|
46
|
+
|
47
|
+
assertNull(Cookie.get('foobar'));
|
48
|
+
assertNull(Cookie.get('another'));
|
49
|
+
}
|
50
|
+
|
51
|
+
</script>
|
52
|
+
|
53
|
+
</head>
|
54
|
+
|
55
|
+
<body>
|
56
|
+
<div id="fixture">
|
57
|
+
<div id="content"></div>
|
58
|
+
</div>
|
59
|
+
</body>
|
60
|
+
</html>
|
@@ -1,112 +1,112 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml">
|
4
|
-
<head>
|
5
|
-
<!-- You will need to change this to point to your jsUnitCore.js -->
|
6
|
-
<script src="http://localhost:3000/jsunit/app/jsUnitCore.js" type="text/javascript"></script>
|
7
|
-
|
8
|
-
<script src="../../javascripts/jquery.js" type="text/javascript"></script>
|
9
|
-
<script src="../../javascripts/cookie.js" type="text/javascript"></script>
|
10
|
-
<script src="../../javascripts/json.js" type="text/javascript"></script>
|
11
|
-
<script src="../../vendor/assets/javascripts/flash.js" type="text/javascript"></script>
|
12
|
-
<script type="text/javascript">
|
13
|
-
Include.jsUnitCore();
|
14
|
-
Include.allProduction();
|
15
|
-
Include.allCommonTest();
|
16
|
-
Include.testHelper();
|
17
|
-
</script>
|
18
|
-
|
19
|
-
<script language="javascript" type="text/javascript">
|
20
|
-
var content;
|
21
|
-
function setUp() {
|
22
|
-
content = $('#content');
|
23
|
-
content.html("");
|
24
|
-
Cookie.eraseAll();
|
25
|
-
}
|
26
|
-
|
27
|
-
function tearDown() {
|
28
|
-
Cookie.eraseAll();
|
29
|
-
}
|
30
|
-
|
31
|
-
function test_transferFromCookies_setsFlashData_whenCookieExists() {
|
32
|
-
var expectedData = {
|
33
|
-
'error': "The Error",
|
34
|
-
'notice': "The Notice"
|
35
|
-
};
|
36
|
-
setUpCookieWithData(expectedData);
|
37
|
-
Flash.transferFromCookies();
|
38
|
-
assertHashEquals(expectedData, Flash.data);
|
39
|
-
}
|
40
|
-
|
41
|
-
function test_transferFromCookies_setsFlashDataToEmptyHash_whenCookieDoesNotExist() {
|
42
|
-
Flash.transferFromCookies();
|
43
|
-
assertHashEquals({}, Flash.data);
|
44
|
-
}
|
45
|
-
|
46
|
-
function test_transferFromCookies_setsFlashDataToEmptyHash_whenCookieIsEmpty() {
|
47
|
-
setUpCookieWithData("");
|
48
|
-
Flash.transferFromCookies();
|
49
|
-
assertHashEquals({}, Flash.data);
|
50
|
-
}
|
51
|
-
|
52
|
-
function test_transferFromCookies_removeFlashCookie() {
|
53
|
-
setUpCookieWithData({
|
54
|
-
'error': "The Error",
|
55
|
-
'notice': "The Notice"
|
56
|
-
});
|
57
|
-
Flash.transferFromCookies();
|
58
|
-
assertNull(Cookie.get("flash"));
|
59
|
-
}
|
60
|
-
|
61
|
-
// how do I test this??
|
62
|
-
function test_transferFromCookies_whenValueContainsAPlusSign() {
|
63
|
-
setUpCookieWithData({
|
64
|
-
'notice': "Book+%2B+Gift+Box"
|
65
|
-
});
|
66
|
-
Flash.transferFromCookies();
|
67
|
-
assertEquals("Book + Gift Box", Cookie.get("notice"));
|
68
|
-
}
|
69
|
-
|
70
|
-
function test_writeDataTo_whenThereIsACookieValue() {
|
71
|
-
setUpCookieWithData({
|
72
|
-
'error': "This+is%20An+Error"
|
73
|
-
});
|
74
|
-
Flash.transferFromCookies();
|
75
|
-
Flash.writeDataTo('error', content);
|
76
|
-
|
77
|
-
assertEquals("This is An Error", content.html());
|
78
|
-
}
|
79
|
-
|
80
|
-
function test_writeDataTo_whenThereIsNoCookieValue() {
|
81
|
-
setUpCookieWithData({});
|
82
|
-
Flash.transferFromCookies();
|
83
|
-
Flash.writeDataTo('notice', content);
|
84
|
-
|
85
|
-
assertEquals("", content.html());
|
86
|
-
}
|
87
|
-
|
88
|
-
function test_writeDataTo_whenPassedAnElementId() {
|
89
|
-
setUpCookieWithData({
|
90
|
-
'error': "This+is%20An+Error"
|
91
|
-
});
|
92
|
-
|
93
|
-
Flash.transferFromCookies();
|
94
|
-
Flash.writeDataTo('error', '#content');
|
95
|
-
|
96
|
-
assertEquals("This is An Error", content.html());
|
97
|
-
}
|
98
|
-
|
99
|
-
function setUpCookieWithData(values) {
|
100
|
-
Cookie.set('flash', JSON.stringify(values));
|
101
|
-
}
|
102
|
-
|
103
|
-
</script>
|
104
|
-
|
105
|
-
</head>
|
106
|
-
|
107
|
-
<body>
|
108
|
-
<div id="fixture">
|
109
|
-
<div id="content"></div>
|
110
|
-
</div>
|
111
|
-
</body>
|
112
|
-
</html>
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
4
|
+
<head>
|
5
|
+
<!-- You will need to change this to point to your jsUnitCore.js -->
|
6
|
+
<script src="http://localhost:3000/jsunit/app/jsUnitCore.js" type="text/javascript"></script>
|
7
|
+
|
8
|
+
<script src="../../javascripts/jquery.js" type="text/javascript"></script>
|
9
|
+
<script src="../../javascripts/cookie.js" type="text/javascript"></script>
|
10
|
+
<script src="../../javascripts/json.js" type="text/javascript"></script>
|
11
|
+
<script src="../../vendor/assets/javascripts/flash.js" type="text/javascript"></script>
|
12
|
+
<script type="text/javascript">
|
13
|
+
Include.jsUnitCore();
|
14
|
+
Include.allProduction();
|
15
|
+
Include.allCommonTest();
|
16
|
+
Include.testHelper();
|
17
|
+
</script>
|
18
|
+
|
19
|
+
<script language="javascript" type="text/javascript">
|
20
|
+
var content;
|
21
|
+
function setUp() {
|
22
|
+
content = $('#content');
|
23
|
+
content.html("");
|
24
|
+
Cookie.eraseAll();
|
25
|
+
}
|
26
|
+
|
27
|
+
function tearDown() {
|
28
|
+
Cookie.eraseAll();
|
29
|
+
}
|
30
|
+
|
31
|
+
function test_transferFromCookies_setsFlashData_whenCookieExists() {
|
32
|
+
var expectedData = {
|
33
|
+
'error': "The Error",
|
34
|
+
'notice': "The Notice"
|
35
|
+
};
|
36
|
+
setUpCookieWithData(expectedData);
|
37
|
+
Flash.transferFromCookies();
|
38
|
+
assertHashEquals(expectedData, Flash.data);
|
39
|
+
}
|
40
|
+
|
41
|
+
function test_transferFromCookies_setsFlashDataToEmptyHash_whenCookieDoesNotExist() {
|
42
|
+
Flash.transferFromCookies();
|
43
|
+
assertHashEquals({}, Flash.data);
|
44
|
+
}
|
45
|
+
|
46
|
+
function test_transferFromCookies_setsFlashDataToEmptyHash_whenCookieIsEmpty() {
|
47
|
+
setUpCookieWithData("");
|
48
|
+
Flash.transferFromCookies();
|
49
|
+
assertHashEquals({}, Flash.data);
|
50
|
+
}
|
51
|
+
|
52
|
+
function test_transferFromCookies_removeFlashCookie() {
|
53
|
+
setUpCookieWithData({
|
54
|
+
'error': "The Error",
|
55
|
+
'notice': "The Notice"
|
56
|
+
});
|
57
|
+
Flash.transferFromCookies();
|
58
|
+
assertNull(Cookie.get("flash"));
|
59
|
+
}
|
60
|
+
|
61
|
+
// how do I test this??
|
62
|
+
function test_transferFromCookies_whenValueContainsAPlusSign() {
|
63
|
+
setUpCookieWithData({
|
64
|
+
'notice': "Book+%2B+Gift+Box"
|
65
|
+
});
|
66
|
+
Flash.transferFromCookies();
|
67
|
+
assertEquals("Book + Gift Box", Cookie.get("notice"));
|
68
|
+
}
|
69
|
+
|
70
|
+
function test_writeDataTo_whenThereIsACookieValue() {
|
71
|
+
setUpCookieWithData({
|
72
|
+
'error': "This+is%20An+Error"
|
73
|
+
});
|
74
|
+
Flash.transferFromCookies();
|
75
|
+
Flash.writeDataTo('error', content);
|
76
|
+
|
77
|
+
assertEquals("This is An Error", content.html());
|
78
|
+
}
|
79
|
+
|
80
|
+
function test_writeDataTo_whenThereIsNoCookieValue() {
|
81
|
+
setUpCookieWithData({});
|
82
|
+
Flash.transferFromCookies();
|
83
|
+
Flash.writeDataTo('notice', content);
|
84
|
+
|
85
|
+
assertEquals("", content.html());
|
86
|
+
}
|
87
|
+
|
88
|
+
function test_writeDataTo_whenPassedAnElementId() {
|
89
|
+
setUpCookieWithData({
|
90
|
+
'error': "This+is%20An+Error"
|
91
|
+
});
|
92
|
+
|
93
|
+
Flash.transferFromCookies();
|
94
|
+
Flash.writeDataTo('error', '#content');
|
95
|
+
|
96
|
+
assertEquals("This is An Error", content.html());
|
97
|
+
}
|
98
|
+
|
99
|
+
function setUpCookieWithData(values) {
|
100
|
+
Cookie.set('flash', JSON.stringify(values));
|
101
|
+
}
|
102
|
+
|
103
|
+
</script>
|
104
|
+
|
105
|
+
</head>
|
106
|
+
|
107
|
+
<body>
|
108
|
+
<div id="fixture">
|
109
|
+
<div id="content"></div>
|
110
|
+
</div>
|
111
|
+
</body>
|
112
|
+
</html>
|