Skip to content

Instantly share code, notes, and snippets.

@aranair
Last active July 10, 2016 12:12
Show Gist options
  • Select an option

  • Save aranair/5401990f6c4f22aa2fe958db2c3bcf92 to your computer and use it in GitHub Desktop.

Select an option

Save aranair/5401990f6c4f22aa2fe958db2c3bcf92 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
require 'rack/test'
require 'active_record'
require 'logger'
# ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: '25595')
# ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: '25595')
# ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'test', user: 'root', password: '')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :tickets, force: true do |t|
t.integer "priority"
t.string "name"
t.boolean "bool"
end
end
class Ticket < ActiveRecord::Base
enum priority: [:high, :middle, :low]
end
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
Ticket.create!(priority: :high, name: 'test', bool: false)
Ticket.create!(priority: :high, name: 'test', bool: true)
assert_equal({ true => 1, false => 1}, Ticket.group(:bool).count(:name))
assert_equal({0 => 2}, Ticket.group(:priority).count)
assert_equal('high', Ticket.first.priority)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment