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
@@ -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)
|
data/test/cell_generator_test.rb
CHANGED
@@ -1,118 +1,87 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'generators/
|
2
|
+
require 'rails/generators/test_case'
|
3
|
+
require 'rails/generators/cell/cell_generator'
|
3
4
|
|
4
5
|
class CellGeneratorTest < Rails::Generators::TestCase
|
5
|
-
|
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
|
10
|
-
run_generator %w(
|
10
|
+
test 'create the standard assets' do
|
11
|
+
run_generator %w(blog post latest -e erb)
|
11
12
|
|
12
|
-
assert_file
|
13
|
-
assert_file
|
14
|
-
assert_file
|
15
|
-
assert_file
|
16
|
-
assert_file
|
17
|
-
assert_file
|
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
|
30
|
-
run_generator %w(Blog --
|
31
|
-
assert_file
|
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
|
-
|
38
|
-
|
39
|
-
assert_file
|
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
|
-
|
46
|
-
|
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
|
50
|
-
run_generator %w(
|
40
|
+
test 'work with namespaces and slim' do
|
41
|
+
run_generator %w(blog/post latest -e slim)
|
51
42
|
|
52
|
-
assert_file
|
53
|
-
assert_file
|
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
|
57
|
-
run_generator %w(
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
58
|
+
test 'create haml assets with -e haml' do
|
77
59
|
run_generator %w(Blog post latest -e haml)
|
78
60
|
|
79
|
-
assert_file
|
80
|
-
assert_file
|
81
|
-
assert_file
|
82
|
-
assert_file
|
83
|
-
assert_file
|
84
|
-
assert_file
|
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
|
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
|
72
|
+
assert_file 'test/cells/blog_cell_test.rb'
|
100
73
|
end
|
101
74
|
|
102
|
-
test
|
103
|
-
run_generator %w(
|
75
|
+
test 'work with namespace and test_unit' do
|
76
|
+
run_generator %w(blog/post latest -t test_unit)
|
104
77
|
|
105
|
-
assert_file
|
78
|
+
assert_file 'test/cells/blog/post_cell_test.rb', /class Blog::PostCellTest < Cell::TestCase/
|
106
79
|
end
|
107
80
|
|
108
|
-
test
|
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
|
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
|
data/test/cell_test.rb
CHANGED
@@ -1,28 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class CellTest < MiniTest::Spec
|
4
|
-
class
|
5
|
-
|
6
|
-
|
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
|
-
|
17
|
-
|
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/
|
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.
|
6
|
+
destination File.expand_path('../../tmp', File.dirname(__FILE__))
|
6
7
|
setup :prepare_destination
|
7
|
-
tests
|
8
|
+
tests Rails::Generators::ConceptGenerator
|
8
9
|
|
9
|
-
test
|
10
|
-
run_generator %w(
|
10
|
+
test '[erb] standard assets, show view' do
|
11
|
+
run_generator %w(song -e erb)
|
11
12
|
|
12
|
-
assert_file
|
13
|
-
assert_file
|
14
|
-
assert_file
|
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
|
18
|
-
run_generator %w(
|
18
|
+
test '[haml] standard assets, show view' do
|
19
|
+
run_generator %w(song -e haml)
|
19
20
|
|
20
|
-
assert_file
|
21
|
-
assert_file
|
22
|
-
assert_file
|
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
|
data/test/concept_test.rb
CHANGED
@@ -1,94 +1,60 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
7
|
+
# Trailblazer style:
|
8
|
+
module Record
|
9
|
+
class Cell < Cell::Concept # cell("record")
|
10
|
+
self.template_engine = "erb"
|
30
11
|
|
31
|
-
|
32
|
-
|
12
|
+
def show
|
13
|
+
render # Party On, #{model}
|
14
|
+
end
|
33
15
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
87
|
-
it "
|
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 =
|
18
|
+
config.secret_token = SecureRandom.uuid
|
19
|
+
config.secret_key_base = SecureRandom.uuid
|
19
20
|
|
20
21
|
# enable asset pipeline as in development.
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
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
|