gin 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 1.0.2 / 2013-03-08
2
+
3
+ * Minor Enhancements
4
+ * Set Cookie Controller helper
5
+
1
6
  === 1.0.1 / 2013-03-07
2
7
 
3
8
  * Minor Enhancements
data/lib/gin.rb CHANGED
@@ -5,7 +5,7 @@ require 'rack-protection'
5
5
 
6
6
 
7
7
  class Gin
8
- VERSION = '1.0.1'
8
+ VERSION = '1.0.2'
9
9
 
10
10
  LIB_DIR = File.expand_path("..", __FILE__) #:nodoc:
11
11
  PUBLIC_DIR = File.expand_path("../../public/", __FILE__) #:nodoc:
@@ -253,6 +253,23 @@ class Gin::Controller
253
253
  end
254
254
 
255
255
 
256
+ ##
257
+ # Set a cookie on the Rack response.
258
+ #
259
+ # set_cookie "mycookie", "FOO", :expires => 600, :path => "/"
260
+ # set_cookie "mycookie", :expires => 600
261
+
262
+ def set_cookie name, value=nil, opts={}
263
+ if Hash === value
264
+ opts = value
265
+ else
266
+ opts[:value] = value
267
+ end
268
+
269
+ @response.set_cookie name, opts
270
+ end
271
+
272
+
256
273
  ##
257
274
  # Build a path to the given controller and action or route name,
258
275
  # with any expected params. If no controller is specified and the
@@ -236,10 +236,16 @@ class ControllerTest < Test::Unit::TestCase
236
236
 
237
237
 
238
238
  def test_set_cookie
239
- cookie = {:value => "user@example.com", :expires => Time.now + 360}
240
- @ctrl.cookies['test'] = cookie
241
- assert_equal cookie, @ctrl.env["rack.request.cookie_hash"]["test"]
242
- assert_equal "user@example.com", @ctrl.cookies['test'][:value]
239
+ exp = Time.now + 360
240
+ cookie = {:value => "user@example.com", :expires => exp}
241
+
242
+ @ctrl.set_cookie "test", "user@example.com", :expires => exp
243
+ expected = "test=user%40example.com; expires=#{exp.gmtime.strftime("%a, %d %b %Y %H:%M:%S -0000")}"
244
+ assert_equal expected, @ctrl.response['Set-Cookie']
245
+
246
+ @ctrl.set_cookie "test", :path => "/"
247
+ expected << "\ntest=; path=/"
248
+ assert_equal expected, @ctrl.response['Set-Cookie']
243
249
  end
244
250
 
245
251
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-07 00:00:00.000000000 Z
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -150,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  segments:
152
152
  - 0
153
- hash: 1873485601668633173
153
+ hash: -3176863341583704067
154
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  none: false
156
156
  requirements: