cells 3.9.0 → 3.9.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGES.textile +5 -0
  4. data/README.md +14 -1
  5. data/cells.gemspec +2 -1
  6. data/gemfiles/Gemfile.rails3-0 +1 -0
  7. data/gemfiles/Gemfile.rails3-1 +1 -0
  8. data/gemfiles/Gemfile.rails3-2 +1 -0
  9. data/gemfiles/Gemfile.rails4-0 +5 -2
  10. data/gemfiles/Gemfile.rails4-1 +10 -0
  11. data/lib/cell/base.rb +23 -13
  12. data/lib/cell/rails/view_model.rb +3 -3
  13. data/lib/cell/rails3_0_strategy.rb +11 -9
  14. data/lib/cell/rails3_1_strategy.rb +9 -7
  15. data/lib/cell/rails4_0_strategy.rb +9 -8
  16. data/lib/cell/rails4_1_strategy.rb +40 -0
  17. data/lib/cell/test_case.rb +10 -0
  18. data/lib/cells/engines.rb +13 -11
  19. data/lib/cells/version.rb +1 -1
  20. data/lib/generators/cells/base.rb +4 -2
  21. data/test/app/cells/bassist_cell.rb +9 -0
  22. data/test/cell_generator_test.rb +5 -0
  23. data/test/cell_module_test.rb +6 -1
  24. data/test/cells_module_test.rb +4 -4
  25. data/test/deprecations_test.rb +23 -17
  26. data/test/dummy/label/app/cells/label/show.erb +1 -0
  27. data/test/dummy/label/app/cells/label_cell.rb +5 -0
  28. data/test/dummy/label/label.gemspec +20 -0
  29. data/test/dummy/label/lib/label.rb +4 -0
  30. data/test/dummy/label/lib/label/version.rb +3 -0
  31. data/test/helper_test.rb +1 -1
  32. data/test/rails/caching_test.rb +1 -1
  33. data/test/rails/cells_test.rb +2 -2
  34. data/test/rails/integration_test.rb +12 -0
  35. data/test/rails/render_test.rb +42 -45
  36. data/test/rails/router_test.rb +29 -34
  37. data/test/rails/view_model_test.rb +6 -5
  38. data/test/rails/view_test.rb +4 -4
  39. data/test/test_case_test.rb +119 -113
  40. data/test/test_helper.rb +13 -1
  41. metadata +25 -4
data/lib/cells/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cells
2
- VERSION = '3.9.0'
2
+ VERSION = '3.9.1'
3
3
  end
@@ -7,13 +7,15 @@ module Cells
7
7
  class_option :template_engine
8
8
  class_option :test_framework
9
9
  class_option :base_cell_class, :type => :string, :default => "Cell::Rails"
10
+ class_option :base_cell_path
10
11
 
11
12
  argument :actions, :type => :array, :default => [], :banner => "action action"
12
13
  check_class_collision :suffix => "Cell"
13
-
14
+
14
15
  private
15
16
  def base_path
16
- File.join('app/cells', class_path, file_name)
17
+ path = (options[:base_cell_path] || 'app/cells').to_s
18
+ File.join(path, class_path, file_name)
17
19
  end
18
20
  end
19
21
  end
@@ -13,4 +13,13 @@ class BassistCell < Cell::Rails
13
13
 
14
14
  render
15
15
  end
16
+
17
+ def promote
18
+ render
19
+ end
20
+
21
+ def slap
22
+ @note = "D"
23
+ render
24
+ end
16
25
  end
@@ -110,4 +110,9 @@ class CellGeneratorTest < Rails::Generators::TestCase
110
110
 
111
111
  assert_no_file "test/cells/blog_cell_test.rb"
112
112
  end
113
+
114
+ test "generate with custom base_path" do
115
+ run_generator %w(Blog --base-cell-path=app/components)
116
+ assert_file "app/components/blog_cell.rb"
117
+ end
113
118
  end
@@ -178,7 +178,12 @@ class CellModuleTest < MiniTest::Spec
178
178
  assert ! Cell.rails3_0?
179
179
  end
180
180
  elsif Rails::VERSION::MAJOR == 4
181
- assert Cell.rails4_0_or_more?
181
+ if Rails::VERSION::MINOR == 0
182
+ assert ! Cell.rails3_1_or_more?
183
+ assert Cell.rails4_0?
184
+ elsif Rails::VERSION::MINOR == 1
185
+ assert Cell.rails4_1?
186
+ end
182
187
  end
183
188
  end
184
189
  end
@@ -6,17 +6,17 @@ class CellsModuleTest < MiniTest::Spec
6
6
  before do
7
7
  @old_view_paths = Cell::Rails.view_paths.clone
8
8
  end
9
-
9
+
10
10
  after do
11
11
  Cell::Rails.view_paths = @old_view_paths
12
12
  end
13
-
13
+
14
14
  it "provide .before" do
15
15
  Cells.setup do |c|
16
16
  c.append_view_path "/road/to/nowhere"
17
17
  end
18
-
19
- if Cell.rails3_2_or_more? or Cell.rails4_0_or_more?
18
+
19
+ if Cell.rails3_2_or_more? or Cell.rails4_0? or Cell.rails4_1?
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
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  class DeprecationsTest < MiniTest::Spec
9
9
  include Cell::TestCase::TestMethods
10
-
10
+
11
11
  describe "#render_state" do
12
12
  it "work without args and provide #options" do
13
13
  SongwriterCell.class_eval do
@@ -17,7 +17,7 @@ class DeprecationsTest < MiniTest::Spec
17
17
  end
18
18
  assert_equal "D", cell(:songwriter, :note => "D").render_state(:listen)
19
19
  end
20
-
20
+
21
21
  include ActiveSupport::Testing::Deprecation
22
22
  it "mark @options as deprecated, but still work" do
23
23
  res = nil
@@ -29,7 +29,7 @@ class DeprecationsTest < MiniTest::Spec
29
29
  assert_equal "Lockdown", res
30
30
  end
31
31
  end
32
-
32
+
33
33
  describe "render_cell_for" do
34
34
  it "make options available in #options if not receiving state-args" do
35
35
  SongwriterCell.class_eval do
@@ -39,7 +39,7 @@ class DeprecationsTest < MiniTest::Spec
39
39
  end
40
40
  assert_equal "C-minor", Cell::Rails.render_cell_for(:songwriter, :listen, @controller, :note => "C-minor")
41
41
  end
42
-
42
+
43
43
  it "pass options as state-args and still set #options otherwise" do
44
44
  SongwriterCell.class_eval do
45
45
  def listen(args)
@@ -49,43 +49,49 @@ class DeprecationsTest < MiniTest::Spec
49
49
  assert_equal "C-minorC-minor", Cell::Rails.render_cell_for(:songwriter, :listen, @controller, :note => "C-minor")
50
50
  end
51
51
  end
52
-
52
+
53
53
  describe "#state_accepts_args?" do
54
54
  it "be false if state doesn't want args" do
55
55
  assert_not cell(:songwriter).state_accepts_args?(:play)
56
56
  end
57
-
57
+
58
58
  it "be true for one arg" do
