padrino-core 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -9,12 +9,18 @@ module Padrino
9
9
 
10
10
  # Helper method for file references.
11
11
  #
12
- # @param args [Array] Path components relative to ROOT_DIR.
13
- # @example Referencing a file in config called settings.yml:
12
+ # Example:
13
+ # # Referencing a file in config called settings.yml
14
14
  # Padrino.root("config", "settings.yml")
15
+ # # returns PADRINO_ROOT + "/config/setting.yml"
15
16
  def self.root(*args)
16
17
  File.join(PADRINO_ROOT, *args)
17
18
  end
19
+
20
+ # Helper method that return PADRINO_ENV
21
+ def self.env
22
+ PADRINO_ENV
23
+ end
18
24
 
19
25
  # Returns the resulting rack builder mapping each 'mounted' application
20
26
  def self.application
@@ -6,7 +6,7 @@ module Padrino
6
6
 
7
7
  def logger
8
8
  @log_stream ||= self.class.log_to_file? ? Padrino.root("log/#{PADRINO_ENV.downcase}.log") : $stdout
9
- @logger ||= Logger.new(@log_stream)
9
+ @logger ||= Logger.new(@log_stream)
10
10
  end
11
11
 
12
12
  class << self
@@ -27,14 +27,7 @@ module Padrino
27
27
  # Makes the routes defined in the block and in the Modules given
28
28
  # in `extensions` available to the application
29
29
  def controllers(*extensions, &block)
30
- @routes = Padrino::Application.dupe_routes if reload? # This performs a basic controller reload
31
- instance_eval(&block) if block_given?
32
- include(*extensions) if extensions.any?
33
- end
34
-
35
- # Makes the urls defined in the block and in the Modules given
36
- # in `extensions` available to the application
37
- def urls(*extensions, &block)
30
+ self.reset_routes! if reload?
38
31
  instance_eval(&block) if block_given?
39
32
  include(*extensions) if extensions.any?
40
33
  end
@@ -45,9 +38,9 @@ module Padrino
45
38
  # Invoked automatically when an application is first instantiated
46
39
  def setup_application!
47
40
  return if @configured
41
+ self.register_framework_extensions
48
42
  self.calculate_paths
49
43
  self.register_initializers
50
- self.register_framework_extensions
51
44
  self.require_load_paths
52
45
  self.setup_logger
53
46
  @configured = true
@@ -67,13 +60,15 @@ module Padrino
67
60
  set :default_builder, 'StandardFormBuilder'
68
61
  enable :flash
69
62
  # Plugin specific
63
+ enable :padrino_routing
64
+ enable :padrino_mailer
70
65
  enable :padrino_helpers
71
66
  end
72
67
 
73
68
  # Calculates any required paths after app_file and root have been properly configured
74
69
  # Executes as part of the setup_application! method
75
70
  def calculate_paths
76
- raise ApplicationSetupError.new("Please specify 'app_file' configuration option!") unless self.app_file
71
+ raise ApplicationSetupError.new("Please define 'app_file' option for #{self.name} app!") unless self.app_file
77
72
  set :views, find_view_path if find_view_path
78
73
  set :images_path, File.join(self.public, "/images") unless self.respond_to?(:images_path)
79
74
  end
@@ -93,9 +88,11 @@ module Padrino
93
88
 
94
89
  # Registers all desired padrino extension helpers/routing
95
90
  def register_framework_extensions
96
- register Padrino::Routing
97
- register Padrino::Mailer
91
+ return if @registered
92
+ register Padrino::Routing if padrino_routing?
93
+ register Padrino::Mailer if padrino_mailer?
98
94
  register Padrino::Helpers if padrino_helpers?
95
+ @registered = true
99
96
  end
100
97
 
101
98
  # Require all files within the application's load paths
@@ -105,9 +102,9 @@ module Padrino
105
102
 
106
103
  # Creates the log directory and redirects output to file if needed
107
104
  def setup_logger
108
- return unless self.log_to_file?
109
- FileUtils.mkdir_p 'log' unless File.exists?('log')
110
- log = File.new("log/#{PADRINO_ENV.downcase}.log", "a+")
105
+ return unless log_to_file?
106
+ FileUtils.mkdir_p("#{Padrino.root}/log") unless File.exists?("#{Padrino.root}/log")
107
+ log = File.new("#{Padrino.root}/log/#{PADRINO_ENV.downcase}.log", "a+")
111
108
  $stdout.reopen(log)
