cells 3.6.7 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,17 @@
1
+ h2. 3.7.0
2
+
3
+ h3. Changes
4
+ * Cache settings using @Base.cache@ are now inherited.
5
+ * Removed <code>@opts</code>.
6
+ * Removed @#options@ in favor of state-args. If you still want the old behaviour, include the @Deprecations@ module in your cell.
7
+ * The build process is now instantly delegated to Base.build_for on the concrete cell class.
8
+
9
+ h2. 3.6.8
10
+
11
+ h3. Changes
12
+ * Removed <code>@opts</code>.
13
+ * Deprecated @#options@ in favour of state-args.
14
+
1
15
  h2. 3.6.7
2
16
 
3
17
  h3. Changes
@@ -24,7 +24,7 @@ Rails 3.x:
24
24
 
25
25
  Rails 2.3:
26
26
 
27
- gem install cells -v 3.3.8
27
+ gem install cells -v 3.3.9
28
28
 
29
29
 
30
30
  == Generate
@@ -3,28 +3,31 @@ module Cell
3
3
 
4
4
  extend ActiveSupport::Concern
5
5
 
6
- DEFAULT_VIEW_PATHS = [
7
- File.join('app', 'cells'),
8
- ]
9
-
6
+ DEFAULT_VIEW_PATHS = [File.join('app', 'cells')]
7
+
10
8
  module ClassMethods
11
9
  # Called in Railtie at initialization time.
12
10
  def setup_view_paths!
13
11
  self.view_paths = self::DEFAULT_VIEW_PATHS
14
12
  end
15
13
 
14
+ # Main entry point for #render_cell.
16
15
  def render_cell_for(controller, name, state, *args)
17
- cell = create_cell_for(controller, name, *args) # DISCUSS: pass args here?
18
- yield cell if block_given? # DISCUSS: call block before or after render?
16
+ cell = create_cell_for(controller, name, *args)
17
+ yield cell if block_given?
19
18
 
20
- cell.render_state_with_args(state, *args)
19
+ cell.render_state(state, *args)
21
20
  end
22
21
 
23
22
  # Creates a cell instance. Note that this method calls builders which were attached to the
24
23
  # class with Cell::Base.build - this might lead to a different cell being returned.
25
24
  def create_cell_for(controller, name, *args)
26
- build_class_for(controller, class_from_cell_name(name), *args).
27
- new(controller, *args)
25
+ class_from_cell_name(name).build_for(controller, *args)
26
+ end
27
+
28
+ def build_for(controller, *args)
29
+ build_class_for(controller, *args).
30
+ new(controller)
28
31
  end
29
32
 
30
33
  # Adds a builder to the cell class. Builders are used in #render_cell to find out the concrete
@@ -57,31 +60,21 @@ module Cell
57
60
  builders << block
58
61
  end
59
62
 
60
- def build_class_for(controller, target_class, *args)
61
- target_class.builders.each do |blk|
62
- res = controller.instance_exec(*args, &blk) and return res
63
- end
64
- target_class
65
- end
66
-
67
- def builders
68
- @builders ||= []
69
- end
70
-
71
63
  # The cell class constant for +cell_name+.
72
64
  def class_from_cell_name(cell_name)
73
65
  "#{cell_name}_cell".classify.constantize
74
66
  end
75
- end
76
-
77
- module InstanceMethods
78
- def render_state_with_args(state, *args) # TODO: remove me in 4.0.
79
- return render_state(state, *args) if state_accepts_args?(state)
80
- render_state(state) # backward-compat.
67
+
68
+ protected
69
+ def build_class_for(controller, *args)
70
+ builders.each do |blk|
71
+ klass = controller.instance_exec(*args, &blk) and return klass
72
+ end
73
+ self
81
74
  end
82
75
 
83
- def state_accepts_args?(state)
84
- method(state).arity != 0
76
+ def builders
77
+ @builders ||= []
85
78
  end
86
79
  end
87
80
  end
@@ -5,6 +5,13 @@ module Cell
5
5
  module Caching
6
6
  extend ActiveSupport::Concern
7
7
 
8
+ included do
9
+ class_attribute :version_procs, :conditional_procs, :cache_options
10
+ self.version_procs = {}
11
+ self.conditional_procs = {}
12
+ self.cache_options = {}
13
+ end
14
+
8
15
  module ClassMethods
9
16
  # Caches the rendered view of +state+.
10
17
  #
@@ -41,25 +48,16 @@ module Cell
41
48
  #
42
49
  # Two things to mention here.
43
50
  # * The return value of the method/block is <em>appended</em> to the state cache key.
44
- # * You may return a string, a hash, an array, ActiveSupport::Caching will compile it.
51
+ # * You may return a string, a hash, an array, ActiveSupport::Caching will compile it.
52
+ #
53
+ # == Inheritance
54
+ # Please note that cache configuration is inherited to derived cells.
45
55
  def cache(state, *args, &block)
46
56
  options = args.extract_options!
47
-
48
- conditional_procs[state] = options.delete(:if)
49
- version_procs[state] = args.first || block
50
- cache_options[state] = options
51
- end
52
-
53
- def version_procs
54
- @version_procs ||= {}
55
- end
56
-
57
- def conditional_procs
58
- @conditional_procs ||= {}
59
- end
60
57
 
61
- def cache_options
62
- @cache_options ||= {}
58
+ self.conditional_procs = conditional_procs.merge(state => options.delete(:if))
59
+ self.version_procs = version_procs.merge(state => (args.first || block))
60
+ self.cache_options = cache_options.merge(state => options)
63
61
  end
64
62
 
65
63
  def cache_store
@@ -112,7 +110,7 @@ module Cell
112
110
  protected
113
111
  def call_proc_or_method(state, method, *args)
114
112
  return method.call(self, *args) if method.kind_of?(Proc)
115
- state_accepts_args?(state) ? send(method, *args) : send(method)
113
+ send(method, *args)
116
114
  end
117
115
 
118
116
  def call_state_versioner(state, *args)
@@ -0,0 +1,42 @@
1
+ module Cell
2
+ # Makes #options available in Cells 3.7, which was removed in favor of state-args.
3
+ module Deprecations
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ attr_reader :options
8
+ end
9
+
10
+
11
+ module ClassMethods
12
+ def build_for(controller, *args)
13
+ build_class_for(controller, *args).
14
+ new(controller, *args)
15
+ end
16
+ end
17
+
18
+
19
+ module InstanceMethods
20
+ def initialize(parent_controller, *args)
21
+ super(parent_controller) # the real Base.new.
22
+ setup_backwardibility(*args)
23
+ end
24
+
25
+ # Some people still like #options and assume it's a hash.
26
+ def setup_backwardibility(*args)
27
+ @_options = (args.first.is_a?(Hash) and args.size == 1) ? args.first : args
28
+ @options = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(@_options, "#options is deprecated and was removed in Cells 3.7. Please use state-args.")
29
+ end
30
+
31
+ def render_state(state, *args)
32
+ return super(state, *args) if state_accepts_args?(state)
33
+ super(state) # backward-compat.
34
+ end
35
+
36
+ def state_accepts_args?(state)
37
+ method(state).arity != 0
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -42,23 +42,13 @@ module Cell
42
42
  include Rendering
43
43
  include Caching
44
44
 
45
-
46
45
  attr_reader :parent_controller
47
- attr_accessor :options
48
-
49
46
  abstract!
50
47
 
51
48
 
52
- def initialize(parent_controller, *args)
49
+ def initialize(parent_controller)
53
50
  super()
54
- @parent_controller = parent_controller
55
- setup_backwardibility(*args)
56
- end
57
-
58
- # Some people still like #options and assume it's a hash.
59
- def setup_backwardibility(*args)
60
- @options = (args.first.is_a?(Hash) and args.size == 1) ? args.first : args
61
- @opts = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :options)
51
+ @parent_controller = parent_controller
62
52
  end
63
53
 
64
54
  def self.controller_path
@@ -98,7 +98,7 @@ module Cell
98
98
  # DISCUSS: should we allow passing a block here, just as in controllers?
99
99
  @subject_cell = ::Cell::Base.create_cell_for(@controller, name, *args)
