cells 3.6.2 → 3.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.textile CHANGED
@@ -1,3 +1,13 @@
1
+ h2. 3.6.3
2
+
3
+ h3. Bugfixes
4
+ * [Rails 3.0] Helpers are now properly included (only once). Thanks to [paneq] for a fix.
5
+ * `#url_options` in the Metal module is now delegated to `parent_controller` which propagates global URL setting like relative URLs to your cells.
6
+
7
+ h3. Changes
8
+ * `cells/test_case` is no longer required as it should be loaded automatically.
9
+
10
+
1
11
  h2. 3.6.2
2
12
 
3
13
  h3. Bugfixes
data/README.rdoc CHANGED
@@ -22,19 +22,19 @@ Rails 3.x:
22
22
 
23
23
  Rails 2.3:
24
24
 
25
- gem install cells -v 3.3.5
25
+ gem install cells -v 3.3.8
26
26
 
27
27
 
28
28
  == Generate
29
29
 
30
30
  Creating a cell is nothing more than
31
31
 
32
- $ rails generate cell ShoppingCart display -e haml
32
+ $ rails generate cell cart display -e haml
33
33
  create app/cells/
34
- create app/cells/shopping_cart
35
- create app/cells/shopping_cart_cell.rb
36
- create app/cells/shopping_cart/display.html.haml
37
- create test/cells/shopping_cart_test.rb
34
+ create app/cells/cart
35
+ create app/cells/cart_cell.rb
36
+ create app/cells/cart/display.html.haml
37
+ create test/cells/cart_test.rb
38
38
 
39
39
  That looks very familiar.
40
40
 
@@ -43,15 +43,15 @@ That looks very familiar.
43
43
  Now, render your cart. Why not put it in <tt>layouts/application.html.erb</tt> for now?
44
44
 
45
45
  <div id="header">
46
- <%= render_cell :shopping_cart, :display, :user => @current_user %>
46
+ <%= render_cell :cart, :display, :user => @current_user %>
47
47
 
48
48
  Feels like rendering a controller action. For good encapsulation we pass the current +user+ from outside into the cell - a dependency injection.
49
49
 
50
50
  == Code
51
51
 
52
- Time to improve our cell code. Let's start with <tt>app/cells/shopping_cart_cell.rb</tt>:
52
+ Time to improve our cell code. Let's start with <tt>app/cells/cart_cell.rb</tt>:
53
53
 
54
- class ShoppingCartCell < Cell::Rails
54
+ class CartCell < Cell::Rails
55
55
  def display(args)
56
56
  user = args[:user]
57
57
  @items = user.items_in_cart
@@ -65,7 +65,7 @@ Is that a controller? Hell, yeah. We even got a +#render+ method as we know it f
65
65
 
66
66
  == Views
67
67
 
68
- Since a plain call to +#render+ will start rendering <tt>app/cells/shopping_cart/display.html.haml</tt> we should put some meaningful markup there.
68
+ Since a plain call to +#render+ will start rendering <tt>app/cells/cart/display.html.haml</tt> we should put some meaningful markup there.
69
69
 
70
70
  #cart
71
71
  You have #{@items.size} items in your shopping cart.
@@ -78,7 +78,7 @@ Yes, Cells support all template types that are supported by Rails itself. Rememb
78
78
 
79
79
  Yes, Cells have helpers just like controllers. If you need some specific helper, do
80
80
 
81
- class ShoppingCartCell < Cell::Rails
81
+ class CartCell < Cell::Rails
82
82
  helper MyExtraHelper
83
83
 
84
84
  and it will be around in your cart views.
@@ -119,19 +119,19 @@ will render the configured +UnauthorizedUserCell+ instead of the original +Login
119
119
 
120
120
  Cells do strict view caching. No cluttered fragment caching. Add
121
121
 
122
- class ShoppingCartCell < Cell::Rails
122
+ class CartCell < Cell::Rails
123
123
  cache :display, :expires_in => 10.minutes
124
124
 
125
125
  and your cart will be re-rendered after 10 minutes.
126
126
 
127
127
  You can expand the state's cache key - why not use a versioner block to do just this?
128
128
 
129
- class ShoppingCartCell < Cell::Rails
129
+ class CartCell < Cell::Rails
130
130
  cache :display do |cell, options|
131
131
  options[:items].md5
132
132
  end
133
133
 
134
- The block's return value is appended to the state key: <tt>"cells/shopping_cart/display/0ecb1360644ce665a4ef"</tt>.
134
+ The block's return value is appended to the state key: <tt>"cells/cart/display/0ecb1360644ce665a4ef"</tt>.
135
135
 
136
136
  Check the {API to learn more}[http://rdoc.info/gems/cells/Cell/Caching/ClassMethods#cache-instance_method].
137
137
 
@@ -141,9 +141,9 @@ Another big advantage compared to monolithic controller/helper/partial piles is
141
141
 
142
142
  === Test::Unit
143
143
 
144
- So what if you wanna test the cart cell? Use the generated <tt>test/cells/shopping_cart_cell_test.rb</tt> test.
144
+ So what if you wanna test the cart cell? Use the generated <tt>test/cells/cart_cell_test.rb</tt> test.
145
145
 
146
- class ShoppingCartCellTest < Cell::TestCase
146
+ class CartCellTest < Cell::TestCase
147
147
  test "display" do
148
148
  invoke :display, :user => @user_fixture
149
149
  assert_select "#cart", "You have 3 items in your shopping cart."
data/lib/cell/rails.rb CHANGED
@@ -33,14 +33,14 @@ module Cell
33
33
 
34
34
 
35
35
  module Metal
36
- delegate :session, :params, :request, :config, :env, :to => :parent_controller
36
+ delegate :session, :params, :request, :config, :env, :url_options, :to => :parent_controller
37
37
  end
38
38
 
39
39
 
40
+ include VersionStrategy
40
41
  include Metal
41
42
  include Rendering
42
43
  include Caching
43
- include VersionStrategy
44
44
 
45
45
 
46
46
  attr_reader :parent_controller
@@ -50,6 +50,7 @@ module Cell
50
50
 
51
51
 
52
52
  def initialize(parent_controller, *args)
53
+ super
53
54
  @parent_controller = parent_controller
54
55
  setup_backwardibility(*args)
55
56
  end
@@ -12,14 +12,12 @@ module Cell
12
12
 
13
13
  module ClassMethods
14
14
  def view_context_class
15
- controller = self
16
-
17
- Cell::Rails::View.class_eval do
18
- include controller._helpers
19
- include controller._routes.url_helpers
15
+ @view_context_class ||= begin
16
+ Class.new(Cell::Rails::View).tap do |klass|
17
+ klass.send(:include, _helpers)
18
+ klass.send(:include, _routes.url_helpers)
19
+ end
20
20
  end
21
-
22
- @view_context_class ||= Cell::Rails::View
23
21
  end
24
22
 
25
23
  # Return the default view path for +state+. Override this if you cell has a differing naming style.
data/lib/cells.rb CHANGED
@@ -83,8 +83,6 @@ end
83
83
  require 'cell/rails'
84
84
  require 'cells/railtie'
85
85
  require 'cells/rails'
86
- require 'cell/test_case' if Rails.env == "test"
87
-
88
86
  require 'cells/rails_compat' # fixes a bug in Rails <3.0.4. # TODO: remove me as soon as we support 3.1, only.
89
87
 
90
88
  Cell::Base = Cell::Rails
data/lib/cells/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cells
2
- VERSION = '3.6.2'
2
+ VERSION = '3.6.3'
3
3
  end
@@ -0,0 +1,2 @@
1
+ module ClubSecurity
2
+ end
@@ -0,0 +1 @@
1
+ <%= respond_to?(:irritate) %> <%= respond_to?(:smile) %>
@@ -0,0 +1,6 @@
1
+ class ClubSecurity::GuardCell < Cell::Base
2
+ helper do
3
+ def irritate; end
4
+ end
5
+ def help; render; end
6
+ end
@@ -0,0 +1 @@
1
+ <%= respond_to?(:irritate) %> <%= respond_to?(:smile) %>
@@ -0,0 +1,8 @@
1
+ class ClubSecurity::MedicCell < Cell::Base
2
+ module NiceGuy
3
+ def smile; end
4
+ end
5
+
6
+ helper NiceGuy
7
+ def help; render; end
8
+ end
data/test/helper_test.rb CHANGED
@@ -1,4 +1,7 @@
1
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'
2
5
 
3
6
  module StringHelper
4
7
  def pick; "plong"; end
@@ -43,5 +46,17 @@ class HelperTest < ActionController::TestCase
43
46
  should "have access to methods provided by helper" do
44
47
  assert_equal "plong", render_cell(:drummer, :assist)
45
48
  end
49
+
50
+ should "mix in required helpers, only" do
51
+ assert_equal "false true", render_cell(:"club_security/medic", :help)
52
+ assert_equal "true false", render_cell(:"club_security/guard", :help)
53
+ end
54
+
55
+ should "include helpers only once" do
56
+ assert_equal "false true", render_cell(:"club_security/medic", :help)
57
+ assert_equal "true false", render_cell(:"club_security/guard", :help)
58
+ assert_equal "false true", render_cell(:"club_security/medic", :help)
59
+ assert_equal "true false", render_cell(:"club_security/guard", :help)
60
+ end
46
61
  end
47
62
  end
@@ -4,7 +4,6 @@ class RailsRenderTest < ActiveSupport::TestCase
4
4
  include Cell::TestCase::TestMethods
5
5
 
6
6
  context "Invoking render" do
7
-
8
7
  should "render a plain view" do
9
8
  BassistCell.class_eval do
10
9
  def play; render; end
@@ -98,6 +97,15 @@ class RailsRenderTest < ActiveSupport::TestCase
98
97
  assert_equal "<b>Doo</b>", render_cell(:bassist, :play)
99
98
  end
100
99
 
100
+ should "respect the #layout class method" do
101
+ puts
102
+ class VanHalenBassistCell < BassistCell
103
+ layout 'b'
104
+ def play; render; end
105
+ end
106
+ assert_equal "<b>Doo</b>", render_cell("rails_render_test/van_halen_bassist", :play)
107
+ end
108
+
101
109
  should "raise an error for a non-existent template" do
102
110
  BassistCell.class_eval do
103
111
  def groove; render; end
@@ -18,6 +18,16 @@ module ApplicationTests
18
18
  assert_response :success
19
19
  assert_equal "Find me at <a href=\"/musician\">vd.com</a>", @response.body
20
20
  end
21
+
22
+ should "delegate #url_options to the parent_controller" do
23
+ @controller.instance_eval do
24
+ def default_url_options
25
+ {:host => "cells.rails.org"}
26
+ end
27
+ end
28
+
29
+ assert_equal "http://cells.rails.org/", BassistCell.new(@controller).root_url
30
+ end
21
31
 
22
32
  should "allow cells to use *_url helpers when mixing in AC::UrlFor" do
23
33
  get "promote"
data/test/test_helper.rb CHANGED
@@ -18,9 +18,6 @@ require "rails/test_help" # adds stuff like @routes, etc.
18
18
  gem_dir = File.join(File.dirname(__FILE__), '..')
19
19
  test_app_dir = File.join(gem_dir, 'test', 'app')
20
20
 
21
- # Important: Load any test ApplicationHelper before loading cells.
22
- Dir[File.join(test_app_dir, *%w[helpers ** *.rb]).to_s].each { |f| require f }
23
-
24
21
  require 'cells'
25
22
 
26
23
  Cell::Rails.append_view_path(File.join(test_app_dir, 'cells'))
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 6
8
- - 2
9
- version: 3.6.2
8
+ - 3
9
+ version: 3.6.3
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-06-29 00:00:00 +02:00
17
+ date: 2011-07-14 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -143,6 +143,11 @@ files:
143
143
  - test/app/cells/bassist/slap.html.erb
144
144
  - test/app/cells/bassist/yell.en.html.erb
145
145
  - test/app/cells/bassist_cell.rb
146
+ - test/app/cells/club_security.rb
147
+ - test/app/cells/club_security/guard/help.html.erb
148
+ - test/app/cells/club_security/guard_cell.rb
149
+ - test/app/cells/club_security/medic/help.html.erb
150
+ - test/app/cells/club_security/medic_cell.rb
146
151
  - test/app/cells/layouts/b.erb
147
152
  - test/app/cells/layouts/metal.html.erb
148
153
  - test/app/cells/producer/capture.html.erb