roadie-rails 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +15 -0
  4. data/Changelog.md +9 -0
  5. data/Gemfile +17 -0
  6. data/Guardfile +16 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +317 -0
  9. data/Rakefile +14 -0
  10. data/Upgrading.md +70 -0
  11. data/lib/roadie-rails.rb +1 -0
  12. data/lib/roadie/rails.rb +21 -0
  13. data/lib/roadie/rails/asset_pipeline_provider.rb +24 -0
  14. data/lib/roadie/rails/automatic.rb +16 -0
  15. data/lib/roadie/rails/document_builder.rb +18 -0
  16. data/lib/roadie/rails/inline_on_delivery.rb +17 -0
  17. data/lib/roadie/rails/mail_inliner.rb +26 -0
  18. data/lib/roadie/rails/mailer.rb +14 -0
  19. data/lib/roadie/rails/options.rb +101 -0
  20. data/lib/roadie/rails/railtie.rb +22 -0
  21. data/lib/roadie/rails/version.rb +5 -0
  22. data/roadie-rails.gemspec +29 -0
  23. data/setup.sh +62 -0
  24. data/spec/integration_spec.rb +119 -0
  25. data/spec/lib/roadie/rails/asset_pipeline_provider_spec.rb +47 -0
  26. data/spec/lib/roadie/rails/automatic_spec.rb +44 -0
  27. data/spec/lib/roadie/rails/document_builder_spec.rb +20 -0
  28. data/spec/lib/roadie/rails/mail_inliner_spec.rb +57 -0
  29. data/spec/lib/roadie/rails/mailer_spec.rb +57 -0
  30. data/spec/lib/roadie/rails/options_spec.rb +136 -0
  31. data/spec/lib/roadie/rails/railtie_spec.rb +48 -0
  32. data/spec/railsapps/README.md +69 -0
  33. data/spec/railsapps/rails_30/.gitignore +2 -0
  34. data/spec/railsapps/rails_30/Gemfile +7 -0
  35. data/spec/railsapps/rails_30/app/mailers/auto_mailer.rb +17 -0
  36. data/spec/railsapps/rails_30/app/mailers/mailer.rb +17 -0
  37. data/spec/railsapps/rails_30/app/views/auto_mailer/normal_email.html.erb +11 -0
  38. data/spec/railsapps/rails_30/app/views/auto_mailer/normal_email.text +1 -0
  39. data/spec/railsapps/rails_30/app/views/mailer/normal_email.html.erb +11 -0
  40. data/spec/railsapps/rails_30/app/views/mailer/normal_email.text +1 -0
  41. data/spec/railsapps/rails_30/config/application.rb +19 -0
  42. data/spec/railsapps/rails_30/config/boot.rb +6 -0
  43. data/spec/railsapps/rails_30/config/environment.rb +5 -0
  44. data/spec/railsapps/rails_30/config/environments/development.rb +10 -0
  45. data/spec/railsapps/rails_30/config/initializers/secret_token.rb +1 -0
  46. data/spec/railsapps/rails_30/config/initializers/session_store.rb +1 -0
  47. data/spec/railsapps/rails_30/config/routes.rb +2 -0
  48. data/spec/railsapps/rails_30/public/images/rails.png +0 -0
  49. data/spec/railsapps/rails_30/public/stylesheets/email.css +2 -0
  50. data/spec/railsapps/rails_30/script/rails +6 -0
  51. data/spec/railsapps/rails_31/.gitignore +2 -0
  52. data/spec/railsapps/rails_31/Gemfile +11 -0
  53. data/spec/railsapps/rails_31/app/assets/images/rails.png +0 -0
  54. data/spec/railsapps/rails_31/app/assets/stylesheets/email.css.scss +2 -0
  55. data/spec/railsapps/rails_31/app/mailers/auto_mailer.rb +17 -0
  56. data/spec/railsapps/rails_31/app/mailers/mailer.rb +17 -0
  57. data/spec/railsapps/rails_31/app/views/auto_mailer/normal_email.html.erb +11 -0
  58. data/spec/railsapps/rails_31/app/views/auto_mailer/normal_email.text +1 -0
  59. data/spec/railsapps/rails_31/app/views/mailer/normal_email.html.erb +11 -0
  60. data/spec/railsapps/rails_31/app/views/mailer/normal_email.text +1 -0
  61. data/spec/railsapps/rails_31/config/application.rb +22 -0
  62. data/spec/railsapps/rails_31/config/boot.rb +6 -0
  63. data/spec/railsapps/rails_31/config/environment.rb +5 -0
  64. data/spec/railsapps/rails_31/config/environments/development.rb +11 -0
  65. data/spec/railsapps/rails_31/config/initializers/secret_token.rb +1 -0
  66. data/spec/railsapps/rails_31/config/initializers/session_store.rb +1 -0
  67. data/spec/railsapps/rails_31/config/initializers/wrap_parameters.rb +4 -0
  68. data/spec/railsapps/rails_31/config/routes.rb +2 -0
  69. data/spec/railsapps/rails_31/script/rails +6 -0
  70. data/spec/railsapps/rails_32/.gitignore +2 -0
  71. data/spec/railsapps/rails_32/Gemfile +11 -0
  72. data/spec/railsapps/rails_32/app/assets/images/rails.png +0 -0
  73. data/spec/railsapps/rails_32/app/assets/stylesheets/email.css.scss +2 -0
  74. data/spec/railsapps/rails_32/app/mailers/auto_mailer.rb +17 -0
  75. data/spec/railsapps/rails_32/app/mailers/mailer.rb +17 -0
  76. data/spec/railsapps/rails_32/app/views/auto_mailer/normal_email.html.erb +11 -0
  77. data/spec/railsapps/rails_32/app/views/auto_mailer/normal_email.text +1 -0
  78. data/spec/railsapps/rails_32/app/views/mailer/normal_email.html.erb +11 -0
  79. data/spec/railsapps/rails_32/app/views/mailer/normal_email.text +1 -0
  80. data/spec/railsapps/rails_32/config/application.rb +22 -0
  81. data/spec/railsapps/rails_32/config/boot.rb +6 -0
  82. data/spec/railsapps/rails_32/config/environment.rb +5 -0
  83. data/spec/railsapps/rails_32/config/environments/development.rb +11 -0
  84. data/spec/railsapps/rails_32/config/initializers/secret_token.rb +1 -0
  85. data/spec/railsapps/rails_32/config/initializers/session_store.rb +1 -0
  86. data/spec/railsapps/rails_32/config/initializers/wrap_parameters.rb +4 -0
  87. data/spec/railsapps/rails_32/config/routes.rb +2 -0
  88. data/spec/railsapps/rails_32/script/rails +6 -0
  89. data/spec/railsapps/rails_40/Gemfile +9 -0
  90. data/spec/railsapps/rails_40/app/assets/images/rails.png +0 -0
  91. data/spec/railsapps/rails_40/app/assets/stylesheets/email.css.scss +2 -0
  92. data/spec/railsapps/rails_40/app/mailers/auto_mailer.rb +17 -0
  93. data/spec/railsapps/rails_40/app/mailers/mailer.rb +17 -0
  94. data/spec/railsapps/rails_40/app/views/auto_mailer/normal_email.html.erb +11 -0
  95. data/spec/railsapps/rails_40/app/views/auto_mailer/normal_email.text +1 -0
  96. data/spec/railsapps/rails_40/app/views/mailer/normal_email.html.erb +11 -0
  97. data/spec/railsapps/rails_40/app/views/mailer/normal_email.text +1 -0
  98. data/spec/railsapps/rails_40/bin/rails +4 -0
  99. data/spec/railsapps/rails_40/config/application.rb +18 -0
  100. data/spec/railsapps/rails_40/config/boot.rb +4 -0
  101. data/spec/railsapps/rails_40/config/environment.rb +5 -0
  102. data/spec/railsapps/rails_40/config/environments/development.rb +9 -0
  103. data/spec/railsapps/rails_40/config/initializers/secret_token.rb +1 -0
  104. data/spec/railsapps/rails_40/config/initializers/session_store.rb +1 -0
  105. data/spec/railsapps/rails_40/config/routes.rb +2 -0
  106. data/spec/railsapps/rails_40_no_pipeline/Gemfile +9 -0
  107. data/spec/railsapps/rails_40_no_pipeline/app/mailers/auto_mailer.rb +17 -0
  108. data/spec/railsapps/rails_40_no_pipeline/app/mailers/mailer.rb +17 -0
  109. data/spec/railsapps/rails_40_no_pipeline/app/views/auto_mailer/normal_email.html.erb +11 -0
  110. data/spec/railsapps/rails_40_no_pipeline/app/views/auto_mailer/normal_email.text +1 -0
  111. data/spec/railsapps/rails_40_no_pipeline/app/views/mailer/normal_email.html.erb +11 -0
  112. data/spec/railsapps/rails_40_no_pipeline/app/views/mailer/normal_email.text +1 -0
  113. data/spec/railsapps/rails_40_no_pipeline/bin/rails +4 -0
  114. data/spec/railsapps/rails_40_no_pipeline/config/application.rb +19 -0
  115. data/spec/railsapps/rails_40_no_pipeline/config/boot.rb +4 -0
  116. data/spec/railsapps/rails_40_no_pipeline/config/environment.rb +5 -0
  117. data/spec/railsapps/rails_40_no_pipeline/config/environments/development.rb +9 -0
  118. data/spec/railsapps/rails_40_no_pipeline/config/initializers/secret_token.rb +1 -0
  119. data/spec/railsapps/rails_40_no_pipeline/config/initializers/session_store.rb +1 -0
  120. data/spec/railsapps/rails_40_no_pipeline/config/routes.rb +2 -0
  121. data/spec/railsapps/rails_40_no_pipeline/log/dee +0 -0
  122. data/spec/railsapps/rails_40_no_pipeline/public/images/rails.png +0 -0
  123. data/spec/railsapps/rails_40_no_pipeline/public/stylesheets/email.css +2 -0
  124. data/spec/railsapps/rails_40_precompiled/Gemfile +9 -0
  125. data/spec/railsapps/rails_40_precompiled/Rakefile +6 -0
  126. data/spec/railsapps/rails_40_precompiled/app/assets/images/rails.png +0 -0
  127. data/spec/railsapps/rails_40_precompiled/app/assets/stylesheets/email.css.scss +2 -0
  128. data/spec/railsapps/rails_40_precompiled/app/mailers/mailer.rb +17 -0
  129. data/spec/railsapps/rails_40_precompiled/app/views/mailer/normal_email.html.erb +11 -0
  130. data/spec/railsapps/rails_40_precompiled/app/views/mailer/normal_email.text +1 -0
  131. data/spec/railsapps/rails_40_precompiled/bin/rails +4 -0
  132. data/spec/railsapps/rails_40_precompiled/config/application.rb +18 -0
  133. data/spec/railsapps/rails_40_precompiled/config/boot.rb +4 -0
  134. data/spec/railsapps/rails_40_precompiled/config/environment.rb +5 -0
  135. data/spec/railsapps/rails_40_precompiled/config/environments/development.rb +14 -0
  136. data/spec/railsapps/rails_40_precompiled/config/initializers/secret_token.rb +1 -0
  137. data/spec/railsapps/rails_40_precompiled/config/initializers/session_store.rb +1 -0
  138. data/spec/railsapps/rails_40_precompiled/config/routes.rb +2 -0
  139. data/spec/railsapps/rails_40_precompiled/public/assets/email-fad0c62b8f82e2835c1d0bdc19894257.css +5 -0
  140. data/spec/railsapps/rails_40_precompiled/public/assets/email-fad0c62b8f82e2835c1d0bdc19894257.css.gz +0 -0
  141. data/spec/railsapps/rails_40_precompiled/public/assets/manifest-8a3d16aeb2a40fe5057dd998c3edab10.json +1 -0
  142. data/spec/railsapps/rails_40_precompiled/public/assets/rails-231a680f23887d9dd70710ea5efd3c62.png +0 -0
  143. data/spec/railsapps/rails_41/.gitignore +16 -0
  144. data/spec/railsapps/rails_41/Gemfile +8 -0
  145. data/spec/railsapps/rails_41/app/assets/images/rails.png +0 -0
  146. data/spec/railsapps/rails_41/app/assets/stylesheets/email.css.scss +2 -0
  147. data/spec/railsapps/rails_41/app/mailers/auto_mailer.rb +17 -0
  148. data/spec/railsapps/rails_41/app/mailers/mailer.rb +17 -0
  149. data/spec/railsapps/rails_41/app/views/auto_mailer/normal_email.html.erb +11 -0
  150. data/spec/railsapps/rails_41/app/views/auto_mailer/normal_email.text +1 -0
  151. data/spec/railsapps/rails_41/app/views/mailer/normal_email.html.erb +11 -0
  152. data/spec/railsapps/rails_41/app/views/mailer/normal_email.text +1 -0
  153. data/spec/railsapps/rails_41/bin/rails +4 -0
  154. data/spec/railsapps/rails_41/config.ru +4 -0
  155. data/spec/railsapps/rails_41/config/application.rb +13 -0
  156. data/spec/railsapps/rails_41/config/boot.rb +4 -0
  157. data/spec/railsapps/rails_41/config/environment.rb +5 -0
  158. data/spec/railsapps/rails_41/config/environments/development.rb +9 -0
  159. data/spec/railsapps/rails_41/config/initializers/secret_token.rb +1 -0
  160. data/spec/railsapps/rails_41/config/initializers/session_store.rb +1 -0
  161. data/spec/railsapps/rails_41/config/routes.rb +2 -0
  162. data/spec/spec_helper.rb +14 -0
  163. data/spec/support/have_selector_matcher.rb +3 -0
  164. data/spec/support/have_styling_matcher.rb +63 -0
  165. data/spec/support/rails_app.rb +70 -0
  166. metadata +443 -0
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails40::Application.load_tasks
@@ -0,0 +1,2 @@
1
+ body { background-color: green; }
2
+ .image { background: image-url("rails.png"); }
@@ -0,0 +1,17 @@
1
+ class Mailer < ActionMailer::Base
2
+ include Roadie::Rails::Mailer
3
+
4
+ default from: 'john@example.com'
5
+
6
+ def normal_email
7
+ roadie_mail(to: 'example@example.org', subject: "Notification for you") do |format|
8
+ format.html
9
+ format.text
10
+ end
11
+ end
12
+
13
+ private
14
+ def roadie_options
15
+ super.combine(url_options: {protocol: "https"})
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
5
+ <%= stylesheet_link_tag "email" %>
6
+ </head>
7
+ <body>
8
+ <h1>Normal email</h1>
9
+ <div class="image"></div>
10
+ </body>
11
+ </html>
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ # require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "sprockets/railtie"
8
+ # require "rails/test_unit/railtie"
9
+
10
+ # Require the gems listed in Gemfile, including any gems
11
+ # you've limited to :test, :development, or :production.
12
+ Bundler.require(:default, Rails.env)
13
+
14
+ module Rails40
15
+ class Application < Rails::Application
16
+ config.roadie.url_options = {host: 'example.app.org'}
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails40::Application.initialize!
@@ -0,0 +1,14 @@
1
+ Rails40::Application.configure do
2
+ config.cache_classes = false
3
+ config.eager_load = false
4
+ config.consider_all_requests_local = true
5
+ config.action_controller.perform_caching = false
6
+ config.action_mailer.raise_delivery_errors = false
7
+ config.active_support.deprecation = :log
8
+
9
+ config.assets.debug = false
10
+ config.assets.compile = false
11
+ config.assets.digest = true
12
+ config.assets.precompile += %w[email.css other.css]
13
+ config.assets.initialize_on_precompile = false
14
+ end
@@ -0,0 +1 @@
1
+ Rails40::Application.config.secret_key_base = '62c740bbc79cd7fa4dfabc7365c0f7ec98204cfae45a41d2e1423d6084bb762e9310acf46fc7e4cc6215a90c7aeef4107b9f1c7e3b68623fd11af43b716ccf5e'
@@ -0,0 +1 @@
1
+ Rails40::Application.config.session_store :cookie_store, key: '_rails_40_session'
@@ -0,0 +1,2 @@
1
+ Rails40::Application.routes.draw do
2
+ end
@@ -0,0 +1,5 @@
1
+ body {
2
+ background-color: green; }
3
+
4
+ .image {
5
+ background: url(/assets/rails-231a680f23887d9dd70710ea5efd3c62.png); }
@@ -0,0 +1 @@
1
+ {"files":{"rails-231a680f23887d9dd70710ea5efd3c62.png":{"logical_path":"rails.png","mtime":"2013-08-05T10:07:29+02:00","size":6646,"digest":"231a680f23887d9dd70710ea5efd3c62"},"email-fad0c62b8f82e2835c1d0bdc19894257.css":{"logical_path":"email.css","mtime":"2013-11-20T08:39:33+01:00","size":119,"digest":"fad0c62b8f82e2835c1d0bdc19894257"}},"assets":{"rails.png":"rails-231a680f23887d9dd70710ea5efd3c62.png","email.css":"email-fad0c62b8f82e2835c1d0bdc19894257.css"}}
@@ -0,0 +1,16 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*.log
16
+ /tmp
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rails', '4.0.0'
3
+ gem 'sass-rails', '~> 4.0.0'
4
+
5
+ gem 'roadie-rails', :path => '../../..'
6
+
7
+ # Use git version of `roadie` until a full release have been made
8
+ gem 'roadie', git: 'git://github.com/Mange/roadie.git', branch: 'master'
@@ -0,0 +1,2 @@
1
+ body { background-color: green; }
2
+ .image { background: image-url("rails.png"); }
@@ -0,0 +1,17 @@
1
+ class AutoMailer < ActionMailer::Base
2
+ include Roadie::Rails::Automatic
3
+
4
+ default from: 'john@example.com'
5
+
6
+ def normal_email
7
+ mail(to: 'example@example.org', subject: "Notification for you") do |format|
8
+ format.html
9
+ format.text
10
+ end
11
+ end
12
+
13
+ private
14
+ def roadie_options
15
+ super.combine(url_options: {protocol: "https"})
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class Mailer < ActionMailer::Base
2
+ include Roadie::Rails::Mailer
3
+
4
+ default from: 'john@example.com'
5
+
6
+ def normal_email
7
+ roadie_mail(to: 'example@example.org', subject: "Notification for you") do |format|
8
+ format.html
9
+ format.text
10
+ end
11
+ end
12
+
13
+ private
14
+ def roadie_options
15
+ super.combine(url_options: {protocol: "https"})
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
5
+ <%= stylesheet_link_tag "email" %>
6
+ </head>
7
+ <body>
8
+ <h1>Normal email</h1>
9
+ <div class="image"></div>
10
+ </body>
11
+ </html>
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
5
+ <%= stylesheet_link_tag "email" %>
6
+ </head>
7
+ <body>
8
+ <h1>Normal email</h1>
9
+ <div class="image"></div>
10
+ </body>
11
+ </html>
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "action_mailer/railtie"
5
+ require "sprockets/railtie"
6
+
7
+ Bundler.require(:default, Rails.env)
8
+
9
+ module Rails41
10
+ class Application < Rails::Application
11
+ config.roadie.url_options = {host: 'example.app.org'}
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails41::Application.initialize!
@@ -0,0 +1,9 @@
1
+ Rails41::Application.configure do
2
+ config.cache_classes = false
3
+ config.eager_load = false
4
+ config.consider_all_requests_local = true
5
+ config.action_controller.perform_caching = false
6
+ config.action_mailer.raise_delivery_errors = false
7
+ config.active_support.deprecation = :log
8
+ config.assets.debug = true
9
+ end
@@ -0,0 +1 @@
1
+ Rails41::Application.config.secret_key_base = '4fc45a45fecece06ff370f3271d9c2f29cdd0b029bde255d77318418e5066681d42c706f5e504b9298f2b5ccbd2c013c39d474e6521ef4c4f056b1368ce22c8f'
@@ -0,0 +1 @@
1
+ Rails41::Application.config.session_store :cookie_store, key: '_rails_41_session'
@@ -0,0 +1,2 @@
1
+ Rails41::Application.routes.draw do
2
+ end
@@ -0,0 +1,14 @@
1
+ require "rspec/collection_matchers"
2
+
3
+ if ENV['CI']
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+ end
7
+
8
+ require 'roadie-rails'
9
+
10
+ RSpec.configure do |config|
11
+ config.run_all_when_everything_filtered = true
12
+ end
13
+
14
+ Dir['./spec/support/**/*.rb'].each { |file| require file }
@@ -0,0 +1,3 @@
1
+ RSpec::Matchers.define :have_selector do |selector|
2
+ match { |dom| dom.at_css selector }
3
+ end
@@ -0,0 +1,63 @@
1
+ RSpec::Matchers.define :have_styling do |rules|
2
+ normalized_rules = StylingExpectation.new(rules)
3
+
4
+ chain(:at_selector) { |selector| @selector = selector }
5
+
6
+ match { |document|
7
+ @selector ||= 'body > *:first'
8
+ normalized_rules == styles_at_selector(document)
9
+ }
10
+
11
+ description {
12
+ "have styles #{normalized_rules.inspect} at selector #{@selector.inspect}"
13
+ }
14
+
15
+ failure_message { |document|
16
+ "expected styles at #{@selector.inspect} to be:\n#{normalized_rules}\nbut was:\n#{styles_at_selector(document)}"
17
+ }
18
+
19
+ failure_message_when_negated {
20
+ "expected styles at #{@selector.inspect} to not be:\n#{normalized_rules}"
21
+ }
22
+
23
+ def styles_at_selector(document)
24
+ expect(document).to have_selector(@selector)
25
+ style = document.at_css(@selector)['style']
26
+ StylingExpectation.new(style || "")
27
+ end
28
+ end
29
+
30
+ class StylingExpectation
31
+ def initialize(styling)
32
+ case styling
33
+ when String then @rules = parse_rules(styling)
34
+ when Array then @rules = styling
35
+ when Hash then @rules = styling.to_a
36
+ else fail "I don't understand #{styling.inspect}!"
37
+ end
38
+ end
39
+
40
+ def ==(other)
41
+ rules == other.rules
42
+ end
43
+
44
+ def to_s() rules.to_s end
45
+
46
+ protected
47
+ attr_reader :rules
48
+
49
+ private
50
+ def parse_rules(css)
51
+ css.split(';').map { |property| parse_property(property) }
52
+ end
53
+
54
+ def parse_property(property)
55
+ rule, value = property.split(':', 2).map(&:strip)
56
+ [rule, normalize_quotes(value)]
57
+ end
58
+
59
+ # JRuby's Nokogiri encodes quotes
60
+ def normalize_quotes(string)
61
+ string.gsub '%22', '"'
62
+ end
63
+ end
@@ -0,0 +1,70 @@
1
+ class RailsApp
2
+ def initialize(name, path, options = {})
3
+ @name = name
4
+ @path = File.expand_path("../../railsapps/#{path}", __FILE__)
5
+ @runner = options.fetch(:runner)
6
+ @using_asset_pipeline = options.fetch(:asset_pipeline)
7
+ reset
8
+ end
9
+
10
+ def to_s() @name end
11
+ def using_asset_pipeline?() @using_asset_pipeline end
12
+
13
+ def read_email(mail_name)
14
+ result = run("puts Mailer.#{mail_name}.to_s")
15
+ raise "No email returned. Did the rails application crash?" if result.strip.empty?
16
+ Mail.read_from_string(result)
17
+ end
18
+
19
+ def read_delivered_email(mail_name)
20
+ result = run("mail = AutoMailer.#{mail_name}; mail.delivery_method(:test); mail.deliver; puts mail.to_s")
21
+ raise "No email returned. Did the rails application crash?" if result.strip.empty?
22
+ Mail.read_from_string(result)
23
+ end
24
+
25
+ def read_providers
26
+ result = run(<<-RUBY).strip
27
+ providers = Rails.application.config.roadie.asset_providers
28
+ puts providers.map { |p| p.class.name }.join(',')
29
+ RUBY
30
+ raise "No output present. Did the application crash?" if result.empty?
31
+ result.split(",")
32
+ end
33
+
34
+ def reset
35
+ @extra_code = ""
36
+ end
37
+
38
+ def before_mail(code)
39
+ @extra_code << "\n" << code << "\n"
40
+ end
41
+
42
+ private
43
+ def run(code)
44
+ Tempfile.open('code') do |file|
45
+ file << @extra_code unless @extra_code.empty?
46
+ file << code
47
+ file.close
48
+ run_file_in_app_context file.path
49
+ end
50
+ end
51
+
52
+ def run_file_in_app_context(file_path)
53
+ # Unset environment variables set by Bundler to get a clean slate
54
+ IO.popen(<<-SH).read
55
+ unset BUNDLE_GEMFILE;
56
+ unset RUBYOPT;
57
+ export RAILS_ENV=development
58
+ cd #{@path.shellescape} && #{runner_script} #{file_path.shellescape}
59
+ SH
60
+ end
61
+
62
+ def runner_script
63
+ case @runner
64
+ when :script then "script/rails runner"
65
+ when :bin then "bin/rails runner"
66
+ else raise "Unknown runner type: #{@runner}"
67
+ end
68
+ end
69
+ end
70
+