cells 3.3.10 → 3.4.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 (103) hide show
  1. data/CHANGES +0 -8
  2. data/Gemfile +4 -1
  3. data/README.rdoc +91 -107
  4. data/Rakefile +0 -4
  5. data/lib/cell.rb +5 -6
  6. data/lib/{cells/cell → cell}/active_helper.rb +1 -1
  7. data/lib/cell/base.rb +134 -0
  8. data/lib/cell/base_methods.rb +100 -0
  9. data/lib/cell/caching.rb +153 -0
  10. data/lib/cell/rails.rb +239 -0
  11. data/lib/cells.rb +25 -3
  12. data/lib/cells/assertions_helper.rb +1 -1
  13. data/lib/cells/helpers/capture_helper.rb +3 -3
  14. data/lib/cells/rails.rb +65 -4
  15. data/lib/cells/version.rb +3 -1
  16. data/rails_generators/cell/cell_generator.rb +47 -35
  17. data/rails_generators/cell/templates/cell.rb +1 -1
  18. data/rails_generators/cells_install/cells_install_generator.rb +5 -3
  19. data/rails_generators/erb/cell_generator.rb +20 -0
  20. data/rails_generators/{cell → erb}/templates/view.html.erb +0 -0
  21. data/test/active_helper_test.rb +1 -0
  22. data/test/app/cells/bad_guitarist_cell.rb +2 -0
  23. data/test/app/cells/bassist_cell.rb +1 -1
  24. data/test/app/controllers/musician_controller.rb +16 -0
  25. data/test/assertions_helper_test.rb +8 -18
  26. data/test/base_methods_test.rb +40 -0
  27. data/test/cell_generator_test.rb +33 -21
  28. data/test/helper_test.rb +31 -123
  29. data/test/rails/caching_test.rb +215 -0
  30. data/test/rails/capture_test.rb +52 -0
  31. data/test/rails/cells_test.rb +88 -0
  32. data/test/rails/integration_test.rb +37 -0
  33. data/test/rails/render_test.rb +140 -0
  34. data/test/rails/router_test.rb +74 -0
  35. data/test/rails/view_test.rb +24 -0
  36. data/test/test_helper.rb +30 -29
  37. metadata +68 -133
  38. data/.gitignore +0 -3
  39. data/about.yml +0 -7
  40. data/cells.gemspec +0 -26
  41. data/lib/cells/cell.rb +0 -16
  42. data/lib/cells/cell/base.rb +0 -470
  43. data/lib/cells/cell/caching.rb +0 -163
  44. data/lib/cells/cell/test_case.rb +0 -158
  45. data/lib/cells/cell/view.rb +0 -55
  46. data/lib/cells/rails/action_controller.rb +0 -37
  47. data/lib/cells/rails/action_view.rb +0 -37
  48. data/rails/init.rb +0 -44
  49. data/rails_generators/cells_install/templates/tasks.rake +0 -6
  50. data/test/app/cells/a/another_state.html.erb +0 -1
  51. data/test/app/cells/a/existing_view.html.erb +0 -1
  52. data/test/app/cells/a/inherited_view.html.erb +0 -1
  53. data/test/app/cells/a/inherited_view.js.erb +0 -1
  54. data/test/app/cells/a/view_with_locals.html.erb +0 -1
  55. data/test/app/cells/a/view_with_render_call.html.erb +0 -1
  56. data/test/app/cells/b/existing_view.html.erb +0 -1
  57. data/test/app/cells/b/existing_view.js.erb +0 -1
  58. data/test/app/cells/b/layouts/metal.html.erb +0 -1
  59. data/test/app/cells/b/view_with_render_call.html.erb +0 -1
  60. data/test/app/cells/bassist/jam.html.erb +0 -3
  61. data/test/app/cells/bassist/play.html.erb +0 -1
  62. data/test/app/cells/cells_test_one/renamed_instance_view.html.erb +0 -1
  63. data/test/app/cells/cells_test_one/super_state.html.erb +0 -1
  64. data/test/app/cells/cells_test_one_cell.rb +0 -20
  65. data/test/app/cells/cells_test_two_cell.rb +0 -4
  66. data/test/app/cells/helper_using/state_using_application_helper.html.erb +0 -3
  67. data/test/app/cells/helper_using/state_with_automatic_helper_invocation.html.erb +0 -3
  68. data/test/app/cells/helper_using/state_with_helper_invocation.html.erb +0 -3
  69. data/test/app/cells/helper_using/state_with_helper_method_invocation.html.erb +0 -3
  70. data/test/app/cells/layouts/metal.html.erb +0 -1
  71. data/test/app/cells/my_child/hello.html.erb +0 -1
  72. data/test/app/cells/my_mother/bye.html.erb +0 -1
  73. data/test/app/cells/my_mother/hello.html.erb +0 -1
  74. data/test/app/cells/my_test/_broken_partial.html.erb +0 -1
  75. data/test/app/cells/my_test/_partial.html.erb +0 -1
  76. data/test/app/cells/my_test/state_with_instance_var.html.erb +0 -1
  77. data/test/app/cells/my_test/state_with_link_to.html.erb +0 -3
  78. data/test/app/cells/my_test/state_with_not_included_helper_method.html.erb +0 -8
  79. data/test/app/cells/my_test/view_containing_broken_partial.html.erb +0 -3
  80. data/test/app/cells/my_test/view_containing_nonexistant_partial.html.erb +0 -3
  81. data/test/app/cells/my_test/view_containing_partial.html.erb +0 -3
  82. data/test/app/cells/my_test/view_containing_partial_without_cell_name.html.erb +0 -3
  83. data/test/app/cells/my_test/view_in_local_test_views_dir.html.erb +0 -1
  84. data/test/app/cells/my_test/view_with_explicit_english_translation.en.html.erb +0 -1
  85. data/test/app/cells/my_test/view_with_explicit_english_translation.html.erb +0 -1
  86. data/test/app/cells/my_test/view_with_instance_var.html.erb +0 -4
  87. data/test/app/cells/really_module/nested/happy_state.html.erb +0 -1
  88. data/test/app/cells/really_module/nested_cell.rb +0 -11
  89. data/test/app/cells/simple/two_templates_state.html.mytpl +0 -1
  90. data/test/app/cells/simple_cell.rb +0 -7
  91. data/test/app/cells/test/beep.html.erb +0 -1
  92. data/test/app/cells/test/state_invoking_capture.html.erb +0 -7
  93. data/test/app/cells/test/state_invoking_content_for.html.erb +0 -7
  94. data/test/app/cells/test/state_invoking_content_for_twice.html.erb +0 -9
  95. data/test/app/cells/test/state_with_not_included_helper_method.html.erb +0 -8
  96. data/test/app/cells/two_helpers_including/state_using_another_helper.html.erb +0 -3
  97. data/test/bugs_test.rb +0 -23
  98. data/test/caching_test.rb +0 -270
  99. data/test/capture_helper_test.rb +0 -59
  100. data/test/cells_test.rb +0 -352
  101. data/test/rails_test.rb +0 -35
  102. data/test/render_test.rb +0 -305
  103. data/test/test_case_test.rb +0 -106
@@ -1,11 +1,72 @@
1
1
  # encoding: utf-8
2
- require 'cells/rails/action_controller'
3
- require 'cells/rails/action_view'
4
2
 
5
- Cell::Base.class_eval do
6
- helper ::ApplicationHelper if defined?(::ApplicationHelper)
3
+ # These Methods are automatically added to all Controllers and Views when
4
+ # the cells plugin is loaded.
5
+ module Cells
6
+ module Rails
7
+ module ActionController
8
+ # Equivalent to ActionController#render_to_string, except it renders a cell
9
+ # rather than a regular templates.
10
+ def render_cell(name, state, opts={})
11
+ ::Cell::Base.render_cell_for(self, name, state, opts)
12
+ end
13
+
14
+ # Expires the cached cell state view, similar to ActionController::expire_fragment.
15
+ # Usually, this method is used in Sweepers.
16
+ # Beside the obvious first two args <tt>cell_name</tt> and <tt>state</tt> you can pass
17
+ # in additional cache key <tt>args</tt> and cache store specific <tt>opts</tt>.
18
+ #
19
+ # Example:
20
+ #
21
+ # class ListSweeper < ActionController::Caching::Sweeper
22
+ # observe List, Item
23
+ #
24
+ # def after_save(record)
25
+ # expire_cell_state :my_listing, :display_list
26
+ # end
27
+ #
28
+ # will expire the view for state <tt>:display_list</tt> in the cell <tt>MyListingCell</tt>.
29
+ def expire_cell_state(cell_name, state, args={}, opts=nil)
30
+ key = ::Cell::Base.cache_key_for(cell_name, state, args)
31
+ ::Cell::Base.expire_cache_key(key, opts)
32
+ end
33
+ end
34
+
35
+
36
+ module ActionView
37
+ # Call a cell state and return its rendered view.
38
+ #
39
+ # ERB example:
40
+ # <div id="login">
41
+ # <%= render_cell :user, :login_prompt, :message => "Please login" %>
42
+ # </div>
43
+ #
44
+ # If you have a <tt>UserCell</tt> cell in <tt>app/cells/user_cell.rb</tt>, which has a
45
+ # <tt>UserCell#login_prompt</tt> method, this will call that method and then will
46
+ # find the view <tt>app/cells/user/login_prompt.html.erb</tt> and render it. This is
47
+ # called the <tt>:login_prompt</tt> <em>state</em> in Cells terminology.
48
+ #
49
+ # If this view file looks like this:
50
+ # <h1><%= @opts[:message] %></h1>
51
+ # <label>name: <input name="user[name]" /></label>
52
+ # <label>password: <input name="user[password]" /></label>
53
+ #
54
+ # The resulting view in the controller will be roughly equivalent to:
55
+ # <div id="login">
56
+ # <h1><%= "Please login" %></h1>
57
+ # <label>name: <input name="user[name]" /></label>
58
+ # <label>password: <input name="user[password]" /></label>
59
+ # </div>
60
+ def render_cell(name, state, opts = {})
61
+ ::Cell::Base.render_cell_for(controller, name, state, opts)
62
+ end
63
+ end
64
+
65
+
66
+ end
7
67
  end
