Skip to content

Commit

Permalink
fix acting_as? for namespaced model classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hzamani committed Aug 17, 2014
1 parent 6e6cd81 commit f6955ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/active_record/acts_as/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ def acts_as(name, scope = nil, options = {})
def acting_as?(other = nil)
if respond_to?(:acting_as_reflection) &&
acting_as_reflection.is_a?(ActiveRecord::Reflection::AssociationReflection)
other.nil? || acting_as_reflection.name.to_s == other.to_s.underscore
case other
when Class
acting_as_reflection.class_name == other.to_s
when Symbol, String
acting_as_reflection.class_name.underscore == other.to_s
when NilClass
true
end
else
false
end
Expand Down
2 changes: 2 additions & 0 deletions spec/acts_as_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
it "returns true for supermodel class and name" do
expect(pen.acting_as? :product).to be true
expect(pen.acting_as? Product).to be true
expect(Inventory::PenLid.is_a? Inventory::ProductFeature).to be true
end

it "returns false for anything other than supermodel" do
Expand All @@ -47,6 +48,7 @@
expect(Pen.is_a? Product).to be true
expect(Pen.is_a? Object).to be true
expect(Pen.is_a? String).to be false
expect(Inventory::PenLid.is_a? Inventory::ProductFeature).to be true
end
end

Expand Down

0 comments on commit f6955ff

Please sign in to comment.