-
-
Save AfolabiOlaoluwa/8c03602c450c07f84196dffdec92a016 to your computer and use it in GitHub Desktop.
Flaky!
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
class Comment < ActiveRecord::Base | |
belongs_to :post, counter_cache: true | |
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
require 'bundler/inline' | |
gemfile(true) do | |
source 'https://rubygems.org' | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem 'activerecord', '6.1.1' | |
gem 'sqlite3' | |
gem 'rspec' | |
gem 'pry' | |
end | |
require 'active_record' | |
require 'rspec' | |
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| | |
t.integer :comments_count, default: 0, null: false | |
end | |
create_table :comments, force: true do |t| | |
t.belongs_to :post | |
end | |
end | |
autoload :Post, './post.rb' | |
autoload :Comment, './comment.rb' | |
RSpec.describe Post do | |
it 'updates something, whatever' do | |
post = Post.create! | |
post.update!(comments_count: 42) | |
expect(post.reload.comments_count).to eq(42) | |
end | |
it 'doesnt really do anything' do | |
expect(Comment.count).to eq(0) | |
end | |
end | |
RSpec::Core::Runner.invoke |
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
class Post < ActiveRecord::Base | |
has_many :comments | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment