cells 4.0.0.beta4 → 4.0.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +19 -0
- data/Rakefile +11 -0
- data/cells.gemspec +3 -4
- data/gemfiles/rails4.2.gemfile +0 -7
- data/lib/cell.rb +19 -19
- data/lib/cell/abstract.rb +9 -0
- data/lib/cell/caching.rb +16 -17
- data/lib/cell/concept.rb +2 -4
- data/lib/cell/prefixes.rb +3 -2
- data/lib/cell/rails.rb +27 -4
- data/lib/cell/railtie.rb +47 -42
- data/lib/cell/testing.rb +12 -9
- data/lib/cell/twin.rb +2 -2
- data/lib/cell/util.rb +16 -0
- data/lib/cell/version.rb +1 -8
- data/lib/cell/view_model.rb +63 -90
- data/test/builder_test.rb +5 -5
- data/test/caching_test.rb +2 -2
- data/test/cell_test.rb +1 -1
- data/test/concept_test.rb +24 -10
- data/test/dummy/config/application.rb +1 -1
- data/test/public_test.rb +8 -9
- data/test/rails4.2/.gitignore +13 -0
- data/test/rails4.2/Gemfile +16 -0
- data/test/rails4.2/README.rdoc +3 -0
- data/test/rails4.2/Rakefile +6 -0
- data/test/rails4.2/app/assets/images/.keep +0 -0
- data/test/rails4.2/app/assets/stylesheets/application.css +17 -0
- data/test/rails4.2/app/cells/song/song.css +1 -0
- data/test/rails4.2/app/cells/song_cell.rb +2 -0
- data/test/rails4.2/app/controllers/application_controller.rb +5 -0
- data/test/rails4.2/app/controllers/concerns/.keep +0 -0
- data/test/rails4.2/app/controllers/index_controller.rb +7 -0
- data/test/rails4.2/app/helpers/application_helper.rb +2 -0
- data/test/rails4.2/app/mailers/.keep +0 -0
- data/test/rails4.2/app/models/.keep +0 -0
- data/test/rails4.2/app/models/concerns/.keep +0 -0
- data/test/rails4.2/app/views/index/index.html.erb +6 -0
- data/test/rails4.2/app/views/layouts/application.html.erb +13 -0
- data/test/rails4.2/bin/bundle +3 -0
- data/test/rails4.2/bin/rails +4 -0
- data/test/rails4.2/bin/rake +4 -0
- data/test/rails4.2/bin/setup +29 -0
- data/test/rails4.2/config.ru +4 -0
- data/test/rails4.2/config/application.rb +38 -0
- data/test/rails4.2/config/boot.rb +3 -0
- data/test/rails4.2/config/environment.rb +5 -0
- data/test/rails4.2/config/environments/development.rb +25 -0
- data/test/rails4.2/config/environments/production.rb +64 -0
- data/test/rails4.2/config/environments/test.rb +42 -0
- data/test/rails4.2/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails4.2/config/initializers/cookies_serializer.rb +3 -0
- data/test/rails4.2/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/rails4.2/config/initializers/inflections.rb +16 -0
- data/test/rails4.2/config/initializers/mime_types.rb +4 -0
- data/test/rails4.2/config/initializers/session_store.rb +3 -0
- data/test/rails4.2/config/initializers/wrap_parameters.rb +9 -0
- data/test/rails4.2/config/locales/en.yml +23 -0
- data/test/rails4.2/config/routes.rb +4 -0
- data/test/rails4.2/config/secrets.yml +22 -0
- data/test/rails4.2/db/seeds.rb +7 -0
- data/test/rails4.2/engines/my_engine/.gitignore +3 -0
- data/test/rails4.2/engines/my_engine/Gemfile +15 -0
- data/test/rails4.2/engines/my_engine/MIT-LICENSE +20 -0
- data/test/rails4.2/engines/my_engine/README.rdoc +3 -0
- data/test/rails4.2/engines/my_engine/Rakefile +24 -0
- data/test/rails4.2/engines/my_engine/app/assets/images/my_engine/.keep +0 -0
- data/test/rails4.2/engines/my_engine/app/assets/stylesheets/my_engine/application.css +15 -0
- data/test/rails4.2/engines/my_engine/app/concepts/user/cell.rb +8 -0
- data/test/rails4.2/engines/my_engine/app/concepts/user/views/show.erb +1 -0
- data/test/rails4.2/engines/my_engine/app/concepts/user/views/user.scss +3 -0
- data/test/rails4.2/engines/my_engine/app/controllers/my_engine/application_controller.rb +4 -0
- data/test/rails4.2/engines/my_engine/app/controllers/my_engine/user_controller.rb +7 -0
- data/test/rails4.2/engines/my_engine/app/helpers/my_engine/application_helper.rb +4 -0
- data/test/rails4.2/engines/my_engine/app/models/my_engine/user.rb +4 -0
- data/test/rails4.2/engines/my_engine/app/views/layouts/my_engine/application.html.erb +14 -0
- data/test/rails4.2/engines/my_engine/app/views/my_engine/user/show.html.erb +3 -0
- data/test/rails4.2/engines/my_engine/bin/rails +12 -0
- data/test/rails4.2/engines/my_engine/config/routes.rb +3 -0
- data/test/rails4.2/engines/my_engine/db/migrate/20150530135920_create_my_engine_users.rb +8 -0
- data/test/rails4.2/engines/my_engine/lib/my_engine.rb +6 -0
- data/test/rails4.2/engines/my_engine/lib/my_engine/engine.rb +9 -0
- data/test/rails4.2/engines/my_engine/lib/my_engine/version.rb +3 -0
- data/test/rails4.2/engines/my_engine/lib/tasks/my_engine_tasks.rake +4 -0
- data/test/rails4.2/engines/my_engine/my_engine.gemspec +24 -0
- data/test/rails4.2/engines/my_engine/test/fixtures/my_engine/users.yml +11 -0
- data/test/rails4.2/engines/my_engine/test/models/my_engine/user_test.rb +9 -0
- data/test/rails4.2/lib/assets/.keep +0 -0
- data/test/rails4.2/lib/tasks/.keep +0 -0
- data/test/rails4.2/log/.keep +0 -0
- data/test/rails4.2/public/404.html +67 -0
- data/test/rails4.2/public/422.html +67 -0
- data/test/rails4.2/public/500.html +66 -0
- data/test/rails4.2/public/favicon.ico +0 -0
- data/test/rails4.2/public/robots.txt +5 -0
- data/test/rails4.2/test/integration/asset_pipeline_test.rb +17 -0
- data/test/rails4.2/test/test_helper.rb +14 -0
- data/test/rails4.2/vendor/assets/stylesheets/.keep +0 -0
- data/test/twin_test.rb +1 -1
- data/test/url_helper_test.rb +1 -1
- metadata +83 -19
data/lib/cell/twin.rb
CHANGED
@@ -13,8 +13,8 @@ module Cell
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(
|
17
|
-
super(
|
16
|
+
def initialize(model, options={})
|
17
|
+
super(build_twin(model, options), controller: options.delete(:controller))
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/cell/util.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Cell::Util
|
2
|
+
def util
|
3
|
+
Inflector
|
4
|
+
end
|
5
|
+
|
6
|
+
class Inflector
|
7
|
+
# copied from ActiveSupport.
|
8
|
+
def self.underscore(constant)
|
9
|
+
constant.gsub(/::/, '/').
|
10
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
11
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
12
|
+
tr("-", "_").
|
13
|
+
downcase
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/cell/version.rb
CHANGED
data/lib/cell/view_model.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
# FIXME: remove AC dependency by delegating forgery
|
2
|
-
require 'action_controller'
|
3
|
-
|
4
1
|
# no helper_method calls
|
5
2
|
# no instance variables
|
6
3
|
# no locals
|
7
4
|
# options are automatically made instance methods via constructor.
|
8
5
|
# call "helpers" in class
|
9
6
|
|
10
|
-
# TODO: CACHE prefixes.
|
11
|
-
|
12
7
|
# TODO: warn when using ::property but not passing in model in constructor.
|
13
8
|
module Cell
|
14
|
-
class ViewModel
|
9
|
+
class ViewModel
|
10
|
+
extend Abstract
|
15
11
|
abstract!
|
16
12
|
|
13
|
+
def controller_path
|
14
|
+
self.class.controller_path
|
15
|
+
end
|
16
|
+
|
17
17
|
extend Uber::InheritableAttr
|
18
18
|
extend Uber::Delegates
|
19
|
+
include Uber::Builder
|
19
20
|
|
20
21
|
inheritable_attr :view_paths
|
21
22
|
self.view_paths = ["app/cells"]
|
@@ -32,35 +33,35 @@ module Cell
|
|
32
33
|
|
33
34
|
include Prefixes
|
34
35
|
extend SelfContained
|
35
|
-
|
36
|
-
include Uber::Builder
|
37
|
-
|
36
|
+
extend Util
|
38
37
|
|
39
38
|
def self.controller_path
|
40
|
-
@controller_path ||= name.sub(/Cell$/, '')
|
39
|
+
@controller_path ||= util.underscore(name.sub(/Cell$/, ''))
|
41
40
|
end
|
42
41
|
|
43
|
-
|
44
|
-
|
42
|
+
# FIXME: this is all rails-only.
|
43
|
+
# DISCUSS: who actually uses forgery protection with cells? it is not working since 4, anyway?
|
44
|
+
# include ActionController::RequestForgeryProtection
|
45
|
+
delegates :parent_controller, :session, :params, :request, :config, :env, :url_options
|
45
46
|
|
46
47
|
attr_reader :model
|
47
48
|
|
48
49
|
|
49
50
|
module Helpers
|
50
51
|
# Renders collection of cells.
|
51
|
-
def
|
52
|
+
def _collection(name, array, options) # private.
|
52
53
|
method = options.delete(:method) || :show
|
53
|
-
join
|
54
|
-
array.collect { |model| cell_for(name, *[
|
54
|
+
join = options.delete(:collection_join)
|
55
|
+
array.collect { |model| cell_for(name, *[model, options]).call(method) }.join(join).html_safe
|
55
56
|
end
|
56
57
|
|
57
58
|
# Returns cell instance.
|
58
|
-
def cell(name,
|
59
|
+
def cell(name, model=nil, options={}, &block) # classic Rails fuzzy API.
|
59
60
|
if model.is_a?(Hash) and array = model.delete(:collection)
|
60
|
-
return
|
61
|
+
return _collection(name, array, model.merge(options))
|
61
62
|
end
|
62
63
|
|
63
|
-
cell_for(name,
|
64
|
+
cell_for(name, model, options, &block)
|
64
65
|
end
|
65
66
|
end
|
66
67
|
extend Helpers
|
@@ -74,62 +75,72 @@ module Cell
|
|
74
75
|
include Helpers
|
75
76
|
|
76
77
|
|
77
|
-
def cell_for(name,
|
78
|
-
class_from_cell_name(name).build_cell(
|
78
|
+
def cell_for(name, *args)
|
79
|
+
class_from_cell_name(name).build_cell(*args)
|
79
80
|
end
|
80
81
|
|
81
82
|
def class_from_cell_name(name)
|
82
83
|
"#{name}_cell".classify.constantize
|
83
84
|
end
|
84
85
|
|
85
|
-
def build_cell(
|
86
|
-
class_builder.call(*args).new(
|
86
|
+
def build_cell(*args)
|
87
|
+
class_builder.call(*args).new(*args) # Uber::Builder::class_builder.
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
90
|
-
|
91
|
-
|
91
|
+
# Get nested cell in instance.
|
92
|
+
def cell(name, model=nil, options={})
|
93
|
+
self.class.cell(name, model, options.merge(controller: parent_controller))
|
92
94
|
end
|
93
95
|
|
94
96
|
|
95
|
-
def initialize(
|
96
|
-
|
97
|
+
def initialize(model=nil, options={}) # in Ruby 2: def m(model: nil, controller:nil, **options) that'll make the controller optional.
|
98
|
+
# options = options.clone # DISCUSS: this could be time consuming when rendering many of em.
|
99
|
+
@parent_controller = options[:controller] # TODO: filter out controller in a performant way.
|
97
100
|
|
98
101
|
setup!(model, options)
|
99
102
|
end
|
100
103
|
attr_reader :parent_controller
|
101
104
|
alias_method :controller, :parent_controller
|
102
105
|
|
106
|
+
module Rendering
|
107
|
+
# Invokes the passed method (defaults to :show) while respecting caching.
|
108
|
+
# In Rails, the return value gets marked html_safe.
|
109
|
+
#
|
110
|
+
# Yields +self+ to an optional block.
|
111
|
+
def call(state=:show, *args)
|
112
|
+
content = render_state(state, *args)
|
113
|
+
yield self if block_given?
|
114
|
+
|
115
|
+
content.to_s
|
116
|
+
end
|
103
117
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
def render_to_string(options)
|
111
|
-
template = template_for(options) # TODO: cache template with path/lookup keys.
|
112
|
-
content = template.render(self, options[:locals])
|
113
|
-
|
114
|
-
# TODO: allow other (global) layout dirs.
|
115
|
-
with_layout(options, content)
|
116
|
-
end
|
118
|
+
private
|
119
|
+
# render :show
|
120
|
+
def render(options={})
|
121
|
+
options = normalize_options(options, caller) # TODO: call render methods with call(:show), call(:comments) instead of directly #comments?
|
122
|
+
render_to_string(options)
|
123
|
+
end
|
117
124
|
|
125
|
+
def render_to_string(options)
|
126
|
+
template = template_for(options) # TODO: cache template with path/lookup keys.
|
127
|
+
content = template.render(self, options[:locals])
|
118
128
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
# your code.
|
123
|
-
#
|
124
|
-
# Yields +self+ (the cell instance) to an optional block.
|
125
|
-
def call(state=:show, *args)
|
126
|
-
content = render_state(state, *args)
|
127
|
-
yield self if block_given?
|
129
|
+
# TODO: allow other (global) layout dirs.
|
130
|
+
with_layout(options, content)
|
131
|
+
end
|
128
132
|
|
129
|
-
|
133
|
+
def render_state(*args)
|
134
|
+
send(*args)
|
135
|
+
end
|
130
136
|
end
|
131
137
|
|
132
|
-
|
138
|
+
include Rendering
|
139
|
+
# alias_method :to_s, :call # FIXME: why doesn't this work?
|
140
|
+
def to_s
|
141
|
+
call
|
142
|
+
end
|
143
|
+
include Caching
|
133
144
|
|
134
145
|
private
|
135
146
|
attr_reader :options
|
@@ -140,15 +151,6 @@ module Cell
|
|
140
151
|
# or: create_twin(model, options)
|
141
152
|
end
|
142
153
|
|
143
|
-
module Rendering
|
144
|
-
def render_state(*args)
|
145
|
-
send(*args)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
include Rendering
|
149
|
-
include Caching
|
150
|
-
|
151
|
-
|
152
154
|
class OutputBuffer < Array
|
153
155
|
def encoding
|
154
156
|
"UTF-8"
|
@@ -192,7 +194,8 @@ module Cell
|
|
192
194
|
|
193
195
|
def normalize_options(options, caller) # TODO: rename to #setup_options! to be inline with Trb.
|
194
196
|
options = if options.is_a?(Hash)
|
195
|
-
|
197
|
+
# TODO: speedup by not doing state_for_implicit_render.
|
198
|
+
{:view => state_for_implicit_render(caller)}.merge(options)
|
196
199
|
else
|
197
200
|
{:view => options.to_s}
|
198
201
|
end
|
@@ -217,35 +220,5 @@ module Cell
|
|
217
220
|
end
|
218
221
|
|
219
222
|
include Layout
|
220
|
-
|
221
|
-
|
222
|
-
if defined?(ActionView)
|
223
|
-
# FIXME: this module is to fix a design flaw in Rails 4.0. the problem is that AV::UrlHelper mixes in the wrong #url_for.
|
224
|
-
# if we could mix in everything else from the helper except for the #url_for, it would be fine.
|
225
|
-
# FIXME: fix that in rails core.
|
226
|
-
if Cell.rails_version <= Gem::Version.new('4.0')
|
227
|
-
include ActionView::Helpers::UrlHelper # gives us breaking #url_for.
|
228
|
-
|
229
|
-
def url_for(options = nil) # from ActionDispatch:R:UrlFor.
|
230
|
-
case options
|
231
|
-
when nil
|
232
|
-
_routes.url_for(url_options.symbolize_keys)
|
233
|
-
when Hash
|
234
|
-
_routes.url_for(options.symbolize_keys.reverse_merge!(url_options))
|
235
|
-
when String
|
236
|
-
options
|
237
|
-
when Array
|
238
|
-
polymorphic_url(options, options.extract_options!)
|
239
|
-
else
|
240
|
-
polymorphic_url(options)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
public :url_for
|
245
|
-
else
|
246
|
-
include ActionView::Helpers::UrlHelper
|
247
|
-
end
|
248
|
-
include ActionView::Helpers::FormTagHelper
|
249
|
-
end
|
250
223
|
end
|
251
224
|
end
|
data/test/builder_test.rb
CHANGED
@@ -34,25 +34,25 @@ class BuilderTest < MiniTest::Spec
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# the original class is used when no builder matches.
|
37
|
-
it { Cell::ViewModel.cell("builder_test/song",
|
37
|
+
it { Cell::ViewModel.cell("builder_test/song", Song.new("Nation States"), {}).must_be_instance_of BuilderTest::SongCell }
|
38
38
|
|
39
39
|
it do
|
40
|
-
cell = Cell::ViewModel.cell("builder_test/song",
|
40
|
+
cell = Cell::ViewModel.cell("builder_test/song", Hit.new("New York"), {})
|
41
41
|
cell.must_be_instance_of BuilderTest::HitCell
|
42
42
|
cell.options.must_equal({})
|
43
43
|
end
|
44
44
|
|
45
45
|
it do
|
46
|
-
cell = Cell::ViewModel.cell("builder_test/song",
|
46
|
+
cell = Cell::ViewModel.cell("builder_test/song", Song.new("San Francisco"), evergreen: true)
|
47
47
|
cell.must_be_instance_of BuilderTest::EvergreenCell
|
48
48
|
cell.options.must_equal({:evergreen=>true})
|
49
49
|
end
|
50
50
|
|
51
51
|
# with collection.
|
52
|
-
it { Cell::ViewModel.cell("builder_test/song",
|
52
|
+
it { Cell::ViewModel.cell("builder_test/song", collection: [Song.new("Nation States"), Hit.new("New York")]).must_equal "* Nation States* **New York**" }
|
53
53
|
|
54
54
|
# with Concept
|
55
55
|
class Track < Cell::Concept
|
56
56
|
end
|
57
|
-
it { Cell::Concept.cell("builder_test/track"
|
57
|
+
it { Cell::Concept.cell("builder_test/track").must_be_instance_of Track }
|
58
58
|
end
|
data/test/caching_test.rb
CHANGED
@@ -117,7 +117,7 @@ end
|
|
117
117
|
|
118
118
|
class CachingTest < MiniTest::Spec
|
119
119
|
class DirectorCell < Cell::ViewModel
|
120
|
-
def initialize(
|
120
|
+
def initialize(counter=0)
|
121
121
|
super
|
122
122
|
@counter = counter
|
123
123
|
end
|
@@ -141,7 +141,7 @@ class CachingTest < MiniTest::Spec
|
|
141
141
|
|
142
142
|
# let (:cell) { DirectorCell.new(nil) }
|
143
143
|
def cellule(*args)
|
144
|
-
DirectorCell.new(
|
144
|
+
DirectorCell.new(*args)
|
145
145
|
end
|
146
146
|
|
147
147
|
# no caching when turned off.
|
data/test/cell_test.rb
CHANGED
@@ -9,5 +9,5 @@ class CellTest < MiniTest::Spec
|
|
9
9
|
it { Cell.rails_version.must_equal Gem::Version.new(ActionPack::VERSION::STRING) }
|
10
10
|
|
11
11
|
# #options
|
12
|
-
it { SongCell.new(nil,
|
12
|
+
it { SongCell.new(nil, genre: "Punkrock").send(:options)[:genre].must_equal "Punkrock" }
|
13
13
|
end
|
data/test/concept_test.rb
CHANGED
@@ -24,6 +24,11 @@ module Record
|
|
24
24
|
class Hit < ::Cell::Concept
|
25
25
|
inherit_views Record::Cell
|
26
26
|
end
|
27
|
+
|
28
|
+
|
29
|
+
def description
|
30
|
+
"A Tribute To Rancid, with #{@options[:tracks]} songs! [#{parent_controller}]"
|
31
|
+
end
|
27
32
|
end
|
28
33
|
end
|
29
34
|
|
@@ -34,27 +39,36 @@ end
|
|
34
39
|
|
35
40
|
class ConceptTest < MiniTest::Spec
|
36
41
|
describe "::controller_path" do
|
37
|
-
it { Record::Cell.new
|
38
|
-
it { Record::Cell::Song.new
|
42
|
+
it { Record::Cell.new.controller_path.must_equal "record" }
|
43
|
+
it { Record::Cell::Song.new.controller_path.must_equal "record/song" }
|
39
44
|
end
|
40
45
|
|
41
46
|
|
42
47
|
describe "#_prefixes" do
|
43
|
-
it { Record::Cell.new
|
44
|
-
it { Record::Cell::Song.new
|
45
|
-
it { Record::Cell::Hit.new
|
48
|
+
it { Record::Cell.new._prefixes.must_equal ["test/fixtures/concepts/record/views"] }
|
49
|
+
it { Record::Cell::Song.new._prefixes.must_equal ["test/fixtures/concepts/record/song/views", "test/fixtures/concepts/record/views"] }
|
50
|
+
it { Record::Cell::Hit.new._prefixes.must_equal ["test/fixtures/concepts/record/hit/views", "test/fixtures/concepts/record/views"] } # with inherit_views.
|
46
51
|
end
|
47
52
|
|
48
|
-
it { Record::Cell.new(
|
53
|
+
it { Record::Cell.new("Wayne").call(:show).must_equal "Party on, Wayne!" }
|
49
54
|
|
50
55
|
|
51
|
-
describe "
|
52
|
-
it { Cell::Concept.cell("record/cell"
|
53
|
-
it { Cell::Concept.cell("record/cell/song"
|
56
|
+
describe "::cell" do
|
57
|
+
it { Cell::Concept.cell("record/cell").must_be_instance_of( Record::Cell) }
|
58
|
+
it { Cell::Concept.cell("record/cell/song").must_be_instance_of Record::Cell::Song }
|
54
59
|
# cell("song", concept: "record/compilation") # record/compilation/cell/song
|
55
60
|
end
|
56
61
|
|
57
62
|
describe "#render" do
|
58
|
-
it { Cell::Concept.cell("record/cell/song"
|
63
|
+
it { Cell::Concept.cell("record/cell/song").show.must_equal "Lalala" }
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#cell (in cell state)" do
|
67
|
+
# test with controller, but remove tests when we don't need it anymore.
|
68
|
+
it { Cell::Concept.cell("record/cell", nil, controller: Object).cell("record/cell", nil, tracks: 24).(:description).must_equal "A Tribute To Rancid, with 24 songs! [Object]" }
|
69
|
+
it { Cell::Concept.cell("record/cell", nil, controller: Object).concept("record/cell", nil, tracks: 24).(:description).must_equal "A Tribute To Rancid, with 24 songs! [Object]" }
|
70
|
+
# concept(.., collection: ..)
|
71
|
+
it("xx") { Cell::Concept.cell("record/cell", nil, controller: Object).
|
72
|
+
concept("record/cell", collection: [1,2], tracks: 24, method: :description).must_equal "A Tribute To Rancid, with 24 songs! [Object]A Tribute To Rancid, with 24 songs! [Object]" }
|
59
73
|
end
|
60
74
|
end
|
@@ -21,7 +21,7 @@ module Dummy
|
|
21
21
|
# enable asset pipeline as in development.
|
22
22
|
config.assets.enabled = true
|
23
23
|
config.assets.compile = true
|
24
|
-
config.cells.with_assets = ["
|
24
|
+
# config.cells.with_assets = ["song/cell"]
|
25
25
|
config.cache_classes = true
|
26
26
|
|
27
27
|
# Show full error reports and disable caching
|
data/test/public_test.rb
CHANGED
@@ -2,8 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class PublicTest < MiniTest::Spec
|
4
4
|
class SongCell < Cell::ViewModel
|
5
|
-
def initialize(
|
6
|
-
@parent_controller = controller # TODO: this is removed in 4.0.
|
5
|
+
def initialize(*args)
|
7
6
|
@initialize_args = *args
|
8
7
|
end
|
9
8
|
attr_reader :initialize_args
|
@@ -18,25 +17,25 @@ class PublicTest < MiniTest::Spec
|
|
18
17
|
end
|
19
18
|
|
20
19
|
# ViewModel.cell returns the cell instance.
|
21
|
-
it { Cell::ViewModel.cell("public_test/song"
|
20
|
+
it { Cell::ViewModel.cell("public_test/song").must_be_instance_of SongCell }
|
22
21
|
|
23
22
|
# ViewModel.cell passes options to cell.
|
24
|
-
it { Cell::ViewModel.cell("public_test/song",
|
23
|
+
it { Cell::ViewModel.cell("public_test/song", Object, genre: "Metal").initialize_args.must_equal [Object, {:genre=>"Metal"}] }
|
25
24
|
|
26
25
|
# ViewModel.cell(collection: []) renders cells.
|
27
|
-
it { Cell::ViewModel.cell('public_test/song',
|
26
|
+
it { Cell::ViewModel.cell('public_test/song', collection: [Object, Module]).must_equal '[Object, {}][Module, {}]' }
|
28
27
|
|
29
28
|
# ViewModel.cell(collection: []) renders cells with custom join.
|
30
|
-
it { Cell::ViewModel.cell('public_test/song',
|
29
|
+
it { Cell::ViewModel.cell('public_test/song', collection: [Object, Module], collection_join: '<br/>').must_equal '[Object, {}]<br/>[Module, {}]' }
|
31
30
|
|
32
31
|
# ViewModel.cell(collection: []) renders html_safe.
|
33
|
-
it { Cell::ViewModel.cell("public_test/song",
|
32
|
+
it { Cell::ViewModel.cell("public_test/song", collection: [Object]).class.must_equal ActiveSupport::SafeBuffer }
|
34
33
|
|
35
34
|
# ViewModel.cell(collection: []) passes generic options to cell.
|
36
|
-
it { Cell::ViewModel.cell('public_test/song',
|
35
|
+
it { Cell::ViewModel.cell('public_test/song', collection: [Object, Module], genre: 'Metal').must_equal "[Object, {:genre=>\"Metal\"}][Module, {:genre=>\"Metal\"}]" }
|
37
36
|
|
38
37
|
# ViewModel.cell(collection: [], method: :detail) invokes #detail instead of #show.
|
39
|
-
it { Cell::ViewModel.cell('public_test/song',
|
38
|
+
it { Cell::ViewModel.cell('public_test/song', collection: [Object, Module], method: :detail).must_equal '* [Object, {}]* [Module, {}]' }
|
40
39
|
end
|
41
40
|
|
42
41
|
# TODO: test AV::concept.
|