8
68
 
69
+
9
70
  # Add extended ActionController behaviour.
10
71
  ActionController::Base.class_eval do
11
72
  include ::Cells::Rails::ActionController
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Cells
2
- VERSION = '3.3.10'
4
+ VERSION = '3.4.0.beta1'
3
5
  end
@@ -1,51 +1,63 @@
1
- require 'rails_generator/generators/components/controller/controller_generator'
2
-
3
- class CellGenerator < ControllerGenerator
4
-
5
- attr_reader :template_type
6
-
7
- def initialize(runtime_args, runtime_options = {})
8
- super
9
- @template_type = options[:haml] ? :haml : :erb
1
+ #require 'rails_generator/generators/components/controller/controller_generator'
2
+ require 'rails/generators/named_base'
3
+ module Cells
4
+ module Generators
5
+ class CellGenerator < ::Rails::Generators::NamedBase
6
+ argument :actions, :type => :array, :default => [], :banner => "action action"
7
+ check_class_collision :suffix => "Cell"
8
+
9
+ def create_cell_files
10
+ template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
10
11
  end
11
12
 
12
- def manifest
13
- record do |m|
14
- # Check for class naming collisions.
15
- m.class_collisions class_path, "#{class_name}Cell"
13
+ hook_for :template_engine
14
+ hook_for :test_framework
15
+
16
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
17
+
18
+
19
+ #attr_reader :template_type
20
+
21
+ #def initialize(runtime_args, runtime_options = {})
22
+ # super
23
+ # @template_type = options[:haml] ? :haml : :erb
24
+ #end
16
25
 
26
+ #def ___manifest
17
27
  # Directories
18
- m.directory File.join('app/cells', class_path)
19
- m.directory File.join('app/cells', class_path, file_name)
20
- m.directory File.join('test/cells')
28
+ #m.directory File.join('app/cells', class_path)
29
+ #m.directory File.join('app/cells', class_path, file_name)
30
+ #m.directory File.join('test/cells')
21
31
 
22
32
  # Cell
23
- m.template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
33
+ #m.template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
24
34
 
25
35
  # View template for each action.
26
- actions.each do |action|
27
- path = File.join('app/cells', class_path, file_name, "#{action}.html.#{template_type}")
28
- m.template "view.html.#{template_type}", path, :assigns => { :action => action, :path => path }
29
- end
36
+ #actions.each do |action|
37
+ # path = File.join('app/cells', class_path, file_name, "#{action}.html.#{template_type}")
38
+ # m.template "view.html.#{template_type}", path, :assigns => { :action => action, :path => path }
39
+ #end
30
40
 
31
41
  # Functional test for the widget.
32
- m.template 'cell_test.rb', File.join('test/cells/', "#{file_name}_cell_test.rb"), :assigns => {:states => actions}
33
- end
34
- end
42
+ #m.template 'cell_test.rb', File.join('test/cells/', "#{file_name}_cell_test.rb"), :assigns => {:states => actions}
43
+ #end
44
+ #end
35
45
 
36
- def add_options!(opt)
37
- opt.separator ''
38
- opt.separator 'Options:'
46
+ #def add_options!(opt)
47
+ # opt.separator ''
48
+ # opt.separator 'Options:'#
39
49
 
40
50
  # Allow option to generate HAML views instead of ERB.
41
- opt.on('--haml',
42
- "Generate HAML output instead of the default ERB.") do |v|
43
- options[:haml] = v
44
- end
45
- end
51
+ #opt.on('--haml',
52
+ #"Generate HAML output instead of the default ERB.") do |v|
53
+ # options[:haml] = v
54
+ #end
55
+ #end
46
56
 
47
- def banner
48
- "Usage: #{$0} cell NAME a_view another_view ... [--haml]"
49
- end
57
+ #def banner
58
+ # "Usage: #{$0} cell NAME a_view another_view ... [--haml]"
59
+ #end
50
60
 
51
61
  end
62
+
63
+ end;end
@@ -1,4 +1,4 @@
1
- class <%= class_name %>Cell < ::Cell::Base
1
+ class <%= class_name %>Cell < Cell::Rails
2
2
 
3
3
  <% for action in actions -%>
4
4
  def <%= action %>
@@ -1,10 +1,12 @@
1
+ # encoding: utf-8
2
+
1
3
  class CellsInstallGenerator < Rails::Generator::Base
4
+
2
5
  def manifest
3
6
  record do |m|
4
7
  m.directory File.join('config', 'initializers')
5
- m.directory File.join('lib', 'tasks')
6
8
  m.template 'initializer.rb', File.join('config', 'initializers', 'cells.rb')
7
- m.template 'tasks.rake', File.join('lib', 'tasks', 'cells.rake')
8
9
  end
9
10
  end
10
- end
11
+
12
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails/generators/erb'
2
+
3
+ module Erb
4
+ module Generators
5
+ class CellGenerator < Base
6
+ argument :actions, :type => :array, :default => [], :banner => "action action"
7
+
8
+ def copy_view_files
9
+ base_path = File.join("app/cells", class_path, file_name)
10
+ empty_directory base_path
11
+ puts base_path.inspect
12
+ actions.each do |action|
13
+ @action = action
14
+ @path = File.join(base_path, filename_with_extensions(action))
15
+ template filename_with_extensions(:view), @path
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -6,6 +6,7 @@ class ActiveHelperTest < ActiveSupport::TestCase
6
6
  context "The Cell::Base class" do
7
7
  setup do
8
8
  require 'active_helper'
9
+ require 'active_helper/rails'
9
10
  class FingeringHelper < ActiveHelper::Base
10
11
  provides :finger
11
12
  end
@@ -0,0 +1,2 @@
1
+ class BadGuitaristCell < BassistCell
2
+ end
@@ -1,3 +1,3 @@
1
1
  class BassistCell < Cell::Base
2
-
2
+ def play; render; end
3
3
  end
@@ -0,0 +1,16 @@
1
+ class MusicianController < ActionController::Base
2
+ def promotion
3
+ render :text => render_cell(:bassist, :play)
4
+ end
5
+
6
+ def featured
7
+ self.view_paths << File.expand_path(File.join(File.dirname(__FILE__), '../views'))
8
+ end
9
+
10
+ def skills
11
+ render :text => render_cell(:bassist, :listen)
12
+ end
13
+
14
+
15
+ def action_method?(name); true; end ### FIXME: fixes NameError: undefined local variable or method `_router' for MusicianController:Class
16
+ end
@@ -4,40 +4,30 @@ require File.join(File.dirname(__FILE__), 'test_helper')
4
4
  class AssertionsHelperTest < ActionController::TestCase
5
5
  context "A TestCase" do
6
6
  setup do
7
- TestCell.class_eval do
8
- def beep; render; end
9
- end
10
- end
11
-
12
- context "calling #cell_mock" do
13
- should "return a cell instance" do
14
- assert_kind_of Cell::Base, cell_mock
15
- end
16
-
17
- should "accept a block" do
18
- assert_respond_to cell_mock { def beep; end}, :beep
7
+ BassistCell.class_eval do
8
+ def play; render; end
19
9
  end
20
10
  end
21
11
 
22
12
  should "respond to #render_cell" do
23
- assert_equal "<h1>beep!</h1>", render_cell(:test, :beep)
13
+ assert_equal "Doo", render_cell(:bassist, :play)
24
14
  end
25
15
 
26
16
  should "respond to #assert_selekt" do
27
- assert_selekt render_cell(:test, :beep), "h1", "beep!"
17
+ assert_selekt "<p>Doo</p>", "p", "Doo"
28
18
  end
29
19
 
30
20
  should "respond to #cell" do
31
- assert_kind_of TestCell, cell(:test)
32
- assert_not cell(:test).respond_to? :opts
21
+ assert_kind_of BassistCell, cell(:bassist)
22
+ assert_not cell(:bassist).respond_to? :opts
33
23
  end
34
24
 
35
25
  should "respond to #cell with a block" do
36
- assert_respond_to cell(:test) { def opts; @opts; end }, :opts
26
+ assert_respond_to cell(:bassist) { def opts; @opts; end }, :opts
37
27
  end
38
28
 
39
29
  should "respond to #cell with options and block" do
40
- assert_equal({:topic => :peace}, cell(:test, :topic => :peace) { def opts; @opts; end }.opts)
30
+ assert_equal({:topic => :peace}, cell(:bassist, :topic => :peace) { def opts; @opts; end }.opts)
41
31
  end
42
32
  end
43
33
  end
@@ -0,0 +1,40 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class BaseMethodsTest < ActiveSupport::TestCase
4
+ context "Cell::Base" do
5
+
6
+ should "provide AbstractBase.render_cell_for" do
7
+ assert_equal "Doo", Cell::Base.render_cell_for(@controller, :bassist, :play)
8
+ end
9
+
10
+ should "provide possible_paths_for_state" do
11
+ assert_equal ["bad_guitarist/play", "bassist/play", "cell/rails/play"], cell(:bad_guitarist).possible_paths_for_state(:play)
12
+ end
13
+
14
+ should "provide cell_name" do
15
+ assert_equal 'bassist', cell(:bassist).cell_name
16
+ assert_equal cell(:bassist).cell_name, BassistCell.cell_name
17
+ end
18
+
19
+ should "provide cell_name for modules, too" do
20
+ class SingerCell
21
+ include Cell::BaseMethods
22
+ end
23
+
24
+ assert_equal "base_methods_test/singer", BaseMethodsTest::SingerCell.cell_name
25
+ end
26
+
27
+
28
+ should "provide class_from_cell_name" do
29
+ assert_equal BassistCell, ::Cell::Base.class_from_cell_name('bassist')
30
+ end
31
+
32
+ should "provide AbstractBase.default_template_format" do
33
+ cell(:bassist).class.default_template_format = :js
34
+
35
+ assert_equal :html, ::Cell::Base.default_template_format
36
+ assert_equal :js, cell(:bassist).class.default_template_format
37
+ end
38
+
39
+ end
40
+ end
@@ -1,33 +1,45 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[test_helper])
2
- require 'rails_generator'
3
- require 'rails_generator/scripts/generate'
4
2
 
5
- # for some reasons the "autoloading" in Rails::Generator::Lookup doesn't work:
6
- Rails::Generator::Base.append_sources Rails::Generator::PathSource.new(:cells, File.join(File.dirname(__FILE__)+'/../rails_generators'))
3
+ #require 'rails/generators/test_unit'
7
4
 