112
109
  $stderr.reopen(log)
113
110
  end
@@ -115,7 +112,8 @@ module Padrino
115
112
  # Returns the load_paths for the application (relative to the application root)
116
113
  def load_paths
117
114
  @load_paths ||= ["urls.rb", "config/urls.rb", "models/*.rb", "app/models/*.rb",
118
- "controllers/*.rb", "app/controllers/*.rb","helpers/*.rb", "app/helpers/*.rb"]
115
+ "mailers/*.rb", "app/mailers/*.rb", "controllers/*.rb", "app/controllers/*.rb",
116
+ "helpers/*.rb", "app/helpers/*.rb"]
119
117
  end
120
118
 
121
119
  # Returns the path to the views directory from root by returning the first that is found
@@ -123,6 +121,12 @@ module Padrino
123
121
  @view_paths = ["views", "app/views"].collect { |path| File.join(self.root, path) }
124
122
  @view_paths.find { |path| Dir[File.join(path, '/**/*')].any? }
125
123
  end
124
+
125
+ # Resets application routes for use in reloading the application
126
+ # This performs a basic routes reload (compatible with sinatra edge)
127
+ def reset_routes!
128
+ @routes = Padrino::Application.dupe_routes; load(self.app_file)
129
+ end
126
130
  end
127
131
  end
128
132
  end
@@ -3,7 +3,7 @@ module Padrino
3
3
  # Requires necessary dependencies as well as application files from root lib and models
4
4
  def load!
5
5
  load_required_gems # load bundler gems
6
- load_dependencies("#{root}/config/apps.rb", "#{root}/config/database.rb")
6
+ load_dependencies("#{root}/config/apps.rb", "#{root}/config/database.rb") # load configuration
7
7
  load_dependencies("#{root}/lib/**/*.rb", "#{root}/models/*.rb") # load root app dependencies
8
8
  reload! # We need to fill our Stat::CACHE but we do that only for development
9
9
  end
@@ -32,6 +32,7 @@ module Padrino
32
32
  require 'bundler'
33
33
  gemfile_path = root("Gemfile")
34
34
  puts "=> Loading GemFile #{gemfile_path} for #{PADRINO_ENV}"
35
+ # TODO possibly support padrino apps where no Gemfile is specified (skip requires, assume explicit dependencies)
35
36
  Bundler::Environment.load(gemfile_path).require_env(PADRINO_ENV)
36
37
  rescue Bundler::DefaultManifestNotFound => e
37
38
  puts "=> You didn't create Bundler Gemfile manifest or you are not in a Sinatra application."
@@ -5,11 +5,12 @@ module Padrino
5
5
  # @example Mounter.new("blog_app", :app_file => "/path/to/root/app.rb").to("/blog")
6
6
  # @example Mounter.new("blog_app", :app_class => "Blog").to("/blog")
7
7
  class Mounter
8
- attr_accessor :name, :uri_root, :app_file, :app_klass
8
+ attr_accessor :name, :uri_root, :app_file, :app_klass, :app_root
9
9
  def initialize(name, options={})
10
10
  @name = name
11
11
  @app_klass = options[:app_class] || name.classify
12
12
  @app_file = options[:app_file] || Padrino.mounted_root(name, 'app.rb')
13
+ @app_root = options[:app_root] if options[:app_root]
13
14
  end
14
15
 
15
16
  # Registers the mounted application onto Padrino
@@ -28,6 +29,7 @@ module Padrino
28
29
  builder.map self.uri_root do
29
30
  app_klass.set :uri_root, app_data.uri_root
30
31
  app_klass.set :app_file, app_data.app_file
32
+ app_klass.set :root, app_data.app_root if app_data.app_root
31
33
  run app_klass
32
34
  end
33
35
  end
@@ -36,7 +38,13 @@ module Padrino
36
38
  class << self
37
39
  # Returns the root to the mounted apps base directory
38
40
  def mounted_root(*args)
39
- File.join(Padrino.root, "apps", *args)
41
+ @mounted_root ||= "apps" # Other apps
42
+ File.join(Padrino.root, @mounted_root, *args)
43
+ end
44
+
45
+ # Set the root directory where padrino search mounted apps
46
+ def mounted_root=(value)
47
+ @mounted_root = value
40
48
  end
41
49
 
