cells 3.8.5 → 3.8.6
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.
- data/CHANGES.textile +7 -1
- data/README.rdoc +63 -12
- data/cells.gemspec +1 -0
- data/lib/cell/base.rb +28 -2
- data/lib/cell/caching.rb +15 -17
- data/lib/cell/rails.rb +21 -0
- data/lib/cell/rails/helper_api.rb +37 -0
- data/lib/cell/rails3_0_strategy.rb +2 -7
- data/lib/cell/rails3_1_strategy.rb +3 -7
- data/lib/cells.rb +0 -12
- data/lib/cells/version.rb +1 -1
- data/lib/generators/test_unit/cell_generator.rb +1 -1
- data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +5 -0
- data/test/app/views/shared/_dong.html.erb +1 -0
- data/test/cell_generator_test.rb +6 -0
- data/test/cell_module_test.rb +14 -1
- data/test/cells_module_test.rb +1 -14
- data/test/rails/caching_test.rb +59 -8
- data/test/rails/cells_test.rb +2 -3
- data/test/rails/render_test.rb +1 -1
- data/test/rails/view_test.rb +11 -0
- data/test/rails_helper_api_test.rb +59 -0
- data/test/test_case_test.rb +2 -2
- metadata +23 -80
data/CHANGES.textile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
h2. 3.8.6
|
2
|
+
|
3
|
+
* @cell/base@ can now be required without trouble.
|
4
|
+
* Generated test files now respect namespaced cells.
|
5
|
+
|
1
6
|
h2. 3.8.5
|
2
7
|
|
3
|
-
*
|
8
|
+
* Added @Cell::Rails::HelperAPI@ module to provide the entire Rails view "API" (quotes on purpose!) in cells running completely outside of Rails. This makes it possible to use gems like simple_form in any Ruby environment, especially interesting for people using Sinatra, webmachine, etc.
|
9
|
+
* Moved @Caching.expire_cache_key@ to @Rails@. Use @Caching.expire_cache_key_for(key, cache_store, ..)@ if you want to expire caches outside of Rails.
|
4
10
|
|
5
11
|
h2. 3.8.4
|
6
12
|
|
data/README.rdoc
CHANGED
@@ -31,11 +31,11 @@ Rails 2.3:
|
|
31
31
|
|
32
32
|
Creating a cell is nothing more than
|
33
33
|
|
34
|
-
$ rails generate cell cart
|
34
|
+
$ rails generate cell cart show -e haml
|
35
35
|
create app/cells/
|
36
36
|
create app/cells/cart
|
37
37
|
create app/cells/cart_cell.rb
|
38
|
-
create app/cells/cart/
|
38
|
+
create app/cells/cart/show.html.haml
|
39
39
|
create test/cells/cart_test.rb
|
40
40
|
|
41
41
|
That looks very familiar.
|
@@ -45,7 +45,7 @@ That looks very familiar.
|
|
45
45
|
Now, render your cart. Why not put it in <tt>layouts/application.html.erb</tt> for now?
|
46
46
|
|
47
47
|
<div id="header">
|
48
|
-
<%= render_cell :cart, :
|
48
|
+
<%= render_cell :cart, :show, :user => @current_user %>
|
49
49
|
|
50
50
|
Feels like rendering a controller action. For good encapsulation we pass the current +user+ from outside into the cell - a dependency injection.
|
51
51
|
|
@@ -54,11 +54,11 @@ Feels like rendering a controller action. For good encapsulation we pass the cur
|
|
54
54
|
Time to improve our cell code. Let's start with <tt>app/cells/cart_cell.rb</tt>:
|
55
55
|
|
56
56
|
class CartCell < Cell::Rails
|
57
|
-
def
|
57
|
+
def show(args)
|
58
58
|
user = args[:user]
|
59
59
|
@items = user.items_in_cart
|
60
60
|
|
61
|
-
render # renders
|
61
|
+
render # renders show.html.haml
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -67,7 +67,7 @@ Is that a controller? Hell, yeah. We even got a +#render+ method as we know it f
|
|
67
67
|
|
68
68
|
== Views
|
69
69
|
|
70
|
-
Since a plain call to +#render+ will start rendering <tt>app/cells/cart/
|
70
|
+
Since a plain call to +#render+ will start rendering <tt>app/cells/cart/show.html.haml</tt> we should put some meaningful markup there.
|
71
71
|
|
72
72
|
#cart
|
73
73
|
You have #{@items.size} items in your shopping cart.
|
@@ -94,6 +94,14 @@ The distinction between partials and views is making things more complex, so why
|
|
94
94
|
%p
|
95
95
|
= render :view => 'items'
|
96
96
|
|
97
|
+
=== Rendering Global Partials
|
98
|
+
|
99
|
+
Sometimes you need to render a global partial from <tt>app/views</tt> within a cell. For instance, the +gmaps4rails+ helper depends on a global partial. While this breaks encapsulation it's still possible in cells - just add the global view path.
|
100
|
+
|
101
|
+
class MapCell < Cell::Rails
|
102
|
+
append_view_path "app/views"
|
103
|
+
|
104
|
+
|
97
105
|
== View Inheritance
|
98
106
|
|
99
107
|
This is where OOP comes back to your view.
|
@@ -122,18 +130,18 @@ will render the configured +UnauthorizedUserCell+ instead of the original +Login
|
|
122
130
|
Cells do strict view caching. No cluttered fragment caching. Add
|
123
131
|
|
124
132
|
class CartCell < Cell::Rails
|
125
|
-
cache :
|
133
|
+
cache :show, :expires_in => 10.minutes
|
126
134
|
|
127
135
|
and your cart will be re-rendered after 10 minutes.
|
128
136
|
|
129
137
|
You can expand the state's cache key - why not use a versioner block to do just this?
|
130
138
|
|
131
139
|
class CartCell < Cell::Rails
|
132
|
-
cache :
|
140
|
+
cache :show do |cell, options|
|
133
141
|
options[:items].md5
|
134
142
|
end
|
135
143
|
|
136
|
-
The block's return value is appended to the state key: <tt>"cells/cart/
|
144
|
+
The block's return value is appended to the state key: <tt>"cells/cart/show/0ecb1360644ce665a4ef"</tt>.
|
137
145
|
|
138
146
|
Check the {API to learn more}[http://rdoc.info/gems/cells/Cell/Caching/ClassMethods#cache-instance_method].
|
139
147
|
|
@@ -146,8 +154,8 @@ Another big advantage compared to monolithic controller/helper/partial piles is
|
|
146
154
|
So what if you wanna test the cart cell? Use the generated <tt>test/cells/cart_cell_test.rb</tt> test.
|
147
155
|
|
148
156
|
class CartCellTest < Cell::TestCase
|
149
|
-
test "
|
150
|
-
invoke :
|
157
|
+
test "show" do
|
158
|
+
invoke :show, :user => @user_fixture
|
151
159
|
assert_select "#cart", "You have 3 items in your shopping cart."
|
152
160
|
end
|
153
161
|
|
@@ -186,11 +194,54 @@ In your <tt>routes.rb</tt> file, mount the cell like a Rack app.
|
|
186
194
|
[ 200, {}, [ Cell::Base.render_cell_for(:post, :show) ]]
|
187
195
|
}
|
188
196
|
|
197
|
+
=== Cells in ActionMailer
|
198
|
+
|
199
|
+
ActionMailer doesn't have request object, so if you inherit from Cell::Rails you will receive an error. Cell::Base will fix that problem, but you will not be able to use any of routes inside your cells.
|
200
|
+
|
201
|
+
You can fix that with {actionmailer_with_request}[https://github.com/weppos/actionmailer_with_request] which (suprise!) brings request object to the ActionMailer.
|
202
|
+
|
203
|
+
== Using Rails Gems Like simple_form Outside Of Rails
|
204
|
+
|
205
|
+
Cells can be used outside of Rails. A new module brought in 3.8.5 provides the Rails view "API" making it possible to use gems like the popular {simple_form}[https://github.com/plataformatec/simple_form] outside Rails!
|
206
|
+
|
207
|
+
All you need to do is providing the cell with some helpers, usually it's the polymorphic routing paths required by the gems.
|
208
|
+
|
209
|
+
module RoutingHelpers
|
210
|
+
def musician_path(model)
|
211
|
+
"/musicians/#{model.id}"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
Then, use the Cell::Rails::HelperAPI module and it should work fine (depending on the quality of the gem you're desiring to use).
|
216
|
+
|
217
|
+
require 'cell/base'
|
218
|
+
require "cell/rails/helper_api"
|
219
|
+
require "simple_form"
|
220
|
+
|
221
|
+
class BassistCell < Cell::Base
|
222
|
+
include Cell::Rails::HelperAPI
|
223
|
+
|
224
|
+
self._helpers = RoutingHelpers
|
225
|
+
|
226
|
+
def show
|
227
|
+
@musician = Musician.find(:first)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
Your views can now use the gem's helpers.
|
232
|
+
|
233
|
+
<%= simple_form_for @musician do |f| %>
|
234
|
+
<%= f.input :name %>
|
235
|
+
<%= f.button :submit %>
|
236
|
+
<% end %>
|
237
|
+
|
238
|
+
Note that this currently "only" works with Rails 3.2.
|
239
|
+
|
189
240
|
== Cells is Rails::Engine aware!
|
190
241
|
|
191
242
|
Now <tt>Rails::Engine</tt>s can contribute to Cells view paths. By default, any 'app/cells' found inside any Engine is automatically included into Cells view paths. If you need to, you can customize the view paths changing/appending to the <tt>'app/cell_views'</tt> path configuration. See the @Cell::EngineIntegration@ for more details.
|
192
243
|
|
193
|
-
==
|
244
|
+
== Generators
|
194
245
|
|
195
246
|
By default, generated cells inherit from <code>Cell::Rails</code>. If you want to change this, specify your new class name in <code>config/application.rb</code>:
|
196
247
|
|
data/cells.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency "shoulda"
|
27
27
|
s.add_development_dependency "haml"
|
28
28
|
s.add_development_dependency "slim"
|
29
|
+
s.add_development_dependency "simple_form"
|
29
30
|
s.add_development_dependency "tzinfo" # FIXME: why the hell do we need this for 3.1?
|
30
31
|
s.add_development_dependency "minitest", ">= 2.8.1"
|
31
32
|
end
|
data/lib/cell/base.rb
CHANGED
@@ -2,10 +2,21 @@ require 'abstract_controller'
|
|
2
2
|
require 'cell/builder'
|
3
3
|
require 'cell/caching'
|
4
4
|
require 'cell/rendering'
|
5
|
-
require 'cell/rails3_0_strategy' if Cells.rails3_0?
|
6
|
-
require 'cell/rails3_1_strategy' if Cells.rails3_1_or_more?
|
7
5
|
|
8
6
|
module Cell
|
7
|
+
def self.rails3_0?
|
8
|
+
::ActionPack::VERSION::MINOR == 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.rails3_1_or_more?
|
12
|
+
::ActionPack::VERSION::MINOR >= 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.rails3_2_or_more? # FIXME: move to tests.
|
16
|
+
::ActionPack::VERSION::MINOR >= 2
|
17
|
+
end
|
18
|
+
|
19
|
+
|
9
20
|
class Base < AbstractController::Base
|
10
21
|
abstract!
|
11
22
|
DEFAULT_VIEW_PATHS = [File.join('app', 'cells')]
|
@@ -14,11 +25,20 @@ module Cell
|
|
14
25
|
include AbstractController
|
15
26
|
include AbstractController::Rendering, Layouts, Helpers, Callbacks, Translation, Logger
|
16
27
|
|
28
|
+
require 'cell/rails3_0_strategy' if Cell.rails3_0?
|
29
|
+
require 'cell/rails3_1_strategy' if Cell.rails3_1_or_more?
|
17
30
|
include VersionStrategy
|
18
31
|
include Rendering
|
19
32
|
include Caching
|
20
33
|
|
21
34
|
class View < ActionView::Base
|
35
|
+
def self.prepare(modules)
|
36
|
+
# TODO: remove for 4.0 if PR https://github.com/rails/rails/pull/6826 is merged.
|
37
|
+
Class.new(self) do # DISCUSS: why are we mixing that stuff into this _anonymous_ class at all? that makes things super complicated.
|
38
|
+
include *modules.reverse
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
22
42
|
def render(*args, &block)
|
23
43
|
options = args.first.is_a?(::Hash) ? args.first : {} # this is copied from #render by intention.
|
24
44
|
|
@@ -28,6 +48,12 @@ module Cell
|
|
28
48
|
end
|
29
49
|
|
30
50
|
|
51
|
+
def self.view_context_class
|
52
|
+
@view_context_class ||= begin
|
53
|
+
Cell::Base::View.prepare(helper_modules)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
31
57
|
# Called in Railtie at initialization time.
|
32
58
|
def self.setup_view_paths!
|
33
59
|
self.view_paths = self::DEFAULT_VIEW_PATHS
|
data/lib/cell/caching.rb
CHANGED
@@ -60,25 +60,15 @@ module Cell
|
|
60
60
|
self.cache_options = cache_options.merge(state => options)
|
61
61
|
end
|
62
62
|
|
63
|
-
def cache_store
|
64
|
-
# DISCUSS: move to instance level and delegate to #config/#parent_controller.
|
65
|
-
# This would allow convenient cache settings per cell (if needed).
|
66
|
-
::ActionController::Base.cache_store
|
67
|
-
end
|
68
|
-
|
69
63
|
# Computes the complete, namespaced cache key for +state+.
|
70
64
|
def state_cache_key(state, key_parts={})
|
71
65
|
expand_cache_key([controller_path, state, key_parts])
|
72
66
|
end
|
73
67
|
|
74
|
-
def
|
68
|
+
def expire_cache_key_for(key, cache_store, *args)
|
75
69
|
cache_store.delete(key, *args)
|
76
70
|
end
|
77
71
|
|
78
|
-
def cache?(state)
|
79
|
-
# DISCUSS: why is it private?
|
80
|
-
ActionController::Base.send(:cache_configured?) and state_cached?(state)
|
81
|
-
end
|
82
72
|
|
83
73
|
protected
|
84
74
|
# Compiles cache key and adds :cells namespace to +key+, according to the
|
@@ -86,28 +76,36 @@ module Cell
|
|
86
76
|
def expand_cache_key(key)
|
87
77
|
::ActiveSupport::Cache.expand_cache_key(key, :cells)
|
88
78
|
end
|
89
|
-
|
90
|
-
def state_cached?(state)
|
91
|
-
version_procs.has_key?(state)
|
92
|
-
end
|
93
79
|
end
|
94
80
|
|
81
|
+
|
95
82
|
def render_state(state, *args)
|
96
83
|
return super(state, *args) unless cache?(state, *args)
|
97
84
|
|
98
85
|
key = self.class.state_cache_key(state, call_state_versioner(state, *args))
|
99
86
|
options = self.class.cache_options[state]
|
100
87
|
|
101
|
-
|
88
|
+
cache_store.fetch(key, options) do
|
102
89
|
super(state, *args)
|
103
90
|
end
|
104
91
|
end
|
105
92
|
|
93
|
+
def cache_configured?
|
94
|
+
@cache_configured
|
95
|
+
end
|
96
|
+
attr_writer :cache_configured
|
97
|
+
|
98
|
+
attr_accessor :cache_store # we want to use DI to set a cache store in cell/rails.
|
99
|
+
|
106
100
|
def cache?(state, *args)
|
107
|
-
|
101
|
+
cache_configured? and state_cached?(state) and call_state_conditional(state, *args)
|
108
102
|
end
|
109
103
|
|
110
104
|
protected
|
105
|
+
def state_cached?(state)
|
106
|
+
self.class.version_procs.has_key?(state)
|
107
|
+
end
|
108
|
+
|
111
109
|
def call_proc_or_method(state, method, *args)
|
112
110
|
return method.call(self, *args) if method.kind_of?(Proc)
|
113
111
|
send(method, *args)
|
data/lib/cell/rails.rb
CHANGED
@@ -2,12 +2,24 @@ require 'cell/rack'
|
|
2
2
|
|
3
3
|
module Cell
|
4
4
|
class Rails < Rack
|
5
|
+
# When this file is included we can savely assume that a rails environment with caching, etc. is available.
|
5
6
|
include ActionController::RequestForgeryProtection
|
6
7
|
|
7
8
|
abstract!
|
8
9
|
delegate :session, :params, :request, :config, :env, :url_options, :to => :parent_controller
|
9
10
|
|
10
11
|
class << self
|
12
|
+
def cache_store
|
13
|
+
# FIXME: i'd love to have an initializer in the cells gem that _sets_ the cache_store attr instead of overriding here.
|
14
|
+
# since i dunno how to do that we'll have this method in rails for now.
|
15
|
+
# DISCUSS: should this be in Cell::Rails::Caching ?
|
16
|
+
ActionController::Base.cache_store
|
17
|
+
end
|
18
|
+
|
19
|
+
def expire_cache_key(key, *args) # FIXME: move to Rails.
|
20
|
+
expire_cache_key_for(key, cache_store ,*args)
|
21
|
+
end
|
22
|
+
|
11
23
|
private
|
12
24
|
# Run builder block in controller instance context.
|
13
25
|
def run_builder_block(block, controller, *args)
|
@@ -15,11 +27,20 @@ module Cell
|
|
15
27
|
end
|
16
28
|
end
|
17
29
|
|
30
|
+
|
18
31
|
attr_reader :parent_controller
|
19
32
|
|
20
33
|
def initialize(parent_controller)
|
21
34
|
super
|
22
35
|
@parent_controller = parent_controller
|
23
36
|
end
|
37
|
+
|
38
|
+
def cache_configured?
|
39
|
+
ActionController::Base.send(:cache_configured?) # DISCUSS: why is it private?
|
40
|
+
end
|
41
|
+
|
42
|
+
def cache_store
|
43
|
+
self.class.cache_store # in Rails, we have a global cache store.
|
44
|
+
end
|
24
45
|
end
|
25
46
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Cell
|
2
|
+
# Allows using many Rails gem in your cells outside of a Rails environment.
|
3
|
+
class Rails
|
4
|
+
module HelperAPI
|
5
|
+
module InternalHelpers
|
6
|
+
def protect_against_forgery? # used in form_tag_helper.rb:651
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
def _routes # FIXME: where is this set in rails?
|
11
|
+
self.class._routes
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
extend ActiveSupport::Concern
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
attr_accessor :_routes
|
19
|
+
|
20
|
+
def helper_modules
|
21
|
+
[_helpers, InternalHelpers]
|
22
|
+
end
|
23
|
+
|
24
|
+
def view_context_class
|
25
|
+
super
|
26
|
+
@view_context_class._routes = _routes
|
27
|
+
@view_context_class
|
28
|
+
end
|
29
|
+
|
30
|
+
def action_methods
|
31
|
+
# DISCUSS: we have to overwrite this to avoid a stupid dependency in AbstractController::UrlFor where _routes.named_routes.helper_names is accessed.
|
32
|
+
public_instance_methods(true).map { |x| x.to_s }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -12,13 +12,8 @@ module Cell
|
|
12
12
|
|
13
13
|
|
14
14
|
module ClassMethods
|
15
|
-
def
|
16
|
-
|
17
|
-
Class.new(Cell::Rails::View).tap do |klass|
|
18
|
-
klass.send(:include, _helpers)
|
19
|
-
klass.send(:include, _routes.url_helpers)
|
20
|
-
end
|
21
|
-
end
|
15
|
+
def helper_modules
|
16
|
+
[_helpers, _routes.url_helpers]
|
22
17
|
end
|
23
18
|
|
24
19
|
# Return the default view path for +state+. Override this if you cell has a differing naming style.
|
@@ -4,16 +4,12 @@ module Cell
|
|
4
4
|
module VersionStrategy
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
include AbstractController::UrlFor # must be included before _routes is set in Railstie.
|
7
|
+
include AbstractController::UrlFor # must be included before _routes is set in Railstie. # TODO: remove that.
|
8
8
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
def
|
12
|
-
|
13
|
-
routes = _routes #if respond_to?(:_routes)
|
14
|
-
helpers = _helpers #if respond_to?(:_helpers)
|
15
|
-
Cell::Rails::View.prepare(routes, helpers)
|
16
|
-
end
|
11
|
+
def helper_modules
|
12
|
+
[_routes.url_helpers, _routes.mounted_helpers, _helpers]
|
17
13
|
end
|
18
14
|
end
|
19
15
|
|
data/lib/cells.rb
CHANGED
@@ -70,18 +70,6 @@ module Cells
|
|
70
70
|
def self.setup
|
71
71
|
yield(Cell::Rails)
|
72
72
|
end
|
73
|
-
|
74
|
-
def self.rails3_0?
|
75
|
-
::Rails::VERSION::MINOR == 0
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.rails3_1_or_more?
|
79
|
-
::Rails::VERSION::MINOR >= 1
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.rails3_2_or_more? # FIXME: move to tests.
|
83
|
-
::Rails::VERSION::MINOR >= 2
|
84
|
-
end
|
85
73
|
end
|
86
74
|
|
87
75
|
require 'cell/rails'
|
data/lib/cells/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
Dong!
|
data/test/cell_generator_test.rb
CHANGED
@@ -100,6 +100,12 @@ class CellGeneratorTest < Rails::Generators::TestCase
|
|
100
100
|
assert_file "test/cells/blog_cell_test.rb"
|
101
101
|
end
|
102
102
|
|
103
|
+
should "work with namespace and test_unit" do
|
104
|
+
run_generator %w(Blog::Post latest -t test_unit)
|
105
|
+
|
106
|
+
assert_file "test/cells/blog/post_cell_test.rb", /class Blog::PostCellTest < Cell::TestCase/
|
107
|
+
end
|
108
|
+
|
103
109
|
should "create test_unit assets with -t rspec" do
|
104
110
|
run_generator %w(Blog post latest -t rspec)
|
105
111
|
|
data/test/cell_module_test.rb
CHANGED
@@ -149,7 +149,7 @@ class CellModuleTest < ActiveSupport::TestCase
|
|
149
149
|
assert_equal BassistCell, ::Cell::Rails.class_from_cell_name('bassist')
|
150
150
|
end
|
151
151
|
|
152
|
-
if
|
152
|
+
if Cell.rails3_0?
|
153
153
|
should "provide possible_paths_for_state" do
|
154
154
|
assert_equal ["bad_guitarist/play", "bassist/play"], cell(:bad_guitarist).send(:possible_paths_for_state, :play)
|
155
155
|
end
|
@@ -166,4 +166,17 @@ class CellModuleTest < ActiveSupport::TestCase
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
169
|
+
|
170
|
+
should "respond to #rails3_1_or_more?" do
|
171
|
+
if Rails::VERSION::MINOR == 0
|
172
|
+
assert ! Cell.rails3_1_or_more?
|
173
|
+
assert Cell.rails3_0?
|
174
|
+
elsif Rails::VERSION::MINOR == 1
|
175
|
+
assert Cell.rails3_1_or_more?
|
176
|
+
assert ! Cell.rails3_0?
|
177
|
+
elsif Rails::VERSION::MINOR == 2
|
178
|
+
assert Cell.rails3_1_or_more?
|
179
|
+
assert ! Cell.rails3_0?
|
180
|
+
end
|
181
|
+
end
|
169
182
|
end
|
data/test/cells_module_test.rb
CHANGED
@@ -16,25 +16,12 @@ class CellsModuleTest < ActiveSupport::TestCase
|
|
16
16
|
c.append_view_path "/road/to/nowhere"
|
17
17
|
end
|
18
18
|
|
19
|
-
if
|
19
|
+
if Cell.rails3_2_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
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
27
|
-
should "respond to #rails3_1_or_more?" do
|
28
|
-
if Rails::VERSION::MINOR == 0
|
29
|
-
assert ! Cells.rails3_1_or_more?
|
30
|
-
assert Cells.rails3_0?
|
31
|
-
elsif Rails::VERSION::MINOR == 1
|
32
|
-
assert Cells.rails3_1_or_more?
|
33
|
-
assert ! Cells.rails3_0?
|
34
|
-
elsif Rails::VERSION::MINOR == 2
|
35
|
-
assert Cells.rails3_1_or_more?
|
36
|
-
assert ! Cells.rails3_0?
|
37
|
-
end
|
38
|
-
end
|
39
26
|
end
|
40
27
|
end
|
data/test/rails/caching_test.rb
CHANGED
@@ -49,24 +49,24 @@ class CachingUnitTest < ActiveSupport::TestCase
|
|
49
49
|
end
|
50
50
|
|
51
51
|
|
52
|
-
context "
|
52
|
+
context "#state_cached?" do
|
53
53
|
should "return true for cached" do
|
54
|
-
assert @
|
54
|
+
assert @cell.send :state_cached?, :count
|
55
55
|
end
|
56
56
|
|
57
57
|
should "return false otherwise" do
|
58
|
-
assert_not @
|
58
|
+
assert_not @cell.send :state_cached?, :sing
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
|
63
|
-
context "
|
63
|
+
context "#cache?" do
|
64
64
|
should "return true for cached" do
|
65
|
-
assert @cell.
|
65
|
+
assert @cell.cache?(:count)
|
66
66
|
end
|
67
67
|
|
68
68
|
should "return false otherwise" do
|
69
|
-
assert_not @cell.
|
69
|
+
assert_not @cell.cache?(:sing)
|
70
70
|
end
|
71
71
|
|
72
72
|
context "perform_caching turned off" do
|
@@ -76,8 +76,38 @@ class CachingUnitTest < ActiveSupport::TestCase
|
|
76
76
|
|
77
77
|
should "always return false if caching turned-off" do
|
78
78
|
::ActionController::Base.perform_caching = false
|
79
|
-
assert_not @cell.
|
80
|
-
assert_not @cell.
|
79
|
+
assert_not @cell.cache?(:count)
|
80
|
+
assert_not @cell.cache?(:sing)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context ".cache_store" do
|
85
|
+
should "return Rails cache store per default" do
|
86
|
+
assert_equal ActionController::Base.cache_store, DirectorCell.cache_store
|
87
|
+
end
|
88
|
+
|
89
|
+
context "Cell::Base" do
|
90
|
+
setup do
|
91
|
+
@class = Class.new(Cell::Base)
|
92
|
+
@cell = @class.new
|
93
|
+
end
|
94
|
+
|
95
|
+
context "#cache_store" do
|
96
|
+
should "be setable from the outside" do
|
97
|
+
assert_equal nil, @cell.cache_store
|
98
|
+
@cell.cache_store = Object
|
99
|
+
assert_equal Object, @cell.cache_store
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "#cache_configured?" do
|
104
|
+
should "be setable from the outside" do
|
105
|
+
assert_equal nil, @cell.cache_configured?
|
106
|
+
@cell.cache_configured = true
|
107
|
+
assert_equal true, @cell.cache_configured?
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
81
111
|
end
|
82
112
|
end
|
83
113
|
end
|
@@ -307,5 +337,26 @@ class CachingFunctionalTest < ActiveSupport::TestCase
|
|
307
337
|
assert_equal "1", render_cell(:director, :count, 3)
|
308
338
|
assert_equal "4", render_cell(:director, :count, 4)
|
309
339
|
end
|
340
|
+
|
341
|
+
should "allow using a different cache store" do
|
342
|
+
class BassistCell < Cell::Base
|
343
|
+
cache :play
|
344
|
+
|
345
|
+
def play(song)
|
346
|
+
render :text => song
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
@cell = BassistCell.new
|
351
|
+
|
352
|
+
assert_equal "New Years", @cell.render_state(:play, "New Years")
|
353
|
+
assert_equal "Liar", @cell.render_state(:play, "Liar")
|
354
|
+
|
355
|
+
@cell.cache_configured = true
|
356
|
+
@cell.cache_store = ActiveSupport::Cache::MemoryStore.new
|
357
|
+
|
358
|
+
assert_equal "New Years", @cell.render_state(:play, "New Years")
|
359
|
+
assert_equal "New Years", @cell.render_state(:play, "Liar")
|
360
|
+
end
|
310
361
|
end
|
311
362
|
end
|
data/test/rails/cells_test.rb
CHANGED
@@ -54,7 +54,7 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
54
54
|
should "respond to .setup_view_paths!" do
|
55
55
|
swap( Cell::Rails, :view_paths => []) do
|
56
56
|
Cell::Rails.setup_view_paths!
|
57
|
-
if
|
57
|
+
if Cell.rails3_2_or_more?
|
58
58
|
assert_equal ActionView::PathSet.new(Cell::Rails::DEFAULT_VIEW_PATHS).paths, Cell::Rails.view_paths.paths
|
59
59
|
else
|
60
60
|
assert_equal ActionView::PathSet.new(Cell::Rails::DEFAULT_VIEW_PATHS), Cell::Rails.view_paths
|
@@ -81,8 +81,7 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
81
81
|
end
|
82
82
|
|
83
83
|
|
84
|
-
if
|
85
|
-
puts "rails-3.0"
|
84
|
+
if Cell.rails3_0?
|
86
85
|
context "invoking find_family_view_for_state" do
|
87
86
|
should "raise an error when a template is missing" do
|
88
87
|
assert_raises ActionView::MissingTemplate do
|
data/test/rails/render_test.rb
CHANGED
data/test/rails/view_test.rb
CHANGED
@@ -4,6 +4,7 @@ class RailsViewTest < ActiveSupport::TestCase
|
|
4
4
|
include Cell::TestCase::TestMethods
|
5
5
|
|
6
6
|
context "A cell view" do
|
7
|
+
# DISCUSS: should we allow :partial from a state, too?
|
7
8
|
context "calling render :partial" do
|
8
9
|
should "render the local cell partial in bassist/dii" do
|
9
10
|
assert_equal("Dii", in_view(:bassist) do
|
@@ -16,6 +17,16 @@ class RailsViewTest < ActiveSupport::TestCase
|
|
16
17
|
render :partial => "bad_guitarist/dii"
|
17
18
|
end)
|
18
19
|
end
|
20
|
+
|
21
|
+
|
22
|
+
should "render the global partial app/views/shared/dong" do
|
23
|
+
class PercussionistCell < BassistCell
|
24
|
+
append_view_path("test/app/views")
|
25
|
+
end
|
26
|
+
assert_equal("Dong!", in_view("rails_view_test/percussionist") do
|
27
|
+
render :partial => "shared/dong"
|
28
|
+
end)
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
32
|
should "respond to render :state" do
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'cell/rails/helper_api'
|
3
|
+
|
4
|
+
|
5
|
+
class RailsHelperAPITest < MiniTest::Spec
|
6
|
+
class ::Fruit
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
include ActiveModel::Conversion
|
9
|
+
|
10
|
+
def initialize(attributes={})
|
11
|
+
@attributes = attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
def title
|
15
|
+
@attributes[:title]
|
16
|
+
end
|
17
|
+
|
18
|
+
def persisted?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
class FakeUrlFor # should be sinatra's url helper instance
|
25
|
+
def url_for(*)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module FakeHelpers
|
30
|
+
def fruits_path(model, *args)
|
31
|
+
"/fruits"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
require "simple_form"
|
36
|
+
class BassistCell < Cell::Base
|
37
|
+
include Cell::Rails::HelperAPI
|
38
|
+
|
39
|
+
self._helpers = FakeHelpers
|
40
|
+
self._routes = FakeUrlFor.new
|
41
|
+
|
42
|
+
def edit
|
43
|
+
@tone = "C"
|
44
|
+
@fruit = Fruit.new(:title => "Banana")
|
45
|
+
render
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "Rails::HelperAPI" do
|
50
|
+
it "allows accessing the request object" do
|
51
|
+
#BassistCell.append_view_path(".")
|
52
|
+
assert_equal '<form accept-charset="UTF-8" action="/fruits" class="simple_form new_fruit" id="new_fruit" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div>
|
53
|
+
<div class="input string required"><label class="string required" for="fruit_title"><abbr title="required">*</abbr> Title</label><input class="string required" id="fruit_title" name="fruit[title]" required="required" size="50" type="text" value="Banana" /></div>
|
54
|
+
<input class="button" name="commit" type="submit" value="Create Fruit" />
|
55
|
+
</form>
|
56
|
+
', BassistCell.new.render_state(:edit) if Cell.rails3_1_or_more? and Rails::VERSION::MINOR == 2
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/test/test_case_test.rb
CHANGED
@@ -47,7 +47,7 @@ class TestCaseTest < Cell::TestCase
|
|
47
47
|
context "#view_assigns" do
|
48
48
|
should "be emtpy when nothing was set" do
|
49
49
|
render_cell(:bassist, :play)
|
50
|
-
if
|
50
|
+
if Cell.rails3_0?
|
51
51
|
assert_equal([:lookup_context], view_assigns.keys)
|
52
52
|
else
|
53
53
|
assert_equal({}, view_assigns)
|
@@ -61,7 +61,7 @@ class TestCaseTest < Cell::TestCase
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
render_cell(:bassist, :sleep)
|
64
|
-
if
|
64
|
+
if Cell.rails3_0?
|
65
65
|
assert_equal([:lookup_context, :duration], view_assigns.keys)
|
66
66
|
assert_equal("8h", view_assigns[:duration])
|
67
67
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cells
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.8.
|
4
|
+
version: 3.8.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: simple_form
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
- !ruby/object:Gem::Dependency
|
111
127
|
name: tzinfo
|
112
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,6 +182,7 @@ files:
|
|
166
182
|
- lib/cell/deprecations.rb
|
167
183
|
- lib/cell/rack.rb
|
168
184
|
- lib/cell/rails.rb
|
185
|
+
- lib/cell/rails/helper_api.rb
|
169
186
|
- lib/cell/rails3_0_strategy.rb
|
170
187
|
- lib/cell/rails3_1_strategy.rb
|
171
188
|
- lib/cell/rendering.rb
|
@@ -216,9 +233,11 @@ files:
|
|
216
233
|
- test/app/cells/layouts/metal.html.erb
|
217
234
|
- test/app/cells/producer/capture.html.erb
|
218
235
|
- test/app/cells/producer/content_for.html.erb
|
236
|
+
- test/app/cells/rails_helper_api_test/bassist/edit.html.erb
|
219
237
|
- test/app/cells/shouter/sing.html.erb
|
220
238
|
- test/app/cells/trumpeter/promote.html.erb
|
221
239
|
- test/app/cells/trumpeter_cell.rb
|
240
|
+
- test/app/views/shared/_dong.html.erb
|
222
241
|
- test/cell_generator_test.rb
|
223
242
|
- test/cell_module_test.rb
|
224
243
|
- test/cells_module_test.rb
|
@@ -265,6 +284,7 @@ files:
|
|
265
284
|
- test/rails/render_test.rb
|
266
285
|
- test/rails/router_test.rb
|
267
286
|
- test/rails/view_test.rb
|
287
|
+
- test/rails_helper_api_test.rb
|
268
288
|
- test/test_case_test.rb
|
269
289
|
- test/test_helper.rb
|
270
290
|
homepage: http://cells.rubyforge.org
|
@@ -291,81 +311,4 @@ rubygems_version: 1.8.24
|
|
291
311
|
signing_key:
|
292
312
|
specification_version: 3
|
293
313
|
summary: View Components for Rails.
|
294
|
-
test_files:
|
295
|
-
- test/app/cells/bad_guitarist/_dii.html.erb
|
296
|
-
- test/app/cells/bad_guitarist_cell.rb
|
297
|
-
- test/app/cells/bassist/_dii.html.erb
|
298
|
-
- test/app/cells/bassist/ahem.html.erb
|
299
|
-
- test/app/cells/bassist/compose.html.erb
|
300
|
-
- test/app/cells/bassist/contact_form.html.erb
|
301
|
-
- test/app/cells/bassist/jam.html.erb
|
302
|
-
- test/app/cells/bassist/play.html.erb
|
303
|
-
- test/app/cells/bassist/play.js.erb
|
304
|
-
- test/app/cells/bassist/pose.html.erb
|
305
|
-
- test/app/cells/bassist/promote.html.erb
|
306
|
-
- test/app/cells/bassist/provoke.html.erb
|
307
|
-
- test/app/cells/bassist/shout.html.erb
|
308
|
-
- test/app/cells/bassist/sing.html.haml
|
309
|
-
- test/app/cells/bassist/slap.html.erb
|
310
|
-
- test/app/cells/bassist/yell.en.html.erb
|
311
|
-
- test/app/cells/bassist_cell.rb
|
312
|
-
- test/app/cells/club_security.rb
|
313
|
-
- test/app/cells/club_security/guard/help.html.erb
|
314
|
-
- test/app/cells/club_security/guard_cell.rb
|
315
|
-
- test/app/cells/club_security/medic/help.html.erb
|
316
|
-
- test/app/cells/club_security/medic_cell.rb
|
317
|
-
- test/app/cells/layouts/b.erb
|
318
|
-
- test/app/cells/layouts/metal.html.erb
|
319
|
-
- test/app/cells/producer/capture.html.erb
|
320
|
-
- test/app/cells/producer/content_for.html.erb
|
321
|
-
- test/app/cells/shouter/sing.html.erb
|
322
|
-
- test/app/cells/trumpeter/promote.html.erb
|
323
|
-
- test/app/cells/trumpeter_cell.rb
|
324
|
-
- test/cell_generator_test.rb
|
325
|
-
- test/cell_module_test.rb
|
326
|
-
- test/cells_module_test.rb
|
327
|
-
- test/deprecations_test.rb
|
328
|
-
- test/dummy/Rakefile
|
329
|
-
- test/dummy/app/controllers/application_controller.rb
|
330
|
-
- test/dummy/app/controllers/musician_controller.rb
|
331
|
-
- test/dummy/app/helpers/application_helper.rb
|
332
|
-
- test/dummy/app/views/layouts/application.html.erb
|
333
|
-
- test/dummy/app/views/musician/featured.html.erb
|
334
|
-
- test/dummy/app/views/musician/featured_with_block.html.erb
|
335
|
-
- test/dummy/app/views/musician/hamlet.html.haml
|
336
|
-
- test/dummy/config.ru
|
337
|
-
- test/dummy/config/application.rb
|
338
|
-
- test/dummy/config/boot.rb
|
339
|
-
- test/dummy/config/database.yml
|
340
|
-
- test/dummy/config/environment.rb
|
341
|
-
- test/dummy/config/environments/development.rb
|
342
|
-
- test/dummy/config/environments/production.rb
|
343
|
-
- test/dummy/config/environments/test.rb
|
344
|
-
- test/dummy/config/locales/en.yml
|
345
|
-
- test/dummy/config/routes.rb
|
346
|
-
- test/dummy/db/test.sqlite3
|
347
|
-
- test/dummy/log/production.log
|
348
|
-
- test/dummy/log/server.log
|
349
|
-
- test/dummy/public/404.html
|
350
|
-
- test/dummy/public/422.html
|
351
|
-
- test/dummy/public/500.html
|
352
|
-
- test/dummy/public/favicon.ico
|
353
|
-
- test/dummy/public/javascripts/application.js
|
354
|
-
- test/dummy/public/javascripts/controls.js
|
355
|
-
- test/dummy/public/javascripts/dragdrop.js
|
356
|
-
- test/dummy/public/javascripts/effects.js
|
357
|
-
- test/dummy/public/javascripts/prototype.js
|
358
|
-
- test/dummy/public/javascripts/rails.js
|
359
|
-
- test/dummy/public/stylesheets/.gitkeep
|
360
|
-
- test/dummy/script/rails
|
361
|
-
- test/helper_test.rb
|
362
|
-
- test/rack_test.rb
|
363
|
-
- test/rails/caching_test.rb
|
364
|
-
- test/rails/capture_test.rb
|
365
|
-
- test/rails/cells_test.rb
|
366
|
-
- test/rails/integration_test.rb
|
367
|
-
- test/rails/render_test.rb
|
368
|
-
- test/rails/router_test.rb
|
369
|
-
- test/rails/view_test.rb
|
370
|
-
- test/test_case_test.rb
|
371
|
-
- test/test_helper.rb
|
314
|
+
test_files: []
|