100
100
  @view_assigns = extract_state_ivars_for(@subject_cell) do
101
- @last_invoke = @subject_cell.render_state_with_args(state, *args)
101
+ @last_invoke = @subject_cell.render_state(state, *args)
102
102
  end
103
103
 
104
104
  @last_invoke
@@ -108,10 +108,11 @@ module Cell
108
108
  # Passes the optional block to <tt>cell.instance_eval</tt>.
109
109
  #
110
110
  # Example:
111
- # assert_equal "Banks kill planet!" cell(:news, :topic => :terror).latest_headline
111
+ # assert_equal "Doo Dumm Dumm..." cell(:bassist).play
112
112
  def cell(name, *args, &block)
113
113
  cell = ::Cell::Base.create_cell_for(@controller, name, *args)
114
114
  cell.instance_eval &block if block_given?
115
+ ActiveSupport::Deprecation.warn("Passing options to TestCase#cell is deprecated, please use state-args in #render_cell.", caller) if args.present?
115
116
  cell
116
117
  end
117
118
 
@@ -122,16 +123,16 @@ module Cell
122
123
  #
123
124
  # assert_equal("<h1>Modularity rocks.</h1>", in_view do content_tag(:h1, "Modularity rocks."))
124
125
  def in_view(cell_class, &block)
125
- subject = cell(cell_class, :block => block)
126
+ subject = cell(cell_class)
126
127
  setup_test_states_in(subject) # add #in_view to subject cell.
127
- subject.render_state(:in_view)
128
+ subject.render_state(:in_view, block)
128
129
  end
129
130
 
130
131
  protected
131
132
  def setup_test_states_in(cell)
132
133
  cell.instance_eval do
133
- def in_view
134
- render :inline => "<%= instance_exec(&block) %>", :locals => {:block => options[:block]}
134
+ def in_view(block=nil)
135
+ render :inline => "<%= instance_exec(&block) %>", :locals => {:block => block}
135
136
  end
136
137
  end
137
138
  end
@@ -147,7 +148,7 @@ module Cell
147
148
 
148
149
 
149
150
  def invoke(state, *args)
150
- @last_invoke = self.class.controller_class.new(@controller, *args).render_state_with_args(state, *args)
151
+ @last_invoke = self.class.controller_class.new(@controller).render_state(state, *args)
151
152
  end
152
153
  end
153
154
  end
@@ -84,5 +84,6 @@ require 'cell/rails'
84
84
  require 'cells/railtie'
85
85
  require 'cells/rails'
86
86
  require 'cells/rails_compat' # fixes a bug in Rails <3.0.4. # TODO: remove me as soon as we support 3.1, only.
87
+ require 'cell/deprecations'
87
88
 
88
89
  Cell::Base = Cell::Rails
@@ -1,3 +1,3 @@
1
1
  module Cells
2
- VERSION = '3.6.7'
2
+ VERSION = '3.7.0'
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class MusicianCell < Cell::Base
4
-
5
4
  end
6
5
 
7
6
  class PianistCell < MusicianCell
@@ -32,24 +31,6 @@ class CellModuleTest < ActiveSupport::TestCase
32
31
  assert_equal "Doo", html
33
32
  assert flag
34
33
  end
35
-
36
- should "make options available in #options if not receiving state-args" do
37
- BassistCell.class_eval do
38
- def listen
39
- render :text => options[:note]
40
- end
41
- end
42
- assert_equal "C-minor", Cell::Base.render_cell_for(@controller, :bassist, :listen, :note => "C-minor")
43
- end
44
-
45
- should "pass options as state-args and still set #options otherwise" do
46
- BassistCell.class_eval do
47
- def listen(args)
48
- render :text => args[:note] + options[:note].to_s
49
- end
50
- end
51
- assert_equal "C-minorC-minor", Cell::Base.render_cell_for(@controller, :bassist, :listen, :note => "C-minor")
52
- end
53
34
  end
54
35
 
55
36
  context "create_cell_for" do
@@ -64,7 +45,7 @@ class CellModuleTest < ActiveSupport::TestCase
64
45
  end
65
46
  end
66
47
 
67
- context "calling build" do
48
+ context "#create_cell_for with #build" do
68
49
  setup do
69
50
  @controller.class_eval do
70
51
  attr_accessor :bassist
@@ -86,13 +67,13 @@ class CellModuleTest < ActiveSupport::TestCase
86
67
 
87
68
  should "execute the block in controller context" do
88
69
  @controller.bassist = true
89
- assert_equal BassistCell, Cell::Base.build_class_for(@controller, MusicianCell, {})
70
+ assert_is_a BassistCell, Cell::Base.create_cell_for(@controller, :musician, {})
90
71
  end
91
72
 
92
73
  should "limit the builder to the receiving class" do
93
- assert_equal PianistCell, Cell::Base.build_class_for(@controller, PianistCell, {}) # don't inherit anything.
74
+ assert_is_a PianistCell, Cell::Base.create_cell_for(@controller, :pianist, {}) # don't inherit anything.
94
75
  @controller.bassist = true
95
- assert_equal BassistCell, Cell::Base.build_class_for(@controller, MusicianCell, {})
76
+ assert_is_a BassistCell, Cell::Base.create_cell_for(@controller, :musician, {})
96
77
  end
97
78
 
98
79
  should "chain build blocks and execute them by ORing them in the same order" do
@@ -104,13 +85,13 @@ class CellModuleTest < ActiveSupport::TestCase
104
85
  UnknownCell # should never be executed.
105
86
  end
106
87
 
107
- assert_equal PianistCell, Cell::Base.build_class_for(@controller, MusicianCell, {}) # bassist is false.
88
+ assert_is_a PianistCell, Cell::Base.create_cell_for(@controller, :musician, {}) # bassist is false.
108
89
  @controller.bassist = true
109
- assert_equal BassistCell, Cell::Base.build_class_for(@controller, MusicianCell, {})
90
+ assert_is_a BassistCell, Cell::Base.create_cell_for(@controller, :musician, {})
110
91
  end
111
92
 
112
93
  should "use the original cell if no builder matches" do
113
- assert_equal MusicianCell, Cell::Base.build_class_for(@controller, MusicianCell, {}) # bassist is false.
94
+ assert_is_a MusicianCell, Cell::Base.create_cell_for(@controller, :musician, {}) # bassist is false.
114
95
  end
115
96
 
116
97
  should "stop at the first builder returning a valid cell" do
@@ -121,16 +102,16 @@ class CellModuleTest < ActiveSupport::TestCase
121
102
  BassistCell.build do |opts|
122
103
  SingerCell if opts[:sing_the_song]
123
104
  end
124
- assert_equal BassistCell, Cell::Base.build_class_for(@controller, BassistCell, {})
125
- assert_equal SingerCell, Cell::Base.build_class_for(@controller, BassistCell, {:sing_the_song => true})
105
+ assert_kind_of BassistCell, Cell::Base.create_cell_for(@controller, :bassist, {})
106
+ assert_kind_of SingerCell, Cell::Base.create_cell_for(@controller, :bassist, {:sing_the_song => true})
126
107
  end
127
108
 
128
109
  should "create the original target class if no block matches" do
129
- assert_equal PianistCell, Cell::Base.build_class_for(@controller, PianistCell, {})
110
+ assert_kind_of PianistCell, Cell::Base.create_cell_for(@controller, :pianist, {})
130
111
  end
131
112
 
132
113
  should "builders should return an empty array per default" do
133
- assert_equal [], PianistCell.builders
114
+ assert_equal [], PianistCell.send(:builders)
134
115
  end
135
116
  end
136
117
 
@@ -154,29 +135,5 @@ class CellModuleTest < ActiveSupport::TestCase
154
135
  assert_equal "cell_module_test/singer", CellModuleTest::SingerCell.cell_name
155
136
  end
156
137
  end
157
-
158
- context "#state_accepts_args?" do
159
- should "be false if state doesn't want args" do
160
- assert_not cell(:bassist).state_accepts_args?(:play)
161
- end
162
-
163
- should "be true for one arg" do
164
- assert(cell(:bassist) do
165
- def listen(args) end
166
- end.state_accepts_args?(:listen))
167
- end
168
-
169
- should "be true for multiple arg" do
170
- assert(cell(:bassist) do
171
- def listen(what, where) end
172
- end.state_accepts_args?(:listen))
173
- end
174
-
175
- should "be true for multiple arg with defaults" do
176
- assert(cell(:bassist) do
177
- def listen(what, where="") end
178
- end.state_accepts_args?(:listen))
179
- end
180
- end
181
138
  end
182
139
  end
@@ -0,0 +1,95 @@
1
+ require 'test_helper'
2
+
3
+ class SongwriterCell < BassistCell
4
+ include Cell::Deprecations
5
+ end
6
+
7
+
8
+ class DeprecationsTest < ActiveSupport::TestCase
9
+ include Cell::TestCase::TestMethods
10
+
11
+ context "#render_state" do
12
+ should "work without args and provide #options" do
13
+ SongwriterCell.class_eval do
14
+ def listen
15
+ render :text => options[:note]
16
+ end
17
+ end
18
+ assert_equal "D", cell(:songwriter, :note => "D").render_state(:listen)
19
+ end
20
+
21
+ include ActiveSupport::Testing::Deprecation
22
+ should "mark @options as deprecated, but still work" do
23
+ res = nil
24
+ assert_deprecated do
25
+ res = cell(:songwriter, :song => "Lockdown").instance_eval do
26
+ options[:song]
27
+ end
28
+ end
29
+ assert_equal "Lockdown", res
30
+ end
31
+ end
32
+
33
+ context "render_cell_for" do
34
+ should "make options available in #options if not receiving state-args" do
35
+ SongwriterCell.class_eval do
36
+ def listen
37
+ render :text => options[:note]
38
+ end
39
+ end
40
+ assert_equal "C-minor", Cell::Base.render_cell_for(@controller, :songwriter, :listen, :note => "C-minor")
41
+ end
42
+
43
+ should "pass options as state-args and still set #options otherwise" do
44
+ SongwriterCell.class_eval do
45
+ def listen(args)
46
+ render :text => args[:note] + options[:note].to_s
47
+ end
48
+ end
49
+ assert_equal "C-minorC-minor", Cell::Base.render_cell_for(@controller, :songwriter, :listen, :note => "C-minor")
50
+ end
51
+ end
52
+
53
+ context "#state_accepts_args?" do
54
+ should "be false if state doesn't want args" do
55
+ assert_not cell(:songwriter).state_accepts_args?(:play)
56
+ end
57
+
58
+ should "be true for one arg" do
59
+ assert(cell(:songwriter) do
60
+ def listen(args) end
61
+ end.state_accepts_args?(:listen))
62
+ end
63
+
64
+ should "be true for multiple arg" do
65
+ assert(cell(:songwriter) do
66
+ def listen(what, where) end
67
+ end.state_accepts_args?(:listen))
68
+ end
69
+
70
+ should "be true for multiple arg with defaults" do
71
+ assert(cell(:songwriter) do
72
+ def listen(what, where="") end
73
+ end.state_accepts_args?(:listen))
74
+ end
75
+ end
76
+
77
+ context ".cache" do
78
+ should "still be able to use options in the block" do
79
+ SongwriterCell.class_eval do
80
+ def count(args)
81
+ render :text => args[:int]
82
+ end
83
+
84
+ cache :count do |cell, i|
85
+ (cell.options[:int] % 2)==0 ? {:count => "even"} : {:count => "odd"}
86
+ end
87
+ end
88
+
89
+ assert_equal "1", render_cell(:songwriter, :count, :int => 1)
90
+ assert_equal "2", render_cell(:songwriter, :count, :int => 2)
91
+ assert_equal "1", render_cell(:songwriter, :count, :int => 3)
92
+ assert_equal "2", render_cell(:songwriter, :count, :int => 4)
93
+ end
94
+ end
95
+ end
@@ -128,6 +128,10 @@ class CachingUnitTest < ActiveSupport::TestCase
128
128
  context ".cache" do
129
129
  setup do
130
130
  @proc = Proc.new{}
131
+
132
+ @parent = Class.new(@class)
133
+ @child = Class.new(@parent)
134
+ @sibbling = Class.new(@parent)
131
135
  end
