Sha256: a70d384e50d1caee5d2074a86370b73e2d896e08a27ba63c42a18bd0e55a5710

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'
describe ConnectionManager::Shards do
  before(:each) do
    Fruit.shard_class_names("SouthernFruit")            
  end
  context 'shards'do    
    it "should return an array of results" do
      a = Fruit.shards do |shard|
        shard.first
      end
      a.should be_a_kind_of(Array)
    end
    
    it "should execute the active record methods on the the provided models" do
      fruit = FactoryGirl.create(:fruit)
      klasses = ["Fruit","SouthernFruit"]
      a = Fruit.shards do |shard|
        shard.where(:id => fruit.id).first
      end
      klasses.include?(a[0].class.name).should be_true
    end
   
      
    it "should not matter how the where statement is formated" do
      fruit = FactoryGirl.create(:fruit)
      afruit = Fruit.shards do |shard|
        shard.where(:id => fruit.id).first
      end
      
      bfruit = Fruit.shards do |shard|
        shard.where(['id = ?', fruit.id]).first
      end
        
      cfruit = Fruit.shards do |shard|
        shard.where('id = ?', fruit.id).first    
      end
      (afruit == bfruit && bfruit == cfruit).should be_true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
connection_manager-1.0.4 spec/lib/shards_spec.rb
connection_manager-1.0.3 spec/lib/shards_spec.rb
connection_manager-1.0.2 spec/lib/shards_spec.rb
connection_manager-1.0.1 spec/lib/shards_spec.rb