Skip to content

Commit

Permalink
[dm-tags] Update spec for Tagging#taggable and require dm-validations
Browse files Browse the repository at this point in the history
* Added dm-validations
* use validates_present instead of an if statment
* updated spec
  • Loading branch information
Matthew Ford authored and Dan Kubb committed Jan 30, 2009
1 parent 80d9911 commit 3dbc4dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions dm-tags/lib/dm-tags/dm_tags.rb
@@ -1,7 +1,9 @@
require 'rubygems'

gem 'dm-core', '~>0.9.11'
gem 'dm-validations', '~>0.9.11'
require 'dm-core'
require 'dm-validations'

module DataMapper
module Resource
Expand Down
6 changes: 3 additions & 3 deletions dm-tags/lib/dm-tags/tagging.rb
Expand Up @@ -9,9 +9,9 @@ class Tagging

belongs_to :tag

validates_present :taggable_type, :taggable_id

def taggable
if taggable_type and taggable_id
Object.const_get(taggable_type).send(:get!, taggable_id)
end
Object.const_get(taggable_type).send(:get!, taggable_id)
end
end
11 changes: 4 additions & 7 deletions dm-tags/spec/dm-tags/tagging_spec.rb
Expand Up @@ -6,6 +6,7 @@
describe Tagging do
before do
@tagging = Tagging.new
@tagged_model =TaggedModel.create
end

it "should be a model which includes DataMapper::Resource" do
Expand All @@ -18,8 +19,6 @@
@tagging.attributes.should have_key(:tag_id)
@tagging.attributes.should have_key(:taggable_id)
@tagging.attributes.should have_key(:taggable_type)
# @tagging.attributes.should have_key(:tagger_id)
# @tagging.attributes.should have_key(:tagger_type)
@tagging.attributes.should have_key(:tag_context)
end

Expand All @@ -42,10 +41,8 @@

it "should have a method Tagging#taggable which returns the associated taggable instance" do
@tagging.should respond_to(:taggable)
@tagging.taggable.should_not be
@tagging.taggable_id = 11111
@tagging.taggable_type = "TaggedModel"
TaggedModel.should_receive(:get!).with(11111)
@tagging.taggable
@tagging.taggable_id = @tagged_model.id
@tagging.taggable_type = @tagged_model.class.to_s
@tagging.taggable.should == @tagged_model
end
end

0 comments on commit 3dbc4dc

Please sign in to comment.