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.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +15 -13
  4. data/Appraisals +23 -0
  5. data/CHANGES.md +20 -3
  6. data/Gemfile +5 -7
  7. data/README.md +317 -236
  8. data/Rakefile +1 -1
  9. data/TODO.md +3 -0
  10. data/cells.gemspec +19 -28
  11. data/gemfiles/rails3.2.gemfile +14 -0
  12. data/gemfiles/rails4.0.gemfile +14 -0
  13. data/gemfiles/rails4.1.gemfile +15 -0
  14. data/gemfiles/rails4.2.gemfile +14 -0
  15. data/lib/cell.rb +28 -21
  16. data/lib/cell/caching.rb +10 -22
  17. data/lib/cell/caching/notification.rb +15 -0
  18. data/lib/cell/concept.rb +4 -69
  19. data/lib/cell/development.rb +11 -0
  20. data/lib/{cells → cell}/engines.rb +1 -1
  21. data/lib/cell/layout.rb +20 -0
  22. data/lib/cell/partial.rb +17 -0
  23. data/lib/cell/{base/prefixes.rb → prefixes.rb} +1 -1
  24. data/lib/cell/rails.rb +58 -50
  25. data/lib/cell/railtie.rb +60 -0
  26. data/lib/cell/{base/self_contained.rb → self_contained.rb} +1 -1
  27. data/lib/cell/templates.rb +60 -0
  28. data/lib/cell/test_case.rb +4 -162
  29. data/lib/cell/testing.rb +15 -0
  30. data/lib/cell/twin.rb +11 -29
  31. data/lib/cell/version.rb +10 -0
  32. data/lib/cell/view_model.rb +196 -88
  33. data/lib/cells.rb +1 -20
  34. data/lib/rails/generators/cell/cell_generator.rb +43 -0
  35. data/lib/rails/generators/cell/templates/cell.rb.erb +8 -0
  36. data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.erb +0 -0
  37. data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.haml +0 -0
  38. data/lib/rails/generators/cell/templates/view.slim +2 -0
  39. data/lib/rails/generators/concept/concept_generator.rb +38 -0
  40. data/lib/{generators/templates/concept/cell.rb → rails/generators/concept/templates/concept.rb.erb} +2 -2
  41. data/lib/{generators → rails/generators/concept}/templates/view.erb +0 -0
  42. data/lib/{generators → rails/generators/concept}/templates/view.haml +0 -0
  43. data/lib/rails/generators/concept/templates/view.slim +2 -0
  44. data/lib/rails/generators/test_unit/cell/cell_generator.rb +21 -0
  45. data/lib/{generators/templates/cell_test.rb → rails/generators/test_unit/cell/templates/unit_test.rb.erb} +3 -3
  46. data/lib/rails/generators/test_unit/concept/concept_generator.rb +21 -0
  47. data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +11 -0
  48. data/lib/{cells → tasks}/cells.rake +0 -0
  49. data/test/builder_test.rb +58 -0
  50. data/test/caching_test.rb +298 -0
  51. data/test/cell_benchmark.rb +32 -0
  52. data/test/cell_generator_test.rb +51 -82
  53. data/test/cell_test.rb +8 -23
  54. data/test/concept_generator_test.rb +22 -13
  55. data/test/concept_test.rb +41 -75
  56. data/test/dummy/app/views/musician/hamlet.html.erb +1 -0
  57. data/test/dummy/config/application.rb +21 -8
  58. data/test/{app/cells/bassist/play.html.erb → fixtures/bassist/play.erb} +0 -0
  59. data/test/fixtures/concepts/record/views/layout.erb +1 -0
  60. data/test/{app → fixtures}/concepts/record/views/show.erb +0 -0
  61. data/test/{app → fixtures}/concepts/record/views/song.erb +0 -0
  62. data/test/fixtures/inherit_views_test/popper/tap.erb +1 -0
  63. data/test/fixtures/inherit_views_test/tapper/play.erb +1 -0
  64. data/test/fixtures/inherit_views_test/tapper/tap.erb +1 -0
  65. data/test/fixtures/partial_test/with_partial/show.erb +1 -0
  66. data/test/fixtures/partials/_show.html.erb +1 -0
  67. data/test/fixtures/partials/_show.xml.erb +1 -0
  68. data/test/fixtures/song/ivar.erb +1 -0
  69. data/test/fixtures/song/show.erb +1 -0
  70. data/test/fixtures/song/with_erb.erb +4 -0
  71. data/test/fixtures/song/with_html.erb +1 -0
  72. data/test/fixtures/song/with_locals.erb +2 -0
  73. data/test/fixtures/song_with_layout/happy.erb +1 -0
  74. data/test/fixtures/song_with_layout/merry.erb +1 -0
  75. data/test/fixtures/song_with_layout/show.erb +1 -0
  76. data/test/fixtures/song_with_layout/show_with_layout.erb +1 -0
  77. data/test/fixtures/templates_caching_test/song/show.erb +1 -0
  78. data/test/fixtures/url_helper_test/song/edit.erb +8 -0
  79. data/test/fixtures/url_helper_test/song/with_block.erb +2 -0
  80. data/test/fixtures/url_helper_test/song/with_capture.erb +4 -0
  81. data/test/fixtures/url_helper_test/song/with_content_tag.erb +6 -0
  82. data/test/fixtures/url_helper_test/song/with_form_for_block.erb +3 -0
  83. data/test/fixtures/url_helper_test/song/with_link_to.erb +3 -0
  84. data/test/layout_test.rb +57 -0
  85. data/test/partial_test.rb +27 -0
  86. data/test/prefixes_test.rb +36 -10
  87. data/test/public_test.rb +42 -0
  88. data/test/rails_extensions_test.rb +51 -0
  89. data/test/render_test.rb +103 -0
  90. data/test/templates_test.rb +45 -0
  91. data/test/test_case_test.rb +21 -122
  92. data/test/test_helper.rb +37 -33
  93. data/test/twin_test.rb +3 -7
  94. data/test/url_helper_test.rb +89 -0
  95. metadata +92 -357
  96. data/gemfiles/Gemfile.rails3-0 +0 -7
  97. data/gemfiles/Gemfile.rails3-1 +0 -7
  98. data/gemfiles/Gemfile.rails3-2 +0 -7
  99. data/gemfiles/Gemfile.rails4-0 +0 -12
  100. data/gemfiles/Gemfile.rails4-1 +0 -12
  101. data/lib/cell/base.rb +0 -82
  102. data/lib/cell/base/view.rb +0 -15
  103. data/lib/cell/builder.rb +0 -71
  104. data/lib/cell/deprecations.rb +0 -41
  105. data/lib/cell/dsl.rb +0 -7
  106. data/lib/cell/rack.rb +0 -32
  107. data/lib/cell/rails/helper_api.rb +0 -37
  108. data/lib/cell/rails/view_model.rb +0 -159
  109. data/lib/cell/rails3_0_strategy.rb +0 -82
  110. data/lib/cell/rails3_1_strategy.rb +0 -40
  111. data/lib/cell/rails4_0_strategy.rb +0 -39
  112. data/lib/cell/rails4_1_strategy.rb +0 -40
  113. data/lib/cell/rendering.rb +0 -109
  114. data/lib/cells/rails.rb +0 -86
  115. data/lib/cells/railtie.rb +0 -38
  116. data/lib/cells/version.rb +0 -3
  117. data/lib/generators/USAGE +0 -30
  118. data/lib/generators/cells/base.rb +0 -22
  119. data/lib/generators/cells/cell_generator.rb +0 -15
  120. data/lib/generators/cells/view_generator.rb +0 -18
  121. data/lib/generators/erb/cell_generator.rb +0 -15
  122. data/lib/generators/erb/concept_generator.rb +0 -17
  123. data/lib/generators/haml/cell_generator.rb +0 -17
  124. data/lib/generators/haml/concept_generator.rb +0 -17
  125. data/lib/generators/rails/cell_generator.rb +0 -16
  126. data/lib/generators/rails/concept_generator.rb +0 -16
  127. data/lib/generators/slim/cell_generator.rb +0 -17
  128. data/lib/generators/templates/cell.rb +0 -9
  129. data/lib/generators/templates/view.slim +0 -4
  130. data/lib/generators/test_unit/cell_generator.rb +0 -14
  131. data/lib/generators/trailblazer/base.rb +0 -21
  132. data/lib/generators/trailblazer/view_generator.rb +0 -18
  133. data/test/app/cells/album/views/cover.haml +0 -1
  134. data/test/app/cells/bad_guitarist/_dii.html.erb +0 -1
  135. data/test/app/cells/bad_guitarist_cell.rb +0 -2
  136. data/test/app/cells/bassist/_dii.html.erb +0 -1
  137. data/test/app/cells/bassist/ahem.html.erb +0 -1
  138. data/test/app/cells/bassist/compose.html.erb +0 -1
  139. data/test/app/cells/bassist/contact_form.html.erb +0 -1
  140. data/test/app/cells/bassist/form_for.erb +0 -3
  141. data/test/app/cells/bassist/form_for_in_haml.haml +0 -2
  142. data/test/app/cells/bassist/jam.html.erb +0 -3
  143. data/test/app/cells/bassist/play.js.erb +0 -1
  144. data/test/app/cells/bassist/pose.html.erb +0 -1
  145. data/test/app/cells/bassist/promote.html.erb +0 -1
  146. data/test/app/cells/bassist/provoke.html.erb +0 -1
  147. data/test/app/cells/bassist/shout.html.erb +0 -1
  148. data/test/app/cells/bassist/sing.html.haml +0 -1
  149. data/test/app/cells/bassist/slap.html.erb +0 -1
  150. data/test/app/cells/bassist/yell.en.html.erb +0 -1
  151. data/test/app/cells/bassist_cell.rb +0 -25
  152. data/test/app/cells/club_security.rb +0 -2
  153. data/test/app/cells/club_security/guard/help.html.erb +0 -1
  154. data/test/app/cells/club_security/guard_cell.rb +0 -6
  155. data/test/app/cells/club_security/medic/help.html.erb +0 -1
  156. data/test/app/cells/club_security/medic_cell.rb +0 -8
  157. data/test/app/cells/layouts/b.erb +0 -1
  158. data/test/app/cells/layouts/metal.html.erb +0 -1
  159. data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +0 -5
  160. data/test/app/cells/shouter/sing.html.erb +0 -1
  161. data/test/app/cells/song/dashboard.haml +0 -7
  162. data/test/app/cells/song/details.html.haml +0 -1
  163. data/test/app/cells/song/info.html.haml +0 -1
  164. data/test/app/cells/song/lyrics.html.haml +0 -6
  165. data/test/app/cells/song/plays.haml +0 -1
  166. data/test/app/cells/song/scale.haml +0 -1
  167. data/test/app/cells/song/show.html.haml +0 -3
  168. data/test/app/cells/song/title.html.haml +0 -1
  169. data/test/app/cells/trumpeter/promote.html.erb +0 -1
  170. data/test/app/cells/trumpeter_cell.rb +0 -8
  171. data/test/app/cells/view_model_test/comments/show.haml +0 -7
  172. data/test/app/concepts/record/views/layout.haml +0 -2
  173. data/test/app/views/shared/_dong.html.erb +0 -1
  174. data/test/cell_module_test.rb +0 -170
  175. data/test/cells_module_test.rb +0 -27
  176. data/test/deprecations_test.rb +0 -101
  177. data/test/dummy/app/helpers/application_helper.rb +0 -2
  178. data/test/dummy/app/views/musician/hamlet.html.haml +0 -1
  179. data/test/dummy/config/environments/development.rb +0 -16
  180. data/test/dummy/config/environments/production.rb +0 -46
  181. data/test/dummy/config/environments/test.rb +0 -33
  182. data/test/dummy/db/test.sqlite3 +0 -0
  183. data/test/dummy/label/app/cells/label/show.erb +0 -1
  184. data/test/dummy/label/app/cells/label_cell.rb +0 -5
  185. data/test/dummy/label/label.gemspec +0 -20
  186. data/test/dummy/label/lib/label.rb +0 -4
  187. data/test/dummy/label/lib/label/version.rb +0 -3
  188. data/test/dummy/public/404.html +0 -26
  189. data/test/dummy/public/422.html +0 -26
  190. data/test/dummy/public/500.html +0 -26
  191. data/test/dummy/public/favicon.ico +0 -0
  192. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  193. data/test/helper_test.rb +0 -81
  194. data/test/rack_test.rb +0 -32
  195. data/test/rails/asset_pipeline_test.rb +0 -20
  196. data/test/rails/caching_test.rb +0 -456
  197. data/test/rails/cells_test.rb +0 -119
  198. data/test/rails/forms_test.rb +0 -75
  199. data/test/rails/integration_test.rb +0 -299
  200. data/test/rails/render_test.rb +0 -189
  201. data/test/rails/view_model_test.rb +0 -226
  202. data/test/rails/view_test.rb +0 -49
  203. data/test/rails_helper_api_test.rb +0 -58
  204. data/test/self_contained_test.rb +0 -31
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+ require 'benchmark'
3
+
4
+ Song = Struct.new(:title)
5
+
6
+
7
+ class SongCell < Cell::ViewModel
8
+ self.view_paths = ['test']
9
+ property :title
10
+
11
+ def show
12
+ render
13
+ end
14
+ end
15
+
16
+ time = Benchmark.measure do
17
+ Cell::ViewModel.cell(:song, nil, collection: 1000.times.collect { Song.new("Anarchy Camp") })
18
+ end
19
+
20
+ puts time
21
+
22
+ # 4.0
23
+ # 0.310000 0.010000 0.320000 ( 0.320382)
24
+
25
+ # no caching of templates, puts
26
+ # 0.570000 0.030000 0.600000 ( 0.600160)
27
+
28
+ # caching of templates
29
+ # 0.090000 0.000000 0.090000 ( 0.085652)
30
+
31
+ # wed, 17.
32
+ # 0.120000 0.010000 0.130000 ( 0.127731)
@@ -1,118 +1,87 @@
1
1
  require 'test_helper'
