spec/collection_spec.rb in efo_nelfo-1.4.0 vs spec/collection_spec.rb in efo_nelfo-1.5.0
- old
+ new
@@ -1,8 +1,23 @@
require 'spec_helper'
describe EfoNelfo::Collection do
+ module EfoNelfo
+ module V21
+ class MyType < EfoNelfo::PostType
+ property :whatever
+ property :version
+ end
+
+ class BT < EfoNelfo::PostType
+ property :post_type
+ property :whatever
+ property :version
+ end
+ end
+ end
+
Owner = Class.new do
def self.version_from_class
'21'
end
end
@@ -13,26 +28,18 @@
it "accepts owner and post_type arguments" do
array.owner.must_equal owner
array.post_type.must_equal "BT"
end
+ it ".delete removes the element at given position" do
+ array << { post_type: "BT", whatever: 'blah' }
+ array.delete(0)
+ array.size.must_equal 0
+ end
+
describe "<<" do
- module EfoNelfo
- module V21
- class MyType < EfoNelfo::PostType
- property :whatever
- property :version
- end
- class BT < EfoNelfo::PostType
- property :post_type
- property :whatever
- property :version
- end
- end
- end
-
describe "passing a hash" do
let(:hash) {
{ post_type: "BT", version: "2.1", whatever: 'blah' }
}
@@ -61,8 +68,29 @@
it "raises an error if the object being added is of wrong type" do
def obj.post_type; 'BH'; end
lambda { array << obj }.must_raise(EfoNelfo::InvalidPostType)
end
end
+ end
+
+ describe "#find_by" do
+ before do
+ array << { post_type: 'BT', whatever: 'foo' }
+ array << { post_type: 'BT', whatever: 'bar' }
+ end
+
+ it "returns the matching rows" do
+ array.find_by(whatever: 'foo').must_be_instance_of Array
+ array.find_by(whatever: 'foo').first.must_be_instance_of EfoNelfo::V21::BT
+ end
+
+ it "returns empty array when no rows could be found" do
+ array.find_by(whatever: 'barr').must_be_empty
+ end
+
+ it "returns empty array when trying to search for a key that doesn't exist" do
+ array.find_by(blue_dragon_breath: 'wtf').must_be_empty
+ end
+
end
end