Permalink
Browse files

Merge pull request #7 from trunkclub/materialize_single

Adds 'from' class method to presenter to materialize a single object.
  • Loading branch information...
2 parents d5204d5 + 110c215 commit 8590d69be7e9b41ebe8131d0afdc8f0efc422bcf Corey Ehmke committed Sep 16, 2013
Showing with 19 additions and 1 deletion.
  1. +5 −1 lib/faceted/model.rb
  2. +14 −0 spec/presenter_spec.rb
View
@@ -44,7 +44,11 @@ def fields
@fields ||= [:id, :excludes]
end
- def materialize(objects=[], args={})
+ def from(object, args={})
+ materialize([object], args).first
+ end
+
+ def materialize(objects=[], args={})
objects.compact.inject([]) do |a, object|
interface = self.new(args)
interface.send(:object=, object)
View
@@ -70,6 +70,20 @@ class AlbumTrack
end
+ describe 'initialized with an instantiated object' do
+
+ let(:musician_presenter) { MyApi::Musician.from(@ar_musician) }
+
+ it 'accepts an object' do
+ musician_presenter.send(:object).should == @ar_musician
+ end
+
+ it 'initializes with the attributes of the object' do
+ musician_presenter.name.should == 'Johnny Cash'
+ end
+
+ end
+
describe 'initialized with a presented object' do
describe 'inherits values from its AR counterpart' do

0 comments on commit 8590d69

Please sign in to comment.