2
- require 'generators/rails/cell_generator'
2
+ require 'rails/generators/test_case'
3
+ require 'rails/generators/cell/cell_generator'
3
4
 
4
5
  class CellGeneratorTest < Rails::Generators::TestCase
5
- destination File.join(Rails.root, "tmp")
6
+ tests Rails::Generators::CellGenerator
7
+ destination File.expand_path('../../tmp', File.dirname(__FILE__))
6
8
  setup :prepare_destination
7
- tests ::Rails::Generators::CellGenerator
8
9
 
9
- test "create the standard assets" do
10
- run_generator %w(Blog post latest)
10
+ test 'create the standard assets' do
11
+ run_generator %w(blog post latest -e erb)
11
12
 
12
- assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
13
- assert_file "app/cells/blog_cell.rb", /def post/
14
- assert_file "app/cells/blog_cell.rb", /def latest/
15
- assert_file "app/cells/blog/post.html.erb", %r(app/cells/blog/post\.html\.erb)
16
- assert_file "app/cells/blog/post.html.erb", %r(<p>)
17
- assert_file "app/cells/blog/latest.html.erb", %r(app/cells/blog/latest\.html\.erb)
18
-
19
-
20
- assert_no_file "app/cells/blog/post.html.haml"
21
- assert_no_file "app/cells/blog/post.html.haml"
22
- assert_no_file "app/cells/blog/latest.html.haml"
23
-
24
- assert_no_file "app/cells/blog/post.html.slim"
25
- assert_no_file "app/cells/blog/post.html.slim"
26
- assert_no_file "app/cells/blog/latest.html.slim"
13
+ assert_file 'app/cells/blog_cell.rb', /class BlogCell < Cell::ViewModel/
14
+ assert_file 'app/cells/blog_cell.rb', /def post/
15
+ assert_file 'app/cells/blog_cell.rb', /def latest/
16
+ assert_file 'app/cells/blog/post.erb', %r{app/cells/blog/post\.erb}
17
+ assert_file 'app/cells/blog/post.erb', %r{<p>}
18
+ assert_file 'app/cells/blog/latest.erb', %r{app/cells/blog/latest\.erb}
27
19
  end
28
20
 
29
- test "create cell that inherits from custom cell class if specified" do
30
- run_generator %w(Blog --base-cell-class=ApplicationCell)
31
- assert_file "app/cells/blog_cell.rb", /class BlogCell < ApplicationCell/
21
+ test 'create cell that inherits from custom cell class if specified' do
22
+ run_generator %w(Blog --parent=ApplicationCell)
23
+ assert_file 'app/cells/blog_cell.rb', /class BlogCell < ApplicationCell/
32
24
  end
33
-
34
- test "work with namespaces" do
35
- run_generator %w(Blog::Post latest)
36
25
 
37
- assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
38
- assert_file "app/cells/blog/post_cell.rb", /def latest/
39
- assert_file "app/cells/blog/post/latest.html.erb", %r(app/cells/blog/post/latest\.html\.erb)
26
+ test 'work with namespaces' do
27
+ run_generator %w(blog/post latest -e erb)
28
+ assert_file 'app/cells/blog/post_cell.rb', /class Blog::PostCell < Cell::ViewModel/
29
+ assert_file 'app/cells/blog/post_cell.rb', /def show/
30
+ assert_file 'app/cells/blog/post_cell.rb', /def latest/
31
+ assert_file 'app/cells/blog/post/latest.erb', %r{app/cells/blog/post/latest\.erb}
40
32
  end
41
-
42
- test "work with namespaces and haml" do
43
- run_generator %w(Blog::Post latest -e haml)
44
33
 
45
- assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
46
- assert_file "app/cells/blog/post/latest.html.haml", %r(app/cells/blog/post/latest\.html\.haml)
34
+ test 'work with namespaces and haml' do
35
+ run_generator %w(blog/post latest -e haml)
36
+ assert_file 'app/cells/blog/post_cell.rb', /class Blog::PostCell < Cell::ViewModel/
37
+ assert_file 'app/cells/blog/post/latest.haml', %r{app/cells/blog/post/latest\.haml}
47
38
  end
48
39
 
49
- test "work with namespaces and slim" do
50
- run_generator %w(Blog::Post latest -e slim)
40
+ test 'work with namespaces and slim' do
41
+ run_generator %w(blog/post latest -e slim)
51
42
 
52
- assert_file "app/cells/blog/post_cell.rb", /class Blog::PostCell < Cell::Rails/
53
- assert_file "app/cells/blog/post/latest.html.slim", %r(app/cells/blog/post/latest\.html\.slim)
43
+ assert_file 'app/cells/blog/post_cell.rb', /class Blog::PostCell < Cell::ViewModel/
44
+ assert_file 'app/cells/blog/post/latest.slim', %r{app/cells/blog/post/latest\.slim}
54
45
  end
