cells 3.8.6 → 3.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.textile +4 -0
- data/Gemfile +1 -1
- data/README.rdoc +2 -2
- data/cells.gemspec +2 -3
- data/lib/cell/base.rb +8 -3
- data/lib/cell/rails.rb +1 -0
- data/lib/cell/rails3_0_strategy.rb +10 -8
- data/lib/cell/rails3_1_strategy.rb +10 -8
- data/lib/cell/test_case.rb +1 -1
- data/lib/cells/engines.rb +0 -2
- data/lib/cells/version.rb +1 -1
- data/test/cell_generator_test.rb +102 -104
- data/test/cell_module_test.rb +37 -33
- data/test/cells_module_test.rb +7 -7
- data/test/deprecations_test.rb +14 -14
- data/test/dummy/config/environments/test.rb +1 -0
- data/test/dummy/config/routes.rb +1 -1
- data/test/helper_test.rb +23 -7
- data/test/rails/caching_test.rb +102 -82
- data/test/rails/capture_test.rb +30 -11
- data/test/rails/cells_test.rb +24 -23
- data/test/rails/integration_test.rb +9 -9
- data/test/rails/render_test.rb +30 -26
- data/test/rails/router_test.rb +6 -6
- data/test/rails/view_test.rb +9 -9
- data/test/rails_helper_api_test.rb +1 -1
- data/test/test_case_test.rb +30 -30
- data/test/test_helper.rb +1 -3
- metadata +6 -29
- data/lib/cell.rb +0 -2
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -4874
- data/test/dummy/public/javascripts/rails.js +0 -118
data/test/rails/capture_test.rb
CHANGED
@@ -1,22 +1,41 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class ProducerCell < Cell::
|
4
|
-
helper ::Cells::Helpers::CaptureHelper
|
3
|
+
class ProducerCell < Cell::Rails
|
4
|
+
#helper ::Cells::Helpers::CaptureHelper
|
5
5
|
|
6
|
-
def logger(*args); puts args.inspect; end
|
7
6
|
end
|
8
7
|
|
9
8
|
class RailsCaptureTest < ActionController::TestCase
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
tests MusicianController
|
10
|
+
|
11
|
+
test "#content_for" do
|
12
|
+
@controller.class_eval do
|
13
|
+
def featured
|
14
|
+
|
15
|
+
render :inline => '<%= render_cell(:producer, :content_for, self) %><pre><%= yield :recorded %></pre>'
|
15
16
|
end
|
16
|
-
@controller = MusicianController.new
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
ProducerCell.class_eval do
|
20
|
+
def content_for(tpl);
|
21
|
+
puts tpl
|
22
|
+
@tpl = tpl
|
23
|
+
|
24
|
+
render; end
|
25
|
+
|
26
|
+
def global_content_for(*args, &block)
|
27
|
+
@tpl.content_for(*args, &block)
|
28
|
+
end
|
29
|
+
helper_method :global_content_for
|
30
|
+
end
|
31
|
+
|
32
|
+
get 'featured'
|
33
|
+
assert_equal "\n<pre>DummDooDiiDoo</pre>", @response.body
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
describe "what" do
|
38
|
+
it "see content from global_capture" do
|
20
39
|
@controller.class_eval do
|
21
40
|
def featured
|
22
41
|
render :inline => '<h3><%= @recorded %></h3>' << render_cell(:producer, :capture)
|
@@ -32,7 +51,7 @@ class RailsCaptureTest < ActionController::TestCase
|
|
32
51
|
end
|
33
52
|
|
34
53
|
|
35
|
-
|
54
|
+
it "see yieldable content from global_content_for" do
|
36
55
|
@controller.class_eval do
|
37
56
|
def featured
|
38
57
|
render_cell(:producer, :content_for)
|
data/test/rails/cells_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class RailsCellsTest <
|
3
|
+
class RailsCellsTest < MiniTest::Spec
|
4
4
|
include Cell::TestCase::TestMethods
|
5
5
|
|
6
6
|
def swap(object, new_values)
|
@@ -16,8 +16,8 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
describe "#render_state" do
|
20
|
+
it "work without args" do
|
21
21
|
BassistCell.class_eval do
|
22
22
|
def listen
|
23
23
|
render :text => "That's a D!"
|
@@ -26,7 +26,7 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
26
26
|
assert_equal "That's a D!", cell(:bassist).render_state(:listen)
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
it "accept state-args" do
|
30
30
|
BassistCell.class_eval do
|
31
31
|
def listen(args)
|
32
32
|
render :text => args[:note]
|
@@ -35,7 +35,7 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
35
35
|
assert_equal "D", cell(:bassist).render_state(:listen, :note => "D")
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
it "accept state-args with default parameters" do
|
39
39
|
BassistCell.class_eval do
|
40
40
|
def listen(first, second="D")
|
41
41
|
render :text => first+second
|
@@ -46,15 +46,15 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
describe "A rails cell" do
|
50
|
+
it "respond to DEFAULT_VIEW_PATHS" do
|
51
51
|
assert_equal ["app/cells"], Cell::Rails::DEFAULT_VIEW_PATHS
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
it "respond to .setup_view_paths!" do
|
55
55
|
swap( Cell::Rails, :view_paths => []) do
|
56
56
|
Cell::Rails.setup_view_paths!
|
57
|
-
if Cell.rails3_2_or_more?
|
57
|
+
if Cell.rails3_2_or_more? or Cell.rails4_0_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
|
@@ -62,28 +62,28 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
it "respond to view_paths" do
|
66
66
|
assert_kind_of ActionView::PathSet, Cell::Rails.view_paths, "must be a PathSet for proper template caching/reloading (see issue#2)"
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
it "respond to view_paths=" do
|
70
70
|
swap( Cell::Rails, :view_paths => ['you', 'are', 'here']) do
|
71
71
|
assert_kind_of ActionView::PathSet, Cell::Rails.view_paths, "must not wipe out the PathSet"
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
it "respond to #request" do
|
76
76
|
assert_equal @request, cell(:bassist).request
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
it "respond to #config" do
|
80
80
|
assert_equal({}, cell(:bassist).config)
|
81
81
|
end
|
82
82
|
|
83
83
|
|
84
84
|
if Cell.rails3_0?
|
85
|
-
|
86
|
-
|
85
|
+
describe "invoking find_family_view_for_state" do
|
86
|
+
it "raise an error when a template is missing" do
|
87
87
|
assert_raises ActionView::MissingTemplate do
|
88
88
|
cell(:bassist).find_template("bassist/playyy")
|
89
89
|
end
|
@@ -91,39 +91,40 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
91
91
|
#puts "format: #{cell(:bassist).find_template("bassist/play.js").formats.inspect}"
|
92
92
|
end
|
93
93
|
|
94
|
-
|
94
|
+
it "return play.html.erb" do
|
95
95
|
assert_equal "bassist/play", cell(:bassist).send(:find_family_view_for_state, :play).virtual_path
|
96
96
|
end
|
97
97
|
|
98
|
-
|
98
|
+
it "find inherited play.html.erb" do
|
99
99
|
assert_equal "bassist/play", cell(:bad_guitarist).send(:find_family_view_for_state, :play).virtual_path
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
|
-
|
104
|
+
describe "delegation" do
|
105
|
+
before do
|
106
106
|
@request.env["action_dispatch.request.request_parameters"] = {:song => "Creatures"}
|
107
107
|
@controller = Class.new(ActionController::Base).new
|
108
108
|
@controller.request = @request
|
109
109
|
@cell = cell(:bassist)
|
110
110
|
end
|
111
111
|
|
112
|
-
|
112
|
+
it "delegate log" do
|
113
|
+
skip
|
113
114
|
assert_nothing_raised do
|
114
115
|
cell(:bassist).class.logger.info("everything is perfect!")
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
118
|
-
|
119
|
+
it "respond to session" do
|
119
120
|
assert_kind_of Hash, @cell.session
|
120
121
|
end
|
121
122
|
|
122
|
-
|
123
|
+
it "respond to #params and return the request parameters" do
|
123
124
|
assert_equal({"song" => "Creatures"}, cell(:bassist).params)
|
124
125
|
end
|
125
126
|
|
126
|
-
|
127
|
+
it "not merge #params and #options" do
|
127
128
|
assert_equal({"song" => "Creatures"}, cell(:bassist, "song" => "Lockdown").params)
|
128
129
|
end
|
129
130
|
end
|
@@ -3,13 +3,13 @@ require 'test_helper'
|
|
3
3
|
class RailsIntegrationTest < ActionController::TestCase
|
4
4
|
tests MusicianController
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
describe "A Rails controller" do
|
7
|
+
it "respond to #render_cell" do
|
8
8
|
get 'promotion'
|
9
9
|
assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />", @response.body
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
it "respond to #render_cell with arbitrary options" do
|
13
13
|
BassistCell.class_eval do
|
14
14
|
def enjoy(what, where="the bar")
|
15
15
|
render :text => "I like #{what} in #{where}."
|
@@ -25,13 +25,13 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
25
25
|
assert_equal "I like The Stranglers in my room.", @response.body
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
it "be able to pass a block to #render_cell" do
|
29
29
|
get 'promotion_with_block'
|
30
30
|
assert_equal "Doo", @response.body
|
31
31
|
assert_equal BassistCell, @controller.flag
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
it "respond to render_cell in the view without escaping twice" do
|
35
35
|
BassistCell.class_eval do
|
36
36
|
def provoke; render; end
|
37
37
|
end
|
@@ -39,12 +39,12 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
39
39
|
assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />", @response.body
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
it "respond to render_cell with a block in the view" do
|
43
43
|
get 'featured_with_block'
|
44
44
|
assert_equal "Doo from BassistCell\n", @response.body
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
it "respond to render_cell in a haml view" do
|
48
48
|
BassistCell.class_eval do
|
49
49
|
def provoke; render; end
|
50
50
|
end
|
@@ -52,7 +52,7 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
52
52
|
assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />\n", @response.body
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
it "make params (and friends) available in a cell" do
|
56
56
|
BassistCell.class_eval do
|
57
57
|
def listen
|
58
58
|
render :text => "That's a #{params[:note]}"
|
@@ -62,7 +62,7 @@ class RailsIntegrationTest < ActionController::TestCase
|
|
62
62
|
assert_equal "That's a D", @response.body
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
it "respond to #config" do
|
66
66
|
BassistCell.class_eval do
|
67
67
|
def listen
|
68
68
|
render :view => 'contact_form' # form_tag internally calls config.allow_forgery_protection
|
data/test/rails/render_test.rb
CHANGED
@@ -1,38 +1,39 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class RailsRenderTest <
|
3
|
+
class RailsRenderTest < MiniTest::Spec
|
4
4
|
include Cell::TestCase::TestMethods
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
describe "Invoking render" do
|
7
|
+
it "render a plain view" do
|
8
8
|
BassistCell.class_eval do
|
9
9
|
def play; render; end
|
10
10
|
end
|
11
11
|
assert_equal "Doo", render_cell(:bassist, :play)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
it "accept :format" do
|
15
15
|
BassistCell.class_eval do
|
16
16
|
def play; render :format => :js; end
|
17
17
|
end
|
18
18
|
assert_equal "alert(\"Doo\");\n", render_cell(:bassist, :play)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
it "accept :format without messing up following render calls" do
|
22
|
+
skip
|
22
23
|
BassistCell.class_eval do
|
23
24
|
def play; render(:format => :js) + render; end
|
24
25
|
end
|
25
26
|
assert_equal "alert(\"Doo\");\nDoo\n", render_cell(:bassist, :play)
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
+
it "also render alternative engines, like haml" do
|
29
30
|
BassistCell.class_eval do
|
30
31
|
def sing; render; end
|
31
32
|
end
|
32
33
|
assert_equal "<h1>Laaa</h1>\n", render_cell(:bassist, :sing)
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
+
it "accept the :nothing option" do
|
36
37
|
BassistCell.class_eval do
|
37
38
|
def sleep; render :nothing => true; end
|
38
39
|
end
|
@@ -40,14 +41,14 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
40
41
|
end
|
41
42
|
|
42
43
|
|
43
|
-
|
44
|
+
it "accept the :view option" do
|
44
45
|
BassistCell.class_eval do
|
45
46
|
def solo; render :view => :play; end
|
46
47
|
end
|
47
48
|
assert_equal "Doo", render_cell(:bassist, :solo)
|
48
49
|
end
|
49
50
|
|
50
|
-
|
51
|
+
it "accept the :text options" do
|
51
52
|
BassistCell.class_eval do
|
52
53
|
def sing; render :text => "Shoobie"; end
|
53
54
|
end
|
@@ -55,14 +56,14 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
55
56
|
assert render_cell(:bassist, :sing).html_safe?
|
56
57
|
end
|
57
58
|
|
58
|
-
|
59
|
+
it "accept the :inline option" do
|
59
60
|
BassistCell.class_eval do
|
60
61
|
def sleep; render :inline => "<%= 'Snooore' %>"; end
|
61
62
|
end
|
62
63
|
assert_equal "Snooore", render_cell(:bassist, :sleep)
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
+
it "accept the :state option with state-args" do
|
66
67
|
BassistCell.class_eval do
|
67
68
|
def listen(band, song)
|
68
69
|
render :text => "Listening to #{band}: #{song}"
|
@@ -80,7 +81,7 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
80
81
|
assert_equal "Listening to Belvedere", render_cell(:bassist, :groove)
|
81
82
|
end
|
82
83
|
|
83
|
-
|
84
|
+
it "accept the :state option" do
|
84
85
|
BassistCell.class_eval do
|
85
86
|
def play; render; end
|
86
87
|
def groove; render :state => :play; end
|
@@ -88,7 +89,7 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
88
89
|
assert_equal "Doo", render_cell(:bassist, :groove)
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
+
it "accept the :locals option" do
|
92
93
|
BassistCell.class_eval do
|
93
94
|
def ahem; render :locals => {:times => 2}; end
|
94
95
|
end
|
@@ -97,14 +98,14 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
97
98
|
|
98
99
|
|
99
100
|
# layout
|
100
|
-
|
101
|
+
it "accept the :layout option" do
|
101
102
|
BassistCell.class_eval do
|
102
103
|
def play; render :layout => 'b'; end
|
103
104
|
end
|
104
105
|
assert_equal "<b>Doo</b>", render_cell(:bassist, :play)
|
105
106
|
end
|
106
107
|
|
107
|
-
|
108
|
+
it "respect the #layout class method" do
|
108
109
|
puts
|
109
110
|
class VanHalenBassistCell < BassistCell
|
110
111
|
layout 'b'
|
@@ -113,29 +114,32 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
113
114
|
assert_equal "<b>Doo</b>", render_cell("rails_render_test/van_halen_bassist", :play)
|
114
115
|
end
|
115
116
|
|
116
|
-
|
117
|
+
it "raise an error for a non-existent template" do
|
117
118
|
BassistCell.class_eval do
|
118
119
|
def groove; render; end
|
119
120
|
end
|
120
121
|
|
121
|
-
|
122
|
+
exception = ActionView::MissingTemplate
|
123
|
+
exception = Cell::VersionStrategy::MissingTemplate if Cell.rails3_0?
|
124
|
+
|
125
|
+
assert_raises exception do
|
122
126
|
render_cell(:bassist, :groove)
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
|
-
|
130
|
+
it "raise an error for a non-existent template" do
|
127
131
|
BadGuitaristCell.class_eval do
|
128
132
|
def groove; render; end
|
129
133
|
end
|
130
134
|
|
131
135
|
if Cell.rails3_0?
|
132
|
-
e =
|
136
|
+
e = assert_raises Cell::Rails::MissingTemplate do
|
133
137
|
render_cell(:bad_guitarist, :groove)
|
134
138
|
end
|
135
139
|
|
136
140
|
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"
|
137
141
|
else # >= 3.1
|
138
|
-
e =
|
142
|
+
e = assert_raises ActionView::MissingTemplate do
|
139
143
|
render_cell(:bad_guitarist, :groove)
|
140
144
|
end
|
141
145
|
|
@@ -143,7 +147,7 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
143
147
|
end
|
144
148
|
end
|
145
149
|
|
146
|
-
|
150
|
+
it "render instance variables from the cell" do
|
147
151
|
BassistCell.class_eval do
|
148
152
|
def slap
|
149
153
|
@note = "D"; render
|
@@ -152,7 +156,7 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
152
156
|
assert_equal "Boing in D", render_cell(:bassist, :slap)
|
153
157
|
end
|
154
158
|
|
155
|
-
|
159
|
+
it "allow subsequent calls to render in the rendered view" do
|
156
160
|
BassistCell.class_eval do
|
157
161
|
def jam; @chords = [:a, :c]; render; end
|
158
162
|
def sing; render; end
|
@@ -160,7 +164,7 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
160
164
|
assert_equal "<h1>Laaa</h1>\n\n<h1>Laaa</h1>\n\n", render_cell(:bassist, :jam)
|
161
165
|
end
|
162
166
|
|
163
|
-
|
167
|
+
it "allow multiple calls to render" do
|
164
168
|
BassistCell.class_eval do
|
165
169
|
def sing; render + render + render; end
|
166
170
|
end
|
@@ -168,7 +172,7 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
168
172
|
end
|
169
173
|
|
170
174
|
# inheriting
|
171
|
-
|
175
|
+
it "inherit play.html.erb from BassistCell" do
|
172
176
|
BassistCell.class_eval do
|
173
177
|
def play; render; end
|
174
178
|
end
|
@@ -176,9 +180,9 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
176
180
|
end
|
177
181
|
end
|
178
182
|
|
179
|
-
|
183
|
+
describe "A cell view" do
|
180
184
|
# rails view api
|
181
|
-
|
185
|
+
it "allow calls to params/response/..." do
|
182
186
|
BassistCell.class_eval do
|
183
187
|
def pose; render; end
|
184
188
|
end
|