Permalink
Browse files

Prevent unintentional change of datetime fields in non-UTC timezones.…

… Fixes #1301
  • Loading branch information...
1 parent e674017 commit 936337d8b574a339ffb4d79988c7df6d2b45e681 @mshibuya mshibuya committed Aug 31, 2012
View
2 app/views/rails_admin/main/_form_datetime.html.haml
@@ -1 +1 @@
-= form.send field.view_helper, field.method_name, field.html_attributes.reverse_merge({ :data => { :datetimepicker => true, :options => field.js_plugin_options.to_json } }).reverse_merge((hdv = field.html_default_value).nil? ? {} : { :value => hdv })
+= form.send field.view_helper, field.method_name, field.html_attributes.merge({:value => (field.value.present? ? field.value : field.html_default_value)}).reverse_merge({ :data => { :datetimepicker => true, :options => field.js_plugin_options.to_json } })
View
10 spec/integration/config/edit/rails_admin_config_edit_spec.rb
@@ -624,6 +624,16 @@ class HelpTest < Tableless
@record = RailsAdmin::AbstractModel.new("FieldTest").first
@record.datetime_field.to_s(:rfc822).should eql(@time.to_s(:rfc822))
end
+
+ it "should do round-trip saving properly with non-UTC timezones" do
+ Time.zone = 'Vienna'
+ time = Time.zone.parse('2012-09-01 12:00:00 +02:00')
+ @record = FieldTest.create!(:datetime_field => time)
+ visit edit_path(:model_name => "field_test", :id => @record.id)
+ click_button "Save"
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
+ @record.datetime_field.should == time
+ end
end
describe "a timestamp field", :active_record => true do

0 comments on commit 936337d

Please sign in to comment.