public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Merge branch 'master' of git@github.com:wycats/merb-core into wycats

* 'master' of git@github.com:wycats/merb-core:
  Make change_priveledge actually work
  bump merb-core version to 0.9.3 in prep for release.
  Add new -R/--rackup option to the full(-ish) list of options.
  Provide opts for alternate rackup config path. This is consistent with 
  --rackup option for thin and gives a little more freedom to specify the 
  rackup config (instead of being forced to rack.rb).
  Testing Merb::Test::RequestHelper#request method to properly handle 
  namespaced routes
  test request helpers support namespaced routes
  Added parentheses to be_kind_of to get rid of warnings when running 
  application_spec.rb
  Fixing pidfiles glob on cluster and pidfile argument
  replaced nested 'if' with an 'elseif'
  params array serialization
Michael S. Klishin (author)
Sat May 03 19:59:06 -0700 2008
commit  f35001ff89ff452ca1ac09cca3274cbd2912ffc4
tree    8bf820bafbec6eb0d27701b53f48a6101cce0c9c
parent  7f8f593329676577dd7588bb9dca9a889ae7b1d7 parent  76f58a0c22c40e3d86dc7fd7b4601abbfa0fa4d5
...
28
29
30
31
 
32
33
 
34
35
36
37
 
38
39
40
...
281
282
283
 
 
 
284
285
286
...
28
29
30
 
31
32
 
33
34
35
36
 
37
38
39
40
...
281
282
283
284
285
286
287
288
289
0
@@ -28,13 +28,13 @@
0
       Merb.environment = Merb::Config[:environment]
0
       Merb.root = Merb::Config[:merb_root]
0
       case Merb::Config[:action]
0
- when :kill
0
+ when :kill
0
         Merb::Server.kill(Merb::Config[:port], 1)
0
- when :kill_9
0
+ when :kill_9
0
         Merb::Server.kill(Merb::Config[:port], 9)
0
       else
0
         Merb::Server.start(Merb::Config[:port], Merb::Config[:cluster])
0
- end
0
+ end
0
     end
0
 
0
     # Start the Merb environment, but only if it hasn't been loaded yet.
0
@@ -281,6 +281,9 @@
0
     #
0
     # :adapter<String>:: name of Rack adapter to use,
0
     # default is "runner"
0
+ #
0
+ # :rackup<String>:: name of Rack init file to use,
0
+ # default is "rack.rb"
0
     #
0
     # :reload_classes<Boolean>:: whether Merb should reload
0
     # classes on each request,
...
550
551
552
553
554
555
556
 
 
 
557
558
559
560
561
 
 
 
 
 
 
562
563
564
...
550
551
552
 
 
 
 
553
554
555
556
557
558
559
 
560
561
562
563
564
565
566
567
568
0
@@ -550,15 +550,19 @@
0
 end
0
 
0
 class Merb::BootLoader::RackUpApplication < Merb::BootLoader
0
-
0
- # Setup the Merb Rack App or read a rack.rb config file located at the
0
- # Merb.root or Merb.root / config / rack.rb with the same syntax as the
0
- # rackup tool that comes with rack. Automatically evals the rack.rb file in
0
+ # Setup the Merb Rack App or read a rackup file located at
0
+ # Merb::Config[:rackup] with the same syntax as the
0
+ # rackup tool that comes with rack. Automatically evals the file in
0
   # the context of a Rack::Builder.new { } block. Allows for mounting
0
   # additional apps or middleware.
0
   def self.run
0
     if File.exists?(Merb.dir_for(:config) / "rack.rb")
0
- Merb::Config[:app] = eval("::Rack::Builder.new {( #{IO.read(Merb.dir_for(:config) / 'rack.rb')}\n )}.to_app", TOPLEVEL_BINDING, __FILE__, __LINE__)
0
+ Merb::Config[:rackup] ||= Merb.dir_for(:config) / "rack.rb"
0
+ end
0
+
0
+ if Merb::Config[:rackup]
0
+ rackup_code = File.read(Merb::Config[:rackup])
0
+ Merb::Config[:app] = eval("::Rack::Builder.new {( #{rackup_code}\n )}.to_app", TOPLEVEL_BINDING, Merb::Config[:rackup])
0
     else
0
       Merb::Config[:app] = ::Merb::Rack::Application.new
0
     end
...
166
167
168
 
 
 
 
169
170
171
...
166
167
168
169
170
171
172
173
174
175
0
@@ -166,6 +166,10 @@
0
             options[:adapter] = adapter
0
           end
0
 
0
+ opts.on("-R", "--rackup FILE", "Load an alternate Rack config file (default is config/rack.rb)") do |rackup|
0
+ options[:rackup] = rackup
0
+ end
0
+
0
           opts.on("-i", "--irb-console", "This flag will start merb in irb console mode. All your models and other classes will be available for you in an irb session.") do |console|
0
             options[:adapter] = 'irb'
0
           end
...
549
550
551
 
 
 
552
553
554
...
549
550
551
552
553
554
555
556
557
0
@@ -549,6 +549,9 @@
0
           parms[key] = val
0
         elsif after == "[]"
0
           (parms[key] ||= []) << val
0
+ elsif after =~ %r(^\[\])
0
+ parms[key] ||= []
0
+ parms[key] << normalize_params({}, after, val)
0
         else
0
           parms[key] ||= {}
0
           parms[key] = normalize_params(parms[key], after, val)
...
16
17
18
19
 
 
 
20
21
22
...
16
17
18
 
19
20
21
22
23
24
0
@@ -16,7 +16,9 @@
0
       def self.start(opts={})
0
         Merb.logger.warn!("Using Ebb adapter")
0
         Merb::Dispatcher.use_mutex = false
0
- ::Ebb.start_server(opts[:app], opts)
0
+ th = Thread.new { ::Ebb.start_server(opts[:app], opts) }
0
+ Merb::Server.change_privilege
0
+ th.join
0
       end
0
     end
0
   end
...
17
18
19
 
20
21
22
...
17
18
19
20
21
22
23
0
@@ -17,6 +17,7 @@
0
         Merb.logger.warn!("Using EventedMongrel adapter")
0
         Merb::Dispatcher.use_mutex = false
0
         server = ::Mongrel::HttpServer.new(opts[:host], opts[:port].to_i)
0
+ Merb::Server.change_privilege
0
         server.register('/', ::Merb::Rack::Handler::Mongrel.new(opts[:app]))
0
         server.run.join
0
       end
...
9
10
11
 
12
13
14
...
9
10
11
12
13
14
15
0
@@ -9,6 +9,7 @@
0
       # :app<String>>:: The application name.
0
       def self.start(opts={})
0
         Merb.logger.warn!("Using FastCGI adapter")
0
+ Merb::Server.change_privilege
0
         ::Rack::Handler::FastCGI.run(opts[:app], opts)
0
       end
0
     end
...
17
18
19
 
20
21
22
...
17
18
19
20
21
22
23
0
@@ -17,6 +17,7 @@
0
       def self.start(opts={})
0
         Merb.logger.warn!("Using Mongrel adapter")
0
         server = ::Mongrel::HttpServer.new(opts[:host], opts[:port].to_i)
0
+ Merb::Server.change_privilege
0
         server.register('/', ::Merb::Rack::Handler::Mongrel.new(opts[:app]))
0
         server.run.join
0
       end
...
13
14
15
 
16
17
18
...
13
14
15
16
17
18
19
0
@@ -13,6 +13,7 @@
0
       # If opts[:runner_code] matches a filename, that file will be read and
0
       # the contents executed. Otherwise the code will be executed directly.
0
       def self.start(opts={})
0
+ Merb::Server.change_privilege
0
         if opts[:runner_code]
0
           if File.exists?(opts[:runner_code])
0
             eval(File.read(opts[:runner_code]), TOPLEVEL_BINDING, __FILE__, __LINE__)
...
20
21
22
 
23
24
25
...
20
21
22
23
24
25
26
0
@@ -20,6 +20,7 @@
0
           opts[:host] = "#{opts[:host]}-#{opts[:port]}"
0
         end
0
         server = ::Thin::Server.start(opts[:host], opts[:port].to_i, opts[:app])
0
+ Merb::Server.change_privilege
0
         ::Thin::Logging.silent = true
0
         server.start!
0
       end
...
27
28
29
 
30
31
32
...
27
28
29
30
31
32
33
0
@@ -27,6 +27,7 @@
0
         }
0
      
0
         server = ::WEBrick::HTTPServer.new(options)
0
+ Merb::Server.change_privilege
0
         server.mount("/", ::Rack::Handler::WEBrick, opts[:app])
0
         server.start
0
       end
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
 
 
 
 
 
 
 
 
 
124
125
126
...
189
190
191
192
 
 
 
 
193
194
195
...
206
207
208
209
 
210
211
212
...
109
110
111
 
 
 
 
 
 
 
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
192
193
194
 
195
196
197
198
199
200
201
...
212
213
214
 
215
216
217
218
0
@@ -109,18 +109,21 @@
0
           Dir.chdir Merb::Config[:merb_root]
0
           at_exit { remove_pid_file(port) }
0
           Merb::Config[:port] = port
0
- if Merb::Config[:user]
0
- if Merb::Config[:group]
0
- change_privilege(Merb::Config[:user], Merb::Config[:group])
0
- else
0
- change_privilege(Merb::Config[:user])
0
- end
0
- end
0
           BootLoader.run
0
           Merb.adapter.start(Merb::Config.to_hash)
0
         end
0
       end
0
 
0
+ def change_privilege
0
+ if Merb::Config[:user]
0
+ if Merb::Config[:group]
0
+ _change_privilege(Merb::Config[:user], Merb::Config[:group])
0
+ else
0
+ _change_privilege(Merb::Config[:user])
0
+ end
0
+ end
0
+ end
0
+
0
       # Removes a PID file used by the server from the filesystem.
0
       # This uses :pid_file options from configuration when provided
0
       # or merb.<port>.pid in log directory by default.
0
@@ -189,7 +192,10 @@
0
       def pid_files
0
         if Merb::Config[:pid_file]
0
           if Merb::Config[:cluster]
0
- Dir[Merb::Config[:pid_file] + ".*.pid"]
0
+ ext = File.extname(Merb::Config[:pid_file])
0
+ base = File.basename(Merb::Config[:pid_file], ext)
0
+ dir = File.dirname(Merb::Config[:pid_file])
0
+ Dir[dir / "#{base}.*#{ext}"]
0
           else
0
             [ Merb::Config[:pid_file] ]
0
           end
0
@@ -206,7 +212,7 @@
0
       #
0
       # ==== Alternatives
0
       # If group is left out, the user will be used as the group.
0
- def change_privilege(user, group=user)
0
+ def _change_privilege(user, group=user)
0
 
0
         puts "Changing privileges to #{user}:#{group}"
0
 
...
245
246
247
248
 
 
 
249
250
251
...
245
246
247
 
248
249
250
251
252
253
0
@@ -245,7 +245,9 @@
0
         request = fake_request(env)
0
 
0
         opts = check_request_for_route(request) # Check that the request will be routed correctly
0
- klass = Object.full_const_get(opts.delete(:controller).to_const_string)
0
+ controller_name = (opts[:namespace] ? opts.delete(:namespace) + '/' : '') + opts.delete(:controller)
0
+ klass = Object.full_const_get(controller_name.snake_case.to_const_string)
0
+
0
         action = opts.delete(:action).to_s
0
         params.merge!(opts)
0
 
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 module Merb
0
- VERSION = '0.9.2' unless defined?(Merb::VERSION)
0
+ VERSION = '0.9.3' unless defined?(Merb::VERSION)
0
 
0
   # Merb::RELEASE meanings:
0
   # 'dev' : unreleased
...
4
5
6
7
 
8
9
10
11
12
13
 
14
15
16
17
 
18
19
20
21
22
 
