Last active
November 13, 2015 20:32
-
-
Save md5/00a4416c3f229695a3f3 to your computer and use it in GitHub Desktop.
Revisions
-
md5 revised this gist
Nov 13, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ class Comment < ActiveRecord::Base factory :post do trait :with_comment do after(:create) do |post| create_list(:comment, 2, post: post) end end end @@ -64,8 +64,8 @@ class BugTest < Minitest::Test def test_association_stuff post = FactoryGirl.create(:post, :with_comment) assert_equal 2, post.comments.count assert_equal 2, Comment.count assert_equal post.id, Comment.first.post.id end end -
md5 revised this gist
Nov 13, 2015 . 1 changed file with 10 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,12 +7,16 @@ gemfile(true) do source 'https://rubygems.org' if ENV['RAILS_VERSION'] gem 'rails', ENV['RAILS_VERSION'] else gem 'rails', github: 'rails/rails' gem 'arel', github: 'rails/arel' gem 'rack', github: 'rack/rack' gem 'sprockets', github: 'rails/sprockets' gem 'sprockets-rails', github: 'rails/sprockets-rails' gem 'sass-rails', github: 'rails/sass-rails' end gem 'sqlite3' gem 'factory_girl' end -
md5 created this gist
Nov 13, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ begin require 'bundler/inline' rescue LoadError => e $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' raise e end gemfile(true) do source 'https://rubygems.org' gem 'rails', github: 'rails/rails' gem 'arel', github: 'rails/arel' gem 'rack', github: 'rack/rack' gem 'sprockets', github: 'rails/sprockets' gem 'sprockets-rails', github: 'rails/sprockets-rails' gem 'sass-rails', github: 'rails/sass-rails' gem 'sqlite3' gem 'factory_girl' end require 'active_record' require 'factory_girl' 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 :posts, force: true do |t| end create_table :comments, force: true do |t| t.integer :post_id end end class Post < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :post, required: true end FactoryGirl.define do factory :post do trait :with_comment do after(:create) do |post| create(:comment, post: post) end end end factory :comment do end end class BugTest < Minitest::Test def test_association_stuff post = FactoryGirl.create(:post, :with_comment) assert_equal 1, post.comments.count assert_equal 1, Comment.count assert_equal post.id, Comment.first.post.id end end