cells 3.11.3 → 4.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +15 -13
  4. data/Appraisals +23 -0
  5. data/CHANGES.md +20 -3
  6. data/Gemfile +5 -7
  7. data/README.md +317 -236
  8. data/Rakefile +1 -1
  9. data/TODO.md +3 -0
  10. data/cells.gemspec +19 -28
  11. data/gemfiles/rails3.2.gemfile +14 -0
  12. data/gemfiles/rails4.0.gemfile +14 -0
  13. data/gemfiles/rails4.1.gemfile +15 -0
  14. data/gemfiles/rails4.2.gemfile +14 -0
  15. data/lib/cell.rb +28 -21
  16. data/lib/cell/caching.rb +10 -22
  17. data/lib/cell/caching/notification.rb +15 -0
  18. data/lib/cell/concept.rb +4 -69
  19. data/lib/cell/development.rb +11 -0
  20. data/lib/{cells → cell}/engines.rb +1 -1
  21. data/lib/cell/layout.rb +20 -0
  22. data/lib/cell/partial.rb +17 -0
  23. data/lib/cell/{base/prefixes.rb → prefixes.rb} +1 -1
  24. data/lib/cell/rails.rb +58 -50
  25. data/lib/cell/railtie.rb +60 -0
  26. data/lib/cell/{base/self_contained.rb → self_contained.rb} +1 -1
  27. data/lib/cell/templates.rb +60 -0
  28. data/lib/cell/test_case.rb +4 -162
  29. data/lib/cell/testing.rb +15 -0
  30. data/lib/cell/twin.rb +11 -29
  31. data/lib/cell/version.rb +10 -0
  32. data/lib/cell/view_model.rb +196 -88
  33. data/lib/cells.rb +1 -20
  34. data/lib/rails/generators/cell/cell_generator.rb +43 -0
  35. data/lib/rails/generators/cell/templates/cell.rb.erb +8 -0
  36. data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.erb +0 -0
  37. data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.haml +0 -0
  38. data/lib/rails/generators/cell/templates/view.slim +2 -0
  39. data/lib/rails/generators/concept/concept_generator.rb +38 -0
  40. data/lib/{generators/templates/concept/cell.rb → rails/generators/concept/templates/concept.rb.erb} +2 -2
  41. data/lib/{generators → rails/generators/concept}/templates/view.erb +0 -0
  42. data/lib/{generators → rails/generators/concept}/templates/view.haml +0 -0
  43. data/lib/rails/generators/concept/templates/view.slim +2 -0
  44. data/lib/rails/generators/test_unit/cell/cell_generator.rb +21 -0
  45. data/lib/{generators/templates/cell_test.rb → rails/generators/test_unit/cell/templates/unit_test.rb.erb} +3 -3
  46. data/lib/rails/generators/test_unit/concept/concept_generator.rb +21 -0
  47. data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +11 -0
  48. data/lib/{cells → tasks}/cells.rake +0 -0
  49. data/test/builder_test.rb +58 -0
  50. data/test/caching_test.rb +298 -0
  51. data/test/cell_benchmark.rb +32 -0
  52. data/test/cell_generator_test.rb +51 -82
  53. data/test/cell_test.rb +8 -23
  54. data/test/concept_generator_test.rb +22 -13
  55. data/test/concept_test.rb +41 -75
  56. data/test/dummy/app/views/musician/hamlet.html.erb +1 -0
  57. data/test/dummy/config/application.rb +21 -8
  58. data/test/{app/cells/bassist/play.html.erb → fixtures/bassist/play.erb} +0 -0
  59. data/test/fixtures/concepts/record/views/layout.erb +1 -0
  60. data/test/{app → fixtures}/concepts/record/views/show.erb +0 -0
  61. data/test/{app → fixtures}/concepts/record/views/song.erb +0 -0
  62. data/test/fixtures/inherit_views_test/popper/tap.erb +1 -0
  63. data/test/fixtures/inherit_views_test/tapper/play.erb +1 -0
  64. data/test/fixtures/inherit_views_test/tapper/tap.erb +1 -0
  65. data/test/fixtures/partial_test/with_partial/show.erb +1 -0
  66. data/test/fixtures/partials/_show.html.erb +1 -0
  67. data/test/fixtures/partials/_show.xml.erb +1 -0
  68. data/test/fixtures/song/ivar.erb +1 -0
  69. data/test/fixtures/song/show.erb +1 -0
  70. data/test/fixtures/song/with_erb.erb +4 -0
  71. data/test/fixtures/song/with_html.erb +1 -0
  72. data/test/fixtures/song/with_locals.erb +2 -0
  73. data/test/fixtures/song_with_layout/happy.erb +1 -0
  74. data/test/fixtures/song_with_layout/merry.erb +1 -0
  75. data/test/fixtures/song_with_layout/show.erb +1 -0
  76. data/test/fixtures/song_with_layout/show_with_layout.erb +1 -0
  77. data/test/fixtures/templates_caching_test/song/show.erb +1 -0
  78. data/test/fixtures/url_helper_test/song/edit.erb +8 -0
  79. data/test/fixtures/url_helper_test/song/with_block.erb +2 -0
  80. data/test/fixtures/url_helper_test/song/with_capture.erb +4 -0
  81. data/test/fixtures/url_helper_test/song/with_content_tag.erb +6 -0
  82. data/test/fixtures/url_helper_test/song/with_form_for_block.erb +3 -0
  83. data/test/fixtures/url_helper_test/song/with_link_to.erb +3 -0
  84. data/test/layout_test.rb +57 -0
  85. data/test/partial_test.rb +27 -0
  86. data/test/prefixes_test.rb +36 -10
  87. data/test/public_test.rb +42 -0
  88. data/test/rails_extensions_test.rb +51 -0
  89. data/test/render_test.rb +103 -0
  90. data/test/templates_test.rb +45 -0
  91. data/test/test_case_test.rb +21 -122
  92. data/test/test_helper.rb +37 -33
  93. data/test/twin_test.rb +3 -7
  94. data/test/url_helper_test.rb +89 -0
  95. metadata +92 -357
  96. data/gemfiles/Gemfile.rails3-0 +0 -7
  97. data/gemfiles/Gemfile.rails3-1 +0 -7
  98. data/gemfiles/Gemfile.rails3-2 +0 -7
  99. data/gemfiles/Gemfile.rails4-0 +0 -12
  100. data/gemfiles/Gemfile.rails4-1 +0 -12
  101. data/lib/cell/base.rb +0 -82
  102. data/lib/cell/base/view.rb +0 -15
  103. data/lib/cell/builder.rb +0 -71
  104. data/lib/cell/deprecations.rb +0 -41
  105. data/lib/cell/dsl.rb +0 -7
  106. data/lib/cell/rack.rb +0 -32
  107. data/lib/cell/rails/helper_api.rb +0 -37
  108. data/lib/cell/rails/view_model.rb +0 -159
  109. data/lib/cell/rails3_0_strategy.rb +0 -82
  110. data/lib/cell/rails3_1_strategy.rb +0 -40
  111. data/lib/cell/rails4_0_strategy.rb +0 -39
  112. data/lib/cell/rails4_1_strategy.rb +0 -40
  113. data/lib/cell/rendering.rb +0 -109
  114. data/lib/cells/rails.rb +0 -86
  115. data/lib/cells/railtie.rb +0 -38
  116. data/lib/cells/version.rb +0 -3
  117. data/lib/generators/USAGE +0 -30
  118. data/lib/generators/cells/base.rb +0 -22
  119. data/lib/generators/cells/cell_generator.rb +0 -15
  120. data/lib/generators/cells/view_generator.rb +0 -18
  121. data/lib/generators/erb/cell_generator.rb +0 -15
  122. data/lib/generators/erb/concept_generator.rb +0 -17
  123. data/lib/generators/haml/cell_generator.rb +0 -17
  124. data/lib/generators/haml/concept_generator.rb +0 -17
  125. data/lib/generators/rails/cell_generator.rb +0 -16
  126. data/lib/generators/rails/concept_generator.rb +0 -16
  127. data/lib/generators/slim/cell_generator.rb +0 -17
  128. data/lib/generators/templates/cell.rb +0 -9
  129. data/lib/generators/templates/view.slim +0 -4
  130. data/lib/generators/test_unit/cell_generator.rb +0 -14
  131. data/lib/generators/trailblazer/base.rb +0 -21
  132. data/lib/generators/trailblazer/view_generator.rb +0 -18
  133. data/test/app/cells/album/views/cover.haml +0 -1
  134. data/test/app/cells/bad_guitarist/_dii.html.erb +0 -1
  135. data/test/app/cells/bad_guitarist_cell.rb +0 -2
  136. data/test/app/cells/bassist/_dii.html.erb +0 -1
  137. data/test/app/cells/bassist/ahem.html.erb +0 -1
  138. data/test/app/cells/bassist/compose.html.erb +0 -1
  139. data/test/app/cells/bassist/contact_form.html.erb +0 -1
  140. data/test/app/cells/bassist/form_for.erb +0 -3
  141. data/test/app/cells/bassist/form_for_in_haml.haml +0 -2
  142. data/test/app/cells/bassist/jam.html.erb +0 -3
  143. data/test/app/cells/bassist/play.js.erb +0 -1
  144. data/test/app/cells/bassist/pose.html.erb +0 -1
  145. data/test/app/cells/bassist/promote.html.erb +0 -1
  146. data/test/app/cells/bassist/provoke.html.erb +0 -1
  147. data/test/app/cells/bassist/shout.html.erb +0 -1
  148. data/test/app/cells/bassist/sing.html.haml +0 -1
  149. data/test/app/cells/bassist/slap.html.erb +0 -1
  150. data/test/app/cells/bassist/yell.en.html.erb +0 -1
  151. data/test/app/cells/bassist_cell.rb +0 -25
  152. data/test/app/cells/club_security.rb +0 -2
  153. data/test/app/cells/club_security/guard/help.html.erb +0 -1
  154. data/test/app/cells/club_security/guard_cell.rb +0 -6
  155. data/test/app/cells/club_security/medic/help.html.erb +0 -1
  156. data/test/app/cells/club_security/medic_cell.rb +0 -8
  157. data/test/app/cells/layouts/b.erb +0 -1
  158. data/test/app/cells/layouts/metal.html.erb +0 -1
  159. data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +0 -5
  160. data/test/app/cells/shouter/sing.html.erb +0 -1
  161. data/test/app/cells/song/dashboard.haml +0 -7
  162. data/test/app/cells/song/details.html.haml +0 -1
  163. data/test/app/cells/song/info.html.haml +0 -1
  164. data/test/app/cells/song/lyrics.html.haml +0 -6
  165. data/test/app/cells/song/plays.haml +0 -1
  166. data/test/app/cells/song/scale.haml +0 -1
  167. data/test/app/cells/song/show.html.haml +0 -3
  168. data/test/app/cells/song/title.html.haml +0 -1
  169. data/test/app/cells/trumpeter/promote.html.erb +0 -1
  170. data/test/app/cells/trumpeter_cell.rb +0 -8
  171. data/test/app/cells/view_model_test/comments/show.haml +0 -7
  172. data/test/app/concepts/record/views/layout.haml +0 -2
  173. data/test/app/views/shared/_dong.html.erb +0 -1
  174. data/test/cell_module_test.rb +0 -170
  175. data/test/cells_module_test.rb +0 -27
  176. data/test/deprecations_test.rb +0 -101
  177. data/test/dummy/app/helpers/application_helper.rb +0 -2
  178. data/test/dummy/app/views/musician/hamlet.html.haml +0 -1
  179. data/test/dummy/config/environments/development.rb +0 -16
  180. data/test/dummy/config/environments/production.rb +0 -46
  181. data/test/dummy/config/environments/test.rb +0 -33
  182. data/test/dummy/db/test.sqlite3 +0 -0
  183. data/test/dummy/label/app/cells/label/show.erb +0 -1
  184. data/test/dummy/label/app/cells/label_cell.rb +0 -5
  185. data/test/dummy/label/label.gemspec +0 -20
  186. data/test/dummy/label/lib/label.rb +0 -4
  187. data/test/dummy/label/lib/label/version.rb +0 -3
  188. data/test/dummy/public/404.html +0 -26
  189. data/test/dummy/public/422.html +0 -26
  190. data/test/dummy/public/500.html +0 -26
  191. data/test/dummy/public/favicon.ico +0 -0
  192. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  193. data/test/helper_test.rb +0 -81
  194. data/test/rack_test.rb +0 -32
  195. data/test/rails/asset_pipeline_test.rb +0 -20
  196. data/test/rails/caching_test.rb +0 -456
  197. data/test/rails/cells_test.rb +0 -119
  198. data/test/rails/forms_test.rb +0 -75
  199. data/test/rails/integration_test.rb +0 -299
  200. data/test/rails/render_test.rb +0 -189
  201. data/test/rails/view_model_test.rb +0 -226
  202. data/test/rails/view_test.rb +0 -49
  203. data/test/rails_helper_api_test.rb +0 -58
  204. data/test/self_contained_test.rb +0 -31
