cells 4.0.5 → 4.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -14
  3. data/CHANGES.md +34 -7
  4. data/Gemfile +2 -2
  5. data/README.md +18 -88
  6. data/benchmarks/class_builder.rb +37 -0
  7. data/benchmarks/collection.rb +47 -0
  8. data/cells.gemspec +5 -7
  9. data/lib/cell.rb +2 -11
  10. data/lib/cell/builder.rb +16 -0
  11. data/lib/cell/collection.rb +54 -0
  12. data/lib/cell/concept.rb +6 -7
  13. data/lib/cell/escaped.rb +1 -0
  14. data/lib/cell/layout.rb +50 -14
  15. data/lib/cell/testing.rb +6 -5
  16. data/lib/cell/util.rb +10 -1
  17. data/lib/cell/version.rb +1 -1
  18. data/lib/cell/view_model.rb +27 -56
  19. data/lib/cells.rb +1 -1
  20. data/test/builder_test.rb +4 -2
  21. data/test/cell_test.rb +9 -2
  22. data/test/concept_test.rb +9 -16
  23. data/test/context_test.rb +33 -0
  24. data/test/fixtures/cell_test/song/show_with_block.erb +1 -0
  25. data/test/fixtures/comment/layout/show.erb +1 -0
  26. data/test/fixtures/comment/show/show.erb +1 -0
  27. data/test/fixtures/song/with_block.erb +1 -0
  28. data/test/layout_test.rb +34 -1
  29. data/test/prefixes_test.rb +3 -3
  30. data/test/public_test.rb +43 -9
  31. data/test/render_test.rb +7 -3
  32. data/test/test_helper.rb +2 -38
  33. data/test/{test_case_test.rb → testing_test.rb} +2 -2
  34. metadata +16 -159
  35. data/gemfiles/rails3.2.gemfile +0 -16
  36. data/gemfiles/rails4.0.gemfile +0 -12
  37. data/gemfiles/rails4.1.gemfile +0 -12
  38. data/gemfiles/rails4.2.gemfile +0 -10
  39. data/lib/cell/caching/notification.rb +0 -15
  40. data/lib/cell/rails.rb +0 -98
  41. data/lib/cell/railtie.rb +0 -69
  42. data/lib/cell/test_case.rb +0 -12
  43. data/lib/cell/translation.rb +0 -19
  44. data/lib/rails/generators/cell/cell_generator.rb +0 -43
  45. data/lib/rails/generators/cell/templates/cell.rb.erb +0 -8
  46. data/lib/rails/generators/cell/templates/view.erb +0 -7
  47. data/lib/rails/generators/cell/templates/view.haml +0 -4
  48. data/lib/rails/generators/cell/templates/view.slim +0 -2
  49. data/lib/rails/generators/concept/concept_generator.rb +0 -38
  50. data/lib/rails/generators/concept/templates/concept.rb.erb +0 -7
  51. data/lib/rails/generators/concept/templates/view.erb +0 -7
  52. data/lib/rails/generators/concept/templates/view.haml +0 -4
  53. data/lib/rails/generators/concept/templates/view.slim +0 -2
  54. data/lib/rails/generators/test_unit/cell/cell_generator.rb +0 -21
  55. data/lib/rails/generators/test_unit/cell/templates/unit_test.rb.erb +0 -11
  56. data/lib/rails/generators/test_unit/concept/concept_generator.rb +0 -21
  57. data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +0 -11
  58. data/test/caching_test.rb +0 -305
  59. data/test/cell_generator_test.rb +0 -90
  60. data/test/concept_generator_test.rb +0 -40
  61. data/test/dummy/Rakefile +0 -7
  62. data/test/dummy/app/assets/javascripts/application.js +0 -2
  63. data/test/dummy/app/cells/album/assets/album.js +0 -1
  64. data/test/dummy/app/concepts/song/assets/songs.js +0 -1
  65. data/test/dummy/app/controllers/application_controller.rb +0 -4
  66. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  67. data/test/dummy/app/views/musician/featured.html.erb +0 -1
  68. data/test/dummy/app/views/musician/featured_with_block.html.erb +0 -4
  69. data/test/dummy/app/views/musician/hamlet.html.erb +0 -1
  70. data/test/dummy/app/views/musician/title.erb +0 -1
  71. data/test/dummy/config.ru +0 -4
  72. data/test/dummy/config/application.rb +0 -41
  73. data/test/dummy/config/boot.rb +0 -10
  74. data/test/dummy/config/database.yml +0 -22
  75. data/test/dummy/config/environment.rb +0 -5
  76. data/test/dummy/config/locales/en.yml +0 -5
  77. data/test/dummy/config/routes.rb +0 -5
  78. data/test/dummy/script/rails +0 -6
  79. data/test/rails/translation_test.rb +0 -45
  80. data/test/rails4.2/.gitignore +0 -13
  81. data/test/rails4.2/Gemfile +0 -18
  82. data/test/rails4.2/README.rdoc +0 -3
  83. data/test/rails4.2/Rakefile +0 -6
  84. data/test/rails4.2/app/assets/images/.keep +0 -0
  85. data/test/rails4.2/app/assets/stylesheets/application.css.erb +0 -19
  86. data/test/rails4.2/app/cells/form_for/show.erb +0 -7
  87. data/test/rails4.2/app/cells/form_for_cell.rb +0 -7
  88. data/test/rails4.2/app/cells/form_tag/show.erb +0 -5
  89. data/test/rails4.2/app/cells/form_tag_cell.rb +0 -5
  90. data/test/rails4.2/app/cells/formtastic/show.erb +0 -12
  91. data/test/rails4.2/app/cells/formtastic_cell.rb +0 -9
  92. data/test/rails4.2/app/cells/simple_form/show.erb +0 -7
  93. data/test/rails4.2/app/cells/simple_form_cell.rb +0 -11
  94. data/test/rails4.2/app/cells/song/song.css +0 -1
  95. data/test/rails4.2/app/cells/song/with_escaped.erb +0 -1
  96. data/test/rails4.2/app/cells/song_cell.rb +0 -18
  97. data/test/rails4.2/app/controllers/application_controller.rb +0 -5
  98. data/test/rails4.2/app/controllers/concerns/.keep +0 -0
  99. data/test/rails4.2/app/controllers/index_controller.rb +0 -7
  100. data/test/rails4.2/app/controllers/songs_controller.rb +0 -25
  101. data/test/rails4.2/app/helpers/application_helper.rb +0 -2
  102. data/test/rails4.2/app/mailers/.keep +0 -0
  103. data/test/rails4.2/app/models/.keep +0 -0
  104. data/test/rails4.2/app/models/artist.rb +0 -25
  105. data/test/rails4.2/app/models/concerns/.keep +0 -0
  106. data/test/rails4.2/app/models/song.rb +0 -25
  107. data/test/rails4.2/app/views/index/index.html.erb +0 -6
  108. data/test/rails4.2/app/views/layouts/application.html.erb +0 -13
  109. data/test/rails4.2/app/views/songs/show.html.erb +0 -1
  110. data/test/rails4.2/app/views/songs/with_escaped.html.erb +0 -1
  111. data/test/rails4.2/bin/bundle +0 -3
  112. data/test/rails4.2/bin/rails +0 -4
  113. data/test/rails4.2/bin/rake +0 -4
  114. data/test/rails4.2/bin/setup +0 -29
  115. data/test/rails4.2/config.ru +0 -4
  116. data/test/rails4.2/config/application.rb +0 -38
  117. data/test/rails4.2/config/boot.rb +0 -3
  118. data/test/rails4.2/config/environment.rb +0 -5
  119. data/test/rails4.2/config/environments/development.rb +0 -25
  120. data/test/rails4.2/config/environments/production.rb +0 -64
  121. data/test/rails4.2/config/environments/test.rb +0 -42
  122. data/test/rails4.2/config/initializers/backtrace_silencers.rb +0 -7
  123. data/test/rails4.2/config/initializers/cookies_serializer.rb +0 -3
  124. data/test/rails4.2/config/initializers/filter_parameter_logging.rb +0 -4
  125. data/test/rails4.2/config/initializers/formtastic.rb +0 -2
  126. data/test/rails4.2/config/initializers/inflections.rb +0 -16
  127. data/test/rails4.2/config/initializers/mime_types.rb +0 -4
  128. data/test/rails4.2/config/initializers/session_store.rb +0 -3
  129. data/test/rails4.2/config/initializers/wrap_parameters.rb +0 -9
  130. data/test/rails4.2/config/locales/en.yml +0 -23
  131. data/test/rails4.2/config/routes.rb +0 -9
  132. data/test/rails4.2/config/secrets.yml +0 -22
  133. data/test/rails4.2/db/seeds.rb +0 -7
  134. data/test/rails4.2/engines/my_engine/.gitignore +0 -3
  135. data/test/rails4.2/engines/my_engine/Gemfile +0 -15
  136. data/test/rails4.2/engines/my_engine/MIT-LICENSE +0 -20
  137. data/test/rails4.2/engines/my_engine/README.rdoc +0 -3
  138. data/test/rails4.2/engines/my_engine/Rakefile +0 -24
  139. data/test/rails4.2/engines/my_engine/app/assets/images/my_engine/.keep +0 -0
  140. data/test/rails4.2/engines/my_engine/app/assets/stylesheets/my_engine/application.css +0 -15
  141. data/test/rails4.2/engines/my_engine/app/concepts/user/cell.rb +0 -8
  142. data/test/rails4.2/engines/my_engine/app/concepts/user/views/show.erb +0 -1
  143. data/test/rails4.2/engines/my_engine/app/concepts/user/views/user.scss +0 -3
  144. data/test/rails4.2/engines/my_engine/app/controllers/my_engine/application_controller.rb +0 -4
  145. data/test/rails4.2/engines/my_engine/app/controllers/my_engine/user_controller.rb +0 -7
  146. data/test/rails4.2/engines/my_engine/app/helpers/my_engine/application_helper.rb +0 -4
  147. data/test/rails4.2/engines/my_engine/app/models/my_engine/user.rb +0 -4
  148. data/test/rails4.2/engines/my_engine/app/views/layouts/my_engine/application.html.erb +0 -14
  149. data/test/rails4.2/engines/my_engine/app/views/my_engine/user/show.html.erb +0 -3
  150. data/test/rails4.2/engines/my_engine/bin/rails +0 -12
  151. data/test/rails4.2/engines/my_engine/config/routes.rb +0 -3
  152. data/test/rails4.2/engines/my_engine/db/migrate/20150530135920_create_my_engine_users.rb +0 -8
  153. data/test/rails4.2/engines/my_engine/lib/my_engine.rb +0 -6
  154. data/test/rails4.2/engines/my_engine/lib/my_engine/engine.rb +0 -9
  155. data/test/rails4.2/engines/my_engine/lib/my_engine/version.rb +0 -3
  156. data/test/rails4.2/engines/my_engine/lib/tasks/my_engine_tasks.rake +0 -4
  157. data/test/rails4.2/engines/my_engine/my_engine.gemspec +0 -24
  158. data/test/rails4.2/engines/my_engine/test/fixtures/my_engine/users.yml +0 -11
  159. data/test/rails4.2/engines/my_engine/test/models/my_engine/user_test.rb +0 -9
  160. data/test/rails4.2/lib/assets/.keep +0 -0
  161. data/test/rails4.2/lib/tasks/.keep +0 -0
  162. data/test/rails4.2/log/.keep +0 -0
  163. data/test/rails4.2/test/integration/asset_pipeline_test.rb +0 -17
  164. data/test/rails4.2/test/integration/controller_test.rb +0 -16
  165. data/test/rails4.2/test/integration/form_for_test.rb +0 -10
  166. data/test/rails4.2/test/integration/form_tag_test.rb +0 -11
  167. data/test/rails4.2/test/integration/formtastic_test.rb +0 -12
  168. data/test/rails4.2/test/integration/simple_form_test.rb +0 -11
  169. data/test/rails4.2/test/integration/url_helper_test.rb +0 -47
  170. data/test/rails4.2/test/test_helper.rb +0 -14
  171. data/test/rails4.2/vendor/assets/stylesheets/.keep +0 -0
  172. data/test/rails_extensions_test.rb +0 -51
@@ -1,21 +0,0 @@
1
- require 'rails/generators/test_unit'
2
-
3
- module TestUnit # :nodoc:
4
- module Generators # :nodoc:
5
- class ConceptGenerator < Base # :nodoc:
6
- source_root File.expand_path('../templates', __FILE__)
7
- argument :actions, type: :array, default: []
8
- check_class_collision suffix: 'ConceptTest'
9
-
10
- def create_test_file
11
- template 'unit_test.rb.erb', File.join('test/concepts', class_path, file_name, 'cell_test.rb')
12
- end
13
-
14
- private
15
-
16
- def states
17
- (['show'] + actions).uniq
18
- end
19
- end
20
- end
21
- end
@@ -1,11 +0,0 @@
1
- require 'test_helper'
2
-
3
- class <%= class_name %>ConceptTest < Cell::TestCase
4
- <% states.each do |state| -%>
5
- test "<%= state %>" do
6
- html = concept("<%= file_name %>/cell").(:<%= state %>)
7
- assert html.match /<p>/
8
- end
9
-
10
- <% end %>
11
- end
@@ -1,305 +0,0 @@
1
- # encoding: utf-8
2
- require 'test_helper'
3
-
4
- class DirectorCell < Cell::ViewModel
5
- attr_reader :count
6
-
7
- def initialize(*)
8
- super
9
- @count = 0
10
- end
11
-
12
- cache :tock
13
-
14
- def tock
15
- @count += 1
16
- end
17
- end
18
-
19
-
20
- class CachingUnitTest < MiniTest::Spec
21
- before :each do
22
- ActionController::Base.cache_store.clear
23
- ActionController::Base.perform_caching = true
24
- end
25
-
26
- let (:director) { DirectorCell }
27
- let (:cellule) { DirectorCell.new(nil) }
28
-
29
-
30
- describe "::state_cache_key" do
31
- # accepts state name, only.
32
- it { director.state_cache_key(:count).must_equal "cells/director/count/" }
33
-
34
- # accepts hash as key parts
35
- if Cell.rails_version >= Gem::Version.new('4.0')
36
- it { director.state_cache_key(:count, b: 2, a: 1).must_equal "cells/director/count/b/2/a/1" }
37
- else
38
- it { director.state_cache_key(:count, b: 2, a: 1).must_equal "cells/director/count/a=1&b=2" }
39
- end
40
-
41
- # accepts array as key parts
42
- it { director.state_cache_key(:count, [1, 2, 3]).must_equal "cells/director/count/1/2/3" }
43
-
44
- # accepts string as key parts
45
- it { director.state_cache_key(:count, "1/2").must_equal "cells/director/count/1/2" }
46
-
47
- # accepts nil as key parts
48
- it { director.state_cache_key(:count, nil).must_equal "cells/director/count/" }
49
- end
50
-
51
-
52
- describe "#state_cached?" do
53
- # true for cached
54
- it { cellule.send(:state_cached?, :tock).must_equal true }
55
-
56
- # false otherwise
57
- it { cellule.send(:state_cached?, :sing).must_equal false }
58
- end
59
-
60
-
61
- describe "#cache?" do
62
- # true for cached
63
- it { cellule.cache?(:tock).must_equal true }
64
-
65
- # false otherwise
66
- it { cellule.cache?(:sing).must_equal false }
67
-
68
- describe "perform_caching turned off" do
69
- after do
70
- ::ActionController::Base.perform_caching = true
71
- end
72
-
73
- # always false
74
- it do
75
- ::ActionController::Base.perform_caching = false
76
- cellule.cache?(:sing).must_equal false
77
- cellule.cache?(:sing).must_equal false
78
- end
79
- end
80
-
81
- describe "#cache_store" do
82
- # rails cache store per default.
83
- it { cellule.cache_store.must_equal ActionController::Base.cache_store }
84
- end
85
- end
86
-
87
-
88
- # describe ".expire_cache_key" do
89
- # before :each do
90
- # @key = @class.state_cache_key(:tock)
91
- # puts "====== key is #{@key}"
92
- # assert_equal "1", render_cell(:director, :tock)
93
- # assert_equal "1", @class.cache_store.read(@key)
94
- # end
95
-
96
- # it "delete the state from cache" do
97
- # @class.expire_cache_key(@key)
98
- # assert_not @class.cache_store.read(@key)
99
- # end
100
-
101
- # it "be available in controllers for sweepers" do
102
- # MusicianController.new.expire_cell_state(DirectorCell, :tock)
103
- # assert_not @class.cache_store.read(@key)
104
- # end
105
-
106
- # it "accept cache options" do
107
- # key = @class.state_cache_key(:tock, volume: 9)
108
- # assert Cell::Rails.cache_store.write(key, 'ONE!')
109
-
110
- # MusicianController.new.expire_cell_state(DirectorCell, :tock, volume: 9)
111
- # assert_equal "1", @class.cache_store.read(@key)
112
- # assert_not ::Cell::Rails.cache_store.read(key)
113
- # end
114
- # end
115
- end
116
-
117
-
118
- class CachingTest < MiniTest::Spec
119
- class DirectorCell < Cell::ViewModel
120
- def initialize(counter=0)
121
- super
122
- @counter = counter
123
- end
124
-
125
- def show # public method.
126
- @counter
127
- end
128
-
129
-
130
- cache :utf8
131
-
132
- def utf8
133
- "æøå" # or any other UTF-8 string
134
- end
135
- end
136
-
137
- before :each do
138
- ActionController::Base.cache_store.clear
139
- ActionController::Base.perform_caching = true
140
- end
141
-
142
- # let (:cell) { DirectorCell.new(nil) }
143
- def director_cell(*args)
144
- DirectorCell.new(*args)
145
- end
146
-
147
- # no caching when turned off.
148
- it do
149
- director_cell.class.cache :show
150
- ActionController::Base.perform_caching = false
151
-
152
- director_cell(1).call.must_equal "1"
153
- director_cell(2).call.must_equal "2"
154
- end
155
-
156
- # cache forever when no options.
157
- it do
158
- director_cell.class.cache :show
159
- director_cell(1).call.must_equal "1"
160
- director_cell(2).call.must_equal "1"
161
- end
162
-
163
- # caches with string state name.
164
- it do
165
- director_cell.class.cache :show
166
- director_cell(1).("show").must_equal "1"
167
- director_cell(2).("show").must_equal "1"
168
- end
169
-
170
-
171
- # no caching when state not configured.
172
- it do
173
- director_cell.class.class_eval do
174
- def dictate
175
- @counter
176
- end
177
- end
178
-
179
- director_cell(1).call(:dictate).must_equal "1"
180
- director_cell(2).call(:dictate).must_equal "2"
181
- end
182
-
183
- # compute key with cell properties from #initialize.
184
- it do
185
- director_cell.class.cache :show do
186
- @counter < 3 ? {count: "<"} : {count: ">"}
187
- end
188
-
189
- director_cell(1).call.must_equal "1"
190
- director_cell(2).call.must_equal "1"
191
- director_cell(3).call.must_equal "3"
192
- director_cell(4).call.must_equal "3"
193
- end
194
-
195
- # compute key with instance method
196
- it do
197
- director_cell.class.cache :show, :version
198
- director_cell.class.class_eval do
199
- def version
200
- @counter < 3 ? {count: "<"} : {count: ">"}
201
- end
202
- end
203
-
204
- director_cell(1).call.must_equal "1"
205
- director_cell(2).call.must_equal "1"
206
- director_cell(3).call.must_equal "3"
207
- director_cell(4).call.must_equal "3"
208
- end
209
-
210
- # allow returning strings for key
211
- it do
212
- director_cell.class.cache :show do
213
- @counter < 3 ? "<" : ">"
214
- end
215
-
216
- director_cell(1).call.must_equal "1"
217
- director_cell(2).call.must_equal "1"
218
- director_cell(3).call.must_equal "3"
219
- director_cell(4).call.must_equal "3"
220
- end
221
-
222
- # allows conditional ifs.
223
- it do
224
- director_cell.class.cache :show, if: lambda { @counter < 3 }
225
-
226
- director_cell(1).call.must_equal "1"
227
- director_cell(2).call.must_equal "1"
228
- director_cell(3).call.must_equal "3"
229
- director_cell(4).call.must_equal "4"
230
- end
231
-
232
- # allows conditional ifs with instance method.
233
- it do
234
- director_cell.class.class_eval do
235
- cache :show, if: :smaller?
236
-
237
- def smaller?
238
- @counter < 3
239
- end
240
- end
241
-
242
- director_cell(1).call.must_equal "1"
243
- director_cell(2).call.must_equal "1"
244
- director_cell(3).call.must_equal "3"
245
- director_cell(4).call.must_equal "4"
246
- end
247
-
248
-
249
- unless ::ActionPack::VERSION::MAJOR == 3 and ::ActionPack::VERSION::MINOR >= 2 # bug in 3.2.
250
- describe "utf-8" do
251
- before do
252
- @key = director_cell.class.state_cache_key(:utf8)
253
- end
254
-
255
- it "has the correct encoding when reading from cache" do
256
- assert_equal "UTF-8", director_cell.call(:utf8).encoding.to_s
257
- assert_equal "UTF-8", director_cell.cache_store.read(@key).encoding.to_s
258
- end
259
- end
260
- end
261
-
262
- # options are passed through to cache store.
263
- # :expires_in.
264
- # tags: lambda { |one, two, three| "#{one},#{two},#{three}" }
265
- class CacheStore
266
- attr_reader :fetch_args
267
-
268
- def fetch(*args)
269
- @fetch_args = args
270
- end
271
- end
272
-
273
- it do
274
- cellule = self.director_cell
275
-
276
- cellule.instance_eval do
277
- def cache_store;
278
- @cache_store ||= CacheStore.new;
279
- end
280
- end
281
-
282
- cellule.class.cache :show, expires_in: 1.minutes, tags: lambda { self.class.to_s }
283
- cellule.call
284
- cellule.cache_store.fetch_args.must_equal ["cells/caching_test/director/show/", {expires_in: 60, tags: "CachingTest::DirectorCell"}]
285
- end
286
- end
287
-
288
-
289
- class CachingInheritanceTest < CachingTest
290
- class DirectorCell < ::DirectorCell
291
- cache :show, expires_in: 10.minutes do
292
- "v1"
293
- end
294
- end
295
-
296
- class DirectorsSonCell < DirectorCell
297
- end
298
-
299
- class DirectorsDaughterCell < ::DirectorCell
300
- cache :show, expires_in: 9.minutes do
301
- "v2"
302
- end
303
- end
304
-
305
- end
@@ -1,90 +0,0 @@
1
- require 'test_helper'
2
- require 'rails/generators/test_case'
3
- require 'rails/generators/cell/cell_generator'
4
-
5
- class CellGeneratorTest < Rails::Generators::TestCase
6
- tests Rails::Generators::CellGenerator
7
- destination File.expand_path('../../tmp', File.dirname(__FILE__))
8
- setup :prepare_destination
9
-
10
- test 'create the standard assets' do
11
- run_generator %w(blog post latest -e erb)
12
-
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}
19
- end
20
-
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/
24
- end
25
-
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}
32
- end
33
-
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}
38
- end
39
-
40
- test 'work with namespaces and slim' do
41
- run_generator %w(blog/post latest -e slim)
42
-
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}
45
- end
46
-
47
- test 'create slim assets with -e slim' do
48
- run_generator %w(blog post latest -e slim)
49
-
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}
56
- end
57
-
58
- test 'create haml assets with -e haml' do
59
- run_generator %w(Blog post latest -e haml)
60
-
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}
67
- end
68
-
69
- test 'create test_unit assets with -t test_unit' do
70
- run_generator %w(Blog post latest -t test_unit)
71
-
72
- # file is there.
73
- assert_file 'test/cells/blog_cell_test.rb'
74
- # file contains #cell(..) call.
75
- assert_file 'test/cells/blog_cell_test.rb', /cell\("blog"\).\(:post\)/
76
- end
77
-
78
- test 'work with namespace and test_unit' do
79
- run_generator %w(blog/post latest -t test_unit)
80
-
81
- assert_file 'test/cells/blog/post_cell_test.rb', /class Blog::PostCellTest < Cell::TestCase/
82
- end
83
-
84
- test 'create test_unit assets with -t rspec' do
85
- run_generator %w(Blog post latest -t rspec)
86
-
87
- assert_no_file 'test/cells/blog_cell_test.rb'
88
- end
89
-
90
- end
@@ -1,40 +0,0 @@
1
- require 'test_helper'
2
- require 'rails/generators/test_case'
3
- require 'rails/generators/concept/concept_generator'
4
-
5
- class ConceptGeneratorTest < Rails::Generators::TestCase
6
- destination File.expand_path('../../tmp', File.dirname(__FILE__))
7
- setup :prepare_destination
8
- tests Rails::Generators::ConceptGenerator
9
-
10
- test '[erb] standard assets, show view' do
11
- run_generator %w(song -e erb)
12
-
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}
16
- end
17
-
18
- test "test unit test" do
19
- run_generator %w(song -t test_unit)
20
-
21
- # file contains #concept(..) call.
22
- assert_file 'test/concepts/song/cell_test.rb', /concept\("song\/cell"\).\(:show\)/
23
- end
24
-
25
- test '[haml] standard assets, show view' do
26
- run_generator %w(song -e haml)
27
-
28
- assert_file 'app/concepts/song/cell.rb', /class Song::Cell < Cell::Concept/
29
- assert_file 'app/concepts/song/cell.rb', /def show/
30
- assert_file 'app/concepts/song/views/show.haml', %r{app/concepts/song/views/show\.haml}
31
- end
32
-
33
- test '[slim] standard assets, show view' do
34
- run_generator %w(song -e slim)
35
-
36
- assert_file 'app/concepts/song/cell.rb', /class Song::Cell < Cell::Concept/
37
- assert_file 'app/concepts/song/cell.rb', /def show/
38
- assert_file 'app/concepts/song/views/show.slim', %r{app/concepts/song/views/show\.slim}
39
- end
40
- end