sass-rails 4.0.0.rc1 → 4.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +25 -15
  4. data/Gemfile +0 -2
  5. data/{README.markdown → README.md} +26 -19
  6. data/Rakefile +1 -1
  7. data/lib/sass/rails.rb +1 -2
  8. data/lib/sass/rails/importer.rb +45 -15
  9. data/lib/sass/rails/railtie.rb +3 -9
  10. data/lib/sass/rails/version.rb +1 -1
  11. data/sass-rails.gemspec +5 -6
  12. data/sass-rails.gemspec.erb +3 -4
  13. data/test/fixtures/alternate_config_project/Gemfile +2 -2
  14. data/test/fixtures/alternate_config_project/config/environments/development.rb +0 -1
  15. data/test/fixtures/alternate_config_project/config/environments/production.rb +2 -1
  16. data/test/fixtures/alternate_config_project/config/environments/test.rb +0 -4
  17. data/test/fixtures/engine_project/.gitignore +3 -1
  18. data/test/fixtures/engine_project/Gemfile +11 -2
  19. data/test/fixtures/engine_project/MIT-LICENSE +20 -0
  20. data/test/fixtures/engine_project/Rakefile +5 -10
  21. data/test/fixtures/engine_project/app/assets/images/engine_project/{.gitkeep → .keep} +0 -0
  22. data/test/fixtures/engine_project/app/assets/javascripts/engine_project/application.js +11 -4
  23. data/test/fixtures/engine_project/app/assets/stylesheets/engine_project/application.css +11 -5
  24. data/test/fixtures/engine_project/app/views/layouts/engine_project/application.html.erb +1 -1
  25. data/test/fixtures/engine_project/engine_project.gemspec +20 -5
  26. data/test/fixtures/engine_project/lib/engine_project/engine.rb +1 -1
  27. data/test/fixtures/engine_project/script/rails +5 -3
  28. data/test/fixtures/engine_project/test/dummy/README.rdoc +28 -0
  29. data/test/fixtures/engine_project/test/dummy/Rakefile +0 -1
  30. data/test/fixtures/engine_project/test/dummy/app/assets/javascripts/application.js +11 -4
  31. data/test/fixtures/engine_project/test/dummy/app/assets/stylesheets/application.css +11 -5
  32. data/test/fixtures/engine_project/test/dummy/app/controllers/application_controller.rb +3 -1
  33. data/test/fixtures/engine_project/test/dummy/app/{mailers/.gitkeep → controllers/concerns/.keep} +0 -0
  34. data/test/fixtures/engine_project/test/dummy/app/{models/.gitkeep → mailers/.keep} +0 -0
  35. data/test/fixtures/engine_project/test/dummy/{lib/assets/.gitkeep → app/models/.keep} +0 -0
  36. data/test/fixtures/engine_project/test/dummy/{log/.gitkeep → app/models/concerns/.keep} +0 -0
  37. data/test/fixtures/engine_project/test/dummy/app/views/layouts/application.html.erb +2 -2
  38. data/test/fixtures/engine_project/test/dummy/bin/bundle +3 -0
  39. data/test/fixtures/engine_project/test/dummy/bin/rails +4 -0
  40. data/test/fixtures/engine_project/test/dummy/bin/rake +4 -0
  41. data/test/fixtures/engine_project/test/dummy/config/application.rb +1 -20
  42. data/test/fixtures/engine_project/test/dummy/config/boot.rb +0 -1
  43. data/test/fixtures/engine_project/test/dummy/config/environment.rb +2 -2
  44. data/test/fixtures/engine_project/test/dummy/config/environments/development.rb +12 -9
  45. data/test/fixtures/engine_project/test/dummy/config/environments/production.rb +49 -20
  46. data/test/fixtures/engine_project/test/dummy/config/environments/test.rb +14 -14
  47. data/test/fixtures/engine_project/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/test/fixtures/engine_project/test/dummy/config/initializers/inflections.rb +9 -3
  49. data/test/fixtures/engine_project/test/dummy/config/initializers/secret_token.rb +6 -1
  50. data/test/fixtures/engine_project/test/dummy/config/initializers/session_store.rb +1 -6
  51. data/test/fixtures/engine_project/test/dummy/config/initializers/wrap_parameters.rb +8 -6
  52. data/test/fixtures/engine_project/test/dummy/config/locales/en.yml +20 -2
  53. data/test/fixtures/engine_project/test/dummy/lib/assets/.keep +0 -0
  54. data/test/fixtures/engine_project/test/dummy/log/.keep +0 -0
  55. data/test/fixtures/engine_project/test/dummy/public/404.html +2 -1
  56. data/test/fixtures/engine_project/test/dummy/public/422.html +1 -1
  57. data/test/fixtures/engine_project/test/dummy/public/500.html +2 -2
  58. data/test/fixtures/sass_project/Gemfile +3 -3
  59. data/test/fixtures/sass_project/config/environments/development.rb +0 -3
  60. data/test/fixtures/sass_project/config/environments/production.rb +0 -3
  61. data/test/fixtures/scss_project/Gemfile +3 -3
  62. data/test/fixtures/scss_project/app/assets/stylesheets/application.css.scss +5 -0
  63. data/test/fixtures/scss_project/app/assets/stylesheets/css_erb_handler.css.erb +3 -0
  64. data/test/fixtures/scss_project/app/assets/stylesheets/css_sass_erb_handler.css.sass.erb +2 -0
  65. data/test/fixtures/scss_project/app/assets/stylesheets/css_scss_erb_handler.css.scss.erb +3 -0
  66. data/test/fixtures/scss_project/app/assets/stylesheets/sass_erb_handler.sass.erb +2 -0
  67. data/test/fixtures/scss_project/app/assets/stylesheets/scss_erb_handler.scss.erb +3 -0
  68. data/test/fixtures/scss_project/app/assets/stylesheets/subfolder/_defaults.css.scss +3 -0
  69. data/test/fixtures/scss_project/app/assets/stylesheets/subfolder/second_level.css.scss +2 -1
  70. data/test/fixtures/scss_project/config/environments/development.rb +0 -3
  71. data/test/fixtures/scss_project/config/environments/production.rb +2 -3
  72. data/test/fixtures/scss_project/config/environments/test.rb +2 -0
  73. data/test/sass_rails_generators_test.rb +62 -0
  74. data/test/sass_rails_logger_test.rb +1 -1
  75. data/test/sass_rails_test.rb +61 -121
  76. data/test/test_helper.rb +2 -5
  77. metadata +54 -58
  78. data/lib/sass/rails/compressor.rb +0 -23
  79. data/test/fixtures/engine_project/db/seeds.rb +0 -7
  80. data/test/fixtures/engine_project/test/dummy/db/seeds.rb +0 -7
  81. data/test/fixtures/engine_project/test/dummy/script/rails +0 -6
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -1,10 +1,16 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Add new inflection rules using the following format
4
- # (all these examples are active by default):
5
- # ActiveSupport::Inflector.inflections do |inflect|
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
6
7
  # inflect.plural /^(ox)$/i, '\1en'
