File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -207,7 +207,7 @@ def initialize(bucket, opts = {})
207207 @content_length = range_value ( opts [ :content_length ] )
208208 @conditions = opts [ :conditions ] || { }
209209 @ignored_fields = [ opts [ :ignore ] ] . flatten . compact
210- @expires = opts [ :expires ]
210+ @expires = opts [ :expires ] || Time . now . utc + 60 * 60
211211
212212 super
213213
@@ -397,17 +397,16 @@ def with_condition(field, condition)
397397 # @api private
398398 private
399399 def format_expiration
400- time = expires || Time . now . utc + 60 *60
401400 time =
402- case time
401+ case expires
403402 when Time
404- time
403+ expires
405404 when DateTime
406- Time . parse ( time . to_s )
405+ Time . parse ( expires . to_s )
407406 when Integer
408- ( Time . now + time )
407+ ( Time . now + expires )
409408 when String
410- Time . parse ( time )
409+ Time . parse ( expires )
411410 end
412411 time . utc . iso8601
413412 end
Original file line number Diff line number Diff line change @@ -352,6 +352,17 @@ def policy_conditions(post)
352352 policy [ "expiration" ] . should == "2011-05-25T01:51:04Z"
353353 end
354354
355+ it "should reuse the default expire set during initialize" do
356+ now = Time . parse ( "2011-05-24T17:54:04-07:00Z" )
357+ Time . stub ( :now ) . and_return ( now )
358+ policy [ "expiration" ] . should == "2011-05-25T01:54:04Z"
359+
360+ later = Time . parse ( "2011-05-24T17:54:05-07:00Z" )
361+ Time . stub ( :now ) . and_return ( later )
362+ later_policy = JSON . load ( Base64 . decode64 ( post . policy ) )
363+ later_policy [ "expiration" ] . should == "2011-05-25T01:54:04Z"
364+ end
365+
355366 context 'when :expires is provided' do
356367
357368 it 'should support Time' do
You can’t perform that action at this time.
0 commit comments