Permalink
Browse files

Refactoring on specs files

  • Loading branch information...
1 parent e9d323b commit 6d5a7450e81c74e3add06b11fb4e6bb4d30ab21b @tinogomes committed Apr 27, 2009
@@ -0,0 +1,10 @@
+require "#{File.dirname(__FILE__)}/spec_helper"
+
+describe FriendshipMessage do
+ it "should require a body" do
+ @message = FriendshipMessage.new
+
+ @message.should_not be_valid
+ @message.errors[:body].should == "can't be blank"
+ end
+end
@@ -0,0 +1,17 @@
+require "#{File.dirname(__FILE__)}/spec_helper"
+
+describe FriendshipRelationType do
+ describe "structure" do
+ it "should belong_to :friendship" do
+ @friendship = Friendship.new
+ @friendship_relation = FriendshipRelationType.new :friendship => @friendship
+ @friendship_relation.friendship.should == @friendship
+ end
+
+ it "should belong_to :relation" do
+ @relation = RelationType.new
+ @friendship_relation = FriendshipRelationType.new :relation => @relation
+ @friendship_relation.relation.should == @relation
+ end
+ end
+end
@@ -0,0 +1,104 @@
+require "#{File.dirname(__FILE__)}/spec_helper"
+
+describe Friendship do
+ fixtures :all
+
+ describe "structure" do
+ before(:each) do
+ @friendship = Friendship.new
+ end
+
+ it "should belong to user" do
+ @friendship.user = @vader
+ @friendship.user.should == @vader
+ end
+
+ it "should_belong to friend" do
+ @friendship.friend = @luke
+ @friendship.friend.should == @luke
+ end
+
+ it "should belong to message" do
+ @message = FriendshipMessage.new :body => "Luke, I'm your father!"
+ @friendship.message = @vader_message_for_luke
+ @friendship.message.should == @vader_message_for_luke
+ end
+
+ it "should has many relations" do
+ @friendship.relations << @friend
+ @friendship.relations << @coworker
+
+ @friendship.relations.should == [@friend, @coworker]
+ end
+ end
+
+ it "should be pending status" do
+ @friendship = Friendship.new(:status => 'pending')
+ @friendship.should be_pending
+ end
+
+ it "should be accepted status" do
+ @friendship = Friendship.new(:status => 'accepted')
+ @friendship.should be_accepted
+ end
+
+ it "should be requested status" do
+ @friendship = Friendship.new(:status => 'requested')
+ @friendship.should be_requested
+ end
+
+ describe "on accept pending friendship" do
+ before(:each) do
+ @friendship = Friendship.create(:user => @vader, :friend => @luke, :status => Friendship::FRIENDSHIP_PENDING)
+ end
+
+ it "should be ok" do
+ @friendship.accept!
+ @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
+ end
+
+ it "should be ok and add new relations" do
+ @friendship.accept!([:met, :coworker])
+ @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
+ @friendship.relations.size == 2
+ @friendship.relations.should == [@met, @coworker]
+ end
+
+ describe "with relations" do
+ before(:each) do
+ [@friend, @met].each do |r|
+ @friendship.relations << r
+ end
+ @friendship.save
+ end
+
+ it "should be ok and no change current relations" do
+ @friendship.accept!
+ @friendship.reload
+
+ @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
+ @friendship.relations.size.should == 2
+ @friendship.relations.should == [@friend, @met]
+ end
+
+ it "should be ok and change relations" do
+ @friendship.accept!([:met, :coworker])
+ @friendship.reload
+
+ @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
+ @friendship.relations.size.should == 2
+ @friendship.relations.should == [@met, @coworker]
+ end
+
+ it "should be ok and clear current relations" do
+ @friendship.accept!([])
+ @friendship.reload
+
+ @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
+ @friendship.relations.size.should == 0
+ @friendship.relations.should == []
+ end
+ end
+
+ end
+end
@@ -1,12 +1,5 @@
require "#{File.dirname(__FILE__)}/spec_helper"
-# unset models used for testing purposes
-Object.unset_class('User')
-
-class User < ActiveRecord::Base
- has_friends
-end
-
describe "has_friends" do
fixtures :all
@@ -210,138 +203,6 @@ class User < ActiveRecord::Base
end
end
- describe FriendshipMessage do
- it "should require a body" do
- @message = FriendshipMessage.new
- @message.should_not be_valid
- @message.errors[:body].should == "can't be blank"
- end
- end
-
- describe RelationType do
- it "should require a name" do
- @relation_type = RelationType.new
- @relation_type.should_not be_valid
- @relation_type.errors[:name].should == "can't be blank"
- end
- end
-
- describe Friendship do
- describe "structure" do
- before(:each) do
- @friendship = Friendship.new
- end
-
- it "should belong to user" do
- @friendship.user = @vader
- @friendship.user.should == @vader
- end
-
- it "should_belong to friend" do
- @friendship.friend = @luke
- @friendship.friend.should == @luke
- end
-
- it "should belong to message" do
- @message = FriendshipMessage.new :body => "Luke, I'm your father!"
- @friendship.message = @vader_message_for_luke
- @friendship.message.should == @vader_message_for_luke
- end
-
- it "should has many relations" do
- @friendship.relations << @friend
- @friendship.relations << @coworker
-
- @friendship.relations.should == [@friend, @coworker]
- end
- end
-
- it "should be pending status" do
- @friendship = Friendship.new(:status => 'pending')
- @friendship.should be_pending
- end
-
- it "should be accepted status" do
- @friendship = Friendship.new(:status => 'accepted')
- @friendship.should be_accepted
- end
-
- it "should be requested status" do
- @friendship = Friendship.new(:status => 'requested')
- @friendship.should be_requested
- end
-
- describe "on accept pending friendship" do
- before(:each) do
- @friendship = Friendship.create(:user => @vader, :friend => @luke, :status => Friendship::FRIENDSHIP_PENDING)
- end
-
- it "should be ok" do
- @friendship.accept!
- @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
- end
-
- it "should be ok and add new relations" do
- @friendship.accept!([:met, :coworker])
- @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
- @friendship.relations.size == 2
- @friendship.relations.should == [@met, @coworker]
- end
-
- describe "with relations" do
- before(:each) do
- [@friend, @met].each do |r|
- @friendship.relations << r
- end
- @friendship.save
- end
-
- it "should be ok and no change current relations" do
- @friendship.accept!
- @friendship.reload
-
- @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
- @friendship.relations.size.should == 2
- @friendship.relations.should == [@friend, @met]
- end
-
- it "should be ok and change relations" do
- @friendship.accept!([:met, :coworker])
- @friendship.reload
-
- @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
- @friendship.relations.size.should == 2
- @friendship.relations.should == [@met, @coworker]
- end
-
- it "should be ok and clear current relations" do
- @friendship.accept!([])
- @friendship.reload
-
- @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
- @friendship.relations.size.should == 0
- @friendship.relations.should == []
- end
- end
-
- end
- end
-
- describe FriendshipRelationType do
- describe "structure" do
- it "should belong_to :friendship" do
- @friendship = Friendship.new
- @friendship_relation = FriendshipRelationType.new :friendship => @friendship
- @friendship_relation.friendship.should == @friendship
- end
- it "should belong_to :relation" do
- @relation = RelationType.new
- @friendship_relation = FriendshipRelationType.new :relation => @relation
- @friendship_relation.relation.should == @relation
- end
- end
- end
-
describe "pagination" do
before(:each) do
pending unless Object.const_defined?('Paginate')
@@ -361,4 +222,5 @@ def create_friendship(user1, user2)
user1.be_friends_with(user2)
user2.be_friends_with(user1)
end
+
end
@@ -0,0 +1,9 @@
+require "#{File.dirname(__FILE__)}/spec_helper"
+
+describe RelationType do
+ it "should require a name" do
+ @relation_type = RelationType.new
+ @relation_type.should_not be_valid
+ @relation_type.errors[:name].should == "can't be blank"
+ end
+end
View
@@ -27,4 +27,11 @@ def self.unset_class(*args)
end
end
-alias :doing :lambda
+alias :doing :lambda
+
+# unset models used for testing purposes
+Object.unset_class('User')
+
+class User < ActiveRecord::Base
+ has_friends
+end

0 comments on commit 6d5a745

Please sign in to comment.