55
46
 
56
- test "create slim assets with -e slim" do
57
- run_generator %w(Blog post latest -e slim)
58
-
59
- assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
60
- assert_file "app/cells/blog_cell.rb", /def post/
61
- assert_file "app/cells/blog_cell.rb", /def latest/
62
- assert_file "app/cells/blog/post.html.slim", %r(app/cells/blog/post\.html\.slim)
63
- assert_file "app/cells/blog/post.html.slim", %r(p)
64
- assert_file "app/cells/blog/latest.html.slim", %r(app/cells/blog/latest\.html\.slim)
65
-
47
+ test 'create slim assets with -e slim' do
48
+ run_generator %w(blog post latest -e slim)
66
49
 
67
- assert_no_file "app/cells/blog/post.html.erb"
68
- assert_no_file "app/cells/blog/post.html.erb"
69
- assert_no_file "app/cells/blog/latest.html.erb"
70
-
71
- assert_no_file "app/cells/blog/post.html.haml"
72
- assert_no_file "app/cells/blog/post.html.haml"
73
- assert_no_file "app/cells/blog/latest.html.haml"
50
+ assert_file 'app/cells/blog_cell.rb', /class BlogCell < Cell::ViewModel/
51
+ assert_file 'app/cells/blog_cell.rb', /def post/
52
+ assert_file 'app/cells/blog_cell.rb', /def latest/
53
+ assert_file 'app/cells/blog/post.slim', %r{app/cells/blog/post\.slim}
54
+ assert_file 'app/cells/blog/post.slim', %r{p}
55
+ assert_file 'app/cells/blog/latest.slim', %r{app/cells/blog/latest\.slim}
74
56
  end
75
57
 
76
- test "create haml assets with -e haml" do
58
+ test 'create haml assets with -e haml' do
77
59
  run_generator %w(Blog post latest -e haml)
78
60
 
79
- assert_file "app/cells/blog_cell.rb", /class BlogCell < Cell::Rails/
80
- assert_file "app/cells/blog_cell.rb", /def post/
81
- assert_file "app/cells/blog_cell.rb", /def latest/
82
- assert_file "app/cells/blog/post.html.haml", %r(app/cells/blog/post\.html\.haml)
83
- assert_file "app/cells/blog/post.html.haml", %r(%p)
84
- assert_file "app/cells/blog/latest.html.haml", %r(app/cells/blog/latest\.html\.haml)
85
-
86
-
87
- assert_no_file "app/cells/blog/post.html.erb"
88
- assert_no_file "app/cells/blog/post.html.erb"
89
- assert_no_file "app/cells/blog/latest.html.erb"
90
-
91
- assert_no_file "app/cells/blog/post.html.slim"
92
- assert_no_file "app/cells/blog/post.html.slim"
93
- assert_no_file "app/cells/blog/latest.html.slim"
61
+ assert_file 'app/cells/blog_cell.rb', /class BlogCell < Cell::ViewModel/
62
+ assert_file 'app/cells/blog_cell.rb', /def post/
63
+ assert_file 'app/cells/blog_cell.rb', /def latest/
64
+ assert_file 'app/cells/blog/post.haml', %r{app/cells/blog/post\.haml}
65
+ assert_file 'app/cells/blog/post.haml', %r{%p}
66
+ assert_file 'app/cells/blog/latest.haml', %r{app/cells/blog/latest\.haml}
94
67
  end
95
68
 
96
- test "create test_unit assets with -t test_unit" do
69
+ test 'create test_unit assets with -t test_unit' do
97
70
  run_generator %w(Blog post latest -t test_unit)
98
71
 
99
- assert_file "test/cells/blog_cell_test.rb"
72
+ assert_file 'test/cells/blog_cell_test.rb'
100
73
  end
101
74
 
102
- test "work with namespace and test_unit" do
103
- run_generator %w(Blog::Post latest -t test_unit)
75
+ test 'work with namespace and test_unit' do
76
+ run_generator %w(blog/post latest -t test_unit)
104
77
 
105
- assert_file "test/cells/blog/post_cell_test.rb", /class Blog::PostCellTest < Cell::TestCase/
78
+ assert_file 'test/cells/blog/post_cell_test.rb', /class Blog::PostCellTest < Cell::TestCase/
106
79
  end
107
80
 
108
- test "create test_unit assets with -t rspec" do
81
+ test 'create test_unit assets with -t rspec' do
109
82
  run_generator %w(Blog post latest -t rspec)
110
83
 
111
- assert_no_file "test/cells/blog_cell_test.rb"
84
+ assert_no_file 'test/cells/blog_cell_test.rb'
112
85
  end
113
86
 
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
118
87
  end
@@ -1,28 +1,13 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  class CellTest < MiniTest::Spec
4
- class ArtistCell < Cell::Rails
5
- end
6
- class SongCell < Cell::Base
7
- include Cell::OptionsConstructor
8
- end
9
-
10
- describe "#initialize" do
11
- it { Class.new(Cell::Base) { include Cell::OptionsConstructor }.new(:song => song=Object.new).song.must_equal song }
12
- it { Class.new(Cell::Rack) { include Cell::OptionsConstructor }.new(Object, :song => song=Object.new).song.must_equal song }
13
- it { Class.new(Cell::Rails) { include Cell::OptionsConstructor }.new(Object, :song => song=Object.new).song.must_equal song }
4
+ class SongCell < Cell::ViewModel
5
+ def show
6
+ end
14
7
  end
8
+ # ::rails_version
9
+ it { Cell.rails_version.must_equal Gem::Version.new(ActionPack::VERSION::STRING) }
15
10
 
16
- describe "::create_cell_for" do
17
- it { Cell::Base.create_cell_for("cell_test/song", :song => song=Object.new).song.must_equal song }
18
- end
19
-
20
- describe "#cell" do
21
- it { Cell::Rails.new(Object).cell("cell_test/artist").must_be_instance_of ArtistCell }
22
- it { Cell::Base.new.cell("cell_test/song").must_be_instance_of SongCell }
23
- end
11
+ # #options
12
+ it { SongCell.new(nil, nil, genre: "Punkrock").send(:options)[:genre].must_equal "Punkrock" }
24
13
  end
25
-
26
- class OptionsConstructorTest < MiniTest::Spec
27
- it { Class.new(Cell::Base) { include Cell::OptionsConstructor }.new(:song => song=Object.new).song.must_equal song }
28
- end
@@ -1,24 +1,33 @@
1
1
  require 'test_helper'
2
- require 'generators/rails/concept_generator'
2
+ require 'rails/generators/test_case'
3
+ require 'rails/generators/concept/concept_generator'
3
4
 
4
5
  class ConceptGeneratorTest < Rails::Generators::TestCase
5
- destination File.join(Rails.root, "tmp")
6
+ destination File.expand_path('../../tmp', File.dirname(__FILE__))
6
7
  setup :prepare_destination
7
- tests ::Rails::Generators::ConceptGenerator
8
+ tests Rails::Generators::ConceptGenerator
8
9
 
9
- test "[erb] standard assets, show view" do
10
- run_generator %w(Song)
10
+ test '[erb] standard assets, show view' do
11
+ run_generator %w(song -e erb)
11
12
 
12
- assert_file "app/concepts/song/cell.rb", /class Song::Cell < Cell::Concept/
13
- assert_file "app/concepts/song/cell.rb", /def show/
14
- assert_file "app/concepts/song/views/show.erb", %r(app/concepts/song/views/show\.erb)
13
+ assert_file 'app/concepts/song/cell.rb', /class Song::Cell < Cell::Concept/
14
+ assert_file 'app/concepts/song/cell.rb', /def show/
15
+ assert_file 'app/concepts/song/views/show.erb', %r{app/concepts/song/views/show\.erb}
15
16
  end