23
24
25
 
 
26
27
 
28
29
 
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
43
44
45
46
 
47
48
49
 
50
51
52
53
54
55
56
 
57
58
59
60
61
 
62
63
64
 
65
66
 
67
68
69
70
71
 
72
73
74
 
 
75
76
 
77
78
79
80
 
 
 
81
82
 
83
84
85
 
 
 
86
87
88
89
90
91
92
 
93
94
95
96
97
 
98
99
100
101
102
 
103
104
105
106
107
 
108
109
110
111
112
113
 
 
 
 
 
 
114
115
116
...
120
121
122
123
 
124
125
126
...
130
131
132
133
 
134
135
136
...
140
141
142
143
 
144
145
146
...
151
152
153
154
 
155
...
4
5
6
 
7
8
9
10
11
12
 
13
14
15
16
 
17
18
19
20
21
 
22
23
 
 
24
25
26
 
27
28
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
43
44
45
 
46
47
48
 
49
50
51
52
53
54
55
 
56
57
58
59
60
 
61
62
63
 
64
65
 
66
67
68
69
70
 
71
72
73
 
74
75
76
 
77
78
79
80
81
82
83
84
85
 
86
87
88
89
90
91
92
93
94
95
96
97
98
 
99
100
101
102
103
 
104
105
106
107
108
 
109
110
111
112
113
 
114
115
116
117
118
119
 
120
121
122
123
124
125
126
127
128
...
132
133
134
 
135
136
137
138
...
142
143
144
 
145
146
147
148
...
152
153
154
 
155
156
157
158
...
163
164
165
 
166
167
0
@@ -4,29 +4,29 @@
0
   before do
0
     Merb::Config.setup
0
   end
0
-
0
+
0
   it "should be able to yield the configuration via #use" do
0
     res = nil
0
     Merb::Config.use {|c| res = c}
0
     res.should == Merb::Config.defaults
0
   end
0
-
0
+
0
   it "should be able to get a configuration key" do
0
     Merb::Config[:host].should == "0.0.0.0"
0
   end
0
-
0
+
0
   it "should be able to set a configuration key" do
0
     Merb::Config[:bar] = "Hello"
0
     Merb::Config[:bar].should == "Hello"
0
   end
0
-
0
+
0
   it "should be able to #delete a configuration key" do
0
- Merb::Config[:bar] = "Hello"
0
- Merb::Config[:bar].should == "Hello"
0
+ Merb::Config[:bar] = "Hello"
0
+ Merb::Config[:bar].should == "Hello"
0
     Merb::Config.delete(:bar)
0
- Merb::Config[:bar].should == nil
0
+ Merb::Config[:bar].should == nil
0
   end
0
-
0
+
0
   it "should be able to #fetch a key that does exist" do
0
     Merb::Config.fetch(:host, "192.168.2.1").should == "0.0.0.0"
0
   end
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
@@ -43,74 +43,86 @@
0
     Merb::Config.parse_args(["-u", "tester"])
0
     Merb::Config[:user].should == "tester"
0
   end
0
-
0
+
0
   it "should support -G to set the group to run Merb as" do
0
     Merb::Config.parse_args(["-G", "tester"])
0
- Merb::Config[:group].should == "tester"
0
+ Merb::Config[:group].should == "tester"
0
   end
0
 
0
   it "should support -f to set the filename to run Merb as" do
0
     Merb::Config.parse_args(["-d"])
0
     Merb::Config[:daemonize].should == true
0
   end
0
-
0
+
0
   it "should support -c to set the number of cluster nodes" do
0
     Merb::Config.parse_args(["-c", "4"])
0
     Merb::Config[:cluster].should == "4"
0
   end
0
-
0
+
0
   it "should support -p to set the port number" do
0
     Merb::Config.parse_args(["-p", "6000"])
0
- Merb::Config[:port].should == "6000"
0
+ Merb::Config[:port].should == "6000"
0
   end
0
-
0
+
0
   it "should support -P to set the PIDfile" do
0
     Merb::Config.parse_args(["-P", "pidfile"])
