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/cells_test.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class RailsCellsTest < MiniTest::Spec
|
4
|
-
include Cell::TestCase::TestMethods
|
5
|
-
|
6
|
-
def swap(object, new_values)
|
7
|
-
old_values = {}
|
8
|
-
new_values.each do |key, value|
|
9
|
-
old_values[key] = object.send key
|
10
|
-
object.send :"#{key}=", value
|
11
|
-
end
|
12
|
-
yield
|
13
|
-
ensure
|
14
|
-
old_values.each do |key, value|
|
15
|
-
object.send :"#{key}=", value
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#render_state" do
|
20
|
-
it "work without args" do
|
21
|
-
BassistCell.class_eval do
|
22
|
-
def listen
|
23
|
-
render :text => "That's a D!"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
assert_equal "That's a D!", cell(:bassist).render_state(:listen)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "accept state-args" do
|
30
|
-
BassistCell.class_eval do
|
31
|
-
def listen(args)
|
32
|
-
render :text => args[:note]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
assert_equal "D", cell(:bassist).render_state(:listen, :note => "D")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "accept state-args with default parameters" do
|
39
|
-
BassistCell.class_eval do
|
40
|
-
def listen(first, second="D")
|
41
|
-
render :text => first+second
|
42
|
-
end
|
43
|
-
end
|
44
|
-
assert_equal "AD", cell(:bassist).render_state(:listen, "A")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
describe "A rails cell" do
|
50
|
-
it "respond to view_paths" do
|
51
|
-
assert_kind_of ActionView::PathSet, Cell::Rails.view_paths, "must be a PathSet for proper template caching/reloading (see issue#2)"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "respond to view_paths=" do
|
55
|
-
swap( Cell::Rails, :view_paths => ['you', 'are', 'here']) do
|
56
|
-
assert_kind_of ActionView::PathSet, Cell::Rails.view_paths, "must not wipe out the PathSet"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
it "respond to #request" do
|
61
|
-
assert_equal @request, cell(:bassist).request
|
62
|
-
end
|
63
|
-
|
64
|
-
it "respond to #config" do
|
65
|
-
assert_equal({}, cell(:bassist).config)
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
if Cell.rails_version.~("3.0")
|
70
|
-
describe "invoking find_family_view_for_state" do
|
71
|
-
it "raise an error when a template is missing" do
|
72
|
-
assert_raises ActionView::MissingTemplate do
|
73
|
-
cell(:bassist).find_template("bassist/playyy")
|
74
|
-
end
|
75
|
-
|
76
|
-
#puts "format: #{cell(:bassist).find_template("bassist/play.js").formats.inspect}"
|
77
|
-
end
|
78
|
-
|
79
|
-
it "return play.html.erb" do
|
80
|
-
assert_equal "bassist/play", cell(:bassist).send(:find_family_view_for_state, :play).virtual_path
|
81
|
-
end
|
82
|
-
|
83
|
-
it "find inherited play.html.erb" do
|
84
|
-
assert_equal "bassist/play", cell(:bad_guitarist).send(:find_family_view_for_state, :play).virtual_path
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "delegation" do
|
90
|
-
before do
|
91
|
-
@request.env["action_dispatch.request.request_parameters"] = {:song => "Creatures"}
|
92
|
-
@controller = Class.new(ActionController::Base).new
|
93
|
-
@controller.request = @request
|
94
|
-
@cell = cell(:bassist)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "delegate log" do
|
98
|
-
skip
|
99
|
-
assert_nothing_raised do
|
100
|
-
cell(:bassist).class.logger.info("everything is perfect!")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it "respond to session" do
|
105
|
-
session_kind = Hash
|
106
|
-
session_kind = ActionController::TestSession if Cell.rails_version >= ("4.0")
|
107
|
-
assert_kind_of session_kind, @cell.session
|
108
|
-
end
|
109
|
-
|
110
|
-
it "respond to #params and return the request parameters" do
|
111
|
-
assert_equal({"song" => "Creatures"}, cell(:bassist).params)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "not merge #params and #options" do
|
115
|
-
assert_equal({"song" => "Creatures"}, cell(:bassist, "song" => "Lockdown").params)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
data/test/rails/forms_test.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class FormsTest < MiniTest::Spec
|
4
|
-
class Song < OpenStruct
|
5
|
-
extend ActiveModel::Naming
|
6
|
-
end
|
7
|
-
|
8
|
-
include Cell::TestCase::TestMethods
|
9
|
-
|
10
|
-
let (:bassist) { cell(:bassist) }
|
11
|
-
|
12
|
-
it "renders input fields within the form tag with ERB" do
|
13
|
-
bassist.instance_eval do
|
14
|
-
def form_for
|
15
|
-
render
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
html = bassist.render_state(:form_for)
|
20
|
-
|
21
|
-
html.must_match Regexp.new("<form.+[name].+<\/form>", Regexp::MULTILINE)
|
22
|
-
end
|
23
|
-
|
24
|
-
class SongFormCell < BassistCell
|
25
|
-
include ViewModel
|
26
|
-
include ActionView::Helpers::FormHelper
|
27
|
-
|
28
|
-
def form
|
29
|
-
render :view => :form_for
|
30
|
-
end
|
31
|
-
|
32
|
-
def dom_class(*)
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def dom_id(*)
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it "renders input fields within the form tag with ERB and ViewModel" do
|
42
|
-
skip if ::Cell.rails_version.~("3.0")
|
43
|
-
|
44
|
-
html = SongFormCell.new(@controller).form
|
45
|
-
puts html.to_s
|
46
|
-
|
47
|
-
html.must_match Regexp.new("<form.+<input id=\"forms_test_song_name\".+<\/form>", Regexp::MULTILINE)
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
class HamlSongFormCell < BassistCell
|
52
|
-
include ViewModel
|
53
|
-
include ActionView::Helpers::FormHelper
|
54
|
-
|
55
|
-
def form
|
56
|
-
render :view => :form_for_in_haml
|
57
|
-
end
|
58
|
-
|
59
|
-
def dom_class(*)
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def dom_id(*)
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it "renders input fields within the form tag with HAML and ViewModel" do
|
69
|
-
skip
|
70
|
-
html = HamlSongFormCell.new(@controller).form
|
71
|
-
puts html.to_s
|
72
|
-
|
73
|
-
html.must_match Regexp.new("<form.+<input id=\"forms_test_song_name\".+<\/form>", Regexp::MULTILINE)
|
74
|
-
end
|
75
|
-
end
|
@@ -1,299 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MusicianController < ActionController::Base
|
4
|
-
def index
|
5
|
-
render :text => render_cell(:bassist, :promote)
|
6
|
-
end
|
7
|
-
|
8
|
-
def promote
|
9
|
-
render :text => render_cell(:trumpeter, :promote)
|
10
|
-
end
|
11
|
-
|
12
|
-
def promotion
|
13
|
-
render :text => render_cell(:bassist, :provoke)
|
14
|
-
end
|
15
|
-
|
16
|
-
def featured
|
17
|
-
end
|
18
|
-
|
19
|
-
def featured_with_block
|
20
|
-
end
|
21
|
-
|
22
|
-
def skills
|
23
|
-
render :text => render_cell(:bassist, :listen)
|
24
|
-
end
|
25
|
-
|
26
|
-
def hamlet
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_reader :flag
|
30
|
-
def promotion_with_block
|
31
|
-
html = render_cell(:bassist, :play) do |cell|
|
32
|
-
@flag = cell.class
|
33
|
-
end
|
34
|
-
|
35
|
-
render :text => html
|
36
|
-
end
|
37
|
-
|
38
|
-
def song
|
39
|
-
render :inline => %{<%= concept("view_methods_test/cell", "Up For Breakfast").call %>} # TODO: concept doesn't need .call
|
40
|
-
end
|
41
|
-
|
42
|
-
def songs
|
43
|
-
render :inline => %{<%= concept("view_methods_test/cell", :collection => %w{Alltax Ronny}) %>} # TODO: concept doesn't need .call
|
44
|
-
end
|
45
|
-
|
46
|
-
def album
|
47
|
-
render :inline => %{<%= cell("view_methods_test/album", "Dreiklang").call %>} # DISCUSS: make .call in #cell?
|
48
|
-
end
|
49
|
-
|
50
|
-
def albums
|
51
|
-
render :inline => %{<%= cell("view_methods_test/album", :collection => %w{Dreiklang Coaster}) %>}
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
ActionController::TestCase.class_eval do
|
56
|
-
def png_src
|
57
|
-
return "/images/me.png" if Cell.rails_version >= 4.0
|
58
|
-
return "/assets/me.png" if Cell.rails_version >= 3.1
|
59
|
-
"/images/me.png"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class ControllerMethodsTest < ActionController::TestCase
|
64
|
-
tests MusicianController
|
65
|
-
|
66
|
-
class SongCell < Cell::Rails
|
67
|
-
include Cell::OptionsConstructor
|
68
|
-
end
|
69
|
-
|
70
|
-
test "#render_cell" do
|
71
|
-
fix_relative_url_root
|
72
|
-
|
73
|
-
get 'promotion'
|
74
|
-
assert_equal "That's me, naked <img alt=\"Me\" src=\"#{png_src}\" />", @response.body
|
75
|
-
end
|
76
|
-
|
77
|
-
test "#render_cell with arbitrary options" do
|
78
|
-
BassistCell.class_eval do
|
79
|
-
def enjoy(what, where="the bar")
|
80
|
-
render :text => "I like #{what} in #{where}."
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
@controller.instance_eval do
|
85
|
-
def promotion
|
86
|
-
render :text => render_cell(:bassist, :enjoy, "The Stranglers", "my room")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
get 'promotion'
|
90
|
-
assert_equal "I like The Stranglers in my room.", @response.body
|
91
|
-
end
|
92
|
-
|
93
|
-
test "#render_cell with block" do
|
94
|
-
get 'promotion_with_block'
|
95
|
-
assert_equal "Doo", @response.body
|
96
|
-
assert_equal BassistCell, @controller.flag
|
97
|
-
end
|
98
|
-
|
99
|
-
test "#cell" do
|
100
|
-
@controller.cell(:bassist).must_be_instance_of BassistCell
|
101
|
-
end
|
102
|
-
|
103
|
-
test "#cell with options" do
|
104
|
-
@controller.cell("controller_methods_test/song", :title => "We Called It America").
|
105
|
-
title.must_equal "We Called It America"
|
106
|
-
end
|
107
|
-
|
108
|
-
if Cell.rails_version >= "5.0" # TODO: make run.
|
109
|
-
test "#render_cell for engine" do
|
110
|
-
@controller.render_cell(:label, :show).must_equal "Fat Wreck"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
test "pass url_helpers to the cell instance" do
|
120
|
-
assert_equal "/musicians", BassistCell.new(@controller).musicians_path
|
121
|
-
end
|
122
|
-
|
123
|
-
test "allow cells to use url_helpers" do
|
124
|
-
get "index"
|
125
|
-
assert_response :success
|
126
|
-
assert_equal "Find me at <a href=\"/musicians\">vd.com</a>\n", @response.body
|
127
|
-
end
|
128
|
-
|
129
|
-
test "delegate #url_options to the parent_controller" do
|
130
|
-
@controller.instance_eval do
|
131
|
-
def default_url_options
|
132
|
-
{:host => "cells.rails.org"}
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
assert_equal "http://cells.rails.org/musicians", BassistCell.new(@controller).musicians_url
|
137
|
-
end
|
138
|
-
|
139
|
-
test "allow cells to use *_url helpers when mixing in AC::UrlFor" do
|
140
|
-
get "promote"
|
141
|
-
assert_response :success
|
142
|
-
assert_equal "Find me at <a href=\"http://test.host/musicians\">vd.com</a>\n", @response.body
|
143
|
-
end
|
144
|
-
|
145
|
-
test "allow cells to use #config" do
|
146
|
-
BassistCell.class_eval do
|
147
|
-
def provoke; render; end
|
148
|
-
end
|
149
|
-
|
150
|
-
fix_relative_url_root
|
151
|
-
|
152
|
-
get "promotion"
|
153
|
-
assert_response :success
|
154
|
-
assert_equal "That's me, naked <img alt=\"Me\" src=\"#{png_src}\" />", @response.body
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
|
159
|
-
class ViewMethodsTest < ActionController::TestCase
|
160
|
-
tests MusicianController
|
161
|
-
|
162
|
-
test "#cell_for" do
|
163
|
-
@controller.instance_eval do
|
164
|
-
def title
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
get :title
|
169
|
-
@response.body.must_equal "First Call"
|
170
|
-
end
|
171
|
-
|
172
|
-
test "#render_cell" do
|
173
|
-
fix_relative_url_root
|
174
|
-
|
175
|
-
get 'featured'
|
176
|
-
assert_equal "That's me, naked <img alt=\"Me\" src=\"#{png_src}\" />", @response.body
|
177
|
-
end
|
178
|
-
|
179
|
-
test "#render_cell with a block" do
|
180
|
-
get 'featured_with_block'
|
181
|
-
assert_equal "Boing in D from BassistCell\n", @response.body
|
182
|
-
end
|
183
|
-
|
184
|
-
test "#render_cell in a haml view" do
|
185
|
-
fix_relative_url_root
|
186
|
-
|
187
|
-
get 'hamlet'
|
188
|
-
assert_equal "That's me, naked <img alt=\"Me\" src=\"#{png_src}\" />\n", @response.body
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
unless ::Cell.rails_version.~("3.0")
|
194
|
-
|
195
|
-
# concept -------------------
|
196
|
-
class Cell < Cell::Concept
|
197
|
-
def show
|
198
|
-
render :text => "<b>#{model}</b>"
|
199
|
-
end
|
200
|
-
|
201
|
-
|
202
|
-
class Collection < ::Cell::Concept
|
203
|
-
def show
|
204
|
-
concept("view_methods_test/cell", "Dreiklang").call
|
205
|
-
end
|
206
|
-
|
207
|
-
def collection
|
208
|
-
concept("view_methods_test/cell", :collection => %w{Dreiklang Coaster})
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
# Concept#concept(:album, "Dreiklang").call
|
214
|
-
test "Concept#cell" do # FIXME: move to HelperTest.
|
215
|
-
Cell::Collection.new(@controller).call.must_equal "<b>Dreiklang</b>"
|
216
|
-
end
|
217
|
-
|
218
|
-
# Concept#concept(:album, collection: [])
|
219
|
-
test "Concept#cell collection: []" do # FIXME: move to HelperTest.
|
220
|
-
Cell::Collection.new(@controller).call(:collection).must_equal "<b>Dreiklang</b>\n<b>Coaster</b>"
|
221
|
-
end
|
222
|
-
|
223
|
-
|
224
|
-
# concept(:song, "Alltax").call
|
225
|
-
test "#concept" do
|
226
|
-
get :song
|
227
|
-
@response.body.must_equal "<b>Up For Breakfast</b>"
|
228
|
-
end
|
229
|
-
|
230
|
-
# concept(:song, collection: [..])
|
231
|
-
test "#concept with collection" do
|
232
|
-
get :songs
|
233
|
-
@response.body.must_equal "<b>Alltax</b>\n<b>Ronny</b>"
|
234
|
-
end
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
# view model ------------------
|
239
|
-
class AlbumCell < ::Cell::ViewModel
|
240
|
-
def show
|
241
|
-
"<b>#{model}</b>"
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
class AlbumsCell < ::Cell::ViewModel
|
246
|
-
def show
|
247
|
-
cell("view_methods_test/album", "Dreiklang").call
|
248
|
-
end
|
249
|
-
|
250
|
-
def collection
|
251
|
-
cell("view_methods_test/album", :collection => %w{Dreiklang Coaster})
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
# ViewModel#cell(:album, "Dreiklang").call
|
256
|
-
test "ViewModel#cell" do # FIXME: move to HelperTest.
|
257
|
-
AlbumsCell.new(@controller).call.must_equal "<b>Dreiklang</b>"
|
258
|
-
end
|
259
|
-
|
260
|
-
test "ViewModel#cell collection: []" do # FIXME: move to HelperTest.
|
261
|
-
AlbumsCell.new(@controller).call(:collection).must_equal "<b>Dreiklang</b>\n<b>Coaster</b>"
|
262
|
-
end
|
263
|
-
|
264
|
-
|
265
|
-
# cell(:album, "Dreiklang").call
|
266
|
-
test "#cell for view model" do
|
267
|
-
get :album
|
268
|
-
@response.body.must_equal "<b>Dreiklang</b>"
|
269
|
-
end
|
270
|
-
|
271
|
-
# cell(:album, collection: [..])
|
272
|
-
test "#cell with collection for view model" do
|
273
|
-
get :albums
|
274
|
-
@response.body.must_equal "<b>Dreiklang</b>\n<b>Coaster</b>"
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
|
279
|
-
test "make params (and friends) available in a cell" do
|
280
|
-
BassistCell.class_eval do
|
281
|
-
def listen
|
282
|
-
render :text => "That's a #{params[:note]}"
|
283
|
-
end
|
284
|
-
end
|
285
|
-
get 'skills', :note => "D"
|
286
|
-
assert_equal "That's a D", @response.body
|
287
|
-
end
|
288
|
-
|
289
|
-
test "respond to #config" do
|
290
|
-
BassistCell.class_eval do
|
291
|
-
def listen
|
292
|
-
render :view => 'contact_form' # form_tag internally calls config.allow_forgery_protection
|
293
|
-
end
|
294
|
-
end
|
295
|
-
get 'skills'
|
296
|
-
|
297
|
-
@response.body.must_match /<form.*action="musician\/index"/
|
298
|
-
end
|
299
|
-
end
|