Skip to content

Instantly share code, notes, and snippets.

@patricksrobertson
Created February 15, 2014 13:50
Show Gist options
  • Save patricksrobertson/9019565 to your computer and use it in GitHub Desktop.
Save patricksrobertson/9019565 to your computer and use it in GitHub Desktop.
node ascending AR test case.
require 'cases/helper'
if current_adapter?(:PostgreSQLAdapter)
class ArelNodeAscendingTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
class State < ActiveRecord::Base
has_many :cities
default_scope { includes(:cities) }
end
class City < ActiveRecord::Base
belongs_to :state
end
def setup
ActiveRecord::Schema.define do
create_table :states do |t|
t.string :name
end
create_table :cities do |t|
t.string :name
t.integer :state_id
end
end
end
def teardown
ActiveRecord::Schema.define do
drop_table :states
drop_table :cities
end
end
def test_bigserial_primary_key
sc = State.create!(name: 'South Carolina')
greenville_sc = sc.cities.create(name: 'Greenville')
nc = State.create(name: 'North Carolina')
greenville_nc = nc.cities.create(name: 'Greenville')
State.order(State.arel_table[:name].asc).joins(:cities).
where(:cities => {:name => "Greenville"}).limit(25)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment