halcyon 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,10 +3,9 @@ describe "Halcyon" do
3
3
  before do
4
4
  @log = ''
5
5
  @logger = Logger.new(StringIO.new(@log))
6
- @config = $config.dup
7
- @config[:logger] = @logger
8
- @config[:app] = 'Specs'
9
- Halcyon.config = @config
6
+ Halcyon.config.use do |c|
7
+ c[:logger] = @logger
8
+ end
10
9
  @app = Halcyon::Runner.new
11
10
  end
12
11
 
@@ -15,11 +14,11 @@ describe "Halcyon" do
15
14
  end
16
15
 
17
16
  it "should provide quick access to the configuration hash" do
18
- Halcyon.config.is_a?(Hash).should.be.true?
17
+ Halcyon.config.is_a?(Halcyon::Config).should.be.true?
19
18
  end
20
19
 
21
20
  it "should provide environment label" do
22
- Halcyon.environment.should == :development
21
+ Halcyon.environment.should == :test
23
22
  Halcyon.environment.should == Halcyon.config[:environment]
24
23
  end
25
24
 
@@ -36,11 +35,12 @@ describe "Halcyon" do
36
35
  end
37
36
 
38
37
  it "should provide sane default paths for essential components" do
39
- Halcyon.paths.is_a?(Hash).should.be.true?
38
+ Halcyon.paths.is_a?(Halcyon::Config::Paths).should.be.true?
40
39
  Halcyon.paths[:controller].should == Halcyon.root/"app"
40
+ Halcyon.paths[:model].should == Halcyon.root/"app"/"models"
41
41
  Halcyon.paths[:lib].should == Halcyon.root/"lib"
42
42
  Halcyon.paths[:config].should == Halcyon.root/"config"
43
- Halcyon.paths[:init].should == Halcyon.root/"config"/"{init,initialize}"
43
+ Halcyon.paths[:init].should == Halcyon.root/"config"/"init"
44
44
  Halcyon.paths[:log].should == Halcyon.root/"log"
45
45
  end
46
46
 
@@ -3,9 +3,9 @@ describe "Halcyon::Application::Router" do
3
3
  before do
4
4
  @log = ''
5
5
  @logger = Logger.new(StringIO.new(@log))
6
- @config = $config.dup
7
- @config[:logger] = @logger
8
- Halcyon.config = @config
6
+ Halcyon.config.use do |c|
7
+ c[:logger] = @logger
8
+ end
9
9
  @app = Halcyon::Runner.new
10
10
  end
11
11
 
@@ -1,39 +1,23 @@
1
- module Kernel
2
- alias_method :__warn, :warn
3
- def warn(msg)
4
- $warning = msg
5
- __warn(msg) if $do_warns
6
- end
7
- end
8
-
9
1
  describe "Halcyon::Runner" do
10
2
 
11
3
  before do
12
4
  @log = ''
13
5
  @logger = Logger.new(StringIO.new(@log))
14
- @config = $config.dup
15
- @config[:logger] = @logger
16
- Halcyon.config = @config
6
+ Halcyon.config.use do |c|
7
+ c[:logger] = @logger
8
+ end
17
9
  @app = Halcyon::Runner.new
18
10
  end
19
11
 
