Skip to content
Browse files

Fix default date value display issue as mentioned in issue #1353

  • Loading branch information...
1 parent fe4a4da commit b7f4d612cdba7f2dfbb4fd24b5780b40dccf402a @bterkuile committed Nov 2, 2012
View
1 lib/rails_admin/config/fields/types/datetime.rb
@@ -52,6 +52,7 @@ def parse_date_string(date_string)
end
def formatted_date_value
+ value = bindings[:object].new_record? && self.value.nil? && !self.default_value.nil? ? self.default_value : nil
value.nil? ? "" : I18n.l(value, :format => localized_date_format).strip
end
View
2 spec/integration/config/edit/rails_admin_config_edit_spec.rb
@@ -39,7 +39,7 @@
default_value true
end
field :date_field do
- default_value Date.today.to_s
+ default_value Date.today
end
end
end
View
21 spec/unit/config/fields/date_spec.rb
@@ -50,4 +50,25 @@
expect(@object.date_field).to eq(::Date.parse(@time.to_s))
end
end
+ describe 'default value' do
+ before :each do
+ RailsAdmin.config FieldTest do
+ field :date_field do
+ default_value Date.current
+ end
+ end
+ @object = FactoryGirl.create(:field_test)
+ @time = ::Time.now.getutc
+ @field = RailsAdmin.config(FieldTest).fields.find{ |f| f.name == :date_field }
+ @field.bindings = {:object => @object}
+ end
+ it "should contain the default value" do
+ expect(@field.default_value).to eq(Date.current)
+ end
+ it "should propagate to the field formatted_date_value when the object is a new record" do
+ object = FactoryGirl.build(:field_test)
+ @field.bindings = {:object => object}
+ expect(@field.formatted_date_value).to eq( Date.current.strftime("%B %d, %Y") )
+ end
+ end
end

0 comments on commit b7f4d61

Please sign in to comment.
Something went wrong with that request. Please try again.