spec/lib/adapters/sequel_spec.rb in protector-0.3.3 vs spec/lib/adapters/sequel_spec.rb in protector-0.4.0
- old
+ new
@@ -40,10 +40,14 @@
describe Protector::Adapters::Sequel do
it "finds out whether object is Sequel relation" do
Protector::Adapters::Sequel.is?(Dummy).should == true
Protector::Adapters::Sequel.is?(Dummy.where).should == true
end
+
+ it "sets the adapter" do
+ Dummy.restrict!('!').protector_meta.adapter.should == Protector::Adapters::Sequel
+ end
end
#
# Model instance
@@ -82,10 +86,58 @@
Dummy.restrict!('!').where(number: 999).first.protector_subject.should == '!'
Dummy.restrict!('!').where(number: 999).to_a.first.protector_subject.should == '!'
Dummy.restrict!('!').eager_graph(fluffies: :loony).all.first.fluffies.first.loony.protector_subject.should == '!'
end
+ context "with open relation" do
+ context "adequate", paranoid: false do
+ it "checks existence" do
+ Dummy.any?.should == true
+ Dummy.restrict!('!').any?.should == true
+ end
+
+ it "counts" do
+ Dummy.count.should == 4
+ Dummy.restrict!('!').count.should == 4
+ end
+
+ it "fetches first" do
+ Dummy.restrict!('!').first.should be_a_kind_of(Dummy)
+ end
+
+ it "fetches all" do
+ fetched = Dummy.restrict!('!').to_a
+
+ Dummy.count.should == 4
+ fetched.length.should == 4
+ end
+ end
+
+ context "paranoid", paranoid: true do
+ it "checks existence" do
+ Dummy.any?.should == true
+ Dummy.restrict!('!').any?.should == false
+ end
+
+ it "counts" do
+ Dummy.count.should == 4
+ Dummy.restrict!('!').count.should == 0
+ end
+
+ it "fetches first" do
+ Dummy.restrict!('!').first.should == nil
+ end
+
+ it "fetches all" do
+ fetched = Dummy.restrict!('!').to_a
+
+ Dummy.count.should == 4
+ fetched.length.should == 0
+ end
+ end
+ end
+
context "with null relation" do
it "checks existence" do
Dummy.any?.should == true
Dummy.restrict!('-').any?.should == false
end
@@ -93,13 +145,11 @@
it "counts" do
Dummy.count.should == 4
Dummy.restrict!('-').count.should == 0
end
- context do
- it "fetches first" do
- Dummy.restrict!('-').first.should == nil
- end
+ it "fetches first" do
+ Dummy.restrict!('-').first.should == nil
end
it "fetches all" do
fetched = Dummy.restrict!('-').to_a
\ No newline at end of file