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:
Fixed custom have_maximum spec matcher to actually wor
Changed max topic length to be shorter (& tested it!)
Michael Hartl (author)
Sat Mar 01 15:27:51 -0800 2008
commit  d546632e7d1c3ee44bdf465fcc530367ae122697
tree    98acd26f1307429b06f8617d05cad5c4670d1dfd
parent  2301490e1439ddd49ee26716a3c346cd3eb2cd37
...
1
 
 
 
2
3
4
5
6
7
8
 
9
...
1
2
3
4
5
6
7
8
9
10
 
11
12
0
@@ -1,9 +1,12 @@
0
 class Topic < ActiveRecord::Base
0
+
0
+ MAX_NAME = 70
0
+
0
   belongs_to :forum, :counter_cache => true
0
   belongs_to :person
0
   has_many :posts, :order => :created_at, :dependent => :destroy,
0
                    :class_name => "ForumPost"
0
   
0
   validates_presence_of :name, :forum, :person
0
- validates_length_of :name, :maximum => MAX_STRING_LENGTH
0
+ validates_length_of :name, :maximum => MAX_NAME
0
 end
...
1
 
 
2
3
4
5
6
7
8
9
10
 
 
 
 
 
 
 
11
12
13
14
 
15
16
17
...
1
2
3
4
5
6
7
8
9
 
 
 
10
11
12
13
14
15
16
17
18
19
 
20
21
22
23
0
@@ -1,17 +1,23 @@
0
 module CustomModelMatchers
0
+
0
+ # Verify that a model instance has a maximum length on the given attribute.
0
   class MaximumLength
0
     def initialize(attribute, maxlength)
0
       @attribute = attribute
0
       @maxlength = maxlength
0
     end
0
     
0
- def matches?(target)
0
- @target = target
0
- !@target.new(@attribute => "a" * (@maxlength + 1)).valid?
0
+ def matches?(model)
0
+ @model = model
0
+ just_right = model
0
+ too_long = model.clone
0
+ just_right.update_attributes(@attribute => "a" * 70)
0
+ too_long.update_attributes(@attribute => "a" * (@maxlength + 1))
0
+ just_right.valid? and not too_long.valid?
0
     end
0
     
0
     def failure_message
0
- "#{@target} #{@attribute} should have maximum length #{@maxlength}"
0
+ "#{@model.to_s} #{@attribute} should have maximum length #{@maxlength}"
0
     end
0
   end
0
   
...
3
4
5
 
 
 
 
 
 
6
7
8
 
9
10
11
...
15
16
17
18
 
19
20
...
3
4
5
6
7
8
9
10
11
12
 
 
13
14
15
16
...
20
21
22
 
23
24
25
0
@@ -3,9 +3,14 @@ require File.dirname(__FILE__) + '/../spec_helper'
0
 describe BlogPostComment do
0
   include CustomModelMatchers
0
   
0
+ before(:each) do
0
+ @comment = BlogPostComment.new(:body => "Hey there", :post => posts(:blog),
0
+ :commenter => people(:aaron))
0
+
0
+ end
0
+
0
   it "should be valid" do
0
- BlogPostComment.new(:body => "Hey there", :post => posts(:blog),
0
- :commenter => people(:aaron)).should be_valid
0
+ @comment.should be_valid
0
   end
0
   
0
   it "should require a body" do
0
@@ -15,6 +20,6 @@ describe BlogPostComment do
0
   end
0
   
0
   it "should have a maximum body length" do
0
- BlogPostComment.should have_maximum(:body, MAX_TEXT_LENGTH)
0
+ @comment.should have_maximum(:body, MAX_TEXT_LENGTH)
0
   end
0
 end
...
3
4
5
 
 
 
 
 
6
7
8
 
9
10
11
...
15
16
17
18
 
19
20
...
3
4
5
6
7
8
9
10
11
 
 
12
13
14
15
...
19
20
21
 
22
23
24
0
@@ -3,9 +3,13 @@ require File.dirname(__FILE__) + '/../spec_helper'
0
 describe ForumPost do
0
   include CustomModelMatchers
0
   
0
+ before(:each) do
0
+ @post = ForumPost.new(:body => "Hey there", :topic => topics(:one),
0
+ :person => people(:quentin))
0
+ end
0
+
0
   it "should be valid" do
0
- ForumPost.new(:body => "Hey there", :topic => topics(:one),
0
- :person => people(:quentin)).should be_valid
0
+ @post.should be_valid
0
   end
0
   
0
   it "should require a body" do
0
@@ -15,6 +19,6 @@ describe ForumPost do
0
   end
0
   
0
   it "should have a maximum body length" do
0
- ForumPost.should have_maximum(:body, MAX_TEXT_LENGTH)
0
+ @post.should have_maximum(:body, MAX_TEXT_LENGTH)
0
   end
0
 end
...
1
2
3
 
 
 
 
 
4
5
6
7
 
8
9
10
...
14
15
16
17
 
18
19
20
...
1
2
3
4
5
6
7
8
9
10
 
 
11
12
13
14
...
18
19
20
 
21
22
23
24
0
@@ -1,10 +1,14 @@
0
 require File.dirname(__FILE__) + '/../spec_helper'
0
 
0
 describe Topic do
0
+
0
+ before(:each) do
0
+ @topic = Topic.new(:name => "A topic", :forum => forums(:one),
0
+ :person => people(:quentin))
0
+ end
0
 
0
   it "should be valid" do
0
- Topic.new(:name => "A topic", :forum => forums(:one),
0
- :person => people(:quentin)).should be_valid
0
+ @topic.should be_valid
0
   end
0
   
0
   it "should require a name" do
0
@@ -14,7 +18,7 @@ describe Topic do
0
   end
0
 
0
   it "should have a max name length" do
0
- Topic.should have_maximum(:name, MAX_STRING_LENGTH)
0
+ @topic.should have_maximum(:name, Topic::MAX_NAME)
0
   end
0
   
0
   it "should have many posts" do
...
3
4
5
 
 
 
 
 
6
7
8
 
9
10
11
...
15
16
17
18
 
19
20
21
...
3
4
5
6
7
8
9
10
11
 
 
12
13
14
15
...
19
20
21
 
22
23
24
25
0
@@ -3,9 +3,13 @@ require File.dirname(__FILE__) + '/../spec_helper'
0
 describe WallComment do
0
   include CustomModelMatchers
0
   
0
+ before(:each) do
0
+ @comment = WallComment.new(:body => "Hey there", :person => people(:quentin),
0
+ :commenter => people(:aaron))
0
+ end
0
+
0
   it "should be valid" do
0
- WallComment.new(:body => "Hey there", :person => people(:quentin),
0
- :commenter => people(:aaron)).should be_valid
0
+ @comment.should be_valid
0
   end
0
   
0
   it "should require a body" do
0
@@ -15,7 +19,7 @@ describe WallComment do
0
   end
0
   
0
   it "should have a maximum body length" do
0
- WallComment.should have_maximum(:body, MAX_TEXT_LENGTH)
0
+ @comment.should have_maximum(:body, MAX_TEXT_LENGTH)
0
   end
0
 end
0
 

Comments

    No one has commented yet.