cells 3.8.6 → 3.8.7

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.
@@ -1,22 +1,22 @@
1
1
  require 'test_helper'
2
2
 
3
- class CellsModuleTest < ActiveSupport::TestCase
4
- context "Cells" do
5
- context "view_paths" do
6
- setup do
3
+ class CellsModuleTest < MiniTest::Spec
4
+ describe "Cells" do
5
+ describe "#view_paths" do
6
+ before do
7
7
  @old_view_paths = Cell::Rails.view_paths.clone
8
8
  end
9
9
 
10
- teardown do
10
+ after do
11
11
  Cell::Rails.view_paths = @old_view_paths
12
12
  end
13
13
 
14
- should "provide .setup" do
14
+ it "provide .before" do
15
15
  Cells.setup do |c|
16
16
  c.append_view_path "/road/to/nowhere"
17
17
  end
18
18
 
19
- if Cell.rails3_2_or_more?
19
+ if Cell.rails3_2_or_more? or Cell.rails4_0_or_more?
20
20
  assert_equal "/road/to/nowhere", Cell::Rails.view_paths.paths.last.to_s
21
21
  else
22
22
  assert_equal "/road/to/nowhere", Cell::Rails.view_paths.last.to_s
@@ -5,11 +5,11 @@ class SongwriterCell < BassistCell
5
5
  end
6
6
 
7
7
 
8
- class DeprecationsTest < ActiveSupport::TestCase
8
+ class DeprecationsTest < MiniTest::Spec
9
9
  include Cell::TestCase::TestMethods
10
10
 
11
- context "#render_state" do
12
- should "work without args and provide #options" do
11
+ describe "#render_state" do
12
+ it "work without args and provide #options" do
13
13
  SongwriterCell.class_eval do
14
14
  def listen
15
15
  render :text => options[:note]
@@ -19,7 +19,7 @@ class DeprecationsTest < ActiveSupport::TestCase
19
19
  end
20
20
 
21
21
  include ActiveSupport::Testing::Deprecation
22
- should "mark @options as deprecated, but still work" do
22
+ it "mark @options as deprecated, but still work" do
23
23
  res = nil
24
24
  assert_deprecated do
25
25
  res = cell(:songwriter, :song => "Lockdown").instance_eval do
@@ -30,8 +30,8 @@ class DeprecationsTest < ActiveSupport::TestCase
30
30
  end
31
31
  end
32
32
 
33
- context "render_cell_for" do
34
- should "make options available in #options if not receiving state-args" do
33
+ describe "render_cell_for" do
34
+ it "make options available in #options if not receiving state-args" do
35
35
  SongwriterCell.class_eval do
36
36
  def listen
37
37
  render :text => options[:note]
@@ -40,7 +40,7 @@ class DeprecationsTest < ActiveSupport::TestCase
40
40
  assert_equal "C-minor", Cell::Rails.render_cell_for(:songwriter, :listen, @controller, :note => "C-minor")
41
41
  end
42
42
 
43
- should "pass options as state-args and still set #options otherwise" do
43
+ it "pass options as state-args and still set #options otherwise" do
44
44
  SongwriterCell.class_eval do
45
45
  def listen(args)
46
46
  render :text => args[:note] + options[:note].to_s
@@ -50,32 +50,32 @@ class DeprecationsTest < ActiveSupport::TestCase
50
50
  end
51
51
  end
52
52
 
53
- context "#state_accepts_args?" do
54
- should "be false if state doesn't want args" do
53
+ describe "#state_accepts_args?" do
54
+ it "be false if state doesn't want args" do
55
55
  assert_not cell(:songwriter).state_accepts_args?(:play)
56
56
  end
57
57
 
58
- should "be true for one arg" do
58
+ it "be true for one arg" do
59
59
  assert(cell(:songwriter) do
60
60
  def listen(args) end
61
61
  end.state_accepts_args?(:listen))
62
62
  end
63
63
 
64
- should "be true for multiple arg" do
64
+ it "be true for multiple arg" do
65
65
  assert(cell(:songwriter) do
66
66
  def listen(what, where) end
67
67
  end.state_accepts_args?(:listen))
68
68
  end
69
69
 
70
- should "be true for multiple arg with defaults" do
70
+ it "be true for multiple arg with defaults" do
71
71
  assert(cell(:songwriter) do
72
72
  def listen(what, where="") end
73
73
  end.state_accepts_args?(:listen))
74
74
  end
75
75
  end
76
76
 
77
- context ".cache" do
78
- should "still be able to use options in the block" do
77
+ describe ".cache" do
78
+ it "still be able to use options in the block" do
79
79
  SongwriterCell.class_eval do
80
80
  def count(args)
81
81
  render :text => args[:int]
@@ -19,6 +19,7 @@ Dummy::Application.configure do
19
19
 
20
20
  # Disable request forgery protection in test environment
21
21
  config.action_controller.allow_forgery_protection = false
22
+ config.secret_key_base = "yo"
22
23
 
23
24
  # Tell Action Mailer not to deliver emails to the real world.
24
25
  # The :test delivery method accumulates sent emails in the
@@ -1,4 +1,4 @@
1
1
  Dummy::Application.routes.draw do
2
- match ':controller(/:action(/:id(.:format)))'
2
+ get ':controller(/:action(/:id(.:format)))'
3
3
  resources :musicians
4
4
  end
data/test/helper_test.rb CHANGED
@@ -16,11 +16,27 @@ class DrummerCell < Cell::Rails
16
16
  end
17
17
 
18
18
 
19
- class HelperTest < ActionController::TestCase
19
+ class HelperTest < MiniTest::Spec
20
20
  include Cell::TestCase::TestMethods
21
21
 
22
- context "a cell view" do
23
- should "have access to all helpers" do
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
+ image_tag("no-more-the-meek.jpg")
29
+ end
30
+ end
31
+
32
+ it "allows using helpers using #controller on instance level" do
33
+ assert_equal "<img alt=\"No-more-the-meek\" src=\"/images/no-more-the-meek.jpg\" />", render_cell("helper_test/song", :show)
34
+ end
35
+ end
36
+
37
+
38
+ describe "a cell view" do
39
+ it "have access to all helpers" do
24
40
  BassistCell.class_eval do
25
41
  def assist
26
42
  render :inline => "<%= submit_tag %>"
@@ -30,7 +46,7 @@ class HelperTest < ActionController::TestCase
30
46
  assert_equal "<input name=\"commit\" type=\"submit\" value=\"Save changes\" />", render_cell(:bassist, :assist)
31
47
  end
32
48
 
33
- should "have access to methods declared with helper_method" do
49
+ it "have access to methods declared with #helper_method" do
34
50
  BassistCell.class_eval do
35
51
  def help; "Great!"; end
36
52
  helper_method :help
@@ -43,16 +59,16 @@ class HelperTest < ActionController::TestCase
43
59
  assert_equal "Great!", render_cell(:bassist, :assist)
44
60
  end
45
61
 
46
- should "have access to methods provided by helper" do
62
+ it "have access to methods provided by helper" do
47
63
  assert_equal "plong", render_cell(:drummer, :assist)
48
64
  end
49
65
 
50
- should "mix in required helpers, only" do
66
+ it "mix in required helpers, only" do
51
67
  assert_equal "false true", render_cell(:"club_security/medic", :help)
52
68
  assert_equal "true false", render_cell(:"club_security/guard", :help)
53
69
  end
54
70
 
55
- should "include helpers only once" do
71
+ it "include helpers only once" do
56
72
  assert_equal "false true", render_cell(:"club_security/medic", :help)
57
73
  assert_equal "true false", render_cell(:"club_security/guard", :help)
58
74
  assert_equal "false true", render_cell(:"club_security/medic", :help)
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'test_helper'
2
3
 
3
4
  class DirectorCell < Cell::Rails
@@ -13,12 +14,17 @@ class DirectorCell < Cell::Rails
13
14
  @count += 1
14
15
  render :text => @count
15
16
  end
17
+
18
+ cache :utf8
19
+ def utf8
20
+ render :text => "æøå" # or any other UTF-8 string
21
+ end
16
22
  end
17
23
 
18
- class CachingUnitTest < ActiveSupport::TestCase
24
+ class CachingUnitTest < MiniTest::Spec
19
25
  include Cell::TestCase::TestMethods
20
26
 
21
- setup do
27
+ before :each do
22
28
  ActionController::Base.cache_store.clear
23
29
  ActionController::Base.perform_caching = true
24
30
  @cell = cell(:director)
@@ -26,82 +32,86 @@ class CachingUnitTest < ActiveSupport::TestCase
26
32
  end
27
33
 
28
34
 
29
- context ".state_cache_key" do
30
- should "accept state only" do
35
+ describe ".state_cache_key" do
36
+ it "accept state only" do
31
37
  assert_equal "cells/director/count/", @class.state_cache_key(:count)
32
38
  end
33
39
 
34
- should "accept hash as key parts" do
35
- assert_equal "cells/director/count/a=1&b=2", @class.state_cache_key(:count, :b=>2, :a=>1)
40
+ it "accept hash as key parts" do
41
+ if Cell.rails4_0_or_more?
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
36
46
  end
37
47
 
38
- should "accept array as key parts" do
48
+ it "accept array as key parts" do
39
49
  assert_equal "cells/director/count/1/2/3", @class.state_cache_key(:count, [1,2,3])
40
50
  end
41
51
 
42
- should "accept string as key parts" do
52
+ it "accept string as key parts" do
43
53
  assert_equal "cells/director/count/1/2", @class.state_cache_key(:count, "1/2")
44
54
  end
45
55
 
46
- should "accept nil as key parts" do
56
+ it "accept nil as key parts" do
47
57
  assert_equal "cells/director/count/", @class.state_cache_key(:count, nil)
48
58
  end
49
59
  end
50
60
 
51
61
 
52
- context "#state_cached?" do
53
- should "return true for cached" do
54
- assert @cell.send :state_cached?, :count
62
+ describe "#state_cached?" do
63
+ it "return true for cached" do
64
+ assert @cell.send :state_cached?, :tock
55
65
  end
56
66
 
57
- should "return false otherwise" do
67
+ it "return false otherwise" do
58
68
  assert_not @cell.send :state_cached?, :sing
59
69
  end
60
70
  end
61
71
 
62
72
 
63
- context "#cache?" do
64
- should "return true for cached" do
65
- assert @cell.cache?(:count)
73
+ describe "#cache?" do
74
+ it "return true for cached" do
75
+ assert @cell.cache?(:tock)
66
76
  end
67
77
 
68
- should "return false otherwise" do
78
+ it "return false otherwise" do
69
79
  assert_not @cell.cache?(:sing)
70
80
  end
71
81
 
72
- context "perform_caching turned off" do
73
- teardown do
82
+ describe "perform_caching turned off" do
83
+ after :each do
74
84
  ::ActionController::Base.perform_caching = true
75
85
  end
76
86
 
77
- should "always return false if caching turned-off" do
87
+ it "always return false if caching turned-off" do
78
88
  ::ActionController::Base.perform_caching = false
79
89
  assert_not @cell.cache?(:count)
80
90
  assert_not @cell.cache?(:sing)
81
91
  end
82
92
  end
83
93
 
84
- context ".cache_store" do
85
- should "return Rails cache store per default" do
94
+ describe ".cache_store" do
95
+ it "return Rails cache store per default" do
86
96
  assert_equal ActionController::Base.cache_store, DirectorCell.cache_store
87
97
  end
88
98
 
89
- context "Cell::Base" do
90
- setup do
99
+ describe "Cell::Base" do
100
+ before :each do
91
101
  @class = Class.new(Cell::Base)
92
102
  @cell = @class.new
93
103
  end
94
104
 
95
- context "#cache_store" do
96
- should "be setable from the outside" do
105
+ describe "#cache_store" do
106
+ it "be setable from the outside" do
97
107
  assert_equal nil, @cell.cache_store
98
108
  @cell.cache_store = Object
