Thursday, June 28, 2007

RSpec for acts_as_taggable

Requirements:

An empty post
- should be valid
- should have no tags
- should allow setting tags

A post with tags
- should show tags
- should be listed as tagged


Implementation:

class Post < ActiveRecord::Base
acts_as_taggable
end


RSpec:

describe "An empty post" do
before(:each) do
@post = Post.new
end

it "should be valid" do
@post.should be_valid
end

it "should have no tags" do
@post.tags.should be_empty
end

it "should allow setting tags" do
@post.tag_list = "tdd, rails"
@post.save
@post.tags.should_not be_empty
end
end

describe "A post with tags" do
before(:each) do
@post = Post.new(:tag_list=>"tdd, python, rails")
@post.save
end

it "should show tags" do
@post.tag_list.names.should == ["tdd", "python", "rails"]
end

it "should be listed as tagged" do
Post.find_tagged_with('tdd').should == [@post]
end
end


More details:
http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids

1 comment:

ashishwave said...

(though this question unrelated to this post, related to your other product/work)

when is resolver going to support ruby (apart from the python, which it supports currently)?