7
8
  # inflect.singular /^(ox)en/i, '\1'
8
9
  # inflect.irregular 'person', 'people'
9
10
  # inflect.uncountable %w( fish sheep )
10
11
  # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -2,6 +2,11 @@
2
2
 
3
3
  # Your secret key for verifying the integrity of signed cookies.
4
4
  # If you change this key, all old signed cookies will become invalid!
5
+
5
6
  # Make sure the secret is at least 30 characters and all random,
6
7
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = 'd6e88517fac324a6d3fa410aa3a90b74b625b0805b4a56377f183909840ec2e55cc7d14e3a6d422fc33e10d25aa658d2a340dd344126b6e8a7321a3e43e688e4'
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure your secret_key_base is kept private
11
+ # if you're sharing your code publicly.
12
+ Dummy::Application.config.secret_key_base = '868d5f3233e4ffc2280b4ce3ba53cbe670ecefcca857cbf731795b8f2987f97d04b5175e2d014dd0d711203d2a45d1a52ed66bda51892f08eb828b0136a36437'
@@ -1,8 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
-
5
- # Use the database for sessions instead of the cookie-based default,
6
- # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rails generate session_migration")
8
- # Dummy::Application.config.session_store :active_record_store
3
+ Dummy::Application.config.session_store :encrypted_cookie_store, key: '_dummy_session'
@@ -1,12 +1,14 @@
1
1
  # Be sure to restart your server when you modify this file.
2
- #
2
+
3
3
  # This file contains settings for ActionController::ParamsWrapper which
