public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Michael Hartl (author)
Thu May 08 10:54:15 -0700 2008
commit  ecb54f90dd7778d814c2bd09859d32618d349b19
tree    ce517c844277de45b71a60c74f7d5301e1c88bec
parent  36f34ca84b0d217e1d6b4b14a852a7a393fd2622
insoshi / spec / models / blog_post_spec.rb
100644 67 lines (52 sloc) 1.604 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
require File.dirname(__FILE__) + '/../spec_helper'
 
describe BlogPost do
  
  before(:each) do
    @post = BlogPost.new(:title => "First post!",
                         :body => "Hey there",
                         :blog => blogs(:one))
  end
  
  it "should be valid" do
    @post.should be_valid
  end
  
  it "should require a title" do
    post = BlogPost.new
    post.should_not be_valid
    post.errors.on(:title).should_not be_empty
  end
  
  it "should require a body" do
    post = BlogPost.new
    post.should_not be_valid
    post.errors.on(:body).should_not be_empty
  end
  
  it "should have a maximum body length" do
    @post.should have_maximum(:body, BlogPost::MAX_BODY)
  end
    
  describe "post activity associations" do
    
    before(:each) do
      @post.save!
      @activity = Activity.find_by_item_id(@post)
    end
    
    it "should have an activity" do
      @activity.should_not be_nil
    end
    
    it "should add an activity to the poster" do
      @post.blog.person.recent_activity.should include_the(@activity)
    end
  end
  
  describe "comment associations" do
    
    before(:each) do
      @post.save
      @post.comments.create(:body => "The body",
                            :commenter => people(:aaron))
    end
    
    it "should have associated comments" do
      @post.comments.should_not be_empty
    end
    
    it "should add activities to the poster" do
      @post.comments.each do |comment|
        activity = Activity.find_by_item_id(comment)
        @post.blog.person.activities.should include_the(activity)
      end
    end
  end
end