99
109
  assert_equal Object, @cell.cache_store
100
110
  end
101
111
  end
102
112
 
103
- context "#cache_configured?" do
104
- should "be setable from the outside" do
113
+ describe "#cache_configured?" do
114
+ it "be setable from the outside" do
105
115
  assert_equal nil, @cell.cache_configured?
106
116
  @cell.cache_configured = true
107
117
  assert_equal true, @cell.cache_configured?
@@ -113,24 +123,24 @@ class CachingUnitTest < ActiveSupport::TestCase
113
123
  end
114
124
 
115
125
 
116
- context ".expire_cache_key" do
117
- setup do
126
+ describe ".expire_cache_key" do
127
+ before :each do
118
128
  @key = @class.state_cache_key(:tock)
119
129
  assert_equal "1", render_cell(:director, :tock)
120
130
  assert_equal "1", @class.cache_store.read(@key)
121
131
  end
122
132
 
123
- should "delete the state from cache" do
133
+ it "delete the state from cache" do
124
134
  @class.expire_cache_key(@key)
125
135
  assert_not @class.cache_store.read(@key)
126
136
  end
127
137
 
128
- should "be available in controllers for sweepers" do
138
+ it "be available in controllers for sweepers" do
129
139
  MusicianController.new.expire_cell_state(DirectorCell, :tock)
130
140
  assert_not @class.cache_store.read(@key)
131
141
  end
132
142
 
133
- should "accept cache options" do
143
+ it "accept cache options" do
134
144
  key = @class.state_cache_key(:tock, :volume => 9)
135
145
  assert Cell::Rails.cache_store.write(key, 'ONE!')
136
146
 
@@ -139,7 +149,8 @@ class CachingUnitTest < ActiveSupport::TestCase
139
149
  assert_not ::Cell::Rails.cache_store.read(key)
140
150
  end
141
151
 
142
- should "raise a deprecation notice when passing in a :symbol" do
152
+ include ActiveSupport::Testing::Deprecation
153
+ it "raise a deprecation notice when passing in a :symbol" do
143
154
  assert_deprecated do
144
155
  MusicianController.new.expire_cell_state(:director, :tock)
145
156
  end
@@ -148,95 +159,93 @@ class CachingUnitTest < ActiveSupport::TestCase
148
159
  end
149
160
 
150
161
 
151
- context ".cache" do
152
- setup do
153
- @proc = Proc.new{}
154
-
155
- @parent = Class.new(@class)
156
- @child = Class.new(@parent)
157
- @sibbling = Class.new(@parent)
158
- end
162
+ describe ".cache" do
163
+ let (:proc) { Proc.new {} }
164
+ let (:parent) { Class.new(Cell::Base) }
165
+ let (:brother) { Class.new(parent) }
166
+ let (:sister) { Class.new(parent) }
159
167
 
160
- should "accept a state name, only" do
168
+ it "accept a state name, only" do
161
169
  @class.cache :count
162
170
 
163
171
  assert_not @class.version_procs[:count]
164
172
  assert_equal({}, @class.cache_options[:count])
165
173
  end
166
174
 
167
- should "accept state and cache options" do
175
+ it "accept state and cache options" do
168
176
  @class.cache :count, :expires_in => 10.minutes
169
177
 
170
178
  assert_not @class.version_procs[:count]
171
179
  assert_equal({:expires_in => 10.minutes}, @class.cache_options[:count])
172
180
  end
173
181
 
174
- should "accept args and versioner block" do
182
+ it "accept args and versioner block" do
175
183
  @class.cache :count, :expires_in => 10.minutes do "v1" end
176
184
 
177
185
  assert_kind_of Proc, @class.version_procs[:count]
178
186
  assert_equal({:expires_in => 10.minutes}, @class.cache_options[:count])
179
187
  end
180
188
 
181
- should "stil accept a versioner proc, only" do
182
- @class.cache :count, @proc
189
+ it "stil accept a versioner proc, only" do
190
+ @class.cache :count, proc
183
191
 
