cells 3.11.3 → 4.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +15 -13
- data/Appraisals +23 -0
- data/CHANGES.md +20 -3
- data/Gemfile +5 -7
- data/README.md +317 -236
- data/Rakefile +1 -1
- data/TODO.md +3 -0
- data/cells.gemspec +19 -28
- data/gemfiles/rails3.2.gemfile +14 -0
- data/gemfiles/rails4.0.gemfile +14 -0
- data/gemfiles/rails4.1.gemfile +15 -0
- data/gemfiles/rails4.2.gemfile +14 -0
- data/lib/cell.rb +28 -21
- data/lib/cell/caching.rb +10 -22
- data/lib/cell/caching/notification.rb +15 -0
- data/lib/cell/concept.rb +4 -69
- data/lib/cell/development.rb +11 -0
- data/lib/{cells → cell}/engines.rb +1 -1
- data/lib/cell/layout.rb +20 -0
- data/lib/cell/partial.rb +17 -0
- data/lib/cell/{base/prefixes.rb → prefixes.rb} +1 -1
- data/lib/cell/rails.rb +58 -50
- data/lib/cell/railtie.rb +60 -0
- data/lib/cell/{base/self_contained.rb → self_contained.rb} +1 -1
- data/lib/cell/templates.rb +60 -0
- data/lib/cell/test_case.rb +4 -162
- data/lib/cell/testing.rb +15 -0
- data/lib/cell/twin.rb +11 -29
- data/lib/cell/version.rb +10 -0
- data/lib/cell/view_model.rb +196 -88
- data/lib/cells.rb +1 -20
- data/lib/rails/generators/cell/cell_generator.rb +43 -0
- data/lib/rails/generators/cell/templates/cell.rb.erb +8 -0
- data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.erb +0 -0
- data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.haml +0 -0
- data/lib/rails/generators/cell/templates/view.slim +2 -0
- data/lib/rails/generators/concept/concept_generator.rb +38 -0
- data/lib/{generators/templates/concept/cell.rb → rails/generators/concept/templates/concept.rb.erb} +2 -2
- data/lib/{generators → rails/generators/concept}/templates/view.erb +0 -0
- data/lib/{generators → rails/generators/concept}/templates/view.haml +0 -0
- data/lib/rails/generators/concept/templates/view.slim +2 -0
- data/lib/rails/generators/test_unit/cell/cell_generator.rb +21 -0
- data/lib/{generators/templates/cell_test.rb → rails/generators/test_unit/cell/templates/unit_test.rb.erb} +3 -3
- data/lib/rails/generators/test_unit/concept/concept_generator.rb +21 -0
- data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +11 -0
- data/lib/{cells → tasks}/cells.rake +0 -0
- data/test/builder_test.rb +58 -0
- data/test/caching_test.rb +298 -0
- data/test/cell_benchmark.rb +32 -0
- data/test/cell_generator_test.rb +51 -82
- data/test/cell_test.rb +8 -23
- data/test/concept_generator_test.rb +22 -13
- data/test/concept_test.rb +41 -75
- data/test/dummy/app/views/musician/hamlet.html.erb +1 -0
- data/test/dummy/config/application.rb +21 -8
- data/test/{app/cells/bassist/play.html.erb → fixtures/bassist/play.erb} +0 -0
- data/test/fixtures/concepts/record/views/layout.erb +1 -0
- data/test/{app → fixtures}/concepts/record/views/show.erb +0 -0
- data/test/{app → fixtures}/concepts/record/views/song.erb +0 -0
- data/test/fixtures/inherit_views_test/popper/tap.erb +1 -0
- data/test/fixtures/inherit_views_test/tapper/play.erb +1 -0
- data/test/fixtures/inherit_views_test/tapper/tap.erb +1 -0
- data/test/fixtures/partial_test/with_partial/show.erb +1 -0
- data/test/fixtures/partials/_show.html.erb +1 -0
- data/test/fixtures/partials/_show.xml.erb +1 -0
- data/test/fixtures/song/ivar.erb +1 -0
- data/test/fixtures/song/show.erb +1 -0
- data/test/fixtures/song/with_erb.erb +4 -0
- data/test/fixtures/song/with_html.erb +1 -0
- data/test/fixtures/song/with_locals.erb +2 -0
- data/test/fixtures/song_with_layout/happy.erb +1 -0
- data/test/fixtures/song_with_layout/merry.erb +1 -0
- data/test/fixtures/song_with_layout/show.erb +1 -0
- data/test/fixtures/song_with_layout/show_with_layout.erb +1 -0
- data/test/fixtures/templates_caching_test/song/show.erb +1 -0
- data/test/fixtures/url_helper_test/song/edit.erb +8 -0
- data/test/fixtures/url_helper_test/song/with_block.erb +2 -0
- data/test/fixtures/url_helper_test/song/with_capture.erb +4 -0
- data/test/fixtures/url_helper_test/song/with_content_tag.erb +6 -0
- data/test/fixtures/url_helper_test/song/with_form_for_block.erb +3 -0
- data/test/fixtures/url_helper_test/song/with_link_to.erb +3 -0
- data/test/layout_test.rb +57 -0
- data/test/partial_test.rb +27 -0
- data/test/prefixes_test.rb +36 -10
- data/test/public_test.rb +42 -0
- data/test/rails_extensions_test.rb +51 -0
- data/test/render_test.rb +103 -0
- data/test/templates_test.rb +45 -0
- data/test/test_case_test.rb +21 -122
- data/test/test_helper.rb +37 -33
- data/test/twin_test.rb +3 -7
- data/test/url_helper_test.rb +89 -0
- metadata +92 -357
- data/gemfiles/Gemfile.rails3-0 +0 -7
- data/gemfiles/Gemfile.rails3-1 +0 -7
- data/gemfiles/Gemfile.rails3-2 +0 -7
- data/gemfiles/Gemfile.rails4-0 +0 -12
- data/gemfiles/Gemfile.rails4-1 +0 -12
- data/lib/cell/base.rb +0 -82
- data/lib/cell/base/view.rb +0 -15
- data/lib/cell/builder.rb +0 -71
- data/lib/cell/deprecations.rb +0 -41
- data/lib/cell/dsl.rb +0 -7
- data/lib/cell/rack.rb +0 -32
- data/lib/cell/rails/helper_api.rb +0 -37
- data/lib/cell/rails/view_model.rb +0 -159
- data/lib/cell/rails3_0_strategy.rb +0 -82
- data/lib/cell/rails3_1_strategy.rb +0 -40
- data/lib/cell/rails4_0_strategy.rb +0 -39
- data/lib/cell/rails4_1_strategy.rb +0 -40
- data/lib/cell/rendering.rb +0 -109
- data/lib/cells/rails.rb +0 -86
- data/lib/cells/railtie.rb +0 -38
- data/lib/cells/version.rb +0 -3
- data/lib/generators/USAGE +0 -30
- data/lib/generators/cells/base.rb +0 -22
- data/lib/generators/cells/cell_generator.rb +0 -15
- data/lib/generators/cells/view_generator.rb +0 -18
- data/lib/generators/erb/cell_generator.rb +0 -15
- data/lib/generators/erb/concept_generator.rb +0 -17
- data/lib/generators/haml/cell_generator.rb +0 -17
- data/lib/generators/haml/concept_generator.rb +0 -17
- data/lib/generators/rails/cell_generator.rb +0 -16
- data/lib/generators/rails/concept_generator.rb +0 -16
- data/lib/generators/slim/cell_generator.rb +0 -17
- data/lib/generators/templates/cell.rb +0 -9
- data/lib/generators/templates/view.slim +0 -4
- data/lib/generators/test_unit/cell_generator.rb +0 -14
- data/lib/generators/trailblazer/base.rb +0 -21
- data/lib/generators/trailblazer/view_generator.rb +0 -18
- data/test/app/cells/album/views/cover.haml +0 -1
- data/test/app/cells/bad_guitarist/_dii.html.erb +0 -1
- data/test/app/cells/bad_guitarist_cell.rb +0 -2
- data/test/app/cells/bassist/_dii.html.erb +0 -1
- data/test/app/cells/bassist/ahem.html.erb +0 -1
- data/test/app/cells/bassist/compose.html.erb +0 -1
- data/test/app/cells/bassist/contact_form.html.erb +0 -1
- data/test/app/cells/bassist/form_for.erb +0 -3
- data/test/app/cells/bassist/form_for_in_haml.haml +0 -2
- data/test/app/cells/bassist/jam.html.erb +0 -3
- data/test/app/cells/bassist/play.js.erb +0 -1
- data/test/app/cells/bassist/pose.html.erb +0 -1
- data/test/app/cells/bassist/promote.html.erb +0 -1
- data/test/app/cells/bassist/provoke.html.erb +0 -1
- data/test/app/cells/bassist/shout.html.erb +0 -1
- data/test/app/cells/bassist/sing.html.haml +0 -1
- data/test/app/cells/bassist/slap.html.erb +0 -1
- data/test/app/cells/bassist/yell.en.html.erb +0 -1
- data/test/app/cells/bassist_cell.rb +0 -25
- data/test/app/cells/club_security.rb +0 -2
- data/test/app/cells/club_security/guard/help.html.erb +0 -1
- data/test/app/cells/club_security/guard_cell.rb +0 -6
- data/test/app/cells/club_security/medic/help.html.erb +0 -1
- data/test/app/cells/club_security/medic_cell.rb +0 -8
- data/test/app/cells/layouts/b.erb +0 -1
- data/test/app/cells/layouts/metal.html.erb +0 -1
- data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +0 -5
- data/test/app/cells/shouter/sing.html.erb +0 -1
- data/test/app/cells/song/dashboard.haml +0 -7
- data/test/app/cells/song/details.html.haml +0 -1
- data/test/app/cells/song/info.html.haml +0 -1
- data/test/app/cells/song/lyrics.html.haml +0 -6
- data/test/app/cells/song/plays.haml +0 -1
- data/test/app/cells/song/scale.haml +0 -1
- data/test/app/cells/song/show.html.haml +0 -3
- data/test/app/cells/song/title.html.haml +0 -1
- data/test/app/cells/trumpeter/promote.html.erb +0 -1
- data/test/app/cells/trumpeter_cell.rb +0 -8
- data/test/app/cells/view_model_test/comments/show.haml +0 -7
- data/test/app/concepts/record/views/layout.haml +0 -2
- data/test/app/views/shared/_dong.html.erb +0 -1
- data/test/cell_module_test.rb +0 -170
- data/test/cells_module_test.rb +0 -27
- data/test/deprecations_test.rb +0 -101
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/musician/hamlet.html.haml +0 -1
- data/test/dummy/config/environments/development.rb +0 -16
- data/test/dummy/config/environments/production.rb +0 -46
- data/test/dummy/config/environments/test.rb +0 -33
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/label/app/cells/label/show.erb +0 -1
- data/test/dummy/label/app/cells/label_cell.rb +0 -5
- data/test/dummy/label/label.gemspec +0 -20
- data/test/dummy/label/lib/label.rb +0 -4
- data/test/dummy/label/lib/label/version.rb +0 -3
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/helper_test.rb +0 -81
- data/test/rack_test.rb +0 -32
- data/test/rails/asset_pipeline_test.rb +0 -20
- data/test/rails/caching_test.rb +0 -456
- data/test/rails/cells_test.rb +0 -119
- data/test/rails/forms_test.rb +0 -75
- data/test/rails/integration_test.rb +0 -299
- data/test/rails/render_test.rb +0 -189
- data/test/rails/view_model_test.rb +0 -226
- data/test/rails/view_test.rb +0 -49
- data/test/rails_helper_api_test.rb +0 -58
- data/test/self_contained_test.rb +0 -31
data/test/rails/render_test.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class RailsRenderTest < MiniTest::Spec
|
4
|
-
include Cell::TestCase::TestMethods
|
5
|
-
|
6
|
-
let (:bassist) { cell(:bassist) }
|
7
|
-
|
8
|
-
describe "Invoking render" do
|
9
|
-
it "render a plain view" do
|
10
|
-
bassist.instance_eval do
|
11
|
-
def play; render; end
|
12
|
-
end
|
13
|
-
assert_equal "Doo", bassist.render_state(:play)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "accept :format" do
|
17
|
-
bassist.instance_eval do
|
18
|
-
def play; render :format => :js; end
|
19
|
-
end
|
20
|
-
assert_equal "alert(\"Doo\");\n", bassist.render_state(:play)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "accept :format without messing up following render calls" do
|
24
|
-
skip
|
25
|
-
bassist.instance_eval do
|
26
|
-
def play; render(:format => :js) + render; end
|
27
|
-
end
|
28
|
-
assert_equal "alert(\"Doo\");\nDoo\n", bassist.render_state(:play)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "also render alternative engines, like haml" do
|
32
|
-
BassistCell.class_eval do
|
33
|
-
def sing; render; end
|
34
|
-
end
|
35
|
-
assert_equal "<h1>Laaa</h1>\n", render_cell(:bassist, :sing)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "accept the :nothing option" do
|
39
|
-
BassistCell.class_eval do
|
40
|
-
def sleep; render :nothing => true; end
|
41
|
-
end
|
42
|
-
assert_equal "", render_cell(:bassist, :sleep)
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
it "accept the :view option" do
|
47
|
-
BassistCell.class_eval do
|
48
|
-
def solo; render :view => :play; end
|
49
|
-
end
|
50
|
-
assert_equal "Doo", render_cell(:bassist, :solo)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "accept the :text options" do
|
54
|
-
BassistCell.class_eval do
|
55
|
-
def sing; render :text => "Shoobie"; end
|
56
|
-
end
|
57
|
-
assert_equal "Shoobie", render_cell(:bassist, :sing)
|
58
|
-
assert render_cell(:bassist, :sing).html_safe?
|
59
|
-
end
|
60
|
-
|
61
|
-
it "accept the :inline option" do
|
62
|
-
BassistCell.class_eval do
|
63
|
-
def sleep; render :inline => "<%= 'Snooore' %>"; end
|
64
|
-
end
|
65
|
-
assert_equal "Snooore", render_cell(:bassist, :sleep)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "accept the :state option with state-args" do
|
69
|
-
BassistCell.class_eval do
|
70
|
-
def listen(band, song)
|
71
|
-
render :text => "Listening to #{band}: #{song}"
|
72
|
-
end
|
73
|
-
def groove; render({:state => :listen}, "Thin Lizzy", "Southbound"); end
|
74
|
-
end
|
75
|
-
assert_equal "Listening to Thin Lizzy: Southbound", render_cell(:bassist, :groove)
|
76
|
-
|
77
|
-
BassistCell.class_eval do
|
78
|
-
def listen(args)
|
79
|
-
render :text => "Listening to #{args[:band]}"
|
80
|
-
end
|
81
|
-
def groove; render({:state => :listen}, :band => "Belvedere"); end
|
82
|
-
end
|
83
|
-
assert_equal "Listening to Belvedere", render_cell(:bassist, :groove)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "accept the :state option" do
|
87
|
-
BassistCell.class_eval do
|
88
|
-
def play; render; end
|
89
|
-
def groove; render :state => :play; end
|
90
|
-
end
|
91
|
-
assert_equal "Doo", render_cell(:bassist, :groove)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "accept the :locals option" do
|
95
|
-
BassistCell.class_eval do
|
96
|
-
def ahem; render :locals => {:times => 2}; end
|
97
|
-
end
|
98
|
-
assert_equal "AhemAhem", render_cell(:bassist, :ahem)
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
# layout
|
103
|
-
it "accept the :layout option" do
|
104
|
-
bassist.instance_eval do
|
105
|
-
def play; render :layout => 'b'; end
|
106
|
-
end
|
107
|
-
assert_equal "<b>Doo</b>", bassist.render_state(:play)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "respect the #layout class method" do
|
111
|
-
puts
|
112
|
-
class VanHalenBassistCell < BassistCell
|
113
|
-
layout 'b'
|
114
|
-
def play; render; end
|
115
|
-
end
|
116
|
-
assert_equal "<b>Doo</b>", render_cell("rails_render_test/van_halen_bassist", :play)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "raise an error for a non-existent template" do
|
120
|
-
BassistCell.class_eval do
|
121
|
-
def groove; render; end
|
122
|
-
end
|
123
|
-
|
124
|
-
exception = ActionView::MissingTemplate
|
125
|
-
exception = Cell::VersionStrategy::MissingTemplate if Cell.rails_version.~("3.0")
|
126
|
-
|
127
|
-
assert_raises exception do
|
128
|
-
render_cell(:bassist, :groove)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
it "raise an error for a non-existent template" do
|
133
|
-
BadGuitaristCell.class_eval do
|
134
|
-
def groove; render; end
|
135
|
-
end
|
136
|
-
|
137
|
-
if Cell.rails_version.~("3.0")
|
138
|
-
e = assert_raises Cell::Rails::MissingTemplate do
|
139
|
-
render_cell(:bad_guitarist, :groove)
|
140
|
-
end
|
141
|
-
|
142
|
-
assert_includes e.message, "Missing template bassist/groove with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]} in view paths"
|
143
|
-
else # >= 3.1
|
144
|
-
e = assert_raises ActionView::MissingTemplate do
|
145
|
-
render_cell(:bad_guitarist, :groove)
|
146
|
-
end
|
147
|
-
|
148
|
-
assert_includes e.message, "Missing template bad_guitarist/groove, bassist/groove with"
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
it "render instance variables from the cell" do
|
153
|
-
assert_equal "Boing in D", render_cell(:bassist, :slap)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "allow subsequent calls to render in the rendered view" do
|
157
|
-
BassistCell.class_eval do
|
158
|
-
def jam; @chords = [:a, :c]; render; end
|
159
|
-
def sing; render; end
|
160
|
-
end
|
161
|
-
assert_equal "<h1>Laaa</h1>\n\n<h1>Laaa</h1>\n\n", render_cell(:bassist, :jam)
|
162
|
-
end
|
163
|
-
|
164
|
-
it "allow multiple calls to render" do
|
165
|
-
BassistCell.class_eval do
|
166
|
-
def sing; render + render + render; end
|
167
|
-
end
|
168
|
-
assert_equal "<h1>Laaa</h1>\n<h1>Laaa</h1>\n<h1>Laaa</h1>\n", render_cell(:bassist, :sing)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "A cell view" do
|
173
|
-
# rails view api
|
174
|
-
it "allow calls to params/response/..." do
|
175
|
-
BassistCell.class_eval do
|
176
|
-
def pose; render; end
|
177
|
-
end
|
178
|
-
|
179
|
-
@request.env["action_dispatch.request.request_parameters"] = {:what => 'get'} # FIXME: duplicated in cells_test.rb.
|
180
|
-
@controller = Class.new(ActionController::Base).new
|
181
|
-
@controller.request = @request
|
182
|
-
@cell = cell(:bassist)
|
183
|
-
|
184
|
-
assert_equal "Come and get me!", @cell.render_state(:pose)
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
end
|
@@ -1,226 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
if Cell.rails_version >= 3.1
|
4
|
-
|
5
|
-
class Song < OpenStruct
|
6
|
-
extend ActiveModel::Naming
|
7
|
-
|
8
|
-
def persisted?
|
9
|
-
true
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_param
|
13
|
-
id
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
class SongCell < Cell::ViewModel
|
20
|
-
def show
|
21
|
-
render
|
22
|
-
end
|
23
|
-
|
24
|
-
def title
|
25
|
-
song.title.upcase
|
26
|
-
end
|
27
|
-
|
28
|
-
def self_url
|
29
|
-
url_for(song)
|
30
|
-
end
|
31
|
-
|
32
|
-
def details
|
33
|
-
render
|
34
|
-
end
|
35
|
-
|
36
|
-
def stats
|
37
|
-
render :details
|
38
|
-
end
|
39
|
-
|
40
|
-
def info
|
41
|
-
render :info
|
42
|
-
end
|
43
|
-
|
44
|
-
def dashboard
|
45
|
-
render :dashboard
|
46
|
-
end
|
47
|
-
|
48
|
-
def scale
|
49
|
-
render :layout => 'b'
|
50
|
-
end
|
51
|
-
|
52
|
-
class Lyrics < self
|
53
|
-
def show
|
54
|
-
render :lyrics
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class PlaysCell < self
|
59
|
-
def show
|
60
|
-
render :plays
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class ViewModelTest < MiniTest::Spec
|
66
|
-
# views :show, :create #=> wrap in render_state(:show, *)
|
67
|
-
let (:cell) { SongCell.new(nil, :title => "Shades Of Truth") }
|
68
|
-
|
69
|
-
it { cell.title.must_equal "Shades Of Truth" }
|
70
|
-
|
71
|
-
class HitCell < Cell::ViewModel
|
72
|
-
property :title, :artist
|
73
|
-
|
74
|
-
def show
|
75
|
-
"Great!"
|
76
|
-
end
|
77
|
-
|
78
|
-
def rate
|
79
|
-
"Fantastic!"
|
80
|
-
end
|
81
|
-
|
82
|
-
attr_accessor :count
|
83
|
-
cache :count
|
84
|
-
|
85
|
-
def title
|
86
|
-
super.upcase
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
let (:song) { Song.new(:title => "Sixtyfive", artist: "Boss") }
|
91
|
-
|
92
|
-
# ::property creates accessor.
|
93
|
-
it { HitCell.new(nil, song).artist.must_equal "Boss" }
|
94
|
-
|
95
|
-
# ::property accessor can be overridden and call super.
|
96
|
-
it { HitCell.new(nil, song).title.must_equal "SIXTYFIVE" }
|
97
|
-
|
98
|
-
|
99
|
-
describe "#call" do
|
100
|
-
let (:cell) { HitCell.new(nil, song) }
|
101
|
-
|
102
|
-
it { cell.call.must_equal "Great!" }
|
103
|
-
it { cell.call(:rate).must_equal "Fantastic!" }
|
104
|
-
|
105
|
-
it "no caching" do
|
106
|
-
cell.instance_eval do
|
107
|
-
def cache_configured?
|
108
|
-
false
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
cell.count = 1
|
113
|
-
cell.call(:count).must_equal "1"
|
114
|
-
cell.count = 2
|
115
|
-
cell.call(:count).must_equal "2"
|
116
|
-
end
|
117
|
-
|
118
|
-
it "with caching" do
|
119
|
-
cell.instance_eval do
|
120
|
-
self.cache_store = ActiveSupport::Cache::MemoryStore.new
|
121
|
-
self.cache_configured = true
|
122
|
-
end
|
123
|
-
|
124
|
-
cell.count = 1
|
125
|
-
cell.call(:count).must_equal "1"
|
126
|
-
cell.count = 2
|
127
|
-
cell.call(:count).must_equal "1"
|
128
|
-
end
|
129
|
-
|
130
|
-
# call(:show) do .. end
|
131
|
-
it do
|
132
|
-
cell.call(:show) do |c|
|
133
|
-
c.instance_variable_set(:@volume, 9)
|
134
|
-
end.must_equal "Great!"
|
135
|
-
|
136
|
-
cell.instance_variable_get(:@volume).must_equal 9
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
# describe "::helper" do
|
142
|
-
# it { assert_raises { HitCell.helper Module.new } }
|
143
|
-
# end
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
|
-
if Cell.rails_version >= "3.2"
|
148
|
-
class ViewModelIntegrationTest < ActionController::TestCase
|
149
|
-
tests MusicianController
|
150
|
-
|
151
|
-
#let (:song) { Song.new(:title => "Blindfold", :id => 1) }
|
152
|
-
#let (:html) { %{<h1>Shades Of Truth</h1>\n} }
|
153
|
-
#let (:cell) { }
|
154
|
-
|
155
|
-
setup do
|
156
|
-
@cell = SongCell.new(@controller, :song => Song.new(:title => "Blindfold", :id => "1"))
|
157
|
-
|
158
|
-
@url = "/songs/1"
|
159
|
-
@url = "http://test.host/songs/1" if Cell.rails_version.>=("4.0")
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
# test "instantiating without model, but call to ::property" do
|
164
|
-
# assert_raises do
|
165
|
-
# @controller.cell("view_model_test/piano_song")
|
166
|
-
# end
|
167
|
-
# end
|
168
|
-
|
169
|
-
|
170
|
-
test "URL helpers in view" do
|
171
|
-
@cell.show.must_equal %{<h1>BLINDFOLD</h1>
|
172
|
-
<a href=\"#{@url}\">Permalink</a>
|
173
|
-
} end
|
174
|
-
|
175
|
-
test "URL helper in instance" do
|
176
|
-
@cell.self_url.must_equal @url
|
177
|
-
end
|
178
|
-
|
179
|
-
test "implicit #render" do
|
180
|
-
@cell.details.must_equal "<h3>BLINDFOLD</h3>\n"
|
181
|
-
SongCell.new(@controller, :song => Song.new(:title => "Blindfold", :id => 1)).details
|
182
|
-
end
|
183
|
-
|
184
|
-
test "explicit #render with one arg" do
|
185
|
-
@cell = SongCell.new(@controller, :song => Song.new(:title => "Blindfold", :id => 1))
|
186
|
-
@cell.stats.must_equal "<h3>BLINDFOLD</h3>\n"
|
187
|
-
end
|
188
|
-
|
189
|
-
test "nested render" do
|
190
|
-
@cell.info.must_equal "<li>BLINDFOLD\n</li>\n"
|
191
|
-
end
|
192
|
-
|
193
|
-
test "nested rendering method" do
|
194
|
-
@cell.dashboard.must_equal "<h1>Dashboard</h1>\n<h3>Lyrics for BLINDFOLD</h3>\n<li>\nIn the Mirror\n</li>\n<li>\nI can see\n</li>\n\nPlays: 99\n\nPlays: 99\n\n"
|
195
|
-
end
|
196
|
-
|
197
|
-
test( "layout") { @cell.scale.must_equal "<b>A Minor!\n</b>" }
|
198
|
-
|
199
|
-
# TODO: when we don't pass :song into Lyrics
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
class CollectionTest < MiniTest::Spec
|
204
|
-
class ReleasePartyCell < Cell::ViewModel
|
205
|
-
def show
|
206
|
-
"Party on, #{model}!"
|
207
|
-
end
|
208
|
-
|
209
|
-
def show_more
|
210
|
-
"Go nuts, #{model}!"
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
|
215
|
-
describe "::collection" do
|
216
|
-
it { Cell::ViewModel.collection("collection_test/release_party", @controller, %w{Garth Wayne}).must_equal "Party on, Garth!\nParty on, Wayne!" }
|
217
|
-
it { Cell::ViewModel.collection("collection_test/release_party", @controller, %w{Garth Wayne}, :show_more).must_equal "Go nuts, Garth!\nGo nuts, Wayne!" }
|
218
|
-
end
|
219
|
-
# TODO: test with builders ("polymorphic collections") and document that.
|
220
|
-
|
221
|
-
describe "::cell" do
|
222
|
-
it { Cell::ViewModel.cell("collection_test/release_party", @controller, "Garth").call.must_equal "Party on, Garth!" }
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
data/test/rails/view_test.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class RailsViewTest < MiniTest::Spec
|
4
|
-
include Cell::TestCase::TestMethods
|
5
|
-
|
6
|
-
describe "A cell view" do
|
7
|
-
# DISCUSS: it we allow :partial from a state, too?
|
8
|
-
describe "calling render :partial" do
|
9
|
-
it "render the local cell partial in bassist/dii" do
|
10
|
-
assert_equal("Dii", in_view(:bassist) do
|
11
|
-
render :partial => 'dii'
|
12
|
-
end)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "render the foreign cell partial in bad_guitarist/dii" do
|
16
|
-
assert_equal("Dooom", in_view(:bassist) do
|
17
|
-
render :partial => "bad_guitarist/dii"
|
18
|
-
end)
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
it "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
|
30
|
-
end
|
31
|
-
|
32
|
-
it "respond to render :state" do
|
33
|
-
assert_equal("Doo", in_view(:bassist) do
|
34
|
-
render :state => :play
|
35
|
-
end)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "respond to render :state with options" do
|
39
|
-
BassistCell.class_eval do
|
40
|
-
def listen(*args)
|
41
|
-
render :text => "Listening to #{args.join(' ')}"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
assert_equal("Listening to Much the Same", in_view(:bassist) do
|
45
|
-
render({:state => :listen}, "Much", "the", "Same")
|
46
|
-
end)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|