8
- class CellGeneratorTest < Test::Unit::TestCase
5
+
6
+ require '/home/nick/projects/rails/railties/lib/rails/test/isolation/abstract_unit'
7
+ #require '/home/nick/projects/rails/railties/test/generators/generators_test_helper'
8
+ require 'rails/generators'
9
+ require 'rails_generators/cell/cell_generator'
10
+ module Rails
11
+ def self.root
12
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
13
+ end
14
+ end
15
+
16
+
17
+ class CellGeneratorTest < Rails::Generators::TestCase
18
+ destination File.join(Rails.root, "tmp")
19
+ setup :prepare_destination
20
+ tests ::Cells::Generators::CellGenerator
21
+
22
+
9
23
  context "Running script/generate cell" do
10
- setup do
11
- FileUtils.mkdir_p(fake_rails_root)
12
- @original_files = file_list
13
- end
14
-
15
- teardown do
16
- FileUtils.rm_r(fake_rails_root)
17
- end
18
-
19
24
  context "Blog post latest" do
20
25
  should "create the standard assets" do
21
- Rails::Generator::Scripts::Generate.new.run(%w(cell Blog post latest), :destination => fake_rails_root)
22
- files = (file_list - @original_files)
23
- assert files.include?(fake_rails_root+"/app/cells/blog_cell.rb")
24
- assert files.include?(fake_rails_root+"/app/cells/blog/post.html.erb")
25
- assert files.include?(fake_rails_root+"/app/cells/blog/latest.html.erb")
26
- assert files.include?(fake_rails_root+"/test/cells/blog_cell_test.rb")
26
+
27
+ require "#{app_path}/config/environment" # we need Rails.application
28
+
29
+
30
+ run_generator ["Blog", "post", "latest"]
31
+
32
+ assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
33
+ assert_file "app/cells/blog/post.html.erb", %r(app/cells/blog/post\.html\.erb)
34
+ assert_file "app/cells/blog/latest.html.erb", %r(app/cells/blog/latest\.html\.erb)
35
+
36
+ #assert files.include?(fake_rails_root+"/app/cells/blog/post.html.erb")
37
+ #assert files.include?(fake_rails_root+"/app/cells/blog/latest.html.erb")
38
+ #assert files.include?(fake_rails_root+"/test/cells/blog_cell_test.rb")
27
39
  end
28
40
 
29
41
  should "create haml assets with --haml" do
30
- Rails::Generator::Scripts::Generate.new.run(%w(cell Blog post latest --haml), :destination => fake_rails_root)
42
+ run_generator ["Blog", "post", "latest", "--haml"]
31
43
  files = (file_list - @original_files)
32
44
  assert files.include?(fake_rails_root+"/app/cells/blog_cell.rb")
33
45
  assert files.include?(fake_rails_root+"/app/cells/blog/post.html.haml")
@@ -1,138 +1,46 @@
1
1
  # encoding: utf-8
2
2
  require File.join(File.dirname(__FILE__), 'test_helper')
3
3
 
4
- module CellsTestHelper
5
- def a_mysterious_helper_method
6
- 'mysterious'
7
- end
4
+ module StringHelper
5
+ def pick; "plong"; end
8
6
  end
9
7
 
10
- module AnotherHelper
11
- def senseless_helper_method
12
- 'senseless'
8
+ class DrummerCell < Cell::Base
9
+ helper StringHelper
10
+
11
+ def assist
12
+ render :inline => "<%= pick %>"
13
13
  end
14
14
  end
15
15
 
16
- class HelperUsingCell < ::Cell::Base
17
- helper CellsTestHelper
18
- helper_method :my_helper_method
19
-
20
- def state_with_helper_invocation
21
- render
22
- end
23
-
24
- def state_with_automatic_helper_invocation
25
- render
26
- end
27
-
28
- def state_with_helper_method_invocation
29
- render
30
- end
31
-
32
- def state_using_application_helper
33
- render
34
- end
35
-
36
- protected
37
-
38
- def my_helper_method
39
- 'helped by a method'
40
- end
41
- end
42
-
43
- class TwoHelpersIncludingCell < HelperUsingCell
44
- helper AnotherHelper
45
-
46
- def state_using_another_helper
47
- render
48
- end
49
- end
50
-
51
- class HelperUsingSubCell < HelperUsingCell
52
- end
53
16
 
54
17
  class HelperTest < ActionController::TestCase
