Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Fix #has_attribute? on persistent models. #824

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tire/model/persistence/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def attribute_names
end

def has_attribute?(name)
properties.include?(name.to_s)
self.class.properties.include?(name.to_s)
end
alias :has_property? :has_attribute?

Expand Down
12 changes: 12 additions & 0 deletions test/unit/model_persistence_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ class << a
assert article.respond_to?(:published_on)
end

should "return true for has_attribute? calls for defined attributes" do
article = PersistentArticle.new :title => 'Test'

assert article.has_attribute?(:title)
assert article.has_attribute?(:published_on)
end

should "return false for has_attribute? calls for unknown attributes" do
article = PersistentArticle.new :title => 'Test'
assert ! article.has_attribute?(:krapulitz)
end

should "have attribute names" do
article = PersistentArticle.new :title => 'Test', :tags => ['one', 'two']
assert_equal ['published_on', 'tags', 'title'], article.attribute_names
Expand Down