@@ -1,3 +0,0 @@
1
- module Label
2
- VERSION = "0.0.1"
3
- end
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The page you were looking for doesn't exist (404)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/404.html -->
21
- <div class="dialog">
22
- <h1>The page you were looking for doesn't exist.</h1>
23
- <p>You may have mistyped the address or the page may have moved.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The change you wanted was rejected (422)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/422.html -->
21
- <div class="dialog">
22
- <h1>The change you wanted was rejected.</h1>
23
- <p>Maybe you tried to change something you didn't have access to.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/500.html -->
21
- <div class="dialog">
22
- <h1>We're sorry, but something went wrong.</h1>
23
- <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
- </div>
25
- </body>
26
- </html>
File without changes
File without changes
@@ -1,81 +0,0 @@
1
- require 'test_helper'
2
- require 'app/cells/club_security'
3
- require 'app/cells/club_security/guard_cell'
4
- require 'app/cells/club_security/medic_cell'
5
-
6
- module StringHelper
7
- def pick; "plong"; end
8
- end
9
-
10
- class DrummerCell < Cell::Rails
11
- helper StringHelper
12
-
13
- def assist
14
- render :inline => "<%= pick %>"
15
- end
16
- end
17
-
18
-
19
- class HelperTest < MiniTest::Spec
20
- include Cell::TestCase::TestMethods
21
-
22
- describe "a cell with included helper modules" do
23
- class SongCell < Cell::Rails
24
- include ActionView::Helpers::TagHelper # for Rails 3.0.
25
- include ActionView::Helpers::AssetTagHelper
26
-
27
- def show
28
- controller.config.relative_url_root = "" if Cell.rails_version.~("3.0")
29
- image_tag("no-more-the-meek.jpg")
30
- end
31
- end
32
-
33
- it "allows using helpers using #controller on instance level" do
34
- alt = "No-more-the-meek"
35
- alt = "No more the meek" if Cell.rails_version >= "4.0"
36
- assert_equal "<img alt=\"#{alt}\" src=\"/images/no-more-the-meek.jpg\" />", render_cell("helper_test/song", :show)
37
- end
38
- end
39
-
40
-
41
- describe "a cell view" do
42
- it "have access to all helpers" do
43
- BassistCell.class_eval do
44
- def assist
45
- render :inline => "<%= submit_tag %>"
46
- end
47
- end
48
-
49
- assert_equal "<input name=\"commit\" type=\"submit\" value=\"Save changes\" />", render_cell(:bassist, :assist)
50
- end
51
-
52
- it "have access to methods declared with #helper_method" do
53
- BassistCell.class_eval do
54
- def help; "Great!"; end
55
- helper_method :help
56
-
57
- def assist
58
- render :inline => "<%= help %>"
59
- end
60
- end
61
-
62
- assert_equal "Great!", render_cell(:bassist, :assist)
63
- end
64
-
65
- it "have access to methods provided by helper" do
66
- assert_equal "plong", render_cell(:drummer, :assist)
67
- end
68
-
69
- it "mix in required helpers, only" do
70
- assert_equal "false true", render_cell(:"club_security/medic", :help)
71
- assert_equal "true false", render_cell(:"club_security/guard", :help)
72
- end
73
-
74
- it "include helpers only once" do
75
- assert_equal "false true", render_cell(:"club_security/medic", :help)
76
- assert_equal "true false", render_cell(:"club_security/guard", :help)
77
- assert_equal "false true", render_cell(:"club_security/medic", :help)
78
- assert_equal "true false", render_cell(:"club_security/guard", :help)
79
- end
80
- end
81
- end
@@ -1,32 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RackTest < MiniTest::Spec
4
- class BassistCell < Cell::Rack
5
- def play
6
- render :text => request.class
7
- end
8
-
9
- def sing
10
- render :text => session[:what]
11
- end
12
- end
13
-
14
- describe "Cell::Rack" do
15
- before do
16
- @request = ActionDispatch::TestRequest.new
17
- end
18
-
19
- it "allows accessing the request object" do
20
- assert_equal "ActionDispatch::TestRequest", BassistCell.new(@request).render_state(:play)
21
- end
22
-
23
- it "allows accessing the session object" do
24
- @request.session[:what] = "Yo!"
25
- assert_equal "Yo!", BassistCell.new(@request).render_state(:sing)
26
- end
27
-
28
- it "works with #render_cell_for" do
29
- assert_equal "ActionDispatch::TestRequest", Cell::Rack.render_cell_for("rack_test/bassist", :play, @request)
30
- end
31
- end
32
- end
@@ -1,20 +0,0 @@
1
- require "test_helper"
2
- require "capybara/rails"
3
-
4
- # This blog post helped so much: http://rakeroutes.com/blog/write-a-gem-for-the-rails-asset-pipeline/
5
- # Thanks, Stephen!!! :)
6
-
7
- if Cell.rails_version >= 3.1
8
-
9
- class AssetPipelineTest < MiniTest::Spec
10
- include Capybara::DSL
11
- register_spec_type(/integration$/, self)
12
-
13
- it "what" do
14
- visit "/assets/application.js"
15
- page.text.must_include 'var Album = {};'
16
- page.text.must_include 'var Songs = [];'
17
- end
18
- end
19
-
20
- end
@@ -1,456 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'test_helper'
3
-
4
- class DirectorCell < Cell::Rails
5
- attr_reader :count
6
-
7
- def initialize(*)
8
- super
9
- @count = 0
10
- end
11
-
12
- cache :tock
13
- def tock
14
- @count += 1
15
- render :text => @count
16
- end
17
-
18
- cache :utf8
19
- def utf8
20
- render :text => "æøå" # or any other UTF-8 string
21
- end
22
- end
23
-
24
- class CachingUnitTest < MiniTest::Spec
25
- include Cell::TestCase::TestMethods
26
-
27
- before :each do
28
- ActionController::Base.cache_store.clear
29
- ActionController::Base.perform_caching = true
30
- @cell = cell(:director)
31
- @class = @cell.class
32
- end
33
-
34
-
35
- describe ".state_cache_key" do
36
- it "accept state only" do
37
- assert_equal "cells/director/count/", @class.state_cache_key(:count)
38
- end
39
-
40
- it "accept hash as key parts" do
41
- if Cell.rails_version >= ("4.0")
42
- assert_equal "cells/director/count/b/2/a/1", @class.state_cache_key(:count, :b=>2, :a=>1)
43
- else
44
- assert_equal "cells/director/count/a=1&b=2", @class.state_cache_key(:count, :b=>2, :a=>1)
45
- end
46
- end
47
-
48
- it "accept array as key parts" do
49
- assert_equal "cells/director/count/1/2/3", @class.state_cache_key(:count, [1,2,3])
50
- end
51
-
52
- it "accept string as key parts" do
53
- assert_equal "cells/director/count/1/2", @class.state_cache_key(:count, "1/2")
54
- end
55
-
56
- it "accept nil as key parts" do
57
- assert_equal "cells/director/count/", @class.state_cache_key(:count, nil)
58
- end
59
- end
60
-
61
-
62
- describe "#state_cached?" do
63
- it "return true for cached" do
64
- assert @cell.send :state_cached?, :tock
65
- end
66
-
67
- it "return false otherwise" do
68
- assert_not @cell.send :state_cached?, :sing
69
- end
70
- end
71
-
72
-
73
- describe "#cache?" do
74
- it "return true for cached" do
75
- assert @cell.cache?(:tock)
76
- end
77
-
78
- it "return false otherwise" do
79
- assert_not @cell.cache?(:sing)
80
- end
81
-
82
- describe "perform_caching turned off" do
83
- after :each do
84
- ::ActionController::Base.perform_caching = true
85
- end
86
-
87
- it "always return false if caching turned-off" do
88
- ::ActionController::Base.perform_caching = false
89
- assert_not @cell.cache?(:count)
90
- assert_not @cell.cache?(:sing)
91
- end
92
- end
93
-
94
- describe ".cache_store" do
95
- it "return Rails cache store per default" do
96
- assert_equal ActionController::Base.cache_store, DirectorCell.cache_store
97
- end
98
-
99
- describe "Cell::Base" do
100
- before :each do
101
- @class = Class.new(Cell::Base)
102
- @cell = @class.new
103
- end
104
-
105
- describe "#cache_store" do
106
- it "be setable from the outside" do
107
- assert_equal nil, @cell.cache_store
108
- @cell.cache_store = Object
109
- assert_equal Object, @cell.cache_store
110
- end
111
- end
112
-
113
- describe "#cache_configured?" do
114
- it "be setable from the outside" do
115
- assert_equal nil, @cell.cache_configured?
116
- @cell.cache_configured = true
117
- assert_equal true, @cell.cache_configured?
118
- end
119
- end
120
-
121
- end
122
- end
123
- end
124
-
125
-
126
- describe ".expire_cache_key" do
127
- before :each do
128
- @key = @class.state_cache_key(:tock)
129
- puts "====== key is #{@key}"
130
- assert_equal "1", render_cell(:director, :tock)
131
- assert_equal "1", @class.cache_store.read(@key)
132
- end
133
-
134
- it "delete the state from cache" do
135
- @class.expire_cache_key(@key)
136
- assert_not @class.cache_store.read(@key)
137
- end
138
-
139
- it "be available in controllers for sweepers" do
140
- MusicianController.new.expire_cell_state(DirectorCell, :tock)
141
- assert_not @class.cache_store.read(@key)
142
- end
143
-
144
- it "accept cache options" do
145
- key = @class.state_cache_key(:tock, :volume => 9)
146
- assert Cell::Rails.cache_store.write(key, 'ONE!')
147
-
148
- MusicianController.new.expire_cell_state(DirectorCell, :tock, :volume => 9)
149
- assert_equal "1", @class.cache_store.read(@key)
150
- assert_not ::Cell::Rails.cache_store.read(key)
151
- end
152
- end
153
- end
154
-
155
- class CachingFunctionalTest < MiniTest::Spec
156
- include Cell::TestCase::TestMethods
157
-
158
- before :each do
159
- ActionController::Base.cache_store.clear
160
- ActionController::Base.perform_caching = true
161
- #setup # from Cell::TestCase::TestMethods
162
-
163
- @cell = cell(:director)
164
- @class = @cell.class
165
- end
166
-
167
- describe "turned off" do
168
- it "not invoke caching" do
169
- ::ActionController::Base.perform_caching = false
170
-
171
- assert_equal "1", @cell.render_state(:tock)
172
- assert_equal "2", @cell.render_state(:tock)
173
- end
174
- end
175
-
176
-
177
- describe "without options" do
178
- it "cache forever" do
179
- @class.cache :tock
180
- assert_equal "1", render_cell(:director, :tock)
181
- assert_equal "1", render_cell(:director, :tock)
182
- end
183
- end
184
-
185
-
186
- describe "uncached states" do
187
- it "not cache at all" do
188
- @class.class_eval do
189
- def dictate
190
- @count ||= 0
191
- render :text => (@count += 1)
192
- end
193
- end
194
-
195
- assert_equal "1", @cell.render_state(:dictate)
196
- assert_equal "2", @cell.render_state(:dictate)
197
- end
198
- end
199
-
200
- describe "with versioner" do
201
- before do
202
- @class.class_eval do
203
- def count(i)
204
- render :text => i
205
- end
206
- end
207
- end
208
-
209
- it "compute the key with a block receiving state-args" do
210
- @class.cache :count do |int|
211
- (int % 2)==0 ? {:count => "even"} : {:count => "odd"}
212
- end
213
- # example cache key: cells/director/count/count=odd
214
-
215
- assert_equal "1", render_cell(:director, :count, 1)
216
- assert_equal "2", render_cell(:director, :count, 2)
217
- assert_equal "1", render_cell(:director, :count, 3)
218
- assert_equal "2", render_cell(:director, :count, 4)
219
- end
220
-
221
- it "compute the key with an instance method" do
222
- @class.cache :count, :version
223
- @class.class_eval do
224
- private
225
- def version(int)
226
- (int % 2)==0 ? {:count => "even"} : {:count => "odd"}
227
- end
228
- end
229
-
230
- assert_equal "1", render_cell(:director, :count, 1)
231
- assert_equal "2", render_cell(:director, :count, 2)
232
- assert_equal "1", render_cell(:director, :count, 3)
233
- assert_equal "2", render_cell(:director, :count, 4)
234
- end
235
-
236
- it "allows returning strings, too" do
237
- @class.cache :count do |int|
238
- (int % 2)==0 ? "even" : "odd"
239
- end
240
-
241
- assert_equal "1", render_cell(:director, :count, 1)
242
- assert_equal "2", render_cell(:director, :count, 2)
243
- assert_equal "1", render_cell(:director, :count, 3)
244
- assert_equal "2", render_cell(:director, :count, 4)
245
- end
246
-
247
- it "be able to use caching conditionally" do
248
- @class.cache :count, :if => lambda { |int| (int % 2) != 0 }
249
-
250
- assert_equal "1", render_cell(:director, :count, 1)
251
- assert_equal "2", render_cell(:director, :count, 2)
252
- assert_equal "1", render_cell(:director, :count, 3)
253
- assert_equal "4", render_cell(:director, :count, 4)
254
- end
255
-
256
- it "cache conditionally with an instance method" do
257
- @class.cache :count, :if => :odd?
258
- @class.class_eval do
259
- def odd?(int)
260
- (int % 2) != 0
261
- end
262
- end
263
-
264
- assert_equal "1", render_cell(:director, :count, 1)
265
- assert_equal "2", render_cell(:director, :count, 2)
266
- assert_equal "1", render_cell(:director, :count, 3)
267
- assert_equal "4", render_cell(:director, :count, 4)
268
- end
269
-
270
- it "allow using a different cache store" do
271
- class BassistCell < Cell::Base
272
- cache :play
273
-
274
- def play(song)
275
- render :text => song
276
- end
277
- end
278
-
279
- @cell = BassistCell.new
280
-
281
- assert_equal "New Years", @cell.render_state(:play, "New Years")
282
- assert_equal "Liar", @cell.render_state(:play, "Liar")
283
-
284
- @cell.cache_configured = true
285
- @cell.cache_store = ActiveSupport::Cache::MemoryStore.new
286
-
287
- assert_equal "New Years", @cell.render_state(:play, "New Years")
288
- assert_equal "New Years", @cell.render_state(:play, "Liar")
289
- end
290
- end
291
-
292
- unless ::ActionPack::VERSION::MAJOR == 3 and ::ActionPack::VERSION::MINOR >= 2 # bug in 3.2.
293
- describe "utf-8" do
294
- before do
295
- @key = @class.state_cache_key(:utf8)
296
- end
297
-
298
- it "have the correct encoding when reading from cache" do
299
- assert_equal "UTF-8", render_cell(:director, :utf8).encoding.to_s
300
- assert_equal "UTF-8", @class.cache_store.read(@key).encoding.to_s
301
- end
302
- end
303
- end
304
-
305
-
306
- def cache_store(&block)
307
- Object.new.instance_eval do
308
- @block = block
309
- def fetch(key, options)
310
- @block.call(key, options)
311
- end
312
- self
313
- end
314
- end
315
-
316
- def cached(&block)
317
- cs = cache_store(&block)
318
-
319
- @cell.instance_eval do
320
- def count(*)
321
- "this should never be returned!"
322
- end
323
-
324
- @cache_store = cs
325
- def cache_store
326
- @cache_store
327
- end
328
- end
329
-
330
- @cell
331
- end
332
-
333
- # ::cache
334
-
335
- describe "with state name, only" do
336
- it do
337
- @class.cache :count
338
-
339
- cached do |key, options|
340
- if options == {} and key == "cells/director/count/"
341
- "cached!"
342
- end
343
- end.render_state(:count, 1, 2, 3).must_equal "cached!"
344
- end
345
- end
346
-
347
- describe "with cache store options" do
348
- it do
349
- @class.cache :count, :expires_in => 10.minutes
350
-
351
- cached do |key, options|
352
- if options == {:expires_in => 600}
353
- "cached!"
354
- end
355
- end.render_state(:count, 1, 2, 3).must_equal "cached!"
356
- end
357
- end
358
-
359
- describe "with versioner block" do
360
- it do
361
- @class.cache :count do "v3" end
362
-
363
- cached do |key, options|
364
- if options == {} and key == "cells/director/count/v3"
365
- "cached!"
366
- end
367
- end.render_state(:count).must_equal "cached!"
368
- end
369
-
370
- it "is executed in instance context" do
371
- @class.cache :count do version end
372
-
373
- @cell.instance_eval do
374
- def version; "v3"; end
375
- end
376
-
377
- cached do |key, options|
378
- if options == {} and key == "cells/director/count/v3"
379
- "cached!"
380
- end
381
- end.render_state(:count).must_equal "cached!"
382
- end
383
- end
384
-
385
- describe "with store options and versioner block" do
386
- it do
387
- @class.cache :count, :expires_in => 10.minutes do "v1" end
388
-
389
- cached do |key, options|
390
- if options == {:expires_in => 600} and key == "cells/director/count/v1"
391
- "cached!"
392
- end
393
- end.render_state(:count, 1, 2, 3).must_equal "cached!"
394
- end
395
- end
396
-
397
- describe "lambda and options as options" do
398
- it "runs lamda at render-time" do
399
- @class.cache :count, :expires_in => 9, :tags => lambda { |one, two, three| "#{one},#{two},#{three}" }
400
-
401
- cached do |key, options|
402
- if options == {:expires_in => 9, :tags => "1,2,3"}
403
- "cached!"
404
- end
405
- end.render_state(:count, 1, 2, 3).must_equal "cached!"
406
- end
407
- end
408
- end
409
-
410
-
411
- class CachingInheritanceTest < CachingFunctionalTest
412
- class DirectorCell < ::DirectorCell
413
- cache :count, :expires_in => 10.minutes do
414
- "v1"
415
- end
416
- end
417
-
418
- class DirectorsSonCell < DirectorCell
419
- end
420
-
421
- class DirectorsDaughterCell < ::DirectorCell
422
- cache :count, :expires_in => 9.minutes do
423
- "v2"
424
- end
425
- end
426
-
427
- it do
428
- @cell = DirectorCell.new(@controller)
429
-
430
- cached do |key, options|
431
- if options == {:expires_in => 600} and key == "cells/caching_inheritance_test/director/count/v1"
432
- "cached!"
433
- end
434
- end.render_state(:count).must_equal "cached!"
435
- end
436
-
437
- it do
438
- @cell = DirectorsDaughterCell.new(@controller)
439
-
440
- cached do |key, options|
441
- if options == {:expires_in => 540} and key == "cells/caching_inheritance_test/directors_daughter/count/v2"
442
- "cached!"
443
- end
444
- end.render_state(:count).must_equal "cached!"
445
- end
446
-
447
- it do
448
- @cell = DirectorsSonCell.new(@controller)
449
-
450
- cached do |key, options|
451
- if options == {:expires_in => 600} and key == "cells/caching_inheritance_test/directors_son/count/v1"
452
- "cached!"
453
- end
454
- end.render_state(:count).must_equal "cached!"
455
- end
456
- end