184
- assert_equal @proc, @class.version_procs[:count]
192
+ assert_equal proc, @class.version_procs[:count]
185
193
  assert_equal({}, @class.cache_options[:count])
186
194
  end
187
195
 
188
- should "stil accept a versioner block" do
196
+ it "stil accept a versioner block" do
189
197
  @class.cache :count do "v1" end
190
198
 
191
199
  assert_kind_of Proc, @class.version_procs[:count]
192
200
  assert_equal({}, @class.cache_options[:count])
193
201
  end
194
202
 
195
- should "inherit caching configuration" do
196
- @parent.cache :inherited_cache_configuration
203
+ it "inherit caching configuration" do
204
+ parent.cache :inherited_cache_configuration
197
205
 
198
- assert @parent.version_procs.has_key?(:inherited_cache_configuration)
199
- assert @child.version_procs.has_key?(:inherited_cache_configuration)
206
+ assert parent.version_procs.has_key?(:inherited_cache_configuration)
207
+ assert brother.version_procs.has_key?(:inherited_cache_configuration)
200
208
  end
201
209
 
202
- should "not overwrite caching configuration in the parent class" do
203
- @child.cache :inherited_cache_configuration
210
+ it "not overwrite caching configuration in the parent class" do
211
+ brother.cache :inherited_cache_configuration
204
212
 
205
- assert_not @parent.version_procs.has_key?(:inherited_cache_configuration)
206
- assert @child.version_procs.has_key?(:inherited_cache_configuration)
213
+ puts parent.version_procs.inspect
214
+ assert ! parent.version_procs.has_key?(:inherited_cache_configuration)
215
+ assert brother.version_procs.has_key?(:inherited_cache_configuration)
207
216
  end
208
217
 
209
- should "not overwrite caching configuration in a sibbling class" do
210
- @sibbling.cache :inherited_cache_configuration
218
+ it "not overwrite caching configuration in a sibbling class" do
219
+ sister.cache :inherited_cache_configuration
211
220
 
212
- assert_not @child.version_procs.has_key?(:inherited_cache_configuration)
213
- assert @sibbling.version_procs.has_key?(:inherited_cache_configuration)
221
+ assert ! brother.version_procs.has_key?(:inherited_cache_configuration)
222
+ assert sister.version_procs.has_key?(:inherited_cache_configuration)
214
223
  end
215
224
 
216
- should "overwrite caching configuration in a child class" do
225
+ it "overwrite caching configuration in a child class" do
217
226
  @class.cache :inherited_cache_configuration
218
- @child.cache :inherited_cache_configuration, @proc
227
+ brother.cache :inherited_cache_configuration, proc
219
228
 
220
- assert_not @parent.version_procs[:inherited_cache_configuration]
221
- assert_equal @proc, @child.version_procs[:inherited_cache_configuration]
229
+ assert ! parent.version_procs[:inherited_cache_configuration]
230
+ assert_equal proc, brother.version_procs[:inherited_cache_configuration]
222
231
  end
223
232
  end
224
233
  end
225
234
 
226
- class CachingFunctionalTest < ActiveSupport::TestCase
235
+ class CachingFunctionalTest < MiniTest::Spec
227
236
  include Cell::TestCase::TestMethods
228
237
 
229
- setup do
238
+ before :each do
230
239
  ActionController::Base.cache_store.clear
231
240
  ActionController::Base.perform_caching = true
232
- setup # from Cell::TestCase::TestMethods
241
+ #setup # from Cell::TestCase::TestMethods
233
242
 
234
243
  @cell = cell(:director)
235
244
  @class = @cell.class
236
245
  end
237
246
 
238
- context "turned off" do
239
- should "not invoke caching" do
247
+ describe "turned off" do
248
+ it "not invoke caching" do
240
249
  ::ActionController::Base.perform_caching = false
241
250
 
242
251
  assert_equal "1", @cell.render_state(:tock)
@@ -245,8 +254,8 @@ class CachingFunctionalTest < ActiveSupport::TestCase
245
254
  end
246
255
 
247
256
 
248
- context "without options" do
249
- should "cache forever" do
257
+ describe "without options" do
258
+ it "cache forever" do
250
259
  @class.cache :tock