59
- assert(cell(:songwriter) do
60
- def listen(args) end
59
+ assert(cell(:songwriter) do
60
+ def listen(args) end
61
61
  end.state_accepts_args?(:listen))
62
62
  end
63
-
63
+
64
64
  it "be true for multiple arg" do
65
- assert(cell(:songwriter) do
66
- def listen(what, where) end
65
+ assert(cell(:songwriter) do
66
+ def listen(what, where) end
67
67
  end.state_accepts_args?(:listen))
68
68
  end
69
-
69
+
70
70
  it "be true for multiple arg with defaults" do
71
- assert(cell(:songwriter) do
72
- def listen(what, where="") end
71
+ assert(cell(:songwriter) do
72
+ def listen(what, where="") end
73
73
  end.state_accepts_args?(:listen))
74
74
  end
75
75
  end
76
-
76
+
77
77
  describe ".cache" do
78
+ after do
79
+ ActionController::Base.perform_caching = false
80
+ end
81
+
78
82
  it "still be able to use options in the block" do
83
+ ActionController::Base.perform_caching = true
84
+
79
85
  SongwriterCell.class_eval do
80
86
  def count(args)
81
87
  render :text => args[:int]
82
88
  end
83
-
89
+
84
90
  cache :count do |cell, i|
85
91
  (cell.options[:int] % 2)==0 ? {:count => "even"} : {:count => "odd"}
86
92
  end
87
93
  end
88
-
94
+
89
95
  assert_equal "1", render_cell(:songwriter, :count, :int => 1)
90
96
  assert_equal "2", render_cell(:songwriter, :count, :int => 2)
91
97
  assert_equal "1", render_cell(:songwriter, :count, :int => 3)
@@ -0,0 +1 @@
1
+ Fat Wreck
@@ -0,0 +1,5 @@
1
+ class LabelCell < Cell::Rails
2
+ def show
3
+ render
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "label/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "label"
9
+ s.version = Label::VERSION
10
+ s.authors = ["TODO: Your name"]
11
+ s.email = ["TODO: Your email"]
12
+ s.homepage = "TODO"
13
+ s.summary = "TODO: Summary of Label."
14
+ s.description = "TODO: Description of Label."
15
+
16
+ s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
17
+ s.test_files = Dir["test/**/*"]
18
+
19
+ #s.add_dependency "railties", ">= 4.0.0"
20
+ end
@@ -0,0 +1,4 @@
1
+ module Label
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Label
2
+ VERSION = "0.0.1"
3
+ end
data/test/helper_test.rb CHANGED
@@ -32,7 +32,7 @@ class HelperTest < MiniTest::Spec
32
32
 
33
33
  it "allows using helpers using #controller on instance level" do
34
34
  alt = "No-more-the-meek"
35
- alt = "No more the meek" if Cell.rails4_0_or_more?
35
+ alt = "No more the meek" if Cell.rails4_0? or Cell.rails4_1?
36
36
  assert_equal "<img alt=\"#{alt}\" src=\"/images/no-more-the-meek.jpg\" />", render_cell("helper_test/song", :show)
37
37
  end
38
38
  end
@@ -38,7 +38,7 @@ class CachingUnitTest < MiniTest::Spec
38
38
  end
39
39
 
40
40
  it "accept hash as key parts" do
41
- if Cell.rails4_0_or_more?
41
+ if Cell.rails4_0? or Cell.rails4_1?
42
42
  assert_equal "cells/director/count/b/2/a/1", @class.state_cache_key(:count, :b=>2, :a=>1)
43
43
  else
44
44
  assert_equal "cells/director/count/a=1&b=2", @class.state_cache_key(:count, :b=>2, :a=>1)
@@ -54,7 +54,7 @@ class RailsCellsTest < MiniTest::Spec
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? or Cell.rails4_0_or_more?
57
+ if Cell.rails3_2_or_more? or Cell.rails4_0? or Cell.rails4_1?
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
@@ -118,7 +118,7 @@ class RailsCellsTest < MiniTest::Spec
118
118
 
119
119
  it "respond to session" do
120
120
  session_kind = Hash
121
- session_kind = ActionController::TestSession if Cell.rails4_0_or_more?
121
+ session_kind = ActionController::TestSession if Cell.rails4_0? or Cell.rails4_1?
122
122
  assert_kind_of session_kind, @cell.session
123
123
  end
124
124
 
@@ -8,6 +8,8 @@ class ControllerMethodsTest < ActionController::TestCase
8
8
  end
9
9
 
10
10
  test "#render_cell" do
11
+ fix_relative_url_root
12
+
11
13
  get 'promotion'
12
14
  assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />", @response.body
13
15
  end
@@ -42,6 +44,12 @@ class ControllerMethodsTest < ActionController::TestCase
42
44
  @controller.cell_for("controller_methods_test/song", :title => "We Called It America").
43
45
  title.must_equal "We Called It America"
44
46
  end
47
+
48
+ if Cell.rails4_0? or Cell.rails4_1_or_more?
49
+ test "#render_cell for engine" do
50
+ @controller.render_cell(:label, :show).must_equal "Fat Wreck"
51
+ end
52
+ end
45
53
  end
46
54
 
47
55
 
@@ -59,6 +67,8 @@ class ViewMethodsTest < ActionController::TestCase
59
67
  end
60
68
 
61
69
  test "#render_cell" do
70
+ fix_relative_url_root
71
+
62
72
  get 'featured'
63
73
  assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />", @response.body
64
74
  end
@@ -69,6 +79,8 @@ class ViewMethodsTest < ActionController::TestCase
69
79
  end
70
80
 
71
81
  test "#render_cell in a haml view" do
82
+ fix_relative_url_root
83
+
72
84
  get 'hamlet'
73
85
  assert_equal "That's me, naked <img alt=\"Me\" src=\"/images/me.png\" />\n", @response.body
74
86
  end
@@ -2,52 +2,54 @@ require 'test_helper'
2
2
 
3
3
  class RailsRenderTest < MiniTest::Spec
4
4
  include Cell::TestCase::TestMethods
5
-
5
+
6
+ let (:bassist) { cell(:bassist) }
7
+
6
8
  describe "Invoking render" do
7
9
  it "render a plain view" do
8
- BassistCell.class_eval do
10
+ bassist.instance_eval do
9
11
  def play; render; end
10
12
  end
11
- assert_equal "Doo", render_cell(:bassist, :play)
13
+ assert_equal "Doo", bassist.render_state(:play)
12
14
  end
13
-
15
+
14
16
  it "accept :format" do
15
- BassistCell.class_eval do
17
+ bassist.instance_eval do
16
18
  def play; render :format => :js; end
17
19
  end
18
- assert_equal "alert(\"Doo\");\n", render_cell(:bassist, :play)
20
+ assert_equal "alert(\"Doo\");\n", bassist.render_state(:play)
19
21
  end
20
-
22
+
21
23
  it "accept :format without messing up following render calls" do
22
24
  skip
23
- BassistCell.class_eval do
25
+ bassist.instance_eval do
24
26
  def play; render(:format => :js) + render; end
25
27
  end
26
- assert_equal "alert(\"Doo\");\nDoo\n", render_cell(:bassist, :play)
28
+ assert_equal "alert(\"Doo\");\nDoo\n", bassist.render_state(:play)
27
29
  end
28
-
30
+
29
31
  it "also render alternative engines, like haml" do
30
32
  BassistCell.class_eval do
31
33
  def sing; render; end
32
34
  end
33
35
  assert_equal "<h1>Laaa</h1>\n", render_cell(:bassist, :sing)
34
36
  end
35
-
37
+
36
38
  it "accept the :nothing option" do
37
39
  BassistCell.class_eval do
38
40
  def sleep; render :nothing => true; end
39
41
  end
40
42
  assert_equal "", render_cell(:bassist, :sleep)
41
43
  end
42
-
43
-
44
+
45
+
44
46
  it "accept the :view option" do
45
47
  BassistCell.class_eval do
46
48
  def solo; render :view => :play; end
47
49
  end
48
50
  assert_equal "Doo", render_cell(:bassist, :solo)
49
51
  end
50
-
52
+
51
53
  it "accept the :text options" do
52
54
  BassistCell.class_eval do
53
55
  def sing; render :text => "Shoobie"; end
@@ -55,14 +57,14 @@ class RailsRenderTest < MiniTest::Spec
55
57
  assert_equal "Shoobie", render_cell(:bassist, :sing)
56
58
  assert render_cell(:bassist, :sing).html_safe?
57
59
  end
58
-
60
+
59
61
  it "accept the :inline option" do
60
62
  BassistCell.class_eval do
61
63
  def sleep; render :inline => "<%= 'Snooore' %>"; end
62
64
  end
63
65
  assert_equal "Snooore", render_cell(:bassist, :sleep)
64
66
  end
65
-
67
+
66
68
  it "accept the :state option with state-args" do
67
69
  BassistCell.class_eval do
68
70
  def listen(band, song)
@@ -71,7 +73,7 @@ class RailsRenderTest < MiniTest::Spec
71
73
  def groove; render({:state => :listen}, "Thin Lizzy", "Southbound"); end
72
74
  end
73
75
  assert_equal "Listening to Thin Lizzy: Southbound", render_cell(:bassist, :groove)
74
-
76
+
75
77
  BassistCell.class_eval do
76
78
  def listen(args)
77
79
  render :text => "Listening to #{args[:band]}"
@@ -80,7 +82,7 @@ class RailsRenderTest < MiniTest::Spec
80
82
  end
81
83
  assert_equal "Listening to Belvedere", render_cell(:bassist, :groove)
82
84
  end
83
-
85
+
84
86
  it "accept the :state option" do
85
87
  BassistCell.class_eval do
86
88
  def play; render; end
@@ -88,37 +90,37 @@ class RailsRenderTest < MiniTest::Spec
88
90
  end
89
91
  assert_equal "Doo", render_cell(:bassist, :groove)
90
92
  end
91
-
93
+
92
94
  it "accept the :locals option" do
93
95
  BassistCell.class_eval do
94
96
  def ahem; render :locals => {:times => 2}; end
95
97
  end
96
98
  assert_equal "AhemAhem", render_cell(:bassist, :ahem)
97
99
  end
98
-
99
-
100
+
101
+
100
102
  # layout
101
103
  it "accept the :layout option" do
102
- BassistCell.class_eval do
104
+ bassist.instance_eval do
103
105
  def play; render :layout => 'b'; end
104
106
  end
105
- assert_equal "<b>Doo</b>", render_cell(:bassist, :play)
107
+ assert_equal "<b>Doo</b>", bassist.render_state(:play)
106
108
  end
107
-
109
+
108
110
  it "respect the #layout class method" do
109
- puts
111
+ puts
110
112
  class VanHalenBassistCell < BassistCell
111
113
  layout 'b'
112
114
  def play; render; end
113
115
  end
114
116
  assert_equal "<b>Doo</b>", render_cell("rails_render_test/van_halen_bassist", :play)
115
117
  end
116
-
118
+
117
119
  it "raise an error for a non-existent template" do
118
120
  BassistCell.class_eval do
119
121
  def groove; render; end
120
122
  end
121
-
123
+
122
124
  exception = ActionView::MissingTemplate
123
125
  exception = Cell::VersionStrategy::MissingTemplate if Cell.rails3_0?
124
126
 
@@ -126,36 +128,31 @@ class RailsRenderTest < MiniTest::Spec
126
128
  render_cell(:bassist, :groove)
127
129
  end
128
130
  end
129
-
131
+
130
132
  it "raise an error for a non-existent template" do
131
133
  BadGuitaristCell.class_eval do
132
134
  def groove; render; end
133
135
  end
134
-
136
+
135
137
  if Cell.rails3_0?
136
138
  e = assert_raises Cell::Rails::MissingTemplate do
137
139
  render_cell(:bad_guitarist, :groove)
138
140
  end
139
-
141
+
140
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"
141
143
  else # >= 3.1
142
144
  e = assert_raises ActionView::MissingTemplate do
143
145
  render_cell(:bad_guitarist, :groove)
144
146
  end
145
-
147
+
146
148
  assert_includes e.message, "Missing template bad_guitarist/groove, bassist/groove with"
147
149
  end
148
150
  end
149
-
151
+
150
152
  it "render instance variables from the cell" do
151
- BassistCell.class_eval do
152
- def slap
153
- @note = "D"; render
154
- end
155
- end
156
153
  assert_equal "Boing in D", render_cell(:bassist, :slap)
157
154
  end
158
-
155
+
159
156
  it "allow subsequent calls to render in the rendered view" do
160
157
  BassistCell.class_eval do
161
158
  def jam; @chords = [:a, :c]; render; end
@@ -163,14 +160,14 @@ class RailsRenderTest < MiniTest::Spec
163
160
  end
164
161
  assert_equal "<h1>Laaa</h1>\n\n<h1>Laaa</h1>\n\n", render_cell(:bassist, :jam)
165
162
  end
166
-
163
+
167
164
  it "allow multiple calls to render" do
168
165
  BassistCell.class_eval do
169
166
  def sing; render + render + render; end
170
167
  end
171
168
  assert_equal "<h1>Laaa</h1>\n<h1>Laaa</h1>\n<h1>Laaa</h1>\n", render_cell(:bassist, :sing)
172
169
  end
173
-
170
+
174
171
  # inheriting
175
172
  it "inherit play.html.erb from BassistCell" do
176
173
  BassistCell.class_eval do
@@ -179,22 +176,22 @@ class RailsRenderTest < MiniTest::Spec
179
176
  assert_equal "Doo", render_cell(:bad_guitarist, :play)
180
177
  end
181
178
  end
182
-
179
+
183
180
  describe "A cell view" do
184
181
  # rails view api
185
182
  it "allow calls to params/response/..." do
186
183
  BassistCell.class_eval do
187
184
  def pose; render; end
188
185
  end
189
-
186
+
190
187
  @request.env["action_dispatch.request.request_parameters"] = {:what => 'get'} # FIXME: duplicated in cells_test.rb.
191
188
  @controller = Class.new(ActionController::Base).new
192
189
  @controller.request = @request
193
190
  @cell = cell(:bassist)
194
-
191
+
195
192
  assert_equal "Come and get me!", @cell.render_state(:pose)
196
193
  end
197
-
198
-
194
+
195
+
199
196
  end
200
197
  end