Skip to content

Commit

Permalink
Add time_format option to simple column (closes lunich#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptico committed Feb 24, 2011
1 parent 9865e20 commit cc384f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/table_for/simple_column.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module TableHelper
class SimpleColumn < Column # :nodoc:
def content_for(record)
record.send(@attr).to_s
called_record = record.send(@attr)
if @options[:time_format] and called_record.is_a? Time
called_record = called_record.strftime(@options[:time_format])
end
called_record.to_s
end
end
end
9 changes: 8 additions & 1 deletion spec/table_for/simple_column_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# TableHelper::SimpleColumn
let(:klass) { TableHelper::SimpleColumn }
# user (stubbed data)
let(:user) { mock(:id => 12) }
let(:user) { mock(:id => 12, :created_at => Time.gm(2011, "feb", 24, 14, 23, 1)) }
# Instance methods
describe "an instance" do
it_should_behave_like "Column class instance"
Expand All @@ -26,5 +26,12 @@
col = build_column(klass, :id)
col.content_for(user).should == user.id.to_s
end

describe "format" do
it ":time_format should be displayed correctly" do
col = build_column(klass, :created_at, :time_format => '%Y-%m')
col.content_for(user).should == "2011-02"
end
end
end
end

0 comments on commit cc384f2

Please sign in to comment.