Last active
April 24, 2020 11:54
-
-
Save yoelblum/33cc97dafc4ef42c7199249ef67b5a98 to your computer and use it in GitHub Desktop.
or_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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails" | |
gem "sqlite3" | |
end | |
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 :posts, force: true do |t| | |
t.date :start_date | |
t.date :end_date | |
end | |
end | |
class Post < ActiveRecord::Base | |
scope :started, -> { where('start_date < :date', date: Date.today) } | |
scope :without_end_date, -> { where(end_date: nil) } | |
scope :ended, -> { where('end_date < :date', date: Date.today) } | |
end | |
class BugTest < Minitest::Test | |
def test_association_stuff | |
only_end_date = Post.create!(end_date: 2.days.ago) | |
started_without_end = Post.create!(start_date: 2.days.ago, end_date: nil) | |
posts = Post.ended.or(Post.started.without_end_date) | |
assert posts.count == 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment