$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'active_record' require 'unscoped_associations' ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ':memory:' ) ActiveRecord::Schema.define do self.verbose = false create_table :users, :force => true do |t| t.boolean :active end create_table :comments, :force => true do |t| t.integer :user_id t.boolean :public end end class User < ActiveRecord::Base has_many :comments has_many :all_comments, class_name: 'Comment', unscoped: true has_one :last_comment, class_name: 'Comment', order: 'id DESC', unscoped: true default_scope where( active: true ) end class Comment < ActiveRecord::Base belongs_to :user, unscoped: true default_scope where( public: true ) end RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true config.filter_run :focus config.mock_with :rspec config.order = 'random' end