Commit f7324ec

mo khan <mo@mokhan.ca>
2013-07-20 05:04:14
implement include? on the result set for easier rspec matching
1 parent e57551a
Changed files (3)
lib/humble/result_set.rb
@@ -12,5 +12,15 @@ module Humble
         block.call(@mapper.map_from(row))
       end
     end
+
+    def include?(item)
+      self.find do |x|
+        x.id == item.id
+      end
+    end
+
+    def inspect
+      "[#{self.map { |x| x.inspect }.join(", ")}]"
+    end
   end
 end
spec/integration/example_spec.rb
@@ -23,7 +23,7 @@ describe "orm" do
 
   context "when fetching all items" do
     before :each do
-      connection[:movies].insert(:name => 'monsters inc')
+      @id = connection[:movies].insert(:name => 'monsters inc')
     end
 
     let(:results) { session.find_all Movie }
@@ -39,6 +39,10 @@ describe "orm" do
     it "should return instances of the target type" do
       results.first.should be_instance_of(Movie)
     end
+
+    it "should include the saved movie" do
+      results.should include(Movie.new(:id => @id, :name => 'monsters inc'))
+    end
   end
 
   context "when inserting a new record" do
@@ -66,7 +70,6 @@ describe "orm" do
     end
 
     it "should update the new item with the new id" do
-      p movie.id
       movie.id.should_not == -1
     end
   end
Gemfile.lock
@@ -1,7 +1,7 @@
 PATH
   remote: .
   specs:
-    humble (0.0.1374295725)
+    humble (0.0.1374296616)
       sequel
 
 GEM