55
- def test_helper
56
- cell = HelperUsingCell.new(@controller)
57
-
58
- c = cell.render_state(:state_with_helper_invocation)
59
- assert_selekt c, 'p#stateWithHelperInvocation', 'mysterious'
60
- end
61
-
62
- # ActiveSupport::Dependencies.load_paths << File.join(File.dirname(__FILE__), 'helpers')
63
- # test if the HelperUsingCellHelper is automatically included:
64
-
65
- ## FIXME: currently loading should happen in render_view_for_state, since
66
- # there seems to be no automatic mechanism.
67
- def dont_test_auto_helper
68
- # ActionController::Base.helpers_dir = File.join(File.dirname(__FILE__), 'helpers')
69
- ::Cell::Base.helpers_dir = File.join(File.dirname(__FILE__), 'app', 'helpers')
70
- setup
71
-
72
- cell = HelperUsingCell.new(@controller)
73
- c = cell.render_state(:state_with_automatic_helper_invocation)
74
-
75
- assert_selekt c, 'p#stateWithAutomaticHelperInvocation', 'automatic'
76
- end
77
-
78
- def test_helper_method
79
- cell = HelperUsingCell.new(@controller)
80
- c = cell.render_state(:state_with_helper_method_invocation)
81
-
82
- assert_selekt c, 'p#stateWithHelperMethodInvocation', 'helped by a method'
83
- end
84
-
85
- def test_helper_with_subclassing
86
- cell = HelperUsingSubCell.new(@controller)
87
- c = cell.render_state(:state_with_helper_invocation)
88
-
89
- assert_selekt c, 'p#stateWithHelperInvocation', 'mysterious'
90
- end
91
-
92
- def test_helper_including_and_cleanup
93
- # this cell includes a helper, and uses it:
94
- cell = HelperUsingCell.new(@controller)
95
- c = cell.render_state(:state_with_helper_invocation)
96
-
97
- assert_selekt c, 'p#stateWithHelperInvocation', 'mysterious'
98
-
99
- # this cell doesn't include the helper, but uses it anyway, which should
100
- # produce an error:
101
- cell = TestCell.new(@controller)
102
-
103
- # assert_raises (NameError) do
104
- assert_raises (::ActionView::TemplateError) do
105
- cell.render_state(:state_with_not_included_helper_method)
18
+ context "a cell view" do
19
+ should "have access to all helpers" do
20
+ BassistCell.class_eval do
21
+ def assist
22
+ render :inline => "<%= submit_tag %>"
23
+ end
24
+ end
25
+
26
+ assert_equal "<input name=\"commit\" type=\"submit\" value=\"Save changes\" />", render_cell(:bassist, :assist)
106
27
  end
107
- end
108
-
109
- def test_helpers_included_on_different_inheritance_levels
110
- cell = TwoHelpersIncludingCell.new(@controller)
111
- c = cell.render_state(:state_with_helper_invocation)
112
-
113
- assert_selekt c, 'p#stateWithHelperInvocation', 'mysterious'
114
-
115
- c = cell.render_state(:state_using_another_helper)
116
-
117
- assert_selekt c, 'p#stateUsingAnotherHelper', 'senseless'
118
- end
119
-
120
- def test_application_helper
121
- cell = HelperUsingCell.new(@controller)
122
- c = cell.render_state(:state_using_application_helper)
123
-
124
- assert_selekt c, 'p#stateUsingApplicationHelper', 'global'
125
- end
126
-
127
- def test_rails_helper_url_for
128
- cell = HelperUsingCell.new(@controller)
129
- cell.instance_eval do
130
- def state_with_url_for
131
- render :inline => "<%= url_for '/test' %>"
28
+
29
+ should "have access to methods declared with helper_method" do
30
+ BassistCell.class_eval do
31
+ def help; "Great!"; end
32
+ helper_method :help
33
+
34
+ def assist
35
+ render :inline => "<%= help %>"
36
+ end
132
37
  end
38
+
39
+ assert_equal "Great!", render_cell(:bassist, :assist)
40
+ end
41
+
42
+ should "have access to methods provided by helper" do
43
+ assert_equal "plong", render_cell(:drummer, :assist)
133
44
  end
134
- c = cell.render_state(:state_with_url_for)
135
-
136
- assert_equal '/test', c
137
45
  end
138
46
  end