Skip to content

Instantly share code, notes, and snippets.

@Alwahsh
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alwahsh/9359870 to your computer and use it in GitHub Desktop.
Save Alwahsh/9359870 to your computer and use it in GitHub Desktop.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system('bundle')
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :projects do |t|
t.string :name
end
create_table :tasks do |t|
t.integer :project_id
end
end
class Project < ActiveRecord::Base
has_many :tasks
accepts_nested_attributes_for :tasks, allow_destroy: true
end
class Task < ActiveRecord::Base
belongs_to :project
end
class BugTest < Minitest::Test
def test_ids_problem
assert Project.create({"name"=>"Idiot", "task_ids"=>["", "2", "3", "1"]})
end
end
@John222
Copy link

John222 commented Mar 5, 2014

Hi guys. How can i run a gist. With "ruby xxx.rb"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment