Sha256: ccffe3ab9ca3fae744667f89e50c6be6c6886e3a562e8b4b99c18861d4700b16

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

def shared_examples
  describe 'Database Adapters' do
    let(:attributes) do
      {
        name: 'User Name',
        active: true,
        age: 25,
        money: 20.50,
        birth_date: Date.today,
        created_at: DateTime.now,
        updated_at: DateTime.now
      }
    end

    after :each do
      User.delete_all
    end

    describe 'Column types' do
      def setup
        User.mass_insert([attributes])
      end

      def user
        @user ||= User.last
      end

      it 'saves values correctly' do
        assert_equal user.name, 'User Name'
        assert_equal user.active, true
        assert_equal user.age, 25
        assert_equal user.money, 20.50
        assert_equal user.birth_date, Date.today
      end
    end

    describe 'Bulk inseting' do
      def array_of_values_with(size)
        (0...size).map do |i|
          attributes
        end
      end

      it 'saves 500 records correctly' do
        values = array_of_values_with(500)
        User.mass_insert(values)
        assert_equal User.count, 500
      end

      it 'saves 1000 records correctly' do
        values = array_of_values_with(1000)
        User.mass_insert(values)
        assert_equal User.count, 1000
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mass_insert-0.2.4 test/support/shared_examples.rb
mass_insert-0.2.3 test/support/shared_examples.rb
mass_insert-0.2.2 test/support/shared_examples.rb
mass_insert-0.2.1 test/support/shared_examples.rb
mass_insert-0.2.0 test/support/shared_examples.rb