Skip to content

Instantly share code, notes, and snippets.

@artemk
Created September 7, 2012 13:25
Show Gist options
  • Save artemk/3666238 to your computer and use it in GitHub Desktop.
Save artemk/3666238 to your computer and use it in GitHub Desktop.
module DatabaseHelper
def next_id(obj)
table_name = obj.class.table_name
seq = ActiveRecord::Base.connection.default_sequence_name(table_name)
ActiveRecord::Base.connection.select_value("SELECT last_value FROM #{seq}").to_i + 1
end
end
RSpec.configure do |config|
config.include DatabaseHelper
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment