Skip to content

Commit

Permalink
Merge pull request #1383 from bterkuile/master
Browse files Browse the repository at this point in the history
Fix default date value display issue as mentioned in issue #1353
  • Loading branch information
bbenezech committed Nov 9, 2012
2 parents 17d8284 + b7f4d61 commit 4b1a4c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/rails_admin/config/fields/types/datetime.rb
Expand Up @@ -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

Expand Down
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions spec/unit/config/fields/date_spec.rb
Expand Up @@ -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 4b1a4c2

Please sign in to comment.