16
17
 
17
- test "[haml] standard assets, show view" do
18
- run_generator %w(Song -e haml)
18
+ test '[haml] standard assets, show view' do
19
+ run_generator %w(song -e haml)
19
20
 
20
- assert_file "app/concepts/song/cell.rb", /class Song::Cell < Cell::Concept/
21
- assert_file "app/concepts/song/cell.rb", /def show/
22
- assert_file "app/concepts/song/views/show.haml", %r(app/concepts/song/views/show\.haml)
21
+ assert_file 'app/concepts/song/cell.rb', /class Song::Cell < Cell::Concept/
22
+ assert_file 'app/concepts/song/cell.rb', /def show/
23
+ assert_file 'app/concepts/song/views/show.haml', %r{app/concepts/song/views/show\.haml}
24
+ end
25
+
26
+ test '[slim] standard assets, show view' do
27
+ run_generator %w(song -e slim)
28
+
29
+ assert_file 'app/concepts/song/cell.rb', /class Song::Cell < Cell::Concept/
30
+ assert_file 'app/concepts/song/cell.rb', /def show/
31
+ assert_file 'app/concepts/song/views/show.slim', %r{app/concepts/song/views/show\.slim}
23
32
  end
24
33
  end
@@ -1,94 +1,60 @@
1
1
  require 'test_helper'
2
2
 
3
- if Cell.rails_version >= 3.1
4
- Cell::Concept.class_eval do
5
- self.append_view_path "test/app/concepts"
6
- end
7
-
8
- # Trailblazer style:
9
- module Record
10
- class Cell < Cell::Concept # cell("record")
11
- def show
12
- render # Party On, #{model}
13
- end
14
-
15
- # cell(:song, concept: :record)
16
- class Song < self # cell("record/cell/song")
17
- def show
18
- render :view => :song#, :layout => "layout"
19
- # TODO: test layout: .. in ViewModel
20
- end
21
-
22
- def show_with_layout
23
- render :view => :song, :layout => "layout"
24
- end
25
- end
3
+ Cell::Concept.class_eval do
4
+ self.view_paths = ['test/fixtures/concepts']
5
+ end
26
6
 
27
- class Hit < ::Cell::Concept
28
- inherit_views Record::Cell
29
- end
7
+ # Trailblazer style:
8
+ module Record
9
+ class Cell < Cell::Concept # cell("record")
10
+ self.template_engine = "erb"
30
11
 
31
- class Track < ::Cell::Concept
32
- inherit_views Song
12
+ def show
13
+ render # Party On, #{model}
14
+ end
33
15
 
34
- layout "layout"
35
- def show
36
- render :song
37
- end
16
+ # cell(:song, concept: :record)
17
+ class Song < self # cell("record/cell/song")
18
+ def show
19
+ render :view => :song#, :layout => "layout"
20
+ # TODO: test layout: .. in ViewModel
38
21
  end
39
22
  end
40
- end
41
-
42
- # app/cells/comment/views
43
- # app/cells/comment/form/views
44
- # app/cells/comment/views/form inherit_views Comment::Cell, render form/show
45
-
46
-
47
- class ConceptTest < MiniTest::Spec
48
- include Cell::TestCase::TestMethods
49
23
 
50
-
51
- describe "::controller_path" do
52
- it { Record::Cell.new(@controller).controller_path.must_equal "record" }
53
- it { Record::Cell::Song.new(@controller).controller_path.must_equal "record/song" }
24
+ class Hit < ::Cell::Concept
25
+ inherit_views Record::Cell
54
26
  end
27
+ end
28
+ end
55
29
 
30
+ # app/cells/comment/views
31
+ # app/cells/comment/form/views
32
+ # app/cells/comment/views/form inherit_views Comment::Cell, render form/show
56
33
 
57
- describe "#_prefixes" do
58
- it { Record::Cell.new(@controller)._prefixes.must_equal ["record/views"] }
59
- it { Record::Cell::Song.new(@controller)._prefixes.must_equal ["record/song/views", "record/views"] }
60
- it { Record::Cell::Hit.new(@controller)._prefixes.must_equal ["record/hit/views", "record/views"] } # with inherit_views.
61
- end
62
34
 
