Sha256: 6f7f46e5235ebdd625eef3b7c0695fa4d341d61766b02ccaf5cf828f3faa885a

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

require "spec_helper"

describe RailsDbAdmin::QuerySupport do

  before(:each) do
    @connection_class = double(ActiveRecord::Base)
    @adapter = double(ActiveRecord::ConnectionAdapters::AbstractAdapter)
    @connection_class.should_receive(:connection).and_return(@adapter)
    @instance = RailsDbAdmin::QuerySupport.new(@connection_class, 'spec')
  end

  describe "select_top_fifty" do

    it "should pass well formed sql to select_all" do

      @sql = "SELECT  * FROM \"test_table\"  LIMIT 50"

      @adapter.should_receive(:select_all).with(@sql).and_return([])

      @instance.select_top_fifty("test_table")
    end

    it "should return a sql statement and an array of hashes" do

      @sql = "SELECT  * FROM \"test_table\"  LIMIT 50"

      @return_arry = [{:col_a => "some_val"},
                      {:col_a => "some_val2"}]

      @adapter.should_receive(:select_all).with(@sql).and_return([])

      RailsDbAdmin::TableSupport.stub(:database_rows_to_hash).
        and_return(@return_arry)

      sql, records = @instance.select_top_fifty("test_table")
      sql.should eq(@sql)
      records.should eq(@return_arry)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails_db_admin-3.2.0 spec/lib/rails_db_admin/query_support_spec.rb
rails_db_admin-3.0.0 spec/lib/rails_db_admin/query_support_spec.rb
rails_db_admin-2.1.2 spec/lib/rails_db_admin/query_support_spec.rb
rails_db_admin-2.1.1 spec/lib/rails_db_admin/query_support_spec.rb
rails_db_admin-2.1.0 spec/lib/rails_db_admin/query_support_spec.rb
rails_db_admin-2.0.4 spec/lib/rails_db_admin/query_support_spec.rb
rails_db_admin-2.0.3 spec/lib/rails_db_admin/query_support_spec.rb
rails_db_admin-2.0.2 spec/lib/rails_db_admin/query_support_spec.rb
rails_db_admin-2.0.1 spec/lib/rails_db_admin/query_support_spec.rb