fortitude 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +20 -20
  3. data/CHANGES.md +19 -0
  4. data/CONTRIBUTORS.md +2 -0
  5. data/fortitude.gemspec +1 -0
  6. data/lib/fortitude/rails/railtie.rb +27 -75
  7. data/lib/fortitude/rails/rendering_methods.rb +77 -0
  8. data/lib/fortitude/tags/tags_module.rb +1 -0
  9. data/lib/fortitude/tilt/fortitude_template.rb +3 -1
  10. data/lib/fortitude/version.rb +1 -1
  11. data/lib/fortitude/widget/modules_and_subclasses.rb +2 -0
  12. data/spec/helpers/fortitude_rails_helpers.rb +19 -0
  13. data/spec/helpers/global_helper.rb +4 -2
  14. data/spec/rails/capture_system_spec.rb +1 -1
  15. data/spec/rails/development_mode_system_spec.rb +100 -6
  16. data/spec/rails/mailer_system_spec.rb +31 -0
  17. data/spec/rails/rendering_system_spec.rb +3 -3
  18. data/spec/rails/templates/development_mode_system_spec/app/controllers/development_mode_system_spec_controller.rb +16 -0
  19. data/spec/rails/templates/development_mode_system_spec/app/controllers/replaced_controller.rb +5 -0
  20. data/spec/rails/templates/development_mode_system_spec/app/mailers/development_mode_mailer.rb +17 -0
  21. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_formatting_test.rb +7 -0
  22. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_layout_test.rb +5 -0
  23. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_view_test.rb +5 -0
  24. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_formatting_test.rb +5 -0
  25. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_layout_test.rb +5 -0
  26. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_view_test.rb +5 -0
  27. data/spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/reload_widget_with_html_extension.html.rb +8 -0
  28. data/spec/rails/templates/development_mode_system_spec/app/views/layouts/mail_layout.rb +7 -0
  29. data/spec/rails/templates/development_mode_system_spec/app/views/replaced/reload_widget.rb +7 -0
  30. data/spec/rails/templates/development_mode_system_spec/app/views/shared/some_module.rb +5 -0
  31. data/spec/rails/templates/development_mode_system_spec/config/environments/development.rb +39 -0
  32. data/spec/rails/templates/mailer_system_spec/app/controllers/mailer_system_spec_controller.rb +17 -0
  33. data/spec/rails/templates/mailer_system_spec/app/mailers/basic_mailer.rb +25 -0
  34. data/spec/rails/templates/mailer_system_spec/app/views/basic_mailer/basic_mail.rb +5 -0
  35. data/spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_erb_layout_and_fortitude_view.rb +5 -0
  36. data/spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_fortitude_layout.rb +5 -0
  37. data/spec/rails/templates/mailer_system_spec/app/views/basic_mailer/mail_with_fortitude_layout_and_erb_view.html.erb +1 -0
  38. data/spec/rails/templates/mailer_system_spec/app/views/layouts/erb_layout.html.erb +1 -0
  39. data/spec/rails/templates/mailer_system_spec/app/views/layouts/fortitude_layout.rb +8 -0
  40. data/spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail.rb +5 -0
  41. data/spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_erb_layout_and_fortitude_view.rb +5 -0
  42. data/spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_fortitude_layout.rb +5 -0
  43. data/spec/rails/templates/mailer_system_spec/app/views/mailer_system_spec/send_mail_with_fortitude_layout_and_erb_view.rb +5 -0
  44. data/spec/rails/templates/mailer_system_spec/config/environments/production.rb +84 -0
  45. data/spec/rails/templates/rendering_system_spec/app/views/layouts/application.html.erb +1 -1
  46. data/spec/rails/templates/rules_system_spec/app/views/layouts/fortitude_layout_with_p.rb +1 -1
  47. data/spec/system/tilt_system_spec.rb +15 -0
  48. metadata +73 -16
  49. data/spec/helpers/rails_helpers.rb +0 -85
  50. data/spec/helpers/rails_server.rb +0 -390
  51. data/spec/rails/templates/base/app/controllers/application_controller.rb +0 -15
  52. data/spec/rails/templates/base/app/controllers/working_controller.rb +0 -5
  53. data/spec/rails/templates/base/app/views/layouts/application.html.erb +0 -11
  54. data/spec/rails/templates/base/config/routes.rb +0 -4
  55. data/spec/rails/templates/base/config/secrets.yml +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8fe2be7aaffdb2b3e57d0b26fdacbc2c1124a57
