unscoped_associations 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +4 -0
- data/Gemfile +8 -2
- data/README.md +1 -0
- data/Rakefile +7 -1
- data/lib/unscoped_associations/version.rb +1 -1
- data/spec/spec_helper.rb +47 -0
- data/spec/unscoped_associations_spec.rb +10 -0
- data/unscoped_associations.gemspec +2 -0
- metadata +40 -3
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Unscoped Associations
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/unscoped_associations)
|
4
|
+
[](https://travis-ci.org/markets/unscoped_associations)
|
4
5
|
|
5
6
|
Want to skip the `default_scope` when you get objects through associations (for some strange reasons)? Do it easily with this lib. Supported associations:
|
6
7
|
* `:belongs_to`
|
data/Rakefile
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'active_record'
|
5
|
+
require 'unscoped_associations'
|
6
|
+
|
7
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
8
|
+
|
9
|
+
ActiveRecord::Base.establish_connection(
|
10
|
+
:adapter => 'sqlite3',
|
11
|
+
:database => ':memory:'
|
12
|
+
)
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define do
|
15
|
+
self.verbose = false
|
16
|
+
|
17
|
+
create_table :users, :force => true do |t|
|
18
|
+
t.boolean :active
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table :comments, :force => true do |t|
|
22
|
+
t.integer :user_id
|
23
|
+
t.boolean :public
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class User < ActiveRecord::Base
|
28
|
+
has_many :comments
|
29
|
+
has_many :all_comments, class_name: 'Comment', unscoped: true
|
30
|
+
has_one :last_comment, class_name: 'Comment', order: 'id DESC', unscoped: true
|
31
|
+
|
32
|
+
default_scope where( active: true )
|
33
|
+
end
|
34
|
+
|
35
|
+
class Comment < ActiveRecord::Base
|
36
|
+
belongs_to :user, unscoped: true
|
37
|
+
|
38
|
+
default_scope where( public: true )
|
39
|
+
end
|
40
|
+
|
41
|
+
RSpec.configure do |config|
|
42
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
43
|
+
config.run_all_when_everything_filtered = true
|
44
|
+
config.filter_run :focus
|
45
|
+
config.mock_with :rspec
|
46
|
+
config.order = 'random'
|
47
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UnscopedAssociations do
|
4
|
+
it 'belongs_to with unscoped option should skip default_scope' do
|
5
|
+
user = User.create(:active => false)
|
6
|
+
comment = Comment.create(:user_id => user.id)
|
7
|
+
|
8
|
+
expect(comment.user).to eq(user)
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unscoped_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -43,6 +43,38 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sqlite3
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
description: Skip default_scope in your associations
|
47
79
|
email:
|
48
80
|
- srmarc.ai@gmail.com
|
@@ -51,12 +83,15 @@ extensions: []
|
|
51
83
|
extra_rdoc_files: []
|
52
84
|
files:
|
53
85
|
- .gitignore
|
86
|
+
- .travis.yml
|
54
87
|
- Gemfile
|
55
88
|
- LICENSE
|
56
89
|
- README.md
|
57
90
|
- Rakefile
|
58
91
|
- lib/unscoped_associations.rb
|
59
92
|
- lib/unscoped_associations/version.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/unscoped_associations_spec.rb
|
60
95
|
- unscoped_associations.gemspec
|
61
96
|
homepage: https://github.com/markets/unscoped_associations
|
62
97
|
licenses:
|
@@ -83,4 +118,6 @@ rubygems_version: 1.8.23
|
|
83
118
|
signing_key:
|
84
119
|
specification_version: 3
|
85
120
|
summary: Skip default_scope in your associations
|
86
|
-
test_files:
|
121
|
+
test_files:
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/unscoped_associations_spec.rb
|