Skip to content
Browse files

Fix underscore issue

  • Loading branch information...
1 parent 796a314 commit 3b17d995e45702149782c74d88f21b2d667bc4d9 Bantik committed Mar 11, 2013
Showing with 22 additions and 2 deletions.
  1. +2 −2 lib/faceted/presenter.rb
  2. +20 −0 spec/presenter_spec.rb
View
4 lib/faceted/presenter.rb
@@ -22,12 +22,12 @@ def klass
end
def presents(name, args={})
- class_name = args[:class_name] || name.to_s.classify
+ class_name = args[:class_name] || name.to_s.classify # LineItem
@presents = eval(class_name)
define_method :find_by do
args[:find_by] || :id
end
- define_method :"#{class_name.downcase}" do
+ define_method :"#{name}" do
object
end
end
View
20 spec/presenter_spec.rb
@@ -21,6 +21,13 @@ def attributes; {:id => self.id, :name => self.name}; end
def reload; self; end
end
+class AlbumTrack
+ attr_accessor :id, :title
+ def initialize(params={}); params.each{|k,v| self.send("#{k}=",v) if self.respond_to?(k)}; end
+ def attributes; {:id => self.id, :title => self.name}; end
+ def reload; self; end
+end
+
module MyApi
class Birthplace
@@ -45,6 +52,12 @@ class Album
field :name
end
+ class AlbumTrack
+ include Faceted::Presenter
+ presents :album_track
+ field :title
+ end
+
describe Musician do
before do
@@ -130,6 +143,13 @@ class Album
album.id.should == 1
end
+ it 'does not choke on associated objects with underscores in their names' do
+ @ar_album_track = ::AlbumTrack.new(:id => 1, :title => 'The Gambler')
+ ::AlbumTrack.stub(:where) { [@ar_album_track] }
+ track = MyApi::AlbumTrack.new(:id => 1)
+ track.album_track.should == @ar_album_track
+ end
+
end
end

0 comments on commit 3b17d99

Please sign in to comment.
Something went wrong with that request. Please try again.