diff --git a/lib/fog/rackspace/models/storage/file.rb b/lib/fog/rackspace/models/storage/file.rb index 1fe3e2373..87853ac40 100644 --- a/lib/fog/rackspace/models/storage/file.rb +++ b/lib/fog/rackspace/models/storage/file.rb @@ -132,6 +132,24 @@ module Fog end end + # Set last modified + # @param [String, Fog::Time] timestamp + def last_modified=(obj) + if obj.nil? || obj == "" || obj.is_a?(Time) + attributes[:last_modified] = obj + return obj + end + + # This is a work around for swift bug that has existed for 4+ years. The is that fixing the swift bug would cause more problems than its worth. + # For more information refer to https://github.com/fog/fog/pull/1811 + d = Date._strptime(obj,"%Y-%m-%dT%H:%M:%S") + if d + attributes[:last_modified] = Time.utc(d[:year], d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:leftover], d[:zone]) + else + attributes[:last_modified] = Time.parse(obj) + end + end + # Is file published to CDN # @return [Boolean] return true if published to CDN # @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404 diff --git a/tests/rackspace/models/storage/file_tests.rb b/tests/rackspace/models/storage/file_tests.rb index 399330d54..2a4dfd077 100644 --- a/tests/rackspace/models/storage/file_tests.rb +++ b/tests/rackspace/models/storage/file_tests.rb @@ -1,5 +1,35 @@ +require 'fog/rackspace/models/storage/file' + Shindo.tests('Fog::Rackspace::Storage | file', ['rackspace']) do + tests("last_modified=") do + tests("no timezone") do + file = Fog::Storage::Rackspace::File.new + file.last_modified = "2013-05-09T22:20:59.287990" + returns(Fog::Time.utc(2013, 5, 9, 22, 20, 59, 287990, nil) == file.last_modified) { true } + end + tests("with timezone") do + file = Fog::Storage::Rackspace::File.new + file.last_modified = "Thu, 09 May 2015 22:20:59 GMT" + returns(Fog::Time.utc(2015, 5, 9, 22, 20, 59, 0, nil).to_i == file.last_modified.to_i) { true } + end + tests("with time") do + file = Fog::Storage::Rackspace::File.new + file.last_modified = Fog::Time.utc(2015, 5, 9, 22, 20, 59, 0, nil) + returns(Fog::Time.utc(2015, 5, 9, 22, 20, 59, 0, nil) == file.last_modified) { true } + end + tests("nil") do + file = Fog::Storage::Rackspace::File.new + file.last_modified = nil + returns(nil) { file.last_modified } + end + tests("empty string") do + file = Fog::Storage::Rackspace::File.new + file.last_modified = "" + returns("") { file.last_modified } + end + end + pending if Fog.mocking? def object_attributes(file=@instance)