Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactoring on specs files

  • Loading branch information...
commit 6d5a7450e81c74e3add06b11fb4e6bb4d30ab21b 1 parent e9d323b
Celestino Gomes authored
10  spec/friendship_message_spec.rb
... ...
@@ -0,0 +1,10 @@
  1
+require "#{File.dirname(__FILE__)}/spec_helper"
  2
+
  3
+describe FriendshipMessage do
  4
+  it "should require a body" do
  5
+    @message = FriendshipMessage.new
  6
+
  7
+    @message.should_not be_valid
  8
+    @message.errors[:body].should == "can't be blank"
  9
+  end
  10
+end
17  spec/friendship_relation_type_spec.rb
... ...
@@ -0,0 +1,17 @@
  1
+require "#{File.dirname(__FILE__)}/spec_helper"
  2
+
  3
+describe FriendshipRelationType do
  4
+  describe "structure" do
  5
+    it "should belong_to :friendship" do
  6
+      @friendship = Friendship.new
  7
+      @friendship_relation = FriendshipRelationType.new :friendship => @friendship
  8
+      @friendship_relation.friendship.should == @friendship
  9
+    end
  10
+
  11
+    it "should belong_to :relation" do
  12
+      @relation = RelationType.new
  13
+      @friendship_relation = FriendshipRelationType.new :relation => @relation
  14
+      @friendship_relation.relation.should == @relation
  15
+    end
  16
+  end
  17
+end
104  spec/friendship_spec.rb
... ...
@@ -0,0 +1,104 @@
  1
+require "#{File.dirname(__FILE__)}/spec_helper"
  2
+
  3
+describe Friendship do
  4
+  fixtures :all
  5
+  
  6
+  describe "structure" do
  7
+    before(:each) do
  8
+      @friendship = Friendship.new
  9
+    end
  10
+
  11
+    it "should belong to user" do
  12
+      @friendship.user = @vader
  13
+      @friendship.user.should == @vader
  14
+    end
  15
+
  16
+    it "should_belong to friend" do
  17
+      @friendship.friend = @luke
  18
+      @friendship.friend.should == @luke
  19
+    end
  20
+
  21
+    it "should belong to message" do
  22
+      @message = FriendshipMessage.new :body => "Luke, I'm your father!"
  23
+      @friendship.message = @vader_message_for_luke
  24
+      @friendship.message.should == @vader_message_for_luke
  25
+    end
  26
+
  27
+    it "should has many relations" do
  28
+      @friendship.relations << @friend
  29
+      @friendship.relations << @coworker
  30
+
  31
+      @friendship.relations.should == [@friend, @coworker]
  32
+    end
  33
+  end
  34
+
  35
+  it "should be pending status" do
  36
+    @friendship = Friendship.new(:status => 'pending')
  37
+    @friendship.should be_pending
  38
+  end
  39
+
  40
+  it "should be accepted status" do
  41
+    @friendship = Friendship.new(:status => 'accepted')
  42
+    @friendship.should be_accepted
  43
+  end
  44
+
  45
+  it "should be requested status" do
  46
+    @friendship = Friendship.new(:status => 'requested')
  47
+    @friendship.should be_requested
  48
+  end
  49
+
  50
+  describe "on accept pending friendship" do
  51
+    before(:each) do
  52
+      @friendship = Friendship.create(:user => @vader, :friend => @luke, :status => Friendship::FRIENDSHIP_PENDING)
  53
+    end
  54
+
  55
+    it "should be ok" do
  56
+      @friendship.accept!
  57
+      @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
  58
+    end
  59
+
  60
+    it "should be ok and add new relations" do
  61
+      @friendship.accept!([:met, :coworker])
  62
+      @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
  63
+      @friendship.relations.size == 2
  64
+      @friendship.relations.should == [@met, @coworker]
  65
+    end
  66
+
  67
+    describe "with relations" do
  68
+      before(:each) do
  69
+        [@friend, @met].each do |r|
  70
+          @friendship.relations << r
  71
+        end
  72
+        @friendship.save
  73
+      end
  74
+
  75
+      it "should be ok and no change current relations" do
  76
+        @friendship.accept!
  77
+        @friendship.reload
  78
+
  79
+        @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
  80
+        @friendship.relations.size.should == 2
  81
+        @friendship.relations.should == [@friend, @met]
  82
+      end
  83
+
  84
+      it "should be ok and change relations" do
  85
+        @friendship.accept!([:met, :coworker])
  86
+        @friendship.reload
  87
+
  88
+        @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
  89
+        @friendship.relations.size.should == 2
  90
+        @friendship.relations.should == [@met, @coworker]
  91
+      end
  92
+
  93
+      it "should be ok and clear current relations" do
  94
+        @friendship.accept!([])
  95
+        @friendship.reload
  96
+
  97
+        @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
  98
+        @friendship.relations.size.should == 0
  99
+        @friendship.relations.should == []
  100
+      end
  101
+    end
  102
+
  103
+  end
  104
+end
140  spec/has_friends_spec.rb
... ...
@@ -1,12 +1,5 @@
1 1
 require "#{File.dirname(__FILE__)}/spec_helper"
2 2
 
3  
-# unset models used for testing purposes
4  
-Object.unset_class('User')
5  
-
6  
-class User < ActiveRecord::Base
7  
-  has_friends
8  
-end
9  
-
10 3
 describe "has_friends" do
11 4
   fixtures :all
12 5
   
@@ -210,138 +203,6 @@ class User < ActiveRecord::Base
210 203
     end
211 204
   end
212 205
   
213  
-  describe FriendshipMessage do
214  
-    it "should require a body" do
215  
-      @message = FriendshipMessage.new
216  
-      @message.should_not be_valid
217  
-      @message.errors[:body].should == "can't be blank"
218  
-    end
219  
-  end
220  
-  
221  
-  describe RelationType do
222  
-    it "should require a name" do
223  
-      @relation_type = RelationType.new
224  
-      @relation_type.should_not be_valid
225  
-      @relation_type.errors[:name].should == "can't be blank"
226  
-    end
227  
-  end
228  
-  
229  
-  describe Friendship do
230  
-    describe "structure" do
231  
-      before(:each) do
232  
-        @friendship = Friendship.new
233  
-      end
234  
-      
235  
-      it "should belong to user" do
236  
-        @friendship.user = @vader
237  
-        @friendship.user.should == @vader
238  
-      end
239  
-      
240  
-      it "should_belong to friend" do
241  
-        @friendship.friend = @luke
242  
-        @friendship.friend.should == @luke
243  
-      end
244  
-      
245  
-      it "should belong to message" do
246  
-        @message = FriendshipMessage.new :body => "Luke, I'm your father!"
247  
-        @friendship.message = @vader_message_for_luke
248  
-        @friendship.message.should == @vader_message_for_luke
249  
-      end
250  
-      
251  
-      it "should has many relations" do
252  
-        @friendship.relations << @friend
253  
-        @friendship.relations << @coworker
254  
-        
255  
-        @friendship.relations.should == [@friend, @coworker]
256  
-      end
257  
-    end
258  
-    
259  
-    it "should be pending status" do
260  
-      @friendship = Friendship.new(:status => 'pending')
261  
-      @friendship.should be_pending
262  
-    end
263  
-    
264  
-    it "should be accepted status" do
265  
-      @friendship = Friendship.new(:status => 'accepted')
266  
-      @friendship.should be_accepted
267  
-    end
268  
-    
269  
-    it "should be requested status" do
270  
-      @friendship = Friendship.new(:status => 'requested')
271  
-      @friendship.should be_requested
272  
-    end
273  
-    
274  
-    describe "on accept pending friendship" do
275  
-      before(:each) do
276  
-        @friendship = Friendship.create(:user => @vader, :friend => @luke, :status => Friendship::FRIENDSHIP_PENDING)
277  
-      end
278  
-
279  
-      it "should be ok" do
280  
-        @friendship.accept!
281  
-        @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
282  
-      end
283  
-      
284  
-      it "should be ok and add new relations" do
285  
-        @friendship.accept!([:met, :coworker])
286  
-        @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
287  
-        @friendship.relations.size == 2
288  
-        @friendship.relations.should == [@met, @coworker]
289  
-      end
290  
-      
291  
-      describe "with relations" do
292  
-        before(:each) do
293  
-          [@friend, @met].each do |r|
294  
-            @friendship.relations << r
295  
-          end
296  
-          @friendship.save
297  
-        end
298  
-        
299  
-        it "should be ok and no change current relations" do
300  
-          @friendship.accept!
301  
-          @friendship.reload
302  
-
303  
-          @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
304  
-          @friendship.relations.size.should == 2
305  
-          @friendship.relations.should == [@friend, @met]
306  
-        end
307  
-
308  
-        it "should be ok and change relations" do
309  
-          @friendship.accept!([:met, :coworker])
310  
-          @friendship.reload
311  
-
312  
-          @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
313  
-          @friendship.relations.size.should == 2
314  
-          @friendship.relations.should == [@met, @coworker]
315  
-        end
316  
-        
317  
-        it "should be ok and clear current relations" do
318  
-          @friendship.accept!([])
319  
-          @friendship.reload
320  
-
321  
-          @friendship.status.should == Friendship::FRIENDSHIP_ACCEPTED
322  
-          @friendship.relations.size.should == 0
323  
-          @friendship.relations.should == []
324  
-        end
325  
-      end
326  
-
327  
-    end
328  
-  end
329  
-  
330  
-  describe FriendshipRelationType do
331  
-    describe "structure" do
332  
-      it "should belong_to :friendship" do
333  
-        @friendship = Friendship.new
334  
-        @friendship_relation = FriendshipRelationType.new :friendship => @friendship
335  
-        @friendship_relation.friendship.should == @friendship
336  
-      end
337  
-      it "should belong_to :relation" do
338  
-        @relation = RelationType.new
339  
-        @friendship_relation = FriendshipRelationType.new :relation => @relation
340  
-        @friendship_relation.relation.should == @relation
341  
-      end
342  
-    end
343  
-  end
344  
-  
345 206
   describe "pagination" do
346 207
     before(:each) do
347 208
       pending unless Object.const_defined?('Paginate')
@@ -361,4 +222,5 @@ def create_friendship(user1, user2)
361 222
       user1.be_friends_with(user2)
362 223
       user2.be_friends_with(user1)
363 224
     end
  225
+  
364 226
 end
9  spec/relation_type_spec.rb
... ...
@@ -0,0 +1,9 @@
  1
+require "#{File.dirname(__FILE__)}/spec_helper"
  2
+
  3
+describe RelationType do
  4
+  it "should require a name" do
  5
+    @relation_type = RelationType.new
  6
+    @relation_type.should_not be_valid
  7
+    @relation_type.errors[:name].should == "can't be blank"
  8
+  end
  9
+end
9  spec/spec_helper.rb
@@ -27,4 +27,11 @@ def self.unset_class(*args)
27 27
   end
28 28
 end
29 29
 
30  
-alias :doing :lambda
  30
+alias :doing :lambda
  31
+
  32
+# unset models used for testing purposes
  33
+Object.unset_class('User')
  34
+
  35
+class User < ActiveRecord::Base
  36
+  has_friends
  37
+end

0 notes on commit 6d5a745

Please sign in to comment.
Something went wrong with that request. Please try again.