63
- unless ::Cell.rails_version.~("3.0")
64
- it { Record::Cell.new(@controller, "Wayne").render_state(:show).must_equal "Party on, Wayne!" }
65
- end
35
+ class ConceptTest < MiniTest::Spec
36
+ describe "::controller_path" do
37
+ it { Record::Cell.new(@controller).controller_path.must_equal "record" }
38
+ it { Record::Cell::Song.new(@controller).controller_path.must_equal "record/song" }
39
+ end
66
40
 
67
41
 
68
- describe "#cell" do
69
- it { Cell::Concept.cell("record/cell", @controller).must_be_instance_of( Record::Cell) }
70
- it { Cell::Concept.cell("record/cell/song", @controller).must_be_instance_of Record::Cell::Song }
71
- # cell("song", concept: "record/compilation") # record/compilation/cell/song
72
- end
42
+ describe "#_prefixes" do
43
+ it { Record::Cell.new(@controller)._prefixes.must_equal ["record/views"] }
44
+ it { Record::Cell::Song.new(@controller)._prefixes.must_equal ["record/song/views", "record/views"] }
45
+ it { Record::Cell::Hit.new(@controller)._prefixes.must_equal ["record/hit/views", "record/views"] } # with inherit_views.
46
+ end
73
47
 
48
+ it { Record::Cell.new(@controller, "Wayne").call(:show).must_equal "Party on, Wayne!" }
74
49
 
75
- describe "#render with :layout" do
76
- it { Cell::Concept.cell("record/cell/song", @controller).show_with_layout.must_equal "<p>\nLalala\n</p>\n" }
77
- end
78
- describe "#render with ::layout" do
79
- it { Cell::Concept.cell("record/cell/track", @controller).show.must_equal "<p>\nLalala\n</p>\n" }
80
- end
81
- describe "#render" do
82
- it { Cell::Concept.cell("record/cell/song", @controller).show.must_equal "Lalala" }
83
- end
84
50
 
51
+ describe "#cell" do
52
+ it { Cell::Concept.cell("record/cell", @controller).must_be_instance_of( Record::Cell) }
53
+ it { Cell::Concept.cell("record/cell/song", @controller).must_be_instance_of Record::Cell::Song }
54
+ # cell("song", concept: "record/compilation") # record/compilation/cell/song
55
+ end
85
56
 
86
- # inheriting
87
- it "inherit play.html.erb from BassistCell" do
88
- BadGuitaristCell.class_eval do
89
- def play; render; end
90
- end
91
- assert_equal "Doo", render_cell(:bad_guitarist, :play)
92
- end
57
+ describe "#render" do
58
+ it { Cell::Concept.cell("record/cell/song", @controller).show.must_equal "Lalala" }
93
59
  end
94
- end
60
+ end
@@ -0,0 +1 @@
1
+ <%= render_cell :bassist, :provoke %>
@@ -1,28 +1,41 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require "active_model/railtie"
3
+ # require "active_model/railtie"
4
4
  require "action_controller/railtie"
5
5
  require "action_view/railtie"
6
6
 
7
7
  require "cells"
8
- require "sprockets/railtie" if Cell.rails_version >= "3.1"
9
8
 
10
9
  module Dummy
11
10
  class Application < Rails::Application
12
11
  config.encoding = "utf-8"
12
+ config.i18n.enforce_available_locales = false
13
13
 
14
14
  # Configure sensitive parameters which will be filtered from the log file.
15
15
  config.filter_parameters += [:password]
16
16
 
17
17
  config.cache_store = :memory_store
18
- config.secret_token = "some secret phrase of at least 30 characters"
18
+ config.secret_token = SecureRandom.uuid
19
+ config.secret_key_base = SecureRandom.uuid
19
20
 
20
21
  # enable asset pipeline as in development.
21
- if Cell.rails_version >= "3.1"
22
- config.assets.enabled = true
23
- config.assets.compile = true
22
+ config.assets.enabled = true
23
+ config.assets.compile = true
24
+ config.cells.with_assets = ["album", "song"]
25
+ config.cache_classes = true
24
26
 
25
- config.cells.with_assets = ["album", "song"]
26
- end
27
+ # Show full error reports and disable caching
28
+ config.consider_all_requests_local = true
29
+ config.action_controller.perform_caching = false
30
+
31
+ # Raise exceptions instead of rendering exception templates
32
+ config.action_dispatch.show_exceptions = false
33
+
34
+ # Disable request forgery protection in test environment
35
+ config.action_controller.allow_forgery_protection = false
36
+ config.active_support.deprecation = :stderr
37
+
38
+ config.eager_load = false
39
+ config.active_support.test_order = :random
27
40
  end
28
41
  end