Sha256: 15bf4e2dde2e254653ec06b98565c1e54194093213ca5c593747cdb6dba6a483

Contents?: true

Size: 1.94 KB

Versions: 27

Compression:

Stored size: 1.94 KB

Contents

require File.dirname(__FILE__) + '/helper'
require 'fixtures/apps/simple'

class TestSimpleReloader < Test::Unit::TestCase

  context 'for simple reset functionality' do

    should 'reset routes' do
      mock_app do
        1.step(10).each do |i|
          get("/#{i}") { "Foo #{i}" }
        end
      end
      1.step(10).each do |i|
        get "/#{i}"
        assert_equal "Foo #{i}", body
      end
      @app.reset_routes!
      1.step(10).each do |i|
        get "/#{i}"
        assert_equal 404, status
      end
    end

    should 'keep sinatra routes' do
      mock_app do
        get("/"){ "ok" }
      end
      get "/"
      assert_equal 200, status
      get "/__sinatra__/404.png"
      assert_equal 200, status
      assert_equal "image/png", response["Content-Type"]
      @app.reset_routes!
      get "/"
      assert_equal 404, status
      get "/__sinatra__/404.png"
      assert_equal 200, status
      assert_equal "image/png", response["Content-Type"]
    end
  end
  
  context 'for simple reload functionality' do
  
    should 'correctly instantiate SimpleDemo fixture' do
      Padrino.mounted_apps.clear
      Padrino.mount_core("simple_demo")
      assert_equal ["core"], Padrino.mounted_apps.collect(&:name)
      assert SimpleDemo.reload?
      assert_match %r{fixtures/apps/simple.rb}, SimpleDemo.app_file
    end
  
    should 'correctly reload SimpleDemo fixture' do
      @app = SimpleDemo
      get "/"
      assert_equal 200, status
      new_phrase = "The magick number is: #{rand(100)}!"
      buffer     = File.read(SimpleDemo.app_file)
      new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase)
      File.open(SimpleDemo.app_file, "w") { |f| f.write(new_buffer) }
      sleep 1.2 # We need at least a cooldown of 1 sec.
      get "/"
      assert_equal new_phrase, body
  
      # Now we need to prevent to commit a new changed file so we revert it
      File.open(SimpleDemo.app_file, "w") { |f| f.write(buffer) }
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
padrino-core-0.9.6 test/test_reloader_simple.rb
padrino-core-0.9.5 test/test_reloader_simple.rb
padrino-core-0.9.4 test/test_reloader_simple.rb
padrino-core-0.9.3 test/test_reloader_simple.rb
padrino-core-0.9.2 test/test_reloader_simple.rb
padrino-core-0.9.1 test/test_reloader_simple.rb
padrino-core-0.9.0 test/test_reloader_simple.rb
padrino-core-0.8.5 test/test_reloader_simple.rb
padrino-core-0.8.4 test/test_reloader_simple.rb
padrino-core-0.8.3 test/test_reloader_simple.rb
padrino-core-0.8.2 test/test_reloader_simple.rb
padrino-core-0.8.1 test/test_reloader_simple.rb
padrino-core-0.8.0 test/test_reloader_simple.rb
padrino-core-0.7.9 test/test_reloader_simple.rb
padrino-core-0.7.8 test/test_reloader_simple.rb
padrino-core-0.7.7 test/test_reloader_simple.rb
padrino-core-0.7.6 test/test_reloader_simple.rb
padrino-core-0.7.5 test/test_reloader_simple.rb
padrino-core-0.7.4 test/test_reloader_simple.rb
padrino-core-0.7.3 test/test_reloader_simple.rb