This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: ruby | ||
rvm: | ||
- 2.0.0 | ||
- 1.9.3 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
source "https://rubygems.org" | ||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
gemspec | ||
|
||
group :development, :test do | ||
gem 'rspec' | ||
gem 'sqlite3' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
require "bundler/gem_tasks" | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new | ||
|
||
task :default => :spec | ||
task :test => :spec |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
$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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
|
||
describe UnscopedAssociations do | ||
it 'belongs_to with unscoped option should skip default_scope' do | ||
user = User.create(:active => false) | ||
comment = Comment.create(:user_id => user.id) | ||
|
||
expect(comment.user).to eq(user) | ||
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