20
- it "should warn if a non-existent config file is loaded" do
21
- $do_warns = false
22
- path = Halcyon.root/'config'/'config.yml'
23
- Halcyon::Runner.load_config(path).nil?.should == true
24
- $warning.should =~ %r{#{path} not found}
25
- $do_warns = true
26
- end
27
-
28
- it "should set up logging according to configuration" do
29
- time = Time.now.to_s
30
- @app.logger.debug "Test message for #{time}"
31
- @log.should =~ /Test message for #{time}/
32
- end
12
+ # it "should set up logging according to configuration" do
13
+ # time = Time.now.to_s
14
+ # @app.logger.debug "Test message for #{time}"
15
+ # @log.should =~ /Test message for #{time}/
16
+ # end
33
17
 
34
18
  it "should recognize what application it is running as" do
35
19
  # Without setting explicitly in config
36
- Halcyon.app.should == Halcyon.root.split('/').last.camel_case
20
+ Halcyon.app.should == "Specs" # set by the default config for test env
37
21
 
38
22
  # With setting explicitly in config
39
23
  Halcyon.config[:app] = 'Specr'
@@ -48,7 +32,7 @@ describe "Halcyon::Runner" do
48
32
  it "should proxy calls to Halcyon::Application" do
49
33
  status, headers, body = @app.call(Rack::MockRequest.env_for('/'))
50
34
  status.should == 200
51
- body.body[0].should == Specs.new(Rack::MockRequest.env_for('/')).send(:index).to_json
35
+ body.body[0].should == Specs.new(Rack::MockRequest.env_for('/')).send(:index).reject{|(k,v)|k == :headers}.to_json
52
36
  end
53
37
 
54
38
  end
data/spec/spec_helper.rb CHANGED
@@ -4,14 +4,7 @@ require 'logger'
4
4
 
5
5
  # Default Settings
6
6
 
7
- $config = {
8
- :allow_from => :all,
9
- :environment => :development,
10
- :logger => nil,
11
- :logging => {
12
- :level => 'debug'
13
- }
14
- }
7
+ Halcyon.config = Halcyon::Config.new(:environment => :test)
15
8
 
16
9
  # Testing Application
17
10
 
@@ -21,7 +14,14 @@ class Application < Halcyon::Controller; end
21
14
  # Weird edge-case controller
22
15
  class Specs < Application
23
16
 
17
+ before :before_index, :only => [:index]
18
+ after :after_everything_but_index, :except => [:index]
19
+ before :greeter do |controller|
20
+ raise NotFound.new if controller.params[:cause_exception_in_filter_block]
21
+ end
22
+
24
23
  def greeter
24
+ $hello = params[:name]
25
25
  ok("Hello #{params[:name]}")
26
26
  end
27
27
 
@@ -29,6 +29,24 @@ class Specs < Application
29
29
  ok('Found')
30
30
  end
31
31
 
32
+ # For testing headers in responses
33
+ def goob
34
+ ok "boog", 'Date' => Time.now.strftime("%a, %d %h %Y %H:%I:%S %Z"), 'Content-Language' => 'en'
35
+ end
36
+
37
+ # For testing various return types
38
+ def gaff
39
+ $return_value_for_gaff || ok
40
+ end
41
+
42
+ def foobar
43
+ ok('fubr')
44
+ end
45
+
46
+ def unprocessable_entity_test
47
+ error :unprocessable_entity
48
+ end
49
+
32
50
  def cause_exception
33
51
  raise Exception.new("Oops!")
34
52
  end
@@ -45,6 +63,14 @@ class Specs < Application
45
63
  "it's private, so it won't be found by the dispatcher"
46
64
  end
47
65
 
66
+ def before_index
67
+ raise Accepted.new if params[:cause_exception_in_filter]
68
+ end
69
+
70
+ def after_everything_but_index
71
+ raise Created.new if params[:cause_exception_in_filter]
72
+ end
73
+
48
74
  end
49
75
 
50
76
  # Resources controller
@@ -0,0 +1,42 @@
1
+ Halcyon.config.use do |c|
2
+
3
+ # = Framework
4
+ #
5
+ # <tt>allow_from</tt>: specifies what connections to accept;
6
+ # * <tt>all</tt>: allow connections from all clients
7
+ # * <tt>local</tt>: only allow connections from the same host (localhost et al)
8
+ # * <tt>halcyon_clients</tt>: only Halcyon clients (tests the User-Agent only)
9
+ c[:allow_from] = :all
10
+
11
+ # = Environment
12
+ #
13
+ # Uncomment to manually specify the environment to run the application in.
14
+ # Defaults to <tt>:development</tt>.
15
+ #
16
+ # c[:environment] = :production
17
+
18
+ # = Logging
19
+ #
20
+ # Configures the logging client in the framework, including destination,
21
+ # level filter, and what logger to use.
22
+ #
23
+ # <tt>type</tt>: the logger to use (defaults to Ruby's <tt>Logger</tt>)
24
+ # * <tt>Logger</tt>
25
+ # * <tt>Analogger</tt>
26
+ # * <tt>Logging</tt>
27
+ # * <tt>Log4r</tt>
28
+ # <tt>file</tt>: the log file; leave unset for STDOUT
29
+ # <tt>level</tt>: the message filter level (default to <tt>debug</tt>)
30
+ # * specific to the client used, often is: debug, info, warn, error, fatal
31
+ # = Logging
32
+ c[:logging] = {
33
+ :type => 'Logger',
34
+ # :file => nil, # nil is STDOUT
35
+ :level => 'debug'
36
+ }
37
+
38
+ # = Application
39
+ #
40
+ # Your application-specific configuration options here.
41
+
42
+ end
@@ -4,21 +4,14 @@ require 'halcyon'
4
4
  %w().each {|dep|require dep}
5
5
 
6
6
  # = Configuration
7
- # Halcyon.config = Halcyon::Runner.load_config
8
- Halcyon.config = {
9
- :allow_from => 'all',
10
- :logging => {
7
+ Halcyon.config.use do |c|
8
+ c[:allow_from] = :all
9
+ c[:logging] = {
11
10
  :type => 'Logger',
12
- # :file => nil, # STDOUT
11
+ # :file => nil, # nil is STDOUT
13
12
  :level => 'debug'
14
13
  }
15
- }.to_mash
16
-
17
- # = Environment
18
- # Set the environment if not set above; create the <tt>Halcyon.environment</tt>
19
- # configurable attribute. Maps to <tt>Halcyon.config[:environment]</tt>.
20
- Halcyon.configurable_attr(:environment)
21
- Halcyon.environment = :development unless Halcyon.environment
14
+ end
22
15
 
23
16
  # = Routes
24
17
  Halcyon::Application.route do |r|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halcyon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Todd
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-29 00:00:00 -04:00
12
+ date: 2008-06-26 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: merb
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -32,6 +34,7 @@ dependencies:
32
34
  version:
33
35
  - !ruby/object:Gem::Dependency
34
36
  name: json_pure
37
+ type: :runtime
35
38
  version_requirement:
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
@@ -41,6 +44,7 @@ dependencies:
41
44
  version:
42
45
  - !ruby/object:Gem::Dependency
43
46
  name: rubigen
47
+ type: :runtime
44
48
  version_requirement:
45
49
  version_requirements: !ruby/object:Gem::Requirement
46
50
  requirements:
@@ -65,6 +69,7 @@ files:
65
69
  - spec/halcyon
66
70
  - spec/halcyon/application_spec.rb
67
71
  - spec/halcyon/client_spec.rb
72
+ - spec/halcyon/config_spec.rb
68
73
  - spec/halcyon/controller_spec.rb
69
74
  - spec/halcyon/halcyon_spec.rb
70
75
  - spec/halcyon/logging_spec.rb
@@ -73,11 +78,17 @@ files:
73
78
  - spec/spec_helper.rb
74
79
  - lib/halcyon
75
80
  - lib/halcyon/application
81
+ - lib/halcyon/application/hooks.rb
76
82
  - lib/halcyon/application/router.rb
77
83
  - lib/halcyon/application.rb
78
84
  - lib/halcyon/client
79
85
  - lib/halcyon/client/ssl.rb
80
86
  - lib/halcyon/client.rb
87
+ - lib/halcyon/config
88
+ - lib/halcyon/config/file.rb
89
+ - lib/halcyon/config/helpers.rb
90
+ - lib/halcyon/config/paths.rb
91
+ - lib/halcyon/config.rb
81
92
  - lib/halcyon/controller.rb
82
93
  - lib/halcyon/exceptions.rb
83
94
  - lib/halcyon/logging
@@ -94,6 +105,8 @@ files:
94
105
  - lib/halcyon/runner/helpers.rb
95
106
  - lib/halcyon/runner.rb
96
107
  - lib/halcyon.rb
108
+ - lib/rack
109
+ - lib/rack/jsonp.rb
97
110
  - support/generators
98
111
  - support/generators/halcyon
99
112
  - support/generators/halcyon/halcyon_generator.rb
@@ -101,12 +114,11 @@ files:
101
114
  - support/generators/halcyon/templates/app
102
115
  - support/generators/halcyon/templates/app/application.rb
103
116
  - support/generators/halcyon/templates/config
104
- - support/generators/halcyon/templates/config/config.yml
105
117
  - support/generators/halcyon/templates/config/init
106
- - support/generators/halcyon/templates/config/init/environment.rb
107
118
  - support/generators/halcyon/templates/config/init/hooks.rb
108
119
  - support/generators/halcyon/templates/config/init/requires.rb
109
120
  - support/generators/halcyon/templates/config/init/routes.rb
121
+ - support/generators/halcyon/templates/config/init.rb
110
122
  - support/generators/halcyon/templates/lib
111
123
  - support/generators/halcyon/templates/lib/client.rb
112
124
  - support/generators/halcyon/templates/Rakefile
@@ -154,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
166
  requirements:
155
167
  - install the json gem to get faster JSON parsing
156
168
  rubyforge_project: halcyon
157
- rubygems_version: 1.1.0
169
+ rubygems_version: 1.2.0
158
170
  signing_key:
159
171
  specification_version: 2
160
172
  summary: A JSON App Server Framework
@@ -1,36 +0,0 @@
1
- # = Framework
2
- #
3
- # <tt>allow_from</tt>: specifies what connections to accept;
4
- # * <tt>all</tt>: allow connections from all clients
5
- # * <tt>local</tt>: only allow connections from the same host (localhost et al)
6
- # * <tt>halcyon_clients</tt>: only Halcyon clients (tests the User-Agent only)
7
- allow_from: all
8
-
9
- # = Environment
10
- #
11
- # Uncomment to manually specify the environment to run the application in.
12
- # Defaults to <tt>:development</tt>.
13
- #
14
- # environment: production
15
-
16
- # = Logging
17
- #
18
- # Configures the logging client in the framework, including destination,
19
- # level filter, and what logger to use.
20
- #
21
- # <tt>type</tt>: the logger to use (defaults to Ruby's <tt>Logger</tt>)
22
- # * <tt>Logger</tt>
23
- # * <tt>Analogger</tt>
24
- # * <tt>Logging</tt>
25
- # * <tt>Log4r</tt>
26
- # <tt>file</tt>: the log file; leave unset for STDOUT
27
- # <tt>level</tt>: the message filter level (default to <tt>debug</tt>)
28
- # * specific to the client used, often is: debug, info, warn, error, fatal
29
- logging:
30
- type: Logger
31
- # file: # STDOUT
32
- level: debug
33
-
34
- # = Application
35
- #
36
- # Your application-specific configuration options here.
@@ -1,11 +0,0 @@
1
- # = Environment
2
- #
3
- # Sets the environment unless already set.
4
- #
5
- # Creates the <tt>Halcyon.environment</tt> configurable attribute. Since this
6
- # is mapped to <tt>Halcyon.config[:environment]</tt>, environment can be set
7
- # by setting the <tt>environment:</tt> configuration value in the
8
- # <tt>config/config.yml</tt> file.
9
-
10
- Halcyon.configurable_attr(:environment)
11
- Halcyon.environment = :development unless Halcyon.environment