4
- data.tar.gz: 01ada85328794df979d33ccff7a2ea41f88425f3
3
+ metadata.gz: b672c6981cd2da1af20a06cac52a1da20f1e03d1
4
+ data.tar.gz: 1e0c7a205c8c821ea68218c1fe15a729902d9a90
5
5
  SHA512:
6
- metadata.gz: 7394aeae5282f4109dbbe772a882ae066043a253813fc63b6b4e0d1ebdabb31de3e998a66969c347b37262c3a3365af2d6a1bf084e15ed9a8f9a6afa9c672ff5
7
- data.tar.gz: 58b2ad3cdddd71f0120f9039ab9112ecaa4fc542c2104e98565341898e36c6b247dd7c60c07f39cee47d4fb5c47f95f11b0d27bbb75a605050c41fe47d38bd51
6
+ metadata.gz: 281dbee5a7ade09027c4855542f200e1186c23f8d86fafdaa4940e1843df904dab8119d0a5f8b7414a64c378e7588f03dd4a591cc4850fe1f0e3ee8690c7e86a
7
+ data.tar.gz: 17a6d7cdbd63ddfa38f32e671d747c34df382e0558f49549132a68c2d6d84ccc574003870e21ebf769697a0dc6424b85de762459055948cb8acc160005d512e8
@@ -2,15 +2,15 @@ rvm:
2
2
  - "1.8.7"
3
3
  - "1.9.3"
4
4
  - "2.0.0"
5
- - "2.1.2"
6
- - "jruby-1.7.15"
5
+ - "2.1.4"
6
+ - "jruby-1.7.16.1"
7
7
  env:
8
- - FORTITUDE_SPECS_RAILS_VERSION=4.1.6
9
- - FORTITUDE_SPECS_RAILS_VERSION=4.0.10
10
- - FORTITUDE_SPECS_RAILS_VERSION=3.2.19
8
+ - FORTITUDE_SPECS_RAILS_VERSION=4.1.7
9
+ - FORTITUDE_SPECS_RAILS_VERSION=4.0.11
10
+ - FORTITUDE_SPECS_RAILS_VERSION=3.2.20
11
11
  - FORTITUDE_SPECS_RAILS_VERSION=3.1.12
12
12
  - FORTITUDE_SPECS_RAILS_VERSION=3.0.20
13
- - FORTITUDE_NATIVE_EXTENSIONS=false FORTITUDE_SPECS_RAILS_VERSION=4.1.6
13
+ - FORTITUDE_NATIVE_EXTENSIONS=false FORTITUDE_SPECS_RAILS_VERSION=4.1.7
14
14
  - FORTITUDE_NATIVE_EXTENSIONS=false FORTITUDE_SPECS_RAILS_VERSION=3.0.20
15
15
  before_script:
16
16
  - export JRUBY_OPTS="$JRUBY_OPTS -J-Xmx128m -J-Xms128m -J-Xss2048k"
@@ -18,11 +18,11 @@ matrix:
18
18
  exclude:
19
19
  # Rails 4.x doesn't support Ruby 1.8.7
20
20
  - rvm: 1.8.7
21
- env: FORTITUDE_SPECS_RAILS_VERSION=4.1.6
21
+ env: FORTITUDE_SPECS_RAILS_VERSION=4.1.7
22
22
  - rvm: 1.8.7
23
- env: FORTITUDE_NATIVE_EXTENSIONS=false FORTITUDE_SPECS_RAILS_VERSION=4.1.6
23
+ env: FORTITUDE_NATIVE_EXTENSIONS=false FORTITUDE_SPECS_RAILS_VERSION=4.1.7
24
24
  - rvm: 1.8.7
25
- env: FORTITUDE_SPECS_RAILS_VERSION=4.0.10
25
+ env: FORTITUDE_SPECS_RAILS_VERSION=4.0.11
26
26
  # 2014-06-19 ageweke -- ARGH. After trying about seventeen different things, no matter what I do,
27
27
  # Travis fails JRuby builds about 20% of the time with "Killed". Their documentation indicates that this
28
28
  # is likely an out-of-memory issue (i.e., entire VM's memory is consumed). However, I'm running JRuby with
@@ -34,17 +34,17 @@ matrix:
34
34
  # one manually to make sure there aren't other failures, too. This is very frustrating, but I can't seem to
35
35
  # find a way around it. If there's a fix out there somewhere, I'm all ears!
36
36
  allow_failures:
37
- - rvm: jruby-1.7.15
38
- env: FORTITUDE_SPECS_RAILS_VERSION=4.1.6
39
- - rvm: jruby-1.7.15
40
- env: FORTITUDE_SPECS_RAILS_VERSION=4.0.10
41
- - rvm: jruby-1.7.15
42
- env: FORTITUDE_SPECS_RAILS_VERSION=3.2.19
43
- - rvm: jruby-1.7.15
37
+ - rvm: jruby-1.7.16.1
38
+ env: FORTITUDE_SPECS_RAILS_VERSION=4.1.7
39
+ - rvm: jruby-1.7.16.1
40
+ env: FORTITUDE_SPECS_RAILS_VERSION=4.0.11
41
+ - rvm: jruby-1.7.16.1
42
+ env: FORTITUDE_SPECS_RAILS_VERSION=3.2.20
43
+ - rvm: jruby-1.7.16.1
44
44
  env: FORTITUDE_SPECS_RAILS_VERSION=3.1.12
45
- - rvm: jruby-1.7.15
45
+ - rvm: jruby-1.7.16.1
46
46
  env: FORTITUDE_SPECS_RAILS_VERSION=3.0.20
47
- - rvm: jruby-1.7.15
48
- env: FORTITUDE_NATIVE_EXTENSIONS=false FORTITUDE_SPECS_RAILS_VERSION=4.1.6
49
- - rvm: jruby-1.7.15
47
+ - rvm: jruby-1.7.16.1
48
+ env: FORTITUDE_NATIVE_EXTENSIONS=false FORTITUDE_SPECS_RAILS_VERSION=4.1.7
49
+ - rvm: jruby-1.7.16.1
50
50
  env: FORTITUDE_NATIVE_EXTENSIONS=false FORTITUDE_SPECS_RAILS_VERSION=3.0.20
data/CHANGES.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Fortitude Releases
2
2
 
3
+ ## 0.0.6, 11 November 2014
4
+
5
+ * Fixed an issue where naming a widget with an `.html.rb` extension (for example) at the end would work at first,
6
+ but cause really irritating errors (like `uninitialized constant Views::Foo::Bar` apparently _in_ the very file
7
+ that defines `Views::Foo::Bar` correctly in `app/views/foo/bar.html.rb`) when editing code in development mode.
8
+ (Thanks to [Jacob Maine](https://github.com/mainej) for the very detailed bug report!)
9
+ * Fixed an issue where trying to use Fortitude as a Tilt engine, but passing `nil` for the `locals`, would cause an
10
+ exception. (Thanks to [Roman Heinrich](https://github.com/mindreframer) for reporting the bug!)
11
+ * Using Fortitude as a template engine for mailers (`ActionMailer::Base` subclasses) now works. (Believe it or not,
12
+ this was almost completely an issue of forgetting to support this, rather than it being undone — the code
13
+ was complete, and it was just a matter of applying it to `ActionMailer::Base` as well as `ActionController::Base`.)
14
+ (Thanks to [Jacob Maine](https://github.com/mainej) for the bug report and pull request!)
15
+ * The various on-the-fly modules that Fortitude creates and mixes in to widgets (and define helpers, tag methods,
16
+ and `needs` methods) now all have actual names, which makes them much easier to identify in debugging printouts.
17
+ * The code in `spec/` that knew how to reliably create, maintain, shut down, and otherwise manipulate an external
18
+ `rails server` process has now been pulled out into its own gem, `oop_rails_server`; this is so I can also use it
19
+ with a new, closely-related upcoming project, and because reuse is good. ;)
20
+ * Updated the Travis configuration to the very latest Ruby and Rails versions.
21
+
3
22
  ## 0.0.5, 22 September 2014
4
23
 
5
24
  * You can now load both Fortitude and Erector at the same time into a project, and it will "just work": Erector
@@ -4,3 +4,5 @@ Fortitude is written by [Andrew Geweke](https://github.com/ageweke), with contri
4
4
 
5
5
  * [Ahto Jussila](https://github.com/ahto): a patch to provide separate MRI and JRuby gems, so that
6
6
  `gem install fortitude` works properly no matter which platform you're on.
7
+ * [Roman Heinrich](https://github.com/mindreframer): reporting a bug where trying to use Fortitude as a Tilt
8
+ engine to render would fail if the locals passed in were `nil`.
@@ -39,4 +39,5 @@ Gem::Specification.new do |s|
39
39
  s.add_development_dependency "rake-compiler"
40
40
  s.add_development_dependency "json"
41
41
  s.add_development_dependency "tilt", "~> 2.0"
42
+ s.add_development_dependency "oop_rails_server", ">= 0.0.3"
42
43
  end
@@ -130,18 +130,34 @@ module Fortitude
130
130
  # "Search for a file in autoload_paths matching the provided suffix."
131
131
  #
132
132
  # So, we just look to see if the given +path_suffix+ is specifying something like
133
- # <tt>views/foo/bar</tt>; if so, we glue it together properly, removing the initial
134
- # <tt>views/</tt> first. (Otherwise, the mechanism would expect
133
+ # <tt>views/foo/bar</tt> or the fully-qualified version thereof; if so, we glue it together properly,
134
+ # removing the initial <tt>views/</tt> first. (Otherwise, the mechanism would expect
135
135
  # <tt>Views::Foo::Bar</tt> to show up in <tt>app/views/views/foo/bar</tt> (yes, a double
136
136
  # +views+), since <tt>app/views</tt> is on the autoload path.)
137
137
  def search_for_file_with_fortitude(path_suffix)
138
- # This just makes sure our path always ends in exactly one ".rb", whether it started
139
- # with one or not.
140
- new_path_suffix = path_suffix.sub(/(\.rb)?$/, ".rb")
138
+ # Remove any ".rb" extension, if present...
139
+ new_path_suffix = path_suffix.sub(/(\.rb)?$/, "")
141
140
 
142
- if new_path_suffix =~ %r{^views(/.*)$}i
143
- path = File.join(@@_fortitude_views_root, $1)
144
- return path if File.file?(path)
141
+ found_subpath = if new_path_suffix =~ %r{^views(/.*)$}i
142
+ $1
143
+ elsif new_path_suffix =~ %r{^#{Regexp.escape(@@_fortitude_views_root)}(/.*)$}i
144
+ $1
145
+ end
146
+
147
+ if found_subpath
148
+ full_path = File.join(@@_fortitude_views_root, "#{found_subpath}")
149
+ directory = File.dirname(full_path)
150
+ filename = File.basename(full_path)
151
+
152
+ regexp1 = /^#{Regexp.escape(filename)}\./
153
+ regexp2 = /\.rb$/i
154
+ applicable_entries = Dir.entries(directory).select do |entry|
155
+ ((entry == filename) || (entry =~ regexp1 && entry =~ regexp2)) && File.file?(File.join(directory, entry))
156
+ end
157
+ return nil if applicable_entries.length == 0
158
+
159
+ entry_to_use = applicable_entries.sort_by { |e| e.length }.reverse.first
160
+ return File.join(directory, entry_to_use)
145
161
  end
146
162
 
147
163
  # Make sure that we remove the views autoload path before letting the rest of
@@ -184,74 +200,10 @@ module Fortitude
184
200
  end
185
201
 
186
202
  require "fortitude/rails/template_handler"
203
+ require "fortitude/rails/rendering_methods"
187
204
 
188
- # This is our support for render :widget. Although, originally, it looked like creating a new subclass
189
- # of ActionView::Template was going to be the correct thing to do here, it turns out it isn't: the entire
190
- # template system is predicated around the idea that you have a template, which is compiled to output
191
- # Ruby source code, and then that gets evaluated to actually generate output.
192
- #
193
- # Because <tt>render :widget => ...</tt> takes an already-instantiated widget as input, this simply isn't
194
- # possible: you can't reverse-engineer an arbitrary Ruby object into source code, and, without source code,
195
- # the whole templating paradigm doesn't make sense.
196
- #
197
- # So, instead, we simply transform <tt>render :widget => ...</tt> into a <tt>render :text => ...</tt> of the
198
- # widget's output, and let Rails take it away from there.
199
- ::ActionController::Base.class_eval do
200
- def fortitude_rendering_context_for(delegate_object, yield_block)
201
- @_fortitude_rendering_contexts ||= { }
202
- @_fortitude_rendering_contexts[delegate_object.object_id] ||= create_fortitude_rendering_context(
203
- :delegate_object => delegate_object, :yield_block => yield_block)
204
- end
205
-
206
- def create_fortitude_rendering_context(options)
207
- ::Fortitude::RenderingContext.new(options)
208
- end
209
-
210
- def render_with_fortitude(*args, &block)
211
- if (options = args[0]).kind_of?(Hash)
212
- if (widget = options[:widget])
213
- rendering_context = fortitude_rendering_context_for(self, nil)
214
- widget.render_to(rendering_context)
215
-
216
- options = options.dup
217
- options[:text] = rendering_context.output_buffer_holder.output_buffer.html_safe
218
- options[:layout] = true unless options.has_key?(:layout)
219
-
220
- new_args = [ options ] + args[1..-1]
221
- return render_without_fortitude(*new_args, &block)
222
- elsif (widget_block = options[:inline]) && (options[:type] == :fortitude)
223
- options.delete(:inline)
224
-
225
- rendering_context = fortitude_rendering_context_for(self, nil)
226
- widget_class = Class.new(Fortitude::Widgets::Html5)
227
- widget_class.use_instance_variables_for_assigns(true)
228
- widget_class.extra_assigns(:use)
229
- widget_class.send(:define_method, :content, &widget_block)
230
-
231
- assigns = { }
232
- instance_variables.each do |ivar_name|
233
- value = instance_variable_get(ivar_name)
234
- assigns[$1.to_sym] = value if ivar_name =~ /^@(.*)$/
235
- end
236
- assigns = assigns.merge(options[:locals] || { })
237
-
238
- widget = widget_class.new(assigns)
239
- widget.render_to(rendering_context)
240
-
241
- options = options.dup
242
- options[:text] = rendering_context.output_buffer_holder.output_buffer.html_safe
243
- options[:layout] = true unless options.has_key?(:layout)
244
-
245
- new_args = [ options ] + args[1..-1]
246
- return render_without_fortitude(*new_args, &block)
247
- end
248
- end
249
-
250
- return render_without_fortitude(*args, &block)
251
- end
252
-
253
- alias_method_chain :render, :fortitude
254
- end
205
+ ::ActionController::Base.send(:include, ::Fortitude::Rails::RenderingMethods)
206
+ ::ActionMailer::Base.send(:include, ::Fortitude::Rails::RenderingMethods)
255
207
  end
256
208
  end
257
209
  end
@@ -0,0 +1,77 @@
1
+ require 'active_support/concern'
2
+
3
+ module Fortitude
4
+ module Rails
5
+ module RenderingMethods
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ alias_method_chain :render, :fortitude
10
+ end
11
+
12
+ def fortitude_rendering_context_for(delegate_object, yield_block)
13
+ @_fortitude_rendering_contexts ||= { }
14
+ @_fortitude_rendering_contexts[delegate_object.object_id] ||= create_fortitude_rendering_context(
15
+ :delegate_object => delegate_object, :yield_block => yield_block)
16
+ end
17
+
18
+ def create_fortitude_rendering_context(options)
19
+ ::Fortitude::RenderingContext.new(options)
20
+ end
21
+
22
+ # This is our support for render :widget. Although, originally, it looked like creating a new subclass
23
+ # of ActionView::Template was going to be the correct thing to do here, it turns out it isn't: the entire
24
+ # template system is predicated around the idea that you have a template, which is compiled to output
25
+ # Ruby source code, and then that gets evaluated to actually generate output.
26
+ #
27
+ # Because <tt>render :widget => ...</tt> takes an already-instantiated widget as input, this simply isn't
28
+ # possible: you can't reverse-engineer an arbitrary Ruby object into source code, and, without source code,
29
+ # the whole templating paradigm doesn't make sense.
30
+ #
31
+ # So, instead, we simply transform <tt>render :widget => ...</tt> into a <tt>render :text => ...</tt> of the
32
+ # widget's output, and let Rails take it away from there.
33
+ def render_with_fortitude(*args, &block)
34
+ if (options = args[0]).kind_of?(Hash)
35
+ if (widget = options[:widget])
36
+ rendering_context = fortitude_rendering_context_for(self, nil)
37
+ widget.render_to(rendering_context)
38
+
39
+ options = options.dup
40
+ options[:text] = rendering_context.output_buffer_holder.output_buffer.html_safe
41
+ options[:layout] = true unless options.has_key?(:layout)
42
+
43
+ new_args = [ options ] + args[1..-1]
44
+ return render_without_fortitude(*new_args, &block)
45
+ elsif (widget_block = options[:inline]) && (options[:type] == :fortitude)
46
+ options.delete(:inline)
47
+
48
+ rendering_context = fortitude_rendering_context_for(self, nil)
49
+ widget_class = Class.new(Fortitude::Widgets::Html5)
50
+ widget_class.use_instance_variables_for_assigns(true)
51
+ widget_class.extra_assigns(:use)
52
+ widget_class.send(:define_method, :content, &widget_block)
53
+
54
+ assigns = { }
55
+ instance_variables.each do |ivar_name|
56
+ value = instance_variable_get(ivar_name)
57
+ assigns[$1.to_sym] = value if ivar_name =~ /^@(.*)$/
58
+ end
59
+ assigns = assigns.merge(options[:locals] || { })
60
+
61
+ widget = widget_class.new(assigns)
62
+ widget.render_to(rendering_context)
63
+
64
+ options = options.dup
65
+ options[:text] = rendering_context.output_buffer_holder.output_buffer.html_safe
66
+ options[:layout] = true unless options.has_key?(:layout)
67
+
68
+ new_args = [ options ] + args[1..-1]
69
+ return render_without_fortitude(*new_args, &block)
70
+ end
71
+ end
72
+
73
+ return render_without_fortitude(*args, &block)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -7,6 +7,7 @@ module Fortitude
7
7
  include Fortitude::Tags::TagSupport
8
8
 
9
9
  @widget_class = widget_class
10
+ @widget_class.send(:const_set, :DefinedFortitudeTags, self)
10
11
  @widget_class.send(:include, self)
11
12
  end
12
13
 
@@ -19,7 +19,9 @@ module Fortitude
19
19
  end
20
20
  end
21
21
 
22
- def render(scope=Object.new, locals={}, &block)
22
+ def render(scope=Object.new, locals = nil, &block)
23
+ locals ||= { }
24
+
23
25
  rendering_context = Fortitude::RenderingContext.new({
24
26
  :yield_block => block, :render_yield_result => false,
25
27
  :helpers_object => scope, :instance_variables_object => scope })
@@ -1,3 +1,3 @@
1
1
  module Fortitude
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -44,8 +44,10 @@ module Fortitude
44
44
  @tags_module = Fortitude::Tags::TagsModule.new(self)
45
45
  @helpers_module = Module.new
46
46
  include @helpers_module
47
+ const_set(:DefinedFortitudeHelpers, @helpers_module)
47
48
  @needs_module = Module.new
48
49
  include @needs_module
50
+ const_set(:FortitudeNeedsMethods, @helpers_module)
49
51
  end
50
52
  private :create_modules!
51
53
 
@@ -0,0 +1,19 @@
1
+ module Spec
2
+ module Helpers
3
+ module FortitudeRailsHelpers
4
+ def rails_server_project_root
5
+ @rails_server_project_root ||= File.expand_path(File.join(File.dirname(__FILE__), '../..'))
6
+ end
7
+
8
+ def rails_server_additional_gemfile_lines
9
+ [
10
+ "gem 'fortitude', :path => '#{rails_server_project_root}'"
11
+ ]
12
+ end
13
+
14
+ def rails_server_default_version
15
+ ENV['FORTITUDE_SPECS_RAILS_VERSION']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,8 +1,10 @@
1
1
  require 'fortitude'
2
- require 'helpers/rails_helpers'
2
+ require 'oop_rails_server'
3
3
  require 'helpers/system_helpers'
4
+ require 'helpers/fortitude_rails_helpers'
4
5
 
5
6
  RSpec.configure do |c|
6
- c.include RailsHelpers, :type => :rails
7
+ c.include ::OopRailsServer::Helpers, :type => :rails
8
+ c.include ::Spec::Helpers::FortitudeRailsHelpers, :type => :rails
7
9
  c.include SystemHelpers, :type => :system
8
10
  end
@@ -23,7 +23,7 @@ describe "Rails capture support", :type => :rails do
23
23
  end
24
24
 
25
25
  it "should be able to provide content in a widget with provide" do
26
- skip "Rails 3.0.x doesn't support :provide" if @rails_server.rails_version =~ /^3\.0\./
26
+ skip "Rails 3.0.x doesn't support :provide" if rails_server.rails_version =~ /^3\.0\./
27
27
 
28
28
  expect_match('widget_provide',
29
29
  %r{erb_layout_needing_content}i,
@@ -13,11 +13,21 @@ describe "Rails development-mode support", :type => :rails do
13
13
  expect_match("reload_widget", /after_reload/)
14
14
  end
15
15
 
16
+ it "should automatically reload widgets if related files change on disk, even if they're named '.html.rb' at the end" do
17
+ expect_match("reload_widget_with_html_extension", /with_html_extension.*helper: yo/)
18
+ sleep 1
19
+ splat_new_module_for_reload_widget_failing!
20
+ expect_exception("reload_widget_with_html_extension", NameError, "some_helper")
21
+ sleep 1
22
+ splat_new_module_for_reload_widget!
23
+ expect_match("reload_widget_with_html_extension", /with_html_extension.*helper: yo/)
24
+ end
25
+
16
26
  it "should let you change the controller, and that should work fine, too" do
17
- expect_match("reload_widget", /datum\s+one\s+datum/)
27
+ expect(rails_server.get("replaced/reload_widget")).to match(/datum\s+one\s+datum/)
18
28
  sleep 1
19
29
  splat_new_controller!
20
- expect_match("reload_widget", /datum\s+two\s+datum/)
30
+ expect(rails_server.get("replaced/reload_widget")).to match(/datum\s+two\s+datum/)
21
31
  end
22
32
 
23
33
  it "should, by default, format output" do
@@ -32,6 +42,42 @@ describe "Rails development-mode support", :type => :rails do
32
42
  <!-- END Views::DevelopmentModeSystemSpec::SampleOutput depth 0 -->}mi)
33
43
  end
34
44
 
45
+ it "should pick up changes to mailer views" do
46
+ expect_match("mailer_view_test", /mail sent/i)
47
+ mail = mail_sent_to('mailer_view_test@example.com')
48
+ expect(mail[:body].strip).to match(%r{<p>this is the basic mail!</p>}mi)
49
+ clear_mails!
50
+
51
+ sleep 1
52
+ splat_new_mailer_view!
53
+ expect_match("mailer_view_test", /mail sent/i)
54
+ mail = mail_sent_to('mailer_view_test@example.com')
55
+ expect(mail[:body].strip).to match(%r{<p>this is the NEW basic mail!</p>}mi)
56
+ end
57
+
58
+ it "should pick up changes to mailer layouts" do
59
+ expect_match("mailer_layout_test", /mail sent/i)
60
+ mail = mail_sent_to('mailer_layout_test@example.com')
61
+ expect(mail[:body].strip).to match(%r{this is the layout, before.*this is the basic mail!.*this is the layout, after}mi)
62
+ clear_mails!
63
+
64
+ sleep 1
65
+ splat_new_mailer_layout!
66
+ expect_match("mailer_layout_test", /mail sent/i)
67
+ mail = mail_sent_to('mailer_layout_test@example.com')
68
+ expect(mail[:body].strip).to match(%r{this is the NEW layout, before.*this is the basic mail!.*this is the NEW layout, after}mi)
69
+ end
70
+
71
+ it "should format output and output BEGIN/END debugging tags in mailers" do
72
+ expect_match("mailer_formatting_test", /mail sent/i)
73
+ mail = mail_sent_to('mailer_formatting_test@example.com')
74
+ expect(mail[:body].strip).to eq(%{<!-- BEGIN Views::DevelopmentModeMailer::MailerFormattingTest depth 0 -->
75
+ <div>
76
+ <p>this is the text!</p>
77
+ </div>
78
+ <!-- END Views::DevelopmentModeMailer::MailerFormattingTest depth 0 -->})
79
+ end
80
+
35
81
  private
36
82
  def splat_new_widget!
37
83
  reload_file = File.join(rails_server.rails_root, 'app/views/development_mode_system_spec/reload_widget.rb')
@@ -48,17 +94,65 @@ EOS
48
94
  end
49
95
  end
50
96
 
97
+ def splat_new_module_for_reload_widget_failing!
98
+ module_file = File.join(rails_server.rails_root, 'app/views/shared/some_module.rb')
99
+ File.open(module_file, 'w') do |f|
100
+ f.puts <<-EOS
101
+ module Views::Shared::SomeModule
102
+ end
103
+ EOS
104
+ end
105
+ end
106
+
107
+ def splat_new_module_for_reload_widget!
108
+ module_file = File.join(rails_server.rails_root, 'app/views/shared/some_module.rb')
109
+ File.open(module_file, 'w') do |f|
110
+ f.puts <<-EOS
111
+ module Views::Shared::SomeModule
112
+ def some_helper
113
+ "yo"
114
+ end
115
+ end
116
+ EOS
117
+ end
118
+ end
119
+
51
120
  def splat_new_controller!
52
- controller_file = File.join(rails_server.rails_root, 'app/controllers/development_mode_system_spec_controller.rb')
121
+ controller_file = File.join(rails_server.rails_root, 'app/controllers/replaced_controller.rb')
53
122
  File.open(controller_file, 'w') do |f|
54
123
  f.puts <<-EOS
55
- class DevelopmentModeSystemSpecController < ApplicationController
124
+ class ReplacedController < ApplicationController
56
125
  def reload_widget
57
126
  @datum = "two"
58
127
  end
128
+ end
129
+ EOS
130
+ end
131
+ end
132
+
133
+ def splat_new_mailer_view!
134
+ reload_file = File.join(rails_server.rails_root, 'app/views/development_mode_mailer/mailer_view_test.rb')
135
+ File.open(reload_file, 'w') do |f|
136
+ f.puts <<-EOS
137
+ class Views::DevelopmentModeMailer::MailerViewTest < Fortitude::Widgets::Html5
138
+ def content
139
+ p "this is the NEW basic mail!"
140
+ end
141
+ end
142
+ EOS
143
+ end
144
+ end
145
+
59
146
 
60
- def sample_output
61
- @name = "Jessica"
147
+ def splat_new_mailer_layout!
148
+ reload_file = File.join(rails_server.rails_root, 'app/views/layouts/mail_layout.rb')
149
+ File.open(reload_file, 'w') do |f|
150
+ f.puts <<-EOS
151
+ class Views::Layouts::MailLayout < Fortitude::Widgets::Html5
152
+ def content
153
+ p "this is the NEW layout, before"
154
+ yield
155
+ p "this is the NEW layout, after"
62
156
  end
63
157
  end
64
158
  EOS