Skip to content

Commit

Permalink
give better info to user when has_tags called incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdempsey committed Dec 3, 2008
1 parent 1d399ea commit 79e0971
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lib/sequel_taggable/sequel_taggable.rb
Expand Up @@ -31,7 +31,8 @@ def self.extended(klass)
klass.has_tags
end

def has_tags
def has_tags(*args)
raise "has_tags takes no arguments, use 'has_tags_on :#{args.first}, ...' instead" unless args.empty?
has_tags_on :tags
end

Expand Down
35 changes: 12 additions & 23 deletions spec/sequel_taggable/sequel_taggable_spec.rb
Expand Up @@ -30,7 +30,7 @@ class HasTagsOnTestModel < Sequel::Model
it "should create taggable functionality for each of the context names passed" do
class TestModel < Sequel::Model
is :taggable
has_tags_on(:pets, 'skills', :tags)
has_tags_on :pets, 'skills', :tags
end
TestModel.should be_taggable
a = TestModel.new
Expand All @@ -43,26 +43,15 @@ class TestModel < Sequel::Model
a.should respond_to(:tag_list=)
end
end
#
# describe ".has_tags" do
# it "should create a taggable with 'tags' context regardless of passed arguments" do
# class TagsOnly
# include DataMapper::Resource
# property :id, Integer, :serial => true
# has_tags :pets, :skills
# end
# TagsOnly.should be_taggable
# TagsOnly.new.should be_taggable
# a = TagsOnly.new
# a.should respond_to(:tag_list)
# a.should respond_to(:tag_list=)
# a.should respond_to(:tags)
# a.should_not respond_to(:pet_list)
# a.should_not respond_to(:pet_list=)
# a.should_not respond_to(:pets)
# a.should_not respond_to(:skill_list)
# a.should_not respond_to(:skill_list=)
# a.should_not respond_to(:skills)
# end
#end

describe ".has_tags" do
it "should raise an error message if someone uses has_tags with an argument list" do
lambda do
class TagsOnly < Sequel::Model
is :taggable
has_tags :pets, :skills
end
end.should raise_error(RuntimeError)
end
end
end

0 comments on commit 79e0971

Please sign in to comment.