0
     Merb::Config[:pid_file].should == "pidfile"
0
   end
0
-
0
+
0
   it "should have server return PIDfile setting as is with no cluster nodes" do
0
     Merb::Config.parse_args(["-P", "pidfile", "-p", "6000"])
0
- Merb::Server.pid_file(6000).should == "pidfile"
0
+ Merb::Server.pid_file(6000).should == "pidfile"
0
+ Merb::Server.pid_files.should == ["pidfile"]
0
   end
0
-
0
+
0
   it "should support setting of PIDfile with cluster nodes" do
0
     Merb::Config.parse_args(["-P", "/tmp/merb.pidfile", "-c", "2", "-p", "6000"])
0
     Merb::Server.pid_file(6000).should == "/tmp/merb.6000.pidfile"
0
     Merb::Server.pid_file(6001).should == "/tmp/merb.6001.pidfile"
0
+
0
+ Dir.should_receive(:[]).with("/tmp/merb.*.pidfile")
0
+ Merb::Server.pid_files
0
   end
0
-
0
+
0
   it "should support default PIDfile setting" do
0
     Merb::Config.parse_args(["-p", "6000"])
0
     Merb::Server.pid_file(6000).should == Merb.log_path / "merb.6000.pid"
0
+
0
+ Dir.should_receive(:[]).with(Merb.log_path / "merb.*.pid")
0
+ Merb::Server.pid_files
0
   end
0
 
0
   it "should support -h to set the hostname" do
0
     Merb::Config.parse_args(["-h", "hostname"])
0
     Merb::Config[:host].should == "hostname"
0
   end
0
-
0
+
0
   it "should support -i to specify loading IRB" do
0
     Merb::Config.parse_args(["-i"])
0
     Merb::Config[:adapter].should == "irb"
0
   end
0
-
0
+
0
   it "should support -l to specify the log level" do
0
     Merb::Config.parse_args(["-l", "debug"])
0
     Merb::Config[:log_level].should == :debug
0
   end
0
-
0
+
0
   it "should support -L to specify the location of the log file" do
0
     Merb::Config.parse_args(["-L", "log_file"])
0
     Merb::Config[:log_file].should == "log_file"
0
   end
0
-
0
+
0
   it "should support -r to specify a runner" do
0
     Merb::Config.parse_args(["-r", "foo_runner"])
0
     Merb::Config[:runner_code].should == "foo_runner"
0
     Merb::Config[:adapter].should == "runner"
0
   end
0
-
0
+
0
+ it "should support -R to specify a rackup file" do
0
+ Merb::Config.parse_args(["-R", "config.ru"])
0
+ Merb::Config[:rackup].should == "config.ru"
0
+ end
0
+
0
   it "should support -K for a graceful kill" do
0
     Merb::Server.should_receive(:kill).with("all", 1)
0
     Merb.start(["-K", "all"])
0
@@ -120,7 +132,7 @@
0
     Merb::Server.should_receive(:kill).with("all", 9)
0
     Merb.start(["-k", "all"])
0
   end
0
-
0
+
0
   it "should support -X off to turn off the mutex" do
0
     Merb::Config.parse_args(["-X", "off"])
0
     Merb::Config[:use_mutex].should == false
0
@@ -130,7 +142,7 @@
0
     Merb::Config.parse_args(["-X", "on"])
0
     Merb::Config[:use_mutex].should == true
0
   end
0
-
0
+
0
   it "should take Merb.disable into account" do
0
     Merb::Config[:disabled_components].should == []
0
     Merb::Config[:disabled_components] << :foo
0
@@ -140,7 +152,7 @@
0
     Merb.disabled?(:foo).should == true
0
     Merb.disabled?(:foo, :buz).should == true
0
   end
0
-
0
+
0
   it "should take Merb.testing? into account" do
0
     $TESTING.should == true
0
     Merb::Config[:testing].should be_nil
0
@@ -151,6 +163,6 @@
0
     Merb.should be_testing
0
     $TESTING = true; Merb::Config[:testing] = false # reset
