Skip to content

Commit

Permalink
Literalize Date objects properly even if to_s is overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Feb 13, 2010
1 parent ea19b7f commit 34035d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sequel/dataset/sql.rb
Expand Up @@ -791,7 +791,7 @@ def literal_dataset(v)

# SQL fragment for Date, using the ISO8601 format.
def literal_date(v)
requires_sql_standard_datetimes? ? v.strftime("DATE '%Y-%m-%d'") : "'#{v}'"
v.strftime("#{'DATE ' if requires_sql_standard_datetimes?}'%Y-%m-%d'")
end

# SQL fragment for DateTime
Expand Down
7 changes: 7 additions & 0 deletions spec/core/dataset_spec.rb
Expand Up @@ -832,6 +832,13 @@ def @dataset.blah
@dataset.literal(d).should == s
end

specify "should literalize Date properly, even if to_s is overridden" do
d = Date.today
def d.to_s; "adsf" end
s = d.strftime("'%Y-%m-%d'")
@dataset.literal(d).should == s
end

specify "should literalize Time, DateTime, Date properly if SQL standard format is required" do
@dataset.meta_def(:requires_sql_standard_datetimes?){true}

Expand Down

0 comments on commit 34035d8

Please sign in to comment.