public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / spec / models / tag_spec.rb
100644 70 lines (54 sloc) 1.723 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require File.dirname(__FILE__) + '/../spec_helper'
 
ModelStubbing.define_models :tags, :copy => false do
  model Tag do
    [:ruby, :rails, :mongrel, :plugin].each do |t|
      stub t, :name => t.to_s
    end
  end
end
 
describe Tag, "#parse" do
  define_models :tags
 
  it "parses comma separated tags" do
    Tag.parse('a,b,c').should == %w(a b c)
    Tag.parse('a, b c').should == %w(a b\ c)
  end
 
  it "parses simple tags" do
    Tag.parse('"a" "b" "c"').should == %w(a b c)
  end
 
  it "parses space delimited tags" do
    Tag.parse('a b c').should == %w(a b c)
  end
 
  it "parses tags with double quotes" do
    Tag.parse('tagging, it"s, weirdness').should == %w(tagging it"s weirdness)
  end
  
  it "parses tags with single quotes" do
    Tag.parse('"tagging" "it\'s" "weirdness"').should == %w(tagging it's weirdness)
  end
  
  it "parses tags with quotes and spaces" do
    Tag.parse('"tagging" "it\'s weirdness"').should == %w(tagging it's\ weirdness)
  end
  
  it "returns tag array" do
    Tag.parse(%w(a b c)).should == %w(a b c)
  end
  
  it "returns unique tags" do
    ["a, b, b", %("a" "b" " b ")].each do |input|
      Tag.parse(input).should == %w(a b)
    end
  end
end
 
describe Tag do
  define_models :tags
 
  it "finds or creates tags" do
    lambda { Tag.find_or_create %w(ruby rails foo) }.should change { Tag.count }.by(1)
  end
  
  it "creates tags from comma separated list" do
    lambda { Tag.parse_to_tags 'ruby, a, b, rails, c' }.should change { Tag.count }.by(3)
  end
  
  it "equals tags of the same name" do
    tags(:ruby).should == 'ruby'
    tags(:ruby).should == Tag.new(:name => "ruby")
  end
  
  it "selects tags by name" do
    Tag[:ruby].should == tags(:ruby)
  end
end