0
   end
0
-
0
+
0
 end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -1 +1,25 @@
0
+require File.dirname(__FILE__) + '/spec_helper'
0
+
0
+describe Merb::BootLoader::RackUpApplication do
0
+
0
+ it "should default to rack config (rack.rb)" do
0
+ options = {:merb_root => File.dirname(__FILE__) / 'fixture'}
0
+ Merb::Config.setup(options)
0
+ app = Merb::BootLoader::RackUpApplication.run
0
+ app.class.should == Merb::Rack::Application
0
+ end
0
+
0
+ it "should use rackup config that we specified" do
0
+ options = {:rackup => File.dirname(__FILE__) / 'fixture' / 'config' / 'black_hole.rb'}
0
+ Merb::Config.setup(options)
0
+ app = Merb::BootLoader::RackUpApplication.run
0
+ app.class.should == Rack::Adapter::BlackHole
0
+
0
+ env = Rack::MockRequest.env_for("/black_hole")
0
+ status, header, body = app.call(env)
0
+ status.should == 200
0
+ header.should == { "Content-Type" => "text/plain" }
0
+ body.should == ""
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -1 +1,13 @@
0
+# Alternate rackup config
0
+module Rack
0
+ module Adapter
0
+ class BlackHole
0
+ def call(env)
0
+ [ 200, { "Content-Type" => "text/plain" }, "" ]
0
+ end
0
+ end
0
+ end
0
+end
0
+
0
+run Rack::Adapter::BlackHole.new
...
11
12
13
14
 
15
16
17
...
11
12
13
 
14
15
16
17
0
@@ -11,7 +11,7 @@
0
   
0
   it "should return a MockResponse" do
0
     res = Rack::MockRequest.new(@app).get("")
0
- res.should be_kind_of Rack::MockResponse
0
+ res.should be_kind_of(Rack::MockResponse)
0
   end
0
   
0
 end
...
45
46
47
 
 
48
49
50
...
45
46
47
48
49
50
51
52
0
@@ -45,6 +45,8 @@
0
   
0
   {"foo=bar&baz=bat" => {"foo" => "bar", "baz" => "bat"},
0
    "foo[]=bar&foo[]=baz" => {"foo" => ["bar", "baz"]},
0
+ "foo[][bar]=1&foo[][bar]=2" => {"foo" => [{"bar" => "1"},{"bar" => "2"}]},
0
+ "foo[bar][][baz]=1&foo[bar][][baz]=2" => {"foo" => {"bar" => [{"baz" => "1"},{"baz" => "2"}]}},
0
    "foo[1]=bar&foo[2]=baz" => {"foo" => {"1" => "bar", "2" => "baz"}}}.each do |query, parse|
0
 
0
      it "should convert #{query.inspect} to #{parse.inspect} in the query string" do
...
28
29
30
 
 
 
 
 
 
 
 
...
28
29
30
31
32
33
34
35
36
37
38
0
@@ -28,4 +28,12 @@
0
     Merb::Test::ControllerAssertionMock.called(:destroy)
0
   end
0
 end
0
+
0
+module Namespaced
0
+ class SpecHelperController < Merb::Controller
0
+ def index
0
+ Merb::Test::ControllerAssertionMock.called(:index)
0
+ end
0
+ end
0
+end
...
160
161
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
164
165
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
0
@@ -160,6 +160,22 @@
0
       controller.params[:id].should == "my_id"
0
     end
0
   end
0
+
0
+ describe "#request" do
0
+ before(:each) do
0
+ Merb::Router.prepare do |r|
0
+ r.namespace :namespaced do |namespaced|
0
+ namespaced.resources :spec_helper_controller
0
+ end
0
+ end
0
+ end
0
+
0
+ it "should get namespaced index action" do
0
+ Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
0
+ controller = request("/namespaced/spec_helper_controller")
0
+ controller.class.should == Namespaced::SpecHelperController
0
+ end
0
+ end
0
 end
0
 
0
 module Merb::Test::RequestHelper

Comments

    No one has commented yet.