132
136
 
133
137
  should "accept a state name, only" do
@@ -164,14 +168,34 @@ class CachingUnitTest < ActiveSupport::TestCase
164
168
  assert_kind_of Proc, @class.version_procs[:count]
165
169
  assert_equal({}, @class.cache_options[:count])
166
170
  end
167
-
168
- should "not inherit caching configuration" do
169
- @class.cache :count
170
- klass = Class.new(@class)
171
- klass.cache :count, @proc
172
-
173
- assert_not cell(:director).class.version_procs[:count]
174
- assert_equal @proc, klass.version_procs[:count]
171
+
172
+ should "inherit caching configuration" do
173
+ @parent.cache :inherited_cache_configuration
174
+
175
+ assert @parent.version_procs.has_key?(:inherited_cache_configuration)
176
+ assert @child.version_procs.has_key?(:inherited_cache_configuration)
177
+ end
178
+
179
+ should "not overwrite caching configuration in the parent class" do
180
+ @child.cache :inherited_cache_configuration
181
+
182
+ assert_not @parent.version_procs.has_key?(:inherited_cache_configuration)
183
+ assert @child.version_procs.has_key?(:inherited_cache_configuration)
184
+ end
185
+
186
+ should "not overwrite caching configuration in a sibbling class" do
187
+ @sibbling.cache :inherited_cache_configuration
188
+
189
+ assert_not @child.version_procs.has_key?(:inherited_cache_configuration)
190
+ assert @sibbling.version_procs.has_key?(:inherited_cache_configuration)
191
+ end
192
+
193
+ should "overwrite caching configuration in a child class" do
194
+ @class.cache :inherited_cache_configuration
195
+ @child.cache :inherited_cache_configuration, @proc
196
+
197
+ assert_not @parent.version_procs[:inherited_cache_configuration]
198
+ assert_equal @proc, @child.version_procs[:inherited_cache_configuration]
175
199
  end
176
200
  end
177
201
  end
@@ -230,7 +254,7 @@ class CachingFunctionalTest < ActiveSupport::TestCase
230
254
  end
231
255
  end
232
256
 
233
- should "compute the key with a block" do
257
+ should "compute the key with a block receiving state-args" do
234
258
  @class.cache :count do |cell, int|
235
259
  (int % 2)==0 ? {:count => "even"} : {:count => "odd"}
236
260
  end
@@ -242,26 +266,10 @@ class CachingFunctionalTest < ActiveSupport::TestCase
242
266
  assert_equal "2", render_cell(:director, :count, 4)
243
267
  end
244
268
 
245
- should "still be able to use options in the block" do
246
- @class.class_eval do
247
- def count(args)
248
- render :text => args[:int]
249
- end
250
- end
251
-
252
- @class.cache :count do |cell, i|
253
- (cell.options[:int] % 2)==0 ? {:count => "even"} : {:count => "odd"}
254
- end
255
-
256
- assert_equal "1", render_cell(:director, :count, :int => 1)
257
- assert_equal "2", render_cell(:director, :count, :int => 2)
258
- assert_equal "1", render_cell(:director, :count, :int => 3)
259
- assert_equal "2", render_cell(:director, :count, :int => 4)
260
- end
261
-
262
269
  should "compute the key with an instance method" do
263
270
  @class.cache :count, :version
264
271
  @class.class_eval do
272
+ private
265
273
  def version(int)
266
274
  (int % 2)==0 ? {:count => "even"} : {:count => "odd"}
267
275
  end
@@ -20,10 +20,10 @@ class RailsCellsTest < ActiveSupport::TestCase
20
20
  should "work without args" do
21
21
  BassistCell.class_eval do
22
22
  def listen
23
- render :text => options[:note]
23
+ render :text => "That's a D!"
24
24
  end
25
25
  end
26
- assert_equal "D", cell(:bassist, :note => "D").render_state(:listen)
26
+ assert_equal "That's a D!", cell(:bassist).render_state(:listen)
27
27
  end
28
28
 
29
29
  should "accept state-args" do
@@ -76,20 +76,6 @@ class RailsCellsTest < ActiveSupport::TestCase
76
76
  assert_equal({}, cell(:bassist).config)
