merb 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -140,7 +140,7 @@ module Merb
140
140
  # If you need to set a cookie, then use the +cookies+ hash.
141
141
  #
142
142
  def set_cookie(name, value, expires)
143
- (headers['Set-Cookie'] ||='') << (Merb::Const::SET_COOKIE % [
143
+ (headers['Set-Cookie'] ||=[]) << (Merb::Const::SET_COOKIE % [
144
144
  name.to_s,
145
145
  escape(value.to_s),
146
146
  # Cookie expiration time must be GMT. See RFC 2109
@@ -117,9 +117,22 @@ module Merb
117
117
  # end
118
118
  # end
119
119
  #
120
- # This will first check to see if a index.xml.* template extists, if not
121
- # it will call @people.to_xml (as defined in the add_mime_type method) on the passed
122
- # in object if such a method exists for the current content_type
120
+ # This will first check to see if a index.xml.* template extists, if not
121
+ # it will call @people.to_xml (as defined in the add_mime_type method) on the passed
122
+ # in object if such a method exists for the current content_type
123
+ #
124
+ # Conversely, there may be situations where you prefer to be more literal
125
+ # such as when you desire to render a Hash, for those occasions, the
126
+ # the following syntax exists:
127
+ #
128
+ # class People < Application
129
+ # provides :xml
130
+ #
131
+ # def index
132
+ # @people = User.all
133
+ # render :obj => @people
134
+ # end
135
+ # end
123
136
  #
124
137
  # When using multiple calls to render in one action, the context of the render is cached for performance reasons
125
138
  # That is, all instance variables are loaded into the view_context object only on the first call and then this is re-used.
@@ -139,7 +152,7 @@ module Merb
139
152
  choose_template_format(Merb.available_mime_types, opts)
140
153
 
141
154
  # Handles the case where render is called with an object
142
- if obj = args.first
155
+ if obj = args.first || opts[:obj]
143
156
  # Check for a template
144
157
  unless find_template({:action => action}.merge(opts))
145
158
  fmt = content_type
@@ -32,14 +32,22 @@ module Merb
32
32
  ::Merb::Config.parse_args
33
33
 
34
34
  if Merb::Config[:cluster]
35
- delete_pidfiles
36
35
  Merb::Config[:port].to_i.upto(Merb::Config[:port].to_i+Merb::Config[:cluster].to_i-1) do |port|
37
- puts "Starting merb server on port: #{port}"
38
- start(port)
36
+ unless alive?(port)
37
+ delete_pidfiles(port)
38
+ puts "Starting merb server on port: #{port}"
39
+ start(port)
40
+ else
41
+ raise "Merb is already running on port: #{port}"
42
+ end
39
43
  end
40
44
  elsif Merb::Config[:daemonize]
41
- delete_pidfiles(Merb::Config[:port])
42
- start(Merb::Config[:port])
45
+ unless alive?(Merb::Config[:port])
46
+ delete_pidfiles(Merb::Config[:port])
47
+ start(Merb::Config[:port])
48
+ else
49
+ raise "Merb is already running on port: #{port}"
50
+ end
43
51
  else
44
52
  trap('TERM') { exit }
45
53
  mongrel_start(Merb::Config[:port])
@@ -49,7 +57,16 @@ module Merb
49
57
 
50
58
  def store_pid(pid,port)
51
59
  File.open("#{Merb::Config[:merb_root]}/log/merb.#{port}.pid", 'w'){|f| f.write("#{Process.pid}\n")}
52
- end
60
+ end
61
+
62
+ def alive?(port)
63
+ f = Merb::Config[:merb_root] + "/log/merb.#{port}.pid"
64
+ pid = IO.read(f).chomp.to_i
65
+ Process.kill(0, pid)
66
+ true
67
+ rescue
68
+ false
69
+ end
53
70
 
54
71
  def kill(ports, sig=9)
55
72
  begin
@@ -40,9 +40,10 @@ module Merb
40
40
  def request(verb, path, opts = {}, &block)
41
41
  response = StringIO.new
42
42
 
43
- request = opts.delete(:fake_request) || Merb::Test::FakeRequest.with(path, opts.merge(:request_method => (verb.to_s.upcase rescue 'GET')))
44
43
  yield_to_controller = opts.delete(:yields)
45
44
 
45
+ request = opts.delete(:fake_request) || Merb::Test::FakeRequest.with(path_with_options(path, opts), :request_method => (verb.to_s.upcase rescue 'GET'))
46
+
46
47
  if yield_to_controller == :controller
47
48
  request_yielding_controller(request, response, &block)
48
49
  else
@@ -215,7 +216,10 @@ module Merb
215
216
  @controller = klass.build(request, response, status)
216
217
 
217
218
  @controller.send(:setup_session)
218
- @controller.stub!(:setup_session).and_return(true)
219
+ # This will be a mock framework agnostic way of ensuring setup_session is not done again
220
+ class << @controller
221
+ def setup_session; true; end
222
+ end
219
223
 
220
224
  yield @controller if block_given?
221
225
 
@@ -1,5 +1,5 @@
1
1
  module Merb
2
- VERSION = '0.5.2' unless defined?(::Merb::VERSION)
2
+ VERSION = '0.5.3' unless defined?(::Merb::VERSION)
3
3
 
4
4
  class << self
5
5
  def svn_revision
@@ -22,6 +22,8 @@ module Merb
22
22
  end
23
23
  # catch permissions error when packaged as gem
24
24
  rescue Errno::EACCES
25
+ # ... or packaged as gem, mounted on a Read-Only filesystem
26
+ rescue Errno::EROFS
25
27
  end
26
28
 
27
29
  unless (rev = File.read(svn_revision_file_path).strip).empty?
@@ -40,7 +42,8 @@ module Merb
40
42
  # nil : released
41
43
  # You should never check in to trunk with this changed. It should
42
44
  # stay 'svn'. Change it to nil in release tags.
43
- unless defined?(::Merb::RELEASE)
44
- RELEASE = nil #"svn#{" r#{svn_revision_from_file}" if svn_revision_from_file}"
45
- end
45
+ RELEASE=nil
46
+ # unless defined?(::Merb::RELEASE)
47
+ # RELEASE = "svn#{" r#{svn_revision_from_file}" if svn_revision_from_file}"
48
+ # end
46
49
  end
@@ -1,7 +1,7 @@
1
1
  def install_merb_script
2
2
  script_filepath = Merb.root / 'script/merb'
3
3
  FileUtils.rm script_filepath if File.exist? script_filepath
4
- tmpl = "#!/usr/bin/env ruby\nrequire File.expand_path(File.dirname(__FILE__)+'/../config/merb/boot')\nrequire File.expand_path(File.dirname(__FILE__)+'/../framework/merb/server')\nMerb::Server.run\n"
4
+ tmpl = "#!/usr/bin/env ruby\nrequire File.expand_path(File.dirname(__FILE__)+'/../config/boot')\nrequire File.expand_path(File.dirname(__FILE__)+'/../framework/merb/server')\nMerb::Server.run\n"
5
5
  File.open(script_filepath, 'wb') {|f|
6
6
  f.write tmpl
7
7
  f.chmod(0744)
@@ -62,6 +62,16 @@ class RenderObjectController < Merb::Controller
62
62
 
63
63
  end
64
64
 
65
+ class RenderHashObjectController < Merb::Controller
66
+
67
+ def render_object
68
+ provides :xml,:json
69
+ @foo = {:foo => 'bar', :baz => 'quuz'}
70
+ render :obj => @foo
71
+ end
72
+
73
+ end
74
+
65
75
  class RenderObjectWithArgumentsController < Merb::Controller
66
76
 
67
77
  provides :xml, :foo => 'bar'
@@ -158,7 +158,7 @@ describe "Dispatch and before/after filters" do
158
158
 
159
159
  it "should be able to see instance variables" do
160
160
  call_filter_action "one"
161
- @c.cookies.should be_is_a(Hash)
161
+ @c.cookies.should be_is_a(Merb::Cookies)
162
162
  @c.session.data.should == {}
163
163
  @c.response.read.should == ""
164
164
  @c.instance_variable_get("@filter1").should eql( 'called')
@@ -24,7 +24,7 @@ describe Merb::SessionMixin do
24
24
  it "should set the cookie if the cookie is changed" do
25
25
  c = new_controller( 'change', TestCookieSessionController)
26
26
  c.dispatch(:change)
27
- c.headers['Set-Cookie'].should =~ %r{_session_id=} # this could be better
27
+ c.headers['Set-Cookie'].each {|c| c.should =~ %r{_session_id=} }# this could be better
28
28
  end
29
29
  end
30
30
 
@@ -0,0 +1,96 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module CookiesSpecModule
4
+ def cookie_time(time)
5
+ time.gmtime.strftime(Merb::Const::COOKIE_EXPIRATION_FORMAT)
6
+ end
7
+ end
8
+
9
+ describe Merb::Cookies do
10
+ include CookiesSpecModule
11
+
12
+ before do
13
+ @_cookies = Mash.new
14
+ @_headers = {}
15
+ @cookies = Merb::Cookies.new(@_cookies, @_headers)
16
+ end
17
+
18
+ it "should respond to []" do
19
+ @cookies.should respond_to(:[])
20
+ end
21
+
22
+ it "should respond to []=" do
23
+ @cookies.should respond_to(:[]=)
24
+ end
25
+
26
+ it "should respond to delete" do
27
+ @cookies.should respond_to(:delete)
28
+ end
29
+
30
+ it "should accept simple cookies that expire at end of session" do
31
+ @cookies[:foo] = 'bar'
32
+
33
+ @_headers['Set-Cookie'].should == ['foo=bar; path=/;']
34
+
35
+ @cookies[:foo].should == 'bar'
36
+ @cookies['foo'].should == 'bar'
37
+ end
38
+
39
+ it "should accept cookies with expiry dates" do
40
+ expires = Time.now + 2.weeks
41
+ @cookies[:dozen] = {
42
+ :value => 'twelve',
43
+ :expires => expires
44
+ }
45
+
46
+ @_headers['Set-Cookie'].should ==
47
+ ["dozen=twelve; expires=%s; path=/;" % cookie_time(expires)]
48
+
49
+ @cookies[:dozen].should == 'twelve'
50
+ @cookies['dozen'].should == 'twelve'
51
+ end
52
+
53
+ it "should accept multiple cookies" do
54
+ expires = Time.now + 2.weeks
55
+ @cookies[:foo] = 'bar'
56
+ @cookies[:dozen] = {
57
+ :value => 'twelve',
58
+ :expires => expires
59
+ }
60
+
61
+ @_headers['Set-Cookie'].should == [
62
+ 'foo=bar; path=/;',
63
+ "dozen=twelve; expires=%s; path=/;" % cookie_time(expires)
64
+ ]
65
+
66
+ @cookies[:dozen].should == 'twelve'
67
+ @cookies['dozen'].should == 'twelve'
68
+ @cookies[:foo].should == 'bar'
69
+ @cookies['foo'].should == 'bar'
70
+ end
71
+
72
+ it "should give access to currently saved cookies" do
73
+ @_cookies[:original] = 'accessible'
74
+ @cookies[:original].should == 'accessible'
75
+
76
+ @cookies[:foo] = 'bar'
77
+ @cookies[:foo].should == 'bar'
78
+ @cookies[:original].should == 'accessible'
79
+ end
80
+
81
+ it "should overwrite old cookies with new cookies" do
82
+ @_cookies[:foo] = 'bar'
83
+ @cookies[:foo].should == 'bar'
84
+
85
+ @cookies[:foo] = 'new'
86
+ @cookies[:foo].should == 'new'
87
+ end
88
+
89
+ it "should allow deleting of cookies" do
90
+ @_cookies[:foo] = 'bar'
91
+ @cookies[:foo].should == 'bar'
92
+
93
+ @cookies.delete(:foo)
94
+ @cookies[:foo].should == nil
95
+ end
96
+ end
@@ -412,6 +412,23 @@ describe "Merb rendering with an object calls to_json or to_xml on the object (u
412
412
 
413
413
  end
414
414
 
415
+ describe "Merb rendering with a hash object calls to_json or to_xml on the object" do
416
+
417
+ it "render :obj => @foo should call @foo.to_json when json is requested" do
418
+ c = new_spec_controller(:format => 'json', :controller => 'RenderHashObjectController')
419
+ c.dispatch(:render_object)
420
+ JSON.load(c.body).should == {'baz' => "quuz", "foo" => "bar"}
421
+ end
422
+
423
+ it "render @foo should call @foo.to_xml when xml is requested" do
424
+ c = new_spec_controller(:format => 'xml', :controller => 'RenderHashObjectController')
425
+ c.dispatch(:render_object)
426
+ c.body.should match(/<\?xml version="1.0" encoding="UTF-8"\?>\n<hash>/m)
427
+ c.body.should match(/(<baz>quuz<\/baz>\n\s+<foo>bar<\/foo>\n<\/hash>)|(<foo>bar<\/foo>\n\s+<baz>quuz<\/baz>\n<\/hash>)/m)
428
+ end
429
+
430
+ end
431
+
415
432
  describe "Merb rendering with an object and using a block/lambda for provides" do
416
433
 
417
434
  it "render @foo should use the default block when xml is requested" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-14 00:00:00 -06:00
12
+ date: 2008-01-28 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -212,6 +212,7 @@ files:
212
212
  - spec/merb/controller_filters_spec.rb
213
213
  - spec/merb/controller_spec.rb
214
214
  - spec/merb/cookie_store_spec.rb
215
+ - spec/merb/cookies_spec.rb
215
216
  - spec/merb/core_ext
216
217
  - spec/merb/core_ext/class_spec.rb
217
218
  - spec/merb/core_ext/enumerable_spec.rb
@@ -251,7 +252,9 @@ files:
251
252
  - lib/merb
252
253
  - lib/merb/abstract_controller.rb
253
254
  - lib/merb/assets.rb
255
+ - lib/merb/assets.rb.orig
254
256
  - lib/merb/boot_loader.rb
257
+ - lib/merb/boot_loader.rb.orig
255
258
  - lib/merb/caching
256
259
  - lib/merb/caching/action_cache.rb
257
260
  - lib/merb/caching/fragment_cache.rb
@@ -262,6 +265,7 @@ files:
262
265
  - lib/merb/config.rb
263
266
  - lib/merb/constants.rb
264
267
  - lib/merb/controller.rb
268
+ - lib/merb/cookies.rb
265
269
  - lib/merb/core_ext
266
270
  - lib/merb/core_ext/array.rb
267
271
  - lib/merb/core_ext/class.rb
@@ -480,7 +484,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
480
484
  requirements:
481
485
  - install the json gem to get faster json parsing
482
486
  rubyforge_project:
483
- rubygems_version: 0.9.5
487
+ rubygems_version: 1.0.1
484
488
  signing_key:
485
489
  specification_version: 2
486
490
  summary: Merb == Mongrel + Erb. Pocket rocket web framework.