public
Description: rails plugin that allows has_many :through to go through other has_many :throughs
Homepage:
Clone URL: git://github.com/ianwhite/nested_has_many_through.git
Added with_scope and named_scope specs
ianwhite (author)
Wed Apr 30 04:46:17 -0700 2008
commit  50d47663286883e23e39d605cc99dfc9d3163747
tree    e52e8f752cfc5b1fc6f547c77daea9834e644921
parent  0e20ac5e29064b23b6d9aff88ae34ee77254c8d7
...
13
14
15
 
16
17
18
...
56
57
58
 
 
 
 
 
 
 
 
 
 
 
59
60
61
...
13
14
15
16
17
18
19
...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
0
@@ -13,6 +13,7 @@ ActiveRecord::Migration.suppress_messages do
0
     create_table :posts, :force => true do |t|
0
       t.column "author_id", :integer
0
       t.column "category_id", :integer
0
+      t.column "inflamatory", :boolean
0
     end
0
 
0
     create_table :categories, :force => true do |t|
0
@@ -56,6 +57,17 @@ class Author < User
0
 end
0
 
0
 class Post < ActiveRecord::Base
0
+  
0
+  # testing with_scope
0
+  def self.find_inflamatory(*args)
0
+    with_scope :find => {:conditions => {:inflamatory => true}} do
0
+      find(*args)
0
+    end
0
+  end
0
+
0
+  # only test named_scope in edge
0
+  named_scope(:inflamatory) if respond_to?(:named_scope)
0
+  
0
   belongs_to :author
0
   belongs_to :category
0
   has_many :comments
...
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
...
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
71
 
72
73
74
75
 
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
0
@@ -43,28 +43,66 @@ describe 'Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3)' do
0
       @u1.comments.should == [@comment]
0
     end
0
     
0
-    it "a1.commenters.should == []" do
0
-      @a1.commenters.should == []
0
+    it "a1.commenters should be empty" do
0
+      @a1.commenters.should be_empty
0
     end
0
     
0
-    it "a2.commenters.should == [u1]" do
0
+    it "a2.commenters should == [u1]" do
0
       @a2.commenters.should == [@u1]
0
     end
0
     
0
-    it "u1.commented_posts.should == [p2]" do
0
+    it "u1.commented_posts should == [p2]" do
0
       @u1.commented_posts.should == [@p2]
0
     end
0
     
0
-    it "u1.commented_authors.should == [a2]" do
0
+    it "u1.commented_posts.find_inflamatory(:all) should be empty" do
0
+      @u1.commented_posts.find_inflamatory(:all).should be_empty
0
+    end
0
+    
0
+    if ActiveRecord::Base.respond_to?(:named_scope)
0
+      it "u1.commented_posts.inflamatory should be empty" do
0
+        @u1.commented_posts.inflamatory.should be_empty
0
+      end
0
+    end
0
+    
0
+    it "u1.commented_authors should == [a2]" do
0
       @u1.commented_authors.should == [@a2]
0
     end
0
     
0
-    it "u1.posts_of_interest.should == [p1, p2, p3]" do
0
+    it "u1.posts_of_interest should == [p1, p2, p3]" do
0
       @u1.posts_of_interest.should == [@p1, @p2, @p3]
0
     end
0
     
0
-    it "u1.categories_of_interest.should == [c1, c2]" do
0
+    it "u1.categories_of_interest should == [c1, c2]" do
0
       @u1.categories_of_interest.should == [@c1, @c2]
0
     end
0
+    
0
+    describe "when p2 is inflamatory" do
0
+      before do
0
+        @p2.toggle!(:inflamatory)
0
+      end
0
+      
0
+      it "p2 should be inflamatory" do
0
+        @p2.should be_inflamatory
0
+      end
0
+      
0
+      it "u1.commented_posts.find_inflamatory(:all) should == [p2]" do
0
+        @u1.commented_posts.find_inflamatory(:all).should == [@p2]
0
+      end
0
+        
0
+      it "u1.posts_of_interest.find_inflamatory(:all) should == [p2]" do
0
+        @u1.posts_of_interest.find_inflamatory(:all).should == [@p2]
0
+      end
0
+      
0
+      if ActiveRecord::Base.respond_to?(:named_scope)
0
+        it "u1.commented_posts.inflamatory should == [p2]" do
0
+          @u1.commented_posts.inflamatory.should == [@p2]
0
+        end
0
+
0
+        it "u1.posts_of_interest.inflamatory should == [p2]" do
0
+          @u1.posts_of_interest.inflamatory.should == [@p2]
0
+        end
0
+      end
0
+    end
0
   end
0
 end

Comments