42
50
  # Returns the mounted padrino applications (MountedApp objects)
@@ -53,7 +61,7 @@ module Padrino
53
61
  # Mounts the core application onto Padrino project
54
62
  # @example Padrino.mount_core(:app_file => "/path/to/file", :app_class => "Blog")
55
63
  def mount_core(options={})
56
- options.reverse_merge!(:app_file => Padrino.root('app.rb'))
64
+ options.reverse_merge!(:app_file => Padrino.root('app/app.rb'), :app_root => Padrino.root)
57
65
  Mounter.new("core", options).to("/")
58
66
  end
59
67
  end
@@ -1,35 +1,59 @@
1
1
  require 'thor'
2
+ require File.dirname(__FILE__) + "/tasks/helpers"
2
3
 
3
4
  module Padrino
4
5
  module Tasks
5
6
  class Base < Thor
6
7
  include Thor::Actions
7
-
8
- desc "start", "Starts the Padrino application"
8
+ include Padrino::Tasks::Helpers
9
+
10
+ class_option :chdir, :type => :string, :aliases => "-c"
11
+
12
+ desc "start ", "Starts the Padrino application"
13
+
14
+ method_option :environment, :type => :string, :aliases => "-e", :required => true, :default => :development
15
+ method_option :adapter, :type => :string, :aliases => "-a", :required => true, :default => :thin
16
+ method_option :host, :type => :string, :aliases => "-h", :required => true, :default => "localhost"
17
+ method_option :port, :type => :numeric, :aliases => "-p", :required => true, :default => 3000
18
+ method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
19
+ method_option :daemonize, :type => :boolean, :aliases => "-d"
20
+
21
+ desc "start", "Start the Padrino application"
9
22
  def start
10
- say "Starting the Padrino application from root #{destination_root}"
23
+ require File.dirname(__FILE__) + "/tasks/adapter"
24
+ chdir(options.chdir)
25
+ Padrino::Tasks::Adapter.start(options)
11
26
  end
12
-
27
+
13
28
  desc "stop", "Stops the Padrino application"
14
29
  def stop
15
- say "Stopping the Padrino application"
30
+ require File.dirname(__FILE__) + "/tasks/adapter"
31
+ chdir(options.chdir)
32
+ Padrino::Tasks::Adapter.stop
16
33
  end
17
-
34
+
18
35
  desc "test", "Executes all the Padrino test files"
19
36
  def test
20
- say "Executing Padrino test files"
37
+ require File.dirname(__FILE__) + "/tasks/test"
38
+ chdir(options.chdir)
39
+ Padrino::Tasks::Test.start
21
40
  end
22
-
41
+
23
42
  desc "console ENVIRONMENT", "Boots up the Padrino application irb console"
43
+ method_option :boot, :type => :string, :aliases => "-b", :required => true, :default => "config/boot.rb"
24
44
  def console(environment="development")
25
- require File.dirname(__FILE__) + "/version.rb"
26
- raise "Are you in a Padrino Project? We didn't find config/boot.rb !!!" unless File.exist?("config/boot.rb")
45
+ require File.dirname(__FILE__) + "/version"
46
+ boot = options.chdir ? File.join(options.chdir, options.boot) : options.boot
47
+ unless File.exist?(boot)
48
+ puts "=> We didn't find boot file: #{boot} !!!"
49
+ exit
50
+ end
27
51
  ENV["PADRINO_ENV"] ||= environment
28
52
  puts "=> Loading #{environment} console (Padrino v.#{Padrino.version})"
29
53
  irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
30
- libs = " -r irb/completion"
31
- libs << " -r config/boot"
32
- libs << " -r #{File.dirname(__FILE__)}/tasks/console"
54
+ libs = " -r irb/completion"
55
+ libs << " -r #{boot}"
56
+ libs << " -r #{File.dirname(__FILE__)}/tasks/console"
33
57
  exec "#{irb} #{libs} --simple-prompt"
34
58
  end
35
59
  end