77
77
  end
78
78
 
79
- include ActiveSupport::Testing::Deprecation
80
- should "mark @opts as deprecated, but still works" do
81
- res = nil
82
- assert_deprecated do
83
- res = cell(:bassist, :song => "Lockdown").instance_eval do
84
- @opts[:song]
85
- end
86
- end
87
- assert_equal "Lockdown", res
88
- end
89
-
90
- should "respond to #options and return the cell options" do
91
- assert_equal({:song => "Lockdown"}, cell(:bassist, :song => "Lockdown").options)
92
- end
93
79
 
94
80
  if Cells.rails3_0?
95
81
  puts "rails-3.0"
@@ -1,7 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestCaseTest < Cell::TestCase
4
-
4
+ include ActiveSupport::Testing::Deprecation
5
+
5
6
  context "A TestCase" do
6
7
  setup do
7
8
  @test = Cell::TestCase.new(:cell_test)
@@ -19,16 +20,20 @@ class TestCaseTest < Cell::TestCase
19
20
  assert_selector "p", "Doo", "<p>Doo</p>y"
20
21
  end
21
22
 
22
- should "respond to #cell" do
23
- assert_kind_of BassistCell, cell(:bassist)
24
- end
25
-
26
- should "respond to #cell with a block" do
27
- assert_respond_to cell(:bassist){ def whatever; end }, :whatever
28
- end
29
-
30
- should "respond to #cell with options and block" do
31
- assert_equal({:topic => :peace}, cell(:bassist, :topic => :peace).options)
23
+ context "#cell" do
24
+ should "create a cell" do
25
+ assert_kind_of BassistCell, cell(:bassist)
26
+ end
27
+
28
+ should "accept a block" do
29
+ assert_respond_to cell(:bassist){ def whatever; end }, :whatever
30
+ end
31
+
32
+ should "mark options as deprecated" do
33
+ assert_deprecated do
34
+ res = cell(:bassist, :song => "Lockdown")
35
+ end
36
+ end
32
37
  end
33
38
 
34
39
  context "#subject_cell" do
@@ -103,11 +108,11 @@ class TestCaseTest < Cell::TestCase
103
108
 
104
109
  context "#setup_test_states_in" do
105
110
  should "add the :in_view state" do
106
- c = cell(:bassist, :block => lambda{"Cells rock."})
111
+ c = cell(:bassist)
107
112
  assert_not c.respond_to?(:in_view)
108
113
 
109
114
  setup_test_states_in(c)
110
- assert_equal "Cells rock.", c.render_state(:in_view)
115
+ assert_equal "Cells rock.", c.render_state(:in_view, lambda{"Cells rock."})
111
116
  end
112
117
  end
113
118
 
@@ -28,6 +28,10 @@ ActiveSupport::TestCase.class_eval do
28
28
  def assert_not(assertion)
29
29
  assert !assertion
30
30
  end
31
+
32
+ def assert_is_a(klass, object)
33
+ assert object.is_a?(klass)
34
+ end
31
35
  end
32
36
 
33
37
  # Enable dynamic states so we can do Cell.class_eval { def ... } at runtime.
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 3
7
- - 6
8
7
  - 7
9
- version: 3.6.7
8
+ - 0
9
+ version: 3.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Sutterer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-28 00:00:00 +02:00
17
+ date: 2011-10-13 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -130,6 +130,7 @@ files:
130
130
  - cells.gemspec
131
131
  - lib/cell.rb
132
132
  - lib/cell/caching.rb
133
+ - lib/cell/deprecations.rb
133
134
  - lib/cell/rails.rb
134
135
  - lib/cell/rails3_0_strategy.rb
135
136
  - lib/cell/rails3_1_strategy.rb
@@ -185,6 +186,7 @@ files:
185
186
  - test/cell_generator_test.rb
186
187
  - test/cell_module_test.rb
187
188
  - test/cells_module_test.rb
189
+ - test/deprecations_test.rb
188
190
  - test/dummy/Rakefile
189
191
  - test/dummy/app/controllers/application_controller.rb
190
192
  - test/dummy/app/controllers/musician_controller.rb