Sha256: dbc7fca28ee3adffe4c44ae01d899d954c4f0a33a0ac93020a26c34c48b9ef3b

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

require 'test_helper'

class TableTest < ActiveSupport::TestCase

  def setup
    @users_table = RailsDb::Table.new('users')
  end

  test 'columns' do
    assert_equal @users_table.column_names, ["id", "name", "age", "salary", "bio", "created_at", "updated_at", "account_id", "dob", "active", "type"]
  end

  test 'to_csv' do
    User.create(name: 'igor')
    assert_not_equal @users_table.to_csv, ''
  end

  test 'truncate' do
    User.delete_all
    User.create(name: 'igor')
    assert_equal 1, User.count
    @users_table.truncate
    assert_equal 0, User.count
  end

  test 'primary_key' do
    assert_equal 'id', @users_table.primary_key
    projects_users_table = RailsDb::Table.new('projects_users')
    assert_nil projects_users_table.primary_key
  end

  test 'delete' do
    User.delete_all
    user_1 = User.create(name: 'igor')
    user_2 = User.create(name: 'john')
    assert_equal 2, User.count
    @users_table.delete(user_1.id)
    assert_equal 1, User.count
    assert_equal 0, User.where(name: 'igor').count
    assert_equal 1, User.where(name: 'john').count
  end

  test 'as_table' do
    User.delete_all
    user_1 = User.create(name: 'igor')

    klass = @users_table.as_model
    assert_equal 'igor', klass.first.name
  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
rails_db-2.4.0 test/table_test.rb
rails_db-2.3.1 test/table_test.rb
rails_db-2.3.0 test/table_test.rb
rails_db-2.2.1 test/table_test.rb
rails_db-2.2.0 test/table_test.rb
rails_db-2.1.1 test/table_test.rb
rails_db-2.1.0 test/table_test.rb
rails_db-2.0.6 test/table_test.rb
rails_db-2.0.5 test/table_test.rb
rails_db-2.0.4 test/table_test.rb
xplore-0.0.1.alpha test/table_test.rb
rails_db-2.0.3 test/table_test.rb
rails_db-2.0.2 test/table_test.rb
rails_db-2.0.1 test/table_test.rb
rails_db-2.0.0 test/table_test.rb