@@ -0,0 +1,93 @@
1
+ module Padrino
2
+ module Tasks
3
+ module Adapter
4
+
5
+ class << self
6
+
7
+ ADAPTERS = %w[thin mongrel webrick]
8
+
9
+ # Start for the given options a rackup handler
10
+ def start(options)
11
+
12
+ ENV["PADRINO_ENV"] = options.environment.to_s
13
+
14
+ boot = options.chdir ? File.join(options.chdir, options.boot) : options.boot
15
+ unless File.exist?(boot)
16
+ puts "=> Could not find boot file: #{boot.inspect} !!!"
17
+ exit
18
+ end
19
+ require boot
20
+
21
+ puts "=> Padrino/#{Padrino.version} has taken the stage #{options.environment} on port #{options.port}"
22
+
23
+ if options.daemonize?
24
+ unless fork
25
+ puts "=> Daemonized mode is not supported on your platform."
26
+ exit
27
+ end
28
+
29
+ stop # Need to stop a process if it exists
30
+
31
+ fork do
32
+ Process.setsid
33
+ exit if fork
34
+ File.umask 0000
35
+ puts "=> Padrino server has been daemonized with pid #{Process.pid}"
36
+ STDIN.reopen "/dev/null"
37
+ STDOUT.reopen "/dev/null", "a"
38
+ STDERR.reopen STDOUT
39
+
40
+ FileUtils.mkdir_p("tmp/pids") unless File.exist?("tmp/pids")
41
+ pid = "tmp/pids/server.pid"
42
+
43
+ if pid
44
+ File.open(pid, 'w'){ |f| f.write("#{Process.pid}") }
45
+ at_exit { File.delete(pid) if File.exist?(pid) }
46
+ end
47
+
48
+ run_app(options)
49
+
50
+ end
51
+ else
52
+ run_app(options)
53
+ end
54
+ end
55
+
56
+ # Method that run the Padrino.application
57
+ def run_app(options)
58
+
59
+ handler_name = options.adapter.to_s.capitalize
60
+
61
+ begin
62
+ handler = Rack::Handler.get(handler_name.downcase)
63
+ rescue
64
+ puts "#{handler_name} not supported yet, available adapters are: #{ADAPTERS.inspect}"
65
+ exit
66
+ end
67
+
68
+ handler.run Padrino.application, :Host => options.host, :Port => options.port do |server|
69
+ trap(:INT) do
70
+ # Use thins' hard #stop! if available, otherwise just #stop
71
+ server.respond_to?(:stop!) ? server.stop! : server.stop
72
+ puts "<= Padrino has ended his set (crowd applauds)"
73
+ end
74
+ end
75
+ rescue Errno::EADDRINUSE
76
+ puts "=> Someone is already performing on port #{options.port}!"
77
+ end
78
+
79
+ # Method that stop (if exist) a running Padrino.application
80
+ def stop
81
+ if File.exist?("tmp/pids/server.pid")
82
+ pid = File.read("tmp/pids/server.pid").to_i
83
+ print "=> Sending SIGTERM to process with pid #{pid} wait "
84
+ Process.kill(15, pid) rescue nil
85
+ 1.step(5) { |i| sleep i; print "."; $stdout.flush }
86
+ puts " done."
87
+ end
88
+ end
89
+
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,20 @@
1
+ module Padrino
2
+ module Tasks
3
+ module Helpers
4
+
5
+ def chdir(dir)
6
+ return unless dir
7
+ begin
8
+ Dir.chdir(dir.to_s)
9
+ rescue Errno::ENOENT
10
+ puts "=> Specified Padrino root '#{dir}' " +
11
+ "does not appear to exist!"
12
+ rescue Errno::EACCES
13
+ puts "=> Specified Padrino root '#{dir}' " +
14
+ "cannot be accessed by the current user!"
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Padrino
2
+ module Tasks
3
+ module Test
4
+
5
+ class << self
6
+
7
+ # This metod start testing for the given app.
8
+ # It look for any test/test_*.rb file in your app root.
9
+ def start
10
+ puts "=> Starting Test"
11
+ tests = Dir['test/**/test_*.rb'] - ['test/test_helper.rb']
12
+ cmd = "ruby -rubygems -I.:lib -e'%w( #{tests.join(' ')} ).each { |file| require file }'"
13
+ system cmd
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-core}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2009-11-18}
12
+ s.date = %q{2009-11-20}
13
13
  s.default_executable = %q{padrino}
14
14
  s.description = %q{The Padrino core gem required for use of this framework}
15
15
  s.email = %q{nesquena@gmail.com}
@@ -36,16 +36,21 @@ Gem::Specification.new do |s|
36
36
  "lib/padrino-core/stat.rb",
37
37
  "lib/padrino-core/support_lite.rb",
38
38
  "lib/padrino-core/tasks.rb",
39
+ "lib/padrino-core/tasks/adapter.rb",
39
40
  "lib/padrino-core/tasks/console.rb",
41
+ "lib/padrino-core/tasks/helpers.rb",
42
+ "lib/padrino-core/tasks/test.rb",
40
43
  "lib/padrino-core/version.rb",
41
44
  "padrino-core.gemspec",
42
45
  "test/active_support_helpers.rb",
43
- "test/fixtures/extended_app/app.rb",
46
+ "test/fixtures/simple_app/.components",
47
+ "test/fixtures/simple_app/.gitignore",
48
+ "test/fixtures/simple_app/Gemfile",
44
49
  "test/fixtures/simple_app/app.rb",
45
50
  "test/helper.rb",
51
+ "test/test_padrino_application.rb",
46
52
  "test/test_padrino_core.rb",
47
- "test/test_padrino_mounting.rb",
48
- "test/test_padrino_tasks.rb"
53
+ "test/test_padrino_mounter.rb"
49
54
  ]
50
55
  s.homepage = %q{http://github.com/padrino/padrino-core}
51
56
  s.rdoc_options = ["--charset=UTF-8"]
@@ -0,0 +1,6 @@
1
+ ---
2
+ :test: bacon
3
+ :mock: mocha
4
+ :orm: datamapper
5
+ :renderer: erb
6
+ :script: jquery
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ log/**/*
3
+ tmp/**/*
4
+ vendor/gems/gems
5
+ vendor/gems/specifications
6
+ vendor/gems/doc
7
+ vendor/gems/environment.rb
@@ -0,0 +1,9 @@
1
+ clear_sources
2
+ source 'http://gemcutter.org'
3
+
4
+ # Base requirements
5
+ gem 'sinatra', :require_as => 'sinatra/base'
6
+ gem 'rack-flash'
7
+
8
+ # Component requirements
9
+ gem 'haml'
@@ -1,10 +1,41 @@
1
+ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
2
  require 'sinatra/base'
2
3
  require 'haml'
4
+ require 'padrino-core'
3
5
 
4
- # PADRINO_ROOT = File.dirname(__FILE__)
6
+ class Core1Demo < Padrino::Application
7
+ set :app_file, File.dirname(__FILE__) + "/app.rb"
8
+ disable :padrino_routing
9
+ disable :padrino_mailer
10
+ disable :padrino_helpers
11
+
12
+ get "" do
13
+ "Im Core1Demo"
14
+ end
15
+ end
5
16
 
6
- class SimpleCoreDemo < Padrino::Application
7
- configure do
8
- set :root, File.dirname(__FILE__)
17
+ class Core2Demo < Padrino::Application
18
+ set :app_file, File.dirname(__FILE__) + "/app.rb"
19
+ disable :padrino_routing
20
+ disable :padrino_mailer
21
+ disable :padrino_helpers
22
+
23
+ get "" do
24
+ "Im Core2Demo"
9
25
  end
10
- end
26
+ end
27
+
28
+ class Core3Demo < Padrino::Application
29
+ enable :padrino_routing
30
+
31
+ # TODO enabling this causes an error (because routing not loaded yet)
32
+ # get :test, :map => '/test' do
33
+ # "This raises a large error"
34
+ # end
35
+ end
36
+
37
+ orig_stdout = $stdout
38
+ $stdout = log_buffer = StringIO.new
39
+ Padrino.load!
40
+ $stdout = orig_stdout
41
+ log_buffer.rewind && log_buffer.read
@@ -7,14 +7,10 @@ require 'webrat'
7
7
 
8
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+
10
11
  require 'active_support_helpers'
11
- require 'padrino-helpers'
12
- require 'padrino-core'
13
12
 
14
13
  class Test::Unit::TestCase
15
- include Padrino::Helpers::OutputHelpers
16
- include Padrino::Helpers::TagHelpers
17
- include Padrino::Helpers::AssetTagHelpers
18
14
  include Rack::Test::Methods
19
15
  include Webrat::Methods
20
16
  include Webrat::Matchers
@@ -29,25 +25,6 @@ class Test::Unit::TestCase
29
25
  return time
30
26
  end
31
27
 
32
- # assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
33
- # In this case, block is the html to evaluate
34
- def assert_has_tag(name, attributes = {}, &block)
35
- html = block && block.call
36
- matcher = HaveSelector.new(name, attributes)
37
- raise "Please specify a block!" if html.blank?
38
- assert matcher.matches?(html), matcher.failure_message
39
- end
40
-
41
- # assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
42
- # In this case, block is the html to evaluate
43
- def assert_has_no_tag(name, attributes = {}, &block)
44
- html = block && block.call
45
- attributes.merge!(:count => 0)
46
- matcher = HaveSelector.new(name, attributes)
47
- raise "Please specify a block!" if html.blank?
48
- assert matcher.matches?(html), matcher.failure_message
49
- end
50
-
51
28
  # Silences the output by redirecting to stringIO
52
29
  # silence_logger { ...commands... } => "...output..."
53
30
  def silence_logger(&block)
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ PADRINO_ENV = RACK_ENV = 'test' unless defined?(PADRINO_ENV)
4
+ require File.dirname(__FILE__) + '/fixtures/simple_app/app'
5
+ require 'padrino-core'
6
+
7
+ class TestPadrinoApplication < Test::Unit::TestCase
8
+
9
+ def app
10
+ Padrino.application.tap { }
11
+ end
12
+
13
+ def setup
14
+ Padrino.mounted_apps.clear
15
+ Padrino.mount("core_1_demo", :app_file => "#{Padrino.root("app.rb")}").to("/core_1_demo")
16
+ Padrino.mount("core_2_demo", :app_file => "#{Padrino.root("app.rb")}").to("/core_2_demo")
17
+ end
18
+
19
+ context 'for application functionality' do
20
+
21
+ should 'check methods' do
22
+ assert_respond_to Padrino::Application, :new
23
+ assert_respond_to Padrino::Application, :controllers
24
+ assert_respond_to Padrino::Application, :setup_application!
25
+ assert_respond_to Padrino::Application, :default_configuration!
26
+ assert_respond_to Padrino::Application, :calculate_paths
27
+ assert_respond_to Padrino::Application, :register_initializers
28
+ assert_respond_to Padrino::Application, :register_framework_extensions
29
+ assert_respond_to Padrino::Application, :require_load_paths
30
+ assert_respond_to Padrino::Application, :setup_logger
31
+ assert_respond_to Padrino::Application, :load_paths
32
+ assert_respond_to Padrino::Application, :find_view_path
33
+ end
34
+
35
+ should 'have controllers' do
36
+ Core1Demo.controllers do
37
+ get("/controller") { "Im a controller" }
38
+ end
39
+ visit "/core_1_demo/controller"
40
+ assert_contain "Im a controller"
41
+ end
42
+
43
+
44
+ end
45
+ end
@@ -1,17 +1,37 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
- # require File.dirname(__FILE__) + '/fixtures/simple_app/app'
2
+
3
+ PADRINO_ENV = RACK_ENV = 'test' unless defined?(PADRINO_ENV)
4
+ require File.dirname(__FILE__) + '/fixtures/simple_app/app'
5
+ require 'padrino-core'
3
6
 
4
7
  class TestPadrinoCore < Test::Unit::TestCase
8
+
5
9
  context 'for core functionality' do
10
+
11
+ should 'check global methods' do
12
+ assert_respond_to Padrino, :env
13
+ assert_respond_to Padrino, :root
14
+ assert_respond_to Padrino, :load!
15
+ assert_respond_to Padrino, :reload!
16
+ assert_respond_to Padrino, :load_dependencies
17
+ assert_respond_to Padrino, :load_required_gems
18
+ assert_respond_to Padrino, :mounted_root
19
+ assert_respond_to Padrino, :mounted_apps
20
+ assert_respond_to Padrino, :mount
21
+ assert_respond_to Padrino, :mount_core
22
+ assert_respond_to Padrino, :version
23
+ end
24
+
25
+ should 'validate global helpers' do
26
+ assert_equal "test", Padrino.env
27
+ assert_match %r{/test/fixtures/simple_app}, Padrino.root
28
+ end
6
29
 
7
- end
8
-
9
- context 'for loader functionality' do
10
-
11
-
12
- end
13
-
14
- context 'for application functionality' do
15
-
30
+ should 'raise application error if I instantiate a new padrino application without mounted apps' do
31
+ Padrino.mounted_apps.clear
32
+ assert_raise Padrino::ApplicationLoadError do
33
+ Padrino.application.tap { }
34
+ end
35
+ end
16
36
  end
17
37
  end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ PADRINO_ENV = RACK_ENV = 'test' unless defined?(PADRINO_ENV)
4
+ require File.dirname(__FILE__) + '/fixtures/simple_app/app'
5
+ require 'padrino-core'
6
+
7
+ class TestPadrinoMounter < Test::Unit::TestCase
8
+
9
+ def app
10
+ Padrino.application.tap { }
11
+ end
12
+
13
+ def setup
14
+ Padrino.mounted_apps.clear
15
+ Padrino.mount("core_1_demo", :app_file => "#{Padrino.root("app.rb")}").to("/core_1_demo")
16
+ Padrino.mount("core_2_demo", :app_file => "#{Padrino.root("app.rb")}").to("/core_2_demo")
17
+ end
18
+
19
+ context 'for mounter functionality' do
20
+
21
+ should 'check methods' do
22
+ mounter = Padrino::Mounter.new("test", :app_file => "/path/to/test.rb")
23
+ mounter.to("/test")
24
+ assert_kind_of Padrino::Mounter, mounter
25
+ assert_respond_to Padrino::Mounter, :new
26
+ assert_respond_to mounter, :to
27
+ assert_respond_to mounter, :map_onto
28
+ assert_equal "test", mounter.name
29
+ assert_equal "/path/to/test.rb", mounter.app_file
30
+ assert_equal "/test", mounter.uri_root
31
+ assert_nil mounter.app_root
32
+ end
33
+
34
+ should 'mount some apps' do
35
+ assert_equal ["core_1_demo", "core_2_demo"], Padrino.mounted_apps.collect(&:name)
36
+ end
37
+
38
+ should 'mount only a core' do
39
+ Padrino.mounted_apps.clear
40
+ Padrino.mount_core(:app_file => "#{Padrino.root("app.rb")}")
41
+ assert_equal ["core"], Padrino.mounted_apps.collect(&:name)
42
+ end
43
+
44
+ should 'correctly instantiate a new padrino application' do
45
+ visit '/core_1_demo'
46
+ assert_contain "Im Core1Demo"
47
+ visit '/core_2_demo'
48
+ assert_contain "Im Core2Demo"
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-11-18 00:00:00 -08:00
15
+ date: 2009-11-20 00:00:00 -08:00
16
16
  default_executable: padrino
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -110,16 +110,21 @@ files:
110
110
  - lib/padrino-core/stat.rb
111
111
  - lib/padrino-core/support_lite.rb
112
112
  - lib/padrino-core/tasks.rb
113
+ - lib/padrino-core/tasks/adapter.rb
113
114
  - lib/padrino-core/tasks/console.rb
115
+ - lib/padrino-core/tasks/helpers.rb
116
+ - lib/padrino-core/tasks/test.rb
114
117
  - lib/padrino-core/version.rb
115
118
  - padrino-core.gemspec
116
119
  - test/active_support_helpers.rb
117
- - test/fixtures/extended_app/app.rb
120
+ - test/fixtures/simple_app/.components
121
+ - test/fixtures/simple_app/.gitignore
122
+ - test/fixtures/simple_app/Gemfile
118
123
  - test/fixtures/simple_app/app.rb
119
124
  - test/helper.rb
125
+ - test/test_padrino_application.rb
120
126
  - test/test_padrino_core.rb
121
- - test/test_padrino_mounting.rb
122
- - test/test_padrino_tasks.rb
127
+ - test/test_padrino_mounter.rb
123
128
  has_rdoc: true
124
129
  homepage: http://github.com/padrino/padrino-core
125
130
  licenses: []
@@ -1,10 +0,0 @@
1
- require 'sinatra/base'
2
- require 'haml'
3
-
4
- # PADRINO_ROOT = File.dirname(__FILE__)
5
-
6
- class ExtendedCoreDemo < Padrino::Application
7
- configure do
8
- set :root, File.dirname(__FILE__)
9
- end
10
- end
@@ -1,8 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
- # require File.dirname(__FILE__) + '/fixtures/simple_app/app'
3
-
4
- class TestPadrinoMounting < Test::Unit::TestCase
5
- context 'for mounting applications functionality' do
6
-
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
- # require File.dirname(__FILE__) + '/fixtures/simple_app/app'
3
-
4
- class TestPadrinoTasks < Test::Unit::TestCase
5
- context 'for padrino command line tasks' do
6
-
7
- end
8
- end