-
-
Save simon2k/5b4d4043d4b625984ca1 to your computer and use it in GitHub Desktop.
sample rails app for bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails', tag: 'v3.2.22' | |
gem 'pg', '~> 0.18.1' | |
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: 'postgresql', database: 'test') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :surveys, force: true do |t| | |
end | |
create_table :email_templates, force: true do |t| | |
t.string :survey_id | |
end | |
end | |
class Survey < ActiveRecord::Base | |
has_many :email_templates | |
end | |
class EmailTemplate < ActiveRecord::Base | |
belongs_to :survey | |
end | |
class BugTest < ActiveRecord::TestCase | |
def test_association_stuff | |
survey = Survey.create! | |
email_template = EmailTemplate.create!(survey_id: survey.id) | |
assert_equal survey.email_templates.to_a, [email_template] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails', tag: 'v3.2.22' | |
gem 'pg', '~> 0.18.1' | |
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: 'postgresql', database: 'test') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :surveys, force: true | |
create_table :tfs, id: false, force: true do |t| | |
t.string :id | |
end | |
create_table :email_templates, force: true do |t| | |
t.string :object_with_email_template_id | |
t.string :object_with_email_template_type | |
end | |
end | |
class Survey < ActiveRecord::Base | |
has_many :email_templates, as: :object_with_email_template | |
end | |
class Tfs < ActiveRecord::Base | |
has_many :email_templates, as: :object_with_email_template | |
end | |
class EmailTemplate < ActiveRecord::Base | |
belongs_to :object_with_email_template, polymorphic: true | |
end | |
class BugTest < ActiveRecord::TestCase | |
def test_association_stuff | |
survey = Survey.create! | |
tfs = Tfs.create!(id: 'my_tfs') | |
survey_email_template = EmailTemplate.create!(object_with_email_template: survey) | |
assert_equal survey.email_templates.to_a, [survey_email_template] | |
tfs_email_template = EmailTemplate.create!(object_with_email_template: tfs) | |
assert_equal tfs.email_templates.to_a, [tfs_email_template] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment