Sha256: 44c7d6c7a4dbad00d507068a6534bdc8b54c789c16dada363e390125a027d9e9

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

describe ConnectionManager::MethodRecorder do
  before(:all) do
    TestMigrations.up('shard_1_cm_test')
    ConnectionManager::Connections.initialize(:env => 'test')
    class Fruit < ActiveRecord::Base
      shard(:using => ["shard_1_cm_test"])    
    end
    
  end
  context 'shards'do    
    it "it should record methods" do
      a = Fruit.shards.select('fruits.*').where(:id => 1).order('created_at').first
      a.recordings.should eql({:select => ['fruits.*'], :where => [:id =>1], :order => ['created_at'], :first => []})
    end
    
    context '#execute' do
      it "should return an array of results" do
        a = Fruit.shards.first.execute
        a.should be_a_kind_of(Array)
      end
      it "should execute the active record methods on the the provided class" do
        fruit = Factory.create(:fruit)
        class_to_call = Fruit
        a = class_to_call.shards.where(:id => fruit.id).first.execute
        a[0].should be_a_kind_of(class_to_call)
      end
   
      it "should not matter how the where statement is formated" do
        fruit = Factory.create(:fruit)
        a = Fruit.shards.where(:id => fruit.id).first.execute
        b = Fruit.shards.where(['id = ?', fruit.id]).first.execute
        c = Fruit.shards.where('id = ?', fruit.id).first.execute    
        (a == b && b == c).should be_true
      end
    end
  end
  after(:all) do
    TestMigrations.down('shard_1_cm_test')
    ActiveRecord::Base.establish_connection('test') 
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
connection_manager-0.2.6 spec/lib/method_recorder_spec.rb
connection_manager-0.2.5 spec/lib/method_recorder_spec.rb
connection_manager-0.2.4 spec/lib/method_recorder_spec.rb
connection_manager-0.2.3 spec/lib/method_recorder_spec.rb
connection_manager-0.2.2 spec/lib/method_recorder_spec.rb
connection_manager-0.2.1 spec/lib/method_recorder_spec.rb