251
260
  assert_equal "1", render_cell(:director, :tock)
252
261
  assert_equal "1", render_cell(:director, :tock)
@@ -254,8 +263,8 @@ class CachingFunctionalTest < ActiveSupport::TestCase
254
263
  end
255
264
 
256
265
 
257
- context "uncached states" do
258
- should "not cache at all" do
266
+ describe "uncached states" do
267
+ it "not cache at all" do
259
268
  @class.class_eval do
260
269
  def dictate
261
270
  @count ||= 0
@@ -268,8 +277,8 @@ class CachingFunctionalTest < ActiveSupport::TestCase
268
277
  end
269
278
  end
270
279
 
271
- context "with versioner" do
272
- setup do
280
+ describe "with versioner" do
281
+ before do
273
282
  @class.class_eval do
274
283
  def count(i)
275
284
  render :text => i
@@ -277,7 +286,7 @@ class CachingFunctionalTest < ActiveSupport::TestCase
277
286
  end
278
287
  end
279
288
 
280
- should "compute the key with a block receiving state-args" do
289
+ it "compute the key with a block receiving state-args" do
281
290
  @class.cache :count do |cell, int|
282
291
  (int % 2)==0 ? {:count => "even"} : {:count => "odd"}
283
292
  end
@@ -289,7 +298,7 @@ class CachingFunctionalTest < ActiveSupport::TestCase
289
298
  assert_equal "2", render_cell(:director, :count, 4)
290
299
  end
291
300
 
292
- should "compute the key with an instance method" do
301
+ it "compute the key with an instance method" do
293
302
  @class.cache :count, :version
294
303
  @class.class_eval do
295
304
  private
@@ -304,7 +313,7 @@ class CachingFunctionalTest < ActiveSupport::TestCase
304
313
  assert_equal "2", render_cell(:director, :count, 4)
305
314
  end
306
315
 
307
- should "allow returning strings, too" do
316
+ it "allow returning strings, too" do
308
317
  @class.cache :count do |cell, int|
309
318
  (int % 2)==0 ? "even" : "odd"
310
319
  end
@@ -315,7 +324,7 @@ class CachingFunctionalTest < ActiveSupport::TestCase
315
324
  assert_equal "2", render_cell(:director, :count, 4)
316
325
  end
317
326
 
318
- should "be able to use caching conditionally" do
327
+ it "be able to use caching conditionally" do
319
328
  @class.cache :count, :if => proc { |cell, int| (int % 2) != 0 }
320
329
 
321
330
  assert_equal "1", render_cell(:director, :count, 1)
@@ -324,7 +333,7 @@ class CachingFunctionalTest < ActiveSupport::TestCase
324
333
  assert_equal "4", render_cell(:director, :count, 4)
325
334
  end
326
335
 
327
- should "cache conditionally with an instance method" do
336
+ it "cache conditionally with an instance method" do
328
337
  @class.cache :count, :if => :odd?
329
338
  @class.class_eval do
330
339
  def odd?(int)
@@ -338,7 +347,7 @@ class CachingFunctionalTest < ActiveSupport::TestCase
338
347
  assert_equal "4", render_cell(:director, :count, 4)
339
348
  end
340
349
 
341
- should "allow using a different cache store" do
350
+ it "allow using a different cache store" do
342
351
  class BassistCell < Cell::Base
343
352
  cache :play
344
353
 
@@ -359,4 +368,15 @@ class CachingFunctionalTest < ActiveSupport::TestCase
359
368
  assert_equal "New Years", @cell.render_state(:play, "Liar")
360
369
  end
361
370
  end
371
+
372
+ describe "utf-8" do
373
+ before do
374
+ @key = @class.state_cache_key(:utf8)
375
+ end
376
+
377
+ it "have the correct encoding when reading from cache" do
378
+ assert_equal "UTF-8", render_cell(:director, :utf8).encoding.to_s
379
+ assert_equal "UTF-8", @class.cache_store.read(@key).encoding.to_s
380
+ end
381
+ end
362
382
  end