|
201 | 201 | context 'instance methods' do |
202 | 202 | let(:model){ mock(attributes) } |
203 | 203 | let(:attributes){ { |
204 | | - :name => 'Bob Bobson', |
| 204 | + :name => 'Bob Bobson', |
205 | 205 | |
| 206 | + :birthday => Time.new(2012, 2, 27), |
206 | 207 | :friends => [ |
207 | | - mock(:name => "Friend 1", :email => '[email protected]', :friends => []), |
208 | | - mock(:name => "Friend 2", :email => '[email protected]', :friends => []) |
| 208 | + mock(:name => "Friend 1", :email => '[email protected]', :birthday => Time.new(2012, 2, 27), :friends => []), |
| 209 | + mock(:name => "Friend 2", :email => '[email protected]', :birthday => Time.new(2012, 2, 27), :friends => []) |
209 | 210 | ] |
210 | 211 | } } |
211 | 212 | subject{ fresh_class.new(model) } |
|
229 | 230 | expose :computed do |object, options| |
230 | 231 | options[:awesome] |
231 | 232 | end |
| 233 | + |
| 234 | + expose :birthday, :format_with => :timestamp |
| 235 | + |
| 236 | + def timestamp(date) |
| 237 | + date.strftime('%m/%d/%Y') |
| 238 | + end |
232 | 239 | end |
233 | 240 | end |
234 | 241 |
|
@@ -261,6 +268,10 @@ class FriendEntity < Grape::Entity |
261 | 268 | it 'should call through to the proc if there is one' do |
262 | 269 | subject.send(:value_for, :computed, :awesome => 123).should == 123 |
263 | 270 | end |
| 271 | + |
| 272 | + it 'should return a formatted value if format_with is passed' do |
| 273 | + subject.send(:value_for, :birthday).should == '02/27/2012' |
| 274 | + end |
264 | 275 | end |
265 | 276 |
|
266 | 277 | describe '#key_for' do |
|
0 commit comments