Skip to content
Permalink
Browse files

Switch to string representation for tags.

  • Loading branch information...
JoergWMittag committed May 11, 2010
1 parent bfe11d8 commit 38cfa618ee0a80d202c50d2e8248de1777e4f14f
Showing with 19 additions and 10 deletions.
  1. +5 −6 lib/tag.rb
  2. +14 −4 spec/tag_spec.rb
@@ -1,22 +1,21 @@
begin require 'rubygems'; rescue LoadError
else begin gem 'facets', '~> 2.4.1'; rescue Gem::LoadError; end end
require 'facets/multiton'

class Tag
include Multiton

attr_reader :name
attr_accessor :description

private

def initialize name, description = nil
self.name = :"#{name}"
self.name = name.to_s.dup.freeze
self.description = description unless description.nil?
end

private

attr_writer :name

def self.multiton_id name, description = nil
return :"#{name}"
return name.to_s.downcase
end
end
@@ -20,23 +20,33 @@
end

it 'should have the name it was initialized with' do
Tag.new(:name).name.should == :name
Tag.new(:name).name.should == 'name'
end

it 'should return a symbol for the name, even if initialized differently' do
Tag.new('name').name.should == :name
Tag.new(42).name.should == :'42'
it 'should return a string for the name, even if initialized differently' do
Tag.new(:name).name.should == 'name'
Tag.new(42).name.should == '42'
end

it 'should create different Tag objects, if initialized with different names' do
Tag.new(:name).should_not == Tag.new(:bar)
end

it 'should return the same Tag object, if initialized with identical names' do
Tag.new(:Bar, 'Blah').should be_equal(Tag.new('baR', 'Blub'))
(tag = Tag.new :name).should == Tag.new(:name)
tag.should == Tag.new('name')
tag.should == Tag.new('name', 'Baz')
Tag.new(:bar, 'Blah').should == Tag.new('bar', 'Blub')
Tag.new('bar', 'Blah').should == Tag.new('bar', 'Blub')
tag.should be_eql(Tag.new('name'))
tag.should be_eql(Tag.new('name', 'Baz'))
Tag.new(:bar, 'Blah').should be_eql(Tag.new('bar', 'Blub'))
Tag.new('bar', 'Blah').should be_eql(Tag.new('bar', 'Blub'))
tag.should be_equal(Tag.new('name'))
tag.should be_equal(Tag.new('name', 'Baz'))
Tag.new(:bar, 'Blah').should be_equal(Tag.new('bar', 'Blub'))
Tag.new('bar', 'Blah').should be_equal(Tag.new('bar', 'Blub'))
end

it 'should not have a description' do

0 comments on commit 38cfa61

Please sign in to comment.
You can’t perform that action at this time.