4
4
  # is enabled by default.
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
- ActionController::Base.wrap_parameters :format => [:json]
8
-
9
- # Disable root element in JSON by default.
10
- if defined?(ActiveRecord)
11
- ActiveRecord::Base.include_root_in_json = false
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
12
9
  end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -1,5 +1,23 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
3
21
 
4
22
  en:
5
23
  hello: "Hello world"
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>The page you were looking for doesn't exist (404)</title>
5
- <style type="text/css">
5
+ <style>
6
6
  body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
7
  div.dialog {
8
8
  width: 25em;
@@ -22,5 +22,6 @@
22
22
  <h1>The page you were looking for doesn't exist.</h1>
23
23
  <p>You may have mistyped the address or the page may have moved.</p>
24
24
  </div>
25
+ <p>If you are the application owner check the logs for more information.</p>
25
26
  </body>
26
27
  </html>
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>The change you wanted was rejected (422)</title>
5
- <style type="text/css">
5
+ <style>
6
6
  body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
7
  div.dialog {
8
8
  width: 25em;
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>We're sorry, but something went wrong (500)</title>
5
- <style type="text/css">
5
+ <style>
6
6
  body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
7
  div.dialog {
8
8
  width: 25em;
@@ -20,7 +20,7 @@
20
20
  <!-- This file lives in public/500.html -->
21
21
  <div class="dialog">
22
22
  <h1>We're sorry, but something went wrong.</h1>
23
- <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
23
  </div>
24
+ <p>If you are the application owner check the logs for more information.</p>
25
25
  </body>
26
26
  </html>
@@ -1,7 +1,7 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'rails', "~> 4.0.0.beta"
3
+ gem 'rails', '>= 4.0.0.beta', '< 5.0'
4
4
  gem 'sqlite3'
5
5
 
6
6
  # Asset template engines
7
- gem 'sass-rails', :path => File.expand_path('../../../..', __FILE__)
7
+ gem 'sass-rails', path: File.expand_path('../../../..', __FILE__)
@@ -18,7 +18,4 @@ ScssProject::Application.configure do
18
18
 
19
19
  # Only use best-standards-support built into browsers
20
20
  config.action_dispatch.best_standards_support = :builtin
21
-
22
- # Do not compress assets
23
- config.assets.compress = false
24
21
  end
@@ -11,9 +11,6 @@ ScssProject::Application.configure do
11
11
  # Disable Rails's static asset server (Apache or nginx will already do this)
12
12
  config.serve_static_assets = false
13
13
 
14
- # Compress JavaScripts and CSS
15
- config.assets.compress = true
16
-
17
14
  # Specify the default JavaScript compressor
18
15
  config.assets.js_compressor = :uglifier
19
16
 
@@ -1,7 +1,7 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'rails', "~> 4.0.0.beta"
3
+ gem 'rails', '>= 4.0.0.beta', '< 5.0'
4
4
  gem 'sqlite3'
5
5
 
6
6
  # Asset template engines
7
- gem 'sass-rails', :path => File.expand_path('../../../..', __FILE__)
7
+ gem 'sass-rails', path: File.expand_path('../../../..', __FILE__)
@@ -4,6 +4,11 @@
4
4
  @import "subfolder/plain";
5
5
  @import "subfolder/second_level";
6
6
  @import "partials/without_css_ext";
7
+ @import "css_erb_handler";
8
+ @import "scss_erb_handler";
9
+ @import "sass_erb_handler";
10
+ @import "css_scss_erb_handler";
11
+ @import "css_sass_erb_handler";
7
12
 
8
13
  .main {
9
14
  color: yellow;
@@ -0,0 +1,3 @@
1
+ .css-erb-handler {
2
+ margin: <%= 0 %>;
3
+ }
@@ -0,0 +1,2 @@
1
+ .css-sass-erb-handler
2
+ margin: <%= 0 %>
@@ -0,0 +1,3 @@
1
+ .css-scss-erb-handler {
2
+ margin: <%= 0 %>;
3
+ }
@@ -0,0 +1,2 @@
1
+ .sass-erb-handler
2
+ margin: <%= 0 %>
@@ -0,0 +1,3 @@
1
+ .scss-erb-handler {
2
+ margin: <%= 0 %>;
3
+ }
@@ -1 +1,2 @@
1
- @import "another_plain"; /* tests whether relative lookups of non-sass files works. */
1
+ @import "another_plain"; /* tests whether relative lookups of non-sass files works. */
2
+ @import "defaults"; /* tests wheter relative lookups partials in the same directory. */
@@ -20,7 +20,4 @@ ScssProject::Application.configure do
20
20
 
21
21
  # Only use best-standards-support built into browsers
22
22
  config.action_dispatch.best_standards_support = :builtin
23
-
24
- # Do not compress assets
25
- config.assets.compress = false
26
23
  end
@@ -4,6 +4,8 @@ ScssProject::Application.configure do
4
4
  # Code is not reloaded between requests
5
5
  config.cache_classes = true
6
6
 
7
+ config.eager_load = true
8
+
7
9
  # Full error reports are disabled and caching is turned on
8
10
  config.consider_all_requests_local = false
9
11
  config.action_controller.perform_caching = true
@@ -11,9 +13,6 @@ ScssProject::Application.configure do
11
13
  # Disable Rails's static asset server (Apache or nginx will already do this)
12
14
  config.serve_static_assets = false
13
15
 
14
- # Compress JavaScripts and CSS
15
- config.assets.compress = true
16
-
17
16
  # Specify the default JavaScript compressor
18
17
  config.assets.js_compressor = :uglifier
19
18
 
@@ -7,6 +7,8 @@ ScssProject::Application.configure do
7
7
  # and recreated between test runs. Don't rely on the data there!
8
8
  config.cache_classes = true
9
9
 
10
+ config.eager_load = false
11
+
10
12
  # Configure static asset server for tests with Cache-Control for performance
11
13
  config.serve_static_assets = true
12
14
  config.static_cache_control = "public, max-age=3600"
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ class ScaffoldGeneratorTest < Sass::Rails::TestCase
4
+ test "scss files are generated during scaffold generation of scss projects" do
5
+ within_rails_app "scss_project" do
6
+ generate_scaffold
7
+ assert_file_exists "app/assets/stylesheets/foos.css.scss"
8
+ assert_file_exists "app/assets/stylesheets/scaffolds.css.scss"
9
+ assert_not_output /conflict/
10
+ end
11
+ end
12
+
13
+ test "sass files are generated during scaffold generation of sass projects" do
14
+ within_rails_app "sass_project" do
15
+ generate_scaffold
16
+ assert_file_exists "app/assets/stylesheets/foos.css.sass"
17
+ assert_file_exists "app/assets/stylesheets/scaffolds.css.sass"
18
+ assert_not_output /conflict/
19
+ end
20
+ end
21
+
22
+ test "scss files are generated during scaffold generation of a engine project, if is called with --stylesheet-engine=scss" do
23
+ within_rails_app "engine_project" do
24
+ generate_scaffold "--stylesheet-engine=scss"
25
+ assert_file_exists "app/assets/stylesheets/engine_project/foos.css.scss"
26
+ assert_file_exists "app/assets/stylesheets/scaffolds.css.scss"
27
+ assert_not_output /conflict/
28
+ end
29
+ end
30
+
31
+ test "sass files are generated during scaffold generation of a engine project, if is called with --stylesheet-engine=sass" do
32
+ within_rails_app "engine_project" do
33
+ generate_scaffold "--stylesheet-engine=sass"
34
+ assert_file_exists "app/assets/stylesheets/engine_project/foos.css.sass"
35
+ assert_file_exists "app/assets/stylesheets/scaffolds.css.sass"
36
+ assert_not_output /conflict/
37
+ end
38
+ end
39
+
40
+ # DISABLED because we've removed the feature for now.
41
+ # test "scss template has correct dasherized css class for namespaced controllers" do
42
+ # within_rails_app "scss_project" do
43
+ # runcmd "rails generate controller foo/bar"
44
+ # assert_file_exists "app/assets/stylesheets/foo/bar.css.scss"
45
+ # assert_match /\.foo-bar/, File.read("app/assets/stylesheets/foo/bar.css.scss")
46
+ # end
47
+ # end
48
+ #
49
+ # test "sass template has correct dasherized css class for namespaced controllers" do
50
+ # within_rails_app "sass_project" do
51
+ # runcmd "rails generate controller foo/bar"
52
+ # assert_file_exists "app/assets/stylesheets/foo/bar.css.sass"
53
+ # assert_match /\.foo-bar/, File.read("app/assets/stylesheets/foo/bar.css.sass")
54
+ # end
55
+ # end
56
+
57
+ private
58
+
59
+ def generate_scaffold(args = nil)
60
+ runcmd "bundle exec rails generate scaffold foo #{args}"
61
+ end
62
+ end
@@ -12,7 +12,7 @@ class SassRailsLoggerTest < Sass::Rails::TestCase
12
12
  within_rails_app "scss_project" do |app_root|
13
13
  [:debug, :warn, :info, :error, :trace].each do |level|
14
14
  message = "[#{level}]: sass message"
15
- runcmd %{ruby script/rails runner "Sass::logger.log_level = :#{level}; Sass::logger.log(:#{level}, %Q|#{message}|)"}
15
+ runcmd %{ruby script/rails runner "Sass::logger.log_level = :#{level}; Sass::logger.log(:#{level}, %Q|#{message}|)"}, Dir.pwd, true, 'Gemfile', { 'RAILS_ENV' => 'development' }
16
16
 
17
17
  assert File.exists?("#{app_root}/log/development.log"), "log file was not created"
18
18
 
@@ -1,128 +1,74 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class SassRailsTest < Sass::Rails::TestCase
4
- test "classes are loaded" do
4
+ test 'classes are loaded' do
5
5
  assert_kind_of Module, Sass::Rails
6
- assert_kind_of Class, Sass::Rails::CssCompressor
7
6
  assert_kind_of Class, Sass::Rails::Railtie
8
7
  end
9
8
 
10
- test "style config item is honored" do
11
- within_rails_app "alternate_config_project" do
12
- runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'", Dir.pwd, true, "Gemfile", {"RAILS_ENV" => "development"}
13
- assert_output(/compact/)
9
+ test 'style config item is honored in development mode' do
10
+ within_rails_app 'alternate_config_project' do
11
+ runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'", Dir.pwd, true, 'Gemfile', {'RAILS_ENV' => 'development'}
12
+ assert_output /compact/
14
13
  end
15
14
  end
16
15
 
17
- test "css_compressor config item is honored" do
18
- within_rails_app "alternate_config_project" do
19
- runcmd "ruby script/rails runner 'puts Rails.application.config.assets.css_compressor'", Dir.pwd, true, "Gemfile", {"RAILS_ENV" => "production"}
20
- assert_output(/yui/)
16
+ test 'style config item is not honored if environment is not development' do
17
+ within_rails_app 'alternate_config_project' do
18
+ runcmd "ruby script/rails runner 'p Rails.application.config.sass.style'", Dir.pwd, true, 'Gemfile', {'RAILS_ENV' => 'production'}
19
+ assert_equal 'nil', $last_ouput.chomp
21
20
  end
22
21
  end
23
22
 
24
- # This tests both the railtie responsible for passing in the :compact style, and the compressor for honoring it
25
- test "compressor outputs compact style when specified in config" do
26
- command =<<END_OF_COMMAND
27
- puts Rails.application.config.assets.css_compressor.compress(<<CSS)
28
- div {
29
- color: red;
30
- }
31
- span {
32
- color: blue;
33
- }
34
- CSS
35
- END_OF_COMMAND
36
- within_rails_app "alternate_config_project" do
37
- runcmd "ruby script/rails runner '#{command}'", Dir.pwd, true, "Gemfile", {"RAILS_ENV" => "development"}
38
- assert_line_count(3)
23
+ test 'css_compressor config item is not honored in development mode' do
24
+ within_rails_app 'alternate_config_project' do
25
+ runcmd "ruby script/rails runner 'p Rails.application.config.assets.css_compressor'", Dir.pwd, true, 'Gemfile', {'RAILS_ENV' => 'development'}
26
+ assert_equal 'nil', $last_ouput.chomp
39
27
  end
40
28
  end
41
29
 
42
- test "compressor outputs compressed style when no style is specified but compression is true" do
43
- command =<<END_OF_COMMAND
44
- puts Rails.application.config.assets.css_compressor.compress(<<CSS)
45
- div {
46
- color: red;
47
- }
48
- span {
49
- color: blue;
50
- }
51
- CSS
52
- END_OF_COMMAND
53
- within_rails_app "alternate_config_project" do
54
- runcmd "ruby script/rails runner '#{command}'", Dir.pwd, true, "Gemfile", {"RAILS_ENV" => "test"}
55
- assert_line_count(1)
30
+ test 'css_compressor config item is honored if environment is not development' do
31
+ within_rails_app 'alternate_config_project' do
32
+ runcmd "ruby script/rails runner 'puts Rails.application.config.assets.css_compressor'", Dir.pwd, true, 'Gemfile', {'RAILS_ENV' => 'production'}
33
+ assert_output /yui/
56
34
  end
57
35
  end
58
36
 
59
- test "sass uses expanded style by default when no compression" do
60
- within_rails_app "scss_project" do
61
- runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'", Dir.pwd, true, "Gemfile", {"RAILS_ENV" => "development"}
62
- assert_output(/expanded/)
37
+ test 'sass uses expanded style by default in development mode' do
38
+ within_rails_app 'scss_project' do
39
+ runcmd "ruby script/rails runner 'puts Rails.application.config.sass.style'", Dir.pwd, true, 'Gemfile', {'RAILS_ENV' => 'development'}
40
+ assert_output /expanded/
63
41
  end
64
42
  end
65
43
 
66
- test "scss files are generated during scaffold generation of scss projects" do
67
- within_rails_app "scss_project" do
68
- generate_scaffold
69
- assert_file_exists "app/assets/stylesheets/foos.css.scss"
70
- assert_file_exists "app/assets/stylesheets/scaffolds.css.scss"
71
- assert_not_output(/conflict/)
44
+ test 'sass not defines compressor in development mode' do
45
+ within_rails_app 'scss_project' do
46
+ runcmd "ruby script/rails runner 'p Rails.application.config.assets.css_compressor'", Dir.pwd, true, 'Gemfile', {'RAILS_ENV' => 'development'}
47
+ assert_equal 'nil', $last_ouput.chomp
72
48
  end
73
49
  end
74
50
 
75
- test "sass files are generated during scaffold generation of sass projects" do
76
- within_rails_app "sass_project" do
77
- generate_scaffold
78
- assert_file_exists "app/assets/stylesheets/foos.css.sass"
79
- assert_file_exists "app/assets/stylesheets/scaffolds.css.sass"
80
- assert_not_output(/conflict/)
51
+ test 'sass defines compressor by default in test mode' do
52
+ within_rails_app 'scss_project' do
53
+ runcmd "ruby script/rails runner 'puts Rails.application.config.assets.css_compressor'", Dir.pwd, true, 'Gemfile', {'RAILS_ENV' => 'test'}
54
+ assert_equal 'sass', $last_ouput.chomp
81
55
  end
82
56
  end
83
57
 
84
- test "scss files are generated during scaffold generation of a engine project" do
85
- within_rails_app "engine_project" do
86
- generate_scaffold
87
- assert_file_exists "app/assets/stylesheets/engine_project/foos.css.scss"
88
- assert_file_exists "app/assets/stylesheets/scaffolds.css.scss"
89
- assert_not_output(/conflict/)
58
+ test 'sass defines compressor by default in production mode' do
59
+ within_rails_app 'scss_project' do
60
+ runcmd "ruby script/rails runner 'puts Rails.application.config.assets.css_compressor'", Dir.pwd, true, 'Gemfile', {'RAILS_ENV' => 'production'}
61
+ assert_equal 'sass', $last_ouput.chomp
90
62
  end
91
63
  end
92
64
 
93
- test "sass files are generated during scaffold generation of a engine project, if is called with --stylesheet-engine=sass" do
94
- within_rails_app "engine_project" do
95
- generate_scaffold "--stylesheet-engine=sass"
96
- assert_file_exists "app/assets/stylesheets/engine_project/foos.css.sass"
97
- assert_file_exists "app/assets/stylesheets/scaffolds.css.sass"
98
- assert_not_output(/conflict/)
99
- end
100
- end
101
-
102
- # DISABLED because we've removed the feature for now.
103
- # test "scss template has correct dasherized css class for namespaced controllers" do
104
- # within_rails_app "scss_project" do
105
- # runcmd "rails generate controller foo/bar"
106
- # assert_file_exists "app/assets/stylesheets/foo/bar.css.scss"
107
- # assert_match /\.foo-bar/, File.read("app/assets/stylesheets/foo/bar.css.scss")
108
- # end
109
- # end
110
- #
111
- # test "sass template has correct dasherized css class for namespaced controllers" do
112
- # within_rails_app "sass_project" do
113
- # runcmd "rails generate controller foo/bar"
114
- # assert_file_exists "app/assets/stylesheets/foo/bar.css.sass"
115
- # assert_match /\.foo-bar/, File.read("app/assets/stylesheets/foo/bar.css.sass")
116
- # end
117
- # end
118
- #
119
- test "sprockets require works correctly" do
120
- css_output = sprockets_render("scss_project", "css_application.css")
65
+ test 'sprockets require works correctly' do
66
+ css_output = sprockets_render('scss_project', 'css_application.css')
121
67
  assert_match /globbed/, css_output
122
68
  end
123
69
 
124
- test "sass imports work correctly" do
125
- css_output = sprockets_render("scss_project", "application.css.scss")
70
+ test 'sass imports work correctly' do
71
+ css_output = sprockets_render('scss_project', 'application.css.scss')
126
72
  assert_match /main/, css_output
127
73
  assert_match /top-level/, css_output
128
74
  assert_match /partial-sass/, css_output
@@ -135,42 +81,36 @@ END_OF_COMMAND
135
81
  assert_match /plain-old-css/, css_output
136
82
  assert_match /another-plain-old-css/, css_output
137
83
  assert_match /without-css-ext/, css_output
84
+ assert_match /css-erb-handler/, css_output
85
+ assert_match /scss-erb-handler/, css_output
86
+ assert_match /sass-erb-handler/, css_output
87
+ assert_match /css-sass-erb-handler/, css_output
88
+ assert_match /css-scss-erb-handler/, css_output
89
+ assert_match /default-old-css/, css_output
138
90
  end
139
91
 
140
- test "sass asset paths work" do
141
- css_output = sprockets_render("scss_project", "application.css.scss")
142
- assert_match %r{asset-path:\s*"/assets/rails.png"}, css_output, 'asset-path:\s*"/assets/rails.png"'
143
- assert_match %r{asset-url:\s*url\(/assets/rails.png\)}, css_output, 'asset-url:\s*url\(/assets/rails.png\)'
144
- assert_match %r{image-path:\s*"/assets/rails.png"}, css_output, 'image-path:\s*"/assets/rails.png"'
145
- assert_match %r{image-url:\s*url\(/assets/rails.png\)}, css_output, 'image-url:\s*url\(/assets/rails.png\)'
146
- assert_match %r{video-path:\s*"/assets/rails.mp4"}, css_output, 'video-path:\s*"/assets/rails.mp4"'
147
- assert_match %r{video-url:\s*url\(/assets/rails.mp4\)}, css_output, 'video-url:\s*url\(/assets/rails.mp4\)'
148
- assert_match %r{audio-path:\s*"/assets/rails.mp3"}, css_output, 'audio-path:\s*"/assets/rails.mp3"'
149
- assert_match %r{audio-url:\s*url\(/assets/rails.mp3\)}, css_output, 'audio-url:\s*url\(/assets/rails.mp3\)'
150
- assert_match %r{font-path:\s*"/assets/rails.ttf"}, css_output, 'font-path:\s*"/assets/rails.ttf"'
151
- assert_match %r{font-url:\s*url\(/assets/rails.ttf\)}, css_output, 'font-url:\s*url\(/assets/rails.ttf\)'
152
- assert_match %r{font-url-with-query-hash:\s*url\(/assets/rails.ttf\?#iefix\)}, css_output, 'font-url:\s*url\(/assets/rails.ttf?#iefix\)'
153
- assert_match %r{javascript-path:\s*"/assets/rails.js"}, css_output, 'javascript-path:\s*"/assets/rails.js"'
154
- assert_match %r{javascript-url:\s*url\(/assets/rails.js\)}, css_output, 'javascript-url:\s*url\(/assets/rails.js\)'
155
- assert_match %r{stylesheet-path:\s*"/assets/rails.css"}, css_output, 'stylesheet-path:\s*"/assets/rails.css"'
156
- assert_match %r{stylesheet-url:\s*url\(/assets/rails.css\)}, css_output, 'stylesheet-url:\s*url\(/assets/rails.css\)'
92
+ test 'sass asset paths work' do
93
+ css_output = sprockets_render('scss_project', 'application.css.scss')
94
+ assert_match %r{asset-path:\s*"/assets/rails.png"}, css_output, 'asset-path:\s*"/assets/rails.png"'
95
+ assert_match %r{asset-url:\s*url\(/assets/rails.png\)}, css_output, 'asset-url:\s*url\(/assets/rails.png\)'
96
+ assert_match %r{image-path:\s*"/assets/rails.png"}, css_output, 'image-path:\s*"/assets/rails.png"'
97
+ assert_match %r{image-url:\s*url\(/assets/rails.png\)}, css_output, 'image-url:\s*url\(/assets/rails.png\)'
98
+ assert_match %r{video-path:\s*"/videos/rails.mp4"}, css_output, 'video-path:\s*"/videos/rails.mp4"'
99
+ assert_match %r{video-url:\s*url\(/videos/rails.mp4\)}, css_output, 'video-url:\s*url\(/videos/rails.mp4\)'
100
+ assert_match %r{audio-path:\s*"/audios/rails.mp3"}, css_output, 'audio-path:\s*"/audios/rails.mp3"'
101
+ assert_match %r{audio-url:\s*url\(/audios/rails.mp3\)}, css_output, 'audio-url:\s*url\(/audios/rails.mp3\)'
102
+ assert_match %r{font-path:\s*"/fonts/rails.ttf"}, css_output, 'font-path:\s*"/fonts/rails.ttf"'
103
+ assert_match %r{font-url:\s*url\(/fonts/rails.ttf\)}, css_output, 'font-url:\s*url\(/fonts/rails.ttf\)'
104
+ assert_match %r{font-url-with-query-hash:\s*url\(/fonts/rails.ttf\?#iefix\)}, css_output, 'font-url:\s*url\(/fonts/rails.ttf?#iefix\)'
105
+ assert_match %r{javascript-path:\s*"/javascripts/rails.js"}, css_output, 'javascript-path:\s*"/javascripts/rails.js"'
106
+ assert_match %r{javascript-url:\s*url\(/javascripts/rails.js\)}, css_output, 'javascript-url:\s*url\(/javascripts/rails.js\)'
107
+ assert_match %r{stylesheet-path:\s*"/stylesheets/rails.css"}, css_output, 'stylesheet-path:\s*"/stylesheets/rails.css"'
108
+ assert_match %r{stylesheet-url:\s*url\(/stylesheets/rails.css\)}, css_output, 'stylesheet-url:\s*url\(/stylesheets/rails.css\)'
157
109
 
158
110
  asset_data_url_regexp = %r{asset-data-url:\s*url\((.*?)\)}
159
111
  assert_match asset_data_url_regexp, css_output, 'asset-data-url:\s*url\((.*?)\)'
160
112
  asset_data_url_match = css_output.match(asset_data_url_regexp)[1]
161
- asset_data_url_expected = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw%2FeHBhY2tldCBiZWdpbj0i77u%2FIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCNzY5NDE1QkQ2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCNzY5NDE1Q0Q2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiI%2BIDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkE3MzcyNTQ2RDY2QjExRTA5RTMzQTlDQTZFODJBQTFCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkI3Njk0MTVBRDY2QzExRTA5RTMzQTlDQTZFODJBQTFCIi8%2BIDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY%2BIDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8%2B0HhJ9AAAABBJREFUeNpi%2BP%2F%2FPwNAgAEACPwC%2FtuiTRYAAAAASUVORK5CYII%3D"
113
+ asset_data_url_expected = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw%2FeHBhY2tldCBiZWdpbj0i77u%2FIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCNzY5NDE1QkQ2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCNzY5NDE1Q0Q2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiI%2BIDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkE3MzcyNTQ2RDY2QjExRTA5RTMzQTlDQTZFODJBQTFCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkI3Njk0MTVBRDY2QzExRTA5RTMzQTlDQTZFODJBQTFCIi8%2BIDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY%2BIDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8%2B0HhJ9AAAABBJREFUeNpi%2BP%2F%2FPwNAgAEACPwC%2FtuiTRYAAAAASUVORK5CYII%3D'
162
114
  assert_equal asset_data_url_expected, asset_data_url_match
163
115
  end
164
-
165
- test "css compressor compresses" do
166
- assert_equal "div{color:red}\n", Sass::Rails::CssCompressor.new.compress(<<CSS)
167
- div {
168
- color: red;
169
- }
170
- CSS
171
- end
172
-
173
- def generate_scaffold(args = nil)
174
- runcmd "bundle exec rails generate scaffold foo #{args}"
175
- end
176
116
  end