These shared behaviors were leaking before blocks into the specs
using them. Wrapping them in an enclosing describe fixes this and
alleviates the need to destroy_all before each spec.

Signed-off-by: Nick Lewis <[email protected]>
---
 app/models/node.rb                         |    2 +-
 spec/shared_behaviors/controller_mixins.rb |  108 ++++++++++++++-------------
 spec/shared_behaviors/sorted_index.rb      |   18 ++---
 3 files changed, 65 insertions(+), 63 deletions(-)

diff --git a/app/models/node.rb b/app/models/node.rb
index 3ecbb0d..c384004 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -97,7 +97,7 @@ class Node < ActiveRecord::Base
   end
 
   def inherited_classes
-    (node_group_list.map(&:first)- [self]).map(&:node_classes).flatten.uniq
+    (node_group_list.map(&:first) - [self]).map(&:node_classes).flatten.uniq
   end
 
   def all_classes
diff --git a/spec/shared_behaviors/controller_mixins.rb 
b/spec/shared_behaviors/controller_mixins.rb
index c5ecab7..850eb71 100644
--- a/spec/shared_behaviors/controller_mixins.rb
+++ b/spec/shared_behaviors/controller_mixins.rb
@@ -2,79 +2,83 @@
 # ActiveRecord model class to use for describing this behavior.
 
 describe "with search by q and tag", :shared => true do
-  before :each do
-    @for_tag = model.generate(:name => 'for_tag')
-    @for_q = model.generate(:name => 'for_q')
-    model.generate(:name => 'without_search')
-  end
+  describe "when searching" do
+    before :each do
+      @for_tag = model.generate(:name => 'for_tag')
+      @for_q = model.generate(:name => 'for_q')
+      model.generate(:name => 'without_search')
+    end
 
-  describe "without a search" do
-    before { get 'index' }
-    subject { assigns[model.name.tableize] }
+    describe "without a search" do
+      before { get 'index' }
+      subject { assigns[model.name.tableize] }
 
-    it "returns all node groupes" do
-      should == model.all
+      it "returns all node groupes" do
+        should == model.all
+      end
     end
-  end
 
-  describe "with a 'tag' search" do
-    before { get 'index', :tag => 'for_tag' }
-    subject { assigns[model.name.tableize] }
+    describe "with a 'tag' search" do
+      before { get 'index', :tag => 'for_tag' }
+      subject { assigns[model.name.tableize] }
 
-    it "returns node groupes whose name contains the term" do
-      subject.all?{|item| item.name.include?('for_tag')}.should be_true
-    end
+      it "returns node groupes whose name contains the term" do
+        subject.all?{|item| item.name.include?('for_tag')}.should be_true
+      end
 
-    it "does not return node groups whose name does not contain the term" do
-      subject.any?{|item| item.name.include?('for_q')}.should be_false
+      it "does not return node groups whose name does not contain the term" do
+        subject.any?{|item| item.name.include?('for_q')}.should be_false
+      end
     end
-  end
 
-  describe "with a 'q' search" do
-    before { get 'index', :q => 'for_q' }
-    subject { assigns[model.name.tableize] }
+    describe "with a 'q' search" do
+      before { get 'index', :q => 'for_q' }
+      subject { assigns[model.name.tableize] }
 
-    it "returns node groupes whose name contains the term" do
-      subject.all?{|item| item.name.include?('for_q')}.should be_true
-    end
+      it "returns node groupes whose name contains the term" do
+        subject.all?{|item| item.name.include?('for_q')}.should be_true
+      end
 
-    it "does not return node groups whose name does not contain the term" do
-      subject.any?{|item| item.name.include?('for_tag')}.should be_false
+      it "does not return node groups whose name does not contain the term" do
+        subject.any?{|item| item.name.include?('for_tag')}.should be_false
+      end
     end
   end
 end
 
 describe "without JSON pagination", :shared => true do
-  describe "GET index" do
-    describe "as HTML" do
-      before { get 'index', :format => 'html' }
-      subject { assigns[model.name.tableize] }
-
-      # NOTE: Once upon a time, the collection was paginated until it was 
realized that this broke the charts.
-      # it "paginates by the page parameter" do
-        # should be_a_kind_of(WillPaginate::Collection)
-      # end
-
-      it "will paginate" do
-        should be_a_kind_of(WillPaginate::Collection)
+  describe "without JSON pagination" do
+    describe "GET index" do
+      describe "as HTML" do
+        before { get 'index', :format => 'html' }
+        subject { assigns[model.name.tableize] }
+
+        # NOTE: Once upon a time, the collection was paginated until it was 
realized that this broke the charts.
+        # it "paginates by the page parameter" do
+          # should be_a_kind_of(WillPaginate::Collection)
+        # end
+
+        it "will paginate" do
+          should be_a_kind_of(WillPaginate::Collection)
+        end
       end
-    end
 
-    describe "as JSON" do
-      before { get 'index', :format => 'json' }
-      subject { assigns[model.name.tableize] }
+      describe "as JSON" do
+        before { get 'index', :format => 'json' }
+        subject { assigns[model.name.tableize] }
 
-      it "does not paginate" do
-        should_not be_a_kind_of(WillPaginate::Collection)
+        it "does not paginate" do
+          should_not be_a_kind_of(WillPaginate::Collection)
+        end
       end
-    end
 
-    describe "as YAML" do
-      before { get 'index', :format => 'yaml' }
-      subject { assigns[model.name.tableize] }
+      describe "as YAML" do
+        before { get 'index', :format => 'yaml' }
+        subject { assigns[model.name.tableize] }
 
-      it "does not paginate" do
-        should_not be_a_kind_of(WillPaginate::Collection)
+        it "does not paginate" do
+          should_not be_a_kind_of(WillPaginate::Collection)
+        end
       end
     end
   end
diff --git a/spec/shared_behaviors/sorted_index.rb 
b/spec/shared_behaviors/sorted_index.rb
index 639342c..67bdb7c 100644
--- a/spec/shared_behaviors/sorted_index.rb
+++ b/spec/shared_behaviors/sorted_index.rb
@@ -1,14 +1,12 @@
 describe "sorted index", :shared => true do
-  before do
-    model.destroy_all
-  end
-
-  it "should be sorted by default" do
-    c = model.generate! :name => "c"
-    b = model.generate! :name => "b"
-    d = model.generate! :name => "d"
-    a = model.generate! :name => "a"
+  describe "when retrieving" do
+    it "should be sorted by default" do
+      c = model.generate! :name => "c"
+      b = model.generate! :name => "b"
+      d = model.generate! :name => "d"
+      a = model.generate! :name => "a"
 
-    model.all.should == [a,b,c,d]
+      model.all.should == [a,b,c,d]
+    end
   end
 end
-- 
1.7.2.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to