Permalink
Browse files

Added unit tests

  • Loading branch information...
1 parent 913656d commit 68f2e4fe15838e9e53cb707fa7447980dc19dfdd @route route committed Nov 19, 2012
Showing with 74 additions and 19 deletions.
  1. +1 −0 .gitignore
  2. +9 −1 Rakefile
  3. +1 −3 lib/quiet_assets.rb
  4. +0 −3 lib/quiet_assets/version.rb
  5. +13 −12 quiet_assets.gemspec
  6. +50 −0 test/test_quiet_assets.rb
View
@@ -16,3 +16,4 @@ test/tmp
test/version_tmp
tmp
.idea/
+log
View
10 Rakefile 100644 → 100755
@@ -1,2 +1,10 @@
#!/usr/bin/env rake
-require "bundler/gem_tasks"
+require 'bundler/gem_tasks'
+
+require 'rake/testtask'
+
+task :default => :test
+
+task :test do
+ exec 'testrb test/test_*.rb'
+end
View
@@ -1,11 +1,9 @@
-require "quiet_assets/version"
-
module QuietAssets
class Engine < ::Rails::Engine
# Set as true but user can override it
config.quiet_assets = true
- initializer "quiet_assets", :after => "sprockets.environment" do |app|
+ initializer 'quiet_assets', :after => 'sprockets.environment' do |app|
if app.config.quiet_assets == true
# Parse PATH_INFO by assets prefix
ASSETS_PREFIX = "/#{app.config.assets.prefix[/\A\/?(.*?)\/?\z/, 1]}/"
@@ -1,3 +0,0 @@
-module QuietAssets
- VERSION = "1.0.1"
-end
View
@@ -1,16 +1,17 @@
-require File.expand_path('../lib/quiet_assets/version', __FILE__)
-
Gem::Specification.new do |gem|
- gem.name = "quiet_assets"
- gem.version = QuietAssets::VERSION
- gem.authors = ["Dmitry Karpunin", "Dmitry Vorotilin"]
- gem.email = ["koderfunk@gmail.com", "d.vorotilin@gmail.com"]
- gem.homepage = "http://github.com/evrone/quiet_assets"
- gem.description = "Quiet assets turn off rails assets log."
- gem.summary = "Turn off rails assets log."
+ gem.name = 'quiet_assets'
+ gem.version = '1.0.1'
+ gem.authors = ['Dmitry Karpunin', 'Dmitry Vorotilin']
+ gem.email = ['koderfunk@gmail.com', 'd.vorotilin@gmail.com']
+ gem.homepage = 'http://github.com/evrone/quiet_assets'
+ gem.description = 'Quiet assets turn off rails assets log.'
+ gem.summary = 'Turn off rails assets log.'
- gem.files = %w(LICENSE README.md lib/quiet_assets.rb lib/quiet_assets/version.rb quiet_assets.gemspec)
- gem.require_paths = ["lib"]
+ gem.files = %w(LICENSE README.md lib/quiet_assets.rb quiet_assets.gemspec)
+ gem.require_paths = %w(lib)
+ gem.test_files = %w(tests/test_quiet_assets.rb)
- gem.add_dependency "railties", ">= 3.1", "< 5.0"
+ gem.add_dependency 'railties', '>= 3.1', '< 5.0'
+ gem.add_development_dependency 'rake'
+ gem.add_development_dependency 'tzinfo'
end
@@ -0,0 +1,50 @@
+require 'rails'
+require 'tzinfo'
+require 'test/unit'
+require 'active_support'
+require 'action_controller'
+require 'active_support/testing/isolation'
+require File.expand_path('../../lib/quiet_assets', __FILE__)
+
+class HomeController < ActionController::Base
+ def index
+ render :text => 'Hi there!'
+ end
+end
+
+class HelperTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ attr_reader :app
+
+ def setup
+ @stdout = StringIO.new
+
+ @app = Class.new(Rails::Application) do
+ routes.append {
+ root :to => 'home#index'
+ get 'assets/picture' => 'home#index'
+ }
+
+ config.active_support.deprecation = :notify
+ config.secret_token = '685e1a60792fa0d036a82a52c0f97e42'
+ end
+
+ @app.initialize!
+
+ Rails.logger = Logger.new(@stdout)
+ Rails.logger.formatter = ->(s, d, p, m) { "#{m}\n" }
+ end
+
+ def test_assets_url
+ app.call Rack::MockRequest.env_for('/assets/picture')
+ @stdout.rewind
+ assert_equal '', @stdout.read
+ end
+
+ def test_regular_url
+ app.call Rack::MockRequest.env_for('/')
+ @stdout.rewind
+ assert_match /\A\n\nStarted GET \"\/\" for at/, @stdout.read
+ end
+end

0 comments on commit 68f2e4f

Please sign in to comment.