Merge branch 'bowsersenior-master'
This commit is contained in:
		
						commit
						71ceb83ded
					
				@ -10,7 +10,9 @@ module CanCan
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def self.matches_conditions_hash?(subject, conditions)
 | 
					      def self.matches_conditions_hash?(subject, conditions)
 | 
				
			||||||
        subject.class.where(conditions).include?(subject) # TODO don't use a database query here for performance and other instances
 | 
					        # To avoid hitting the db, retrieve the raw Mongo selector from
 | 
				
			||||||
 | 
					        # the Mongoid Criteria and use Mongoid::Matchers#matches?
 | 
				
			||||||
 | 
					        subject.matches?( subject.class.where(conditions).selector )
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def database_records
 | 
					      def database_records
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,7 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
 | 
				
			|||||||
          it "Calls where on the model class when there are criteria" do
 | 
					          it "Calls where on the model class when there are criteria" do
 | 
				
			||||||
            obj = MongoidProject.create(:title => 'Bird')
 | 
					            obj = MongoidProject.create(:title => 'Bird')
 | 
				
			||||||
            @conditions = {:title.nin => ["Fork", "Spoon"]}
 | 
					            @conditions = {:title.nin => ["Fork", "Spoon"]}
 | 
				
			||||||
            mock(MongoidProject).where(@conditions) {[obj]}
 | 
					
 | 
				
			||||||
            @ability.can :read, MongoidProject, @conditions
 | 
					            @ability.can :read, MongoidProject, @conditions
 | 
				
			||||||
            @ability.should be_able_to(:read, obj)
 | 
					            @ability.should be_able_to(:read, obj)
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
@ -135,6 +135,18 @@ if ENV["MODEL_ADAPTER"] == "mongoid"
 | 
				
			|||||||
          obj2 = MongoidProject.create(:age => 40)
 | 
					          obj2 = MongoidProject.create(:age => 40)
 | 
				
			||||||
          @ability.can?(:read, obj2).should == false
 | 
					          @ability.can?(:read, obj2).should == false
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        it "should handle instance not saved to database" do
 | 
				
			||||||
 | 
					          obj = MongoidProject.new(:title => 'Sir')
 | 
				
			||||||
 | 
					          @ability.can :read, MongoidProject, :title.in => ["Sir", "Madam"]
 | 
				
			||||||
 | 
					          @ability.can?(:read, obj).should == true
 | 
				
			||||||
 | 
					          
 | 
				
			||||||
 | 
					          # accessible_by only returns saved records
 | 
				
			||||||
 | 
					          MongoidProject.accessible_by(@ability, :read).entries.should == []
 | 
				
			||||||
 | 
					          
 | 
				
			||||||
 | 
					          obj2 = MongoidProject.new(:title => 'Lord')
 | 
				
			||||||
 | 
					          @ability.can?(:read, obj2).should == false
 | 
				
			||||||
 | 
					        end          
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it "should call where with matching ability conditions" do
 | 
					      it "should call where with matching ability conditions" do
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user