scoped_associations 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f2bc87bc70a1e81d27afec78d623ef6eaf0172d
4
- data.tar.gz: e7601bac5af7d3baa442f745ffc25979252e7e2e
3
+ metadata.gz: 87cba658ebd3925c7a4c54f86a83835dc02765dc
4
+ data.tar.gz: 635d06993d642244a3e5ee70bfe8b3056cd5b17a
5
5
  SHA512:
6
- metadata.gz: f00d2ae4edca75d2ff8eb6b46cc5c2151c035b018e99ae77b3795f934773d8676bbcfdb8e6b149059ab5e963c7e6b6d1cd1ba07fcc3c145e72d2c293738c73d3
7
- data.tar.gz: e60442bf36f1f03f851faa29f1d5a571efaf2bd5a4a054c92aa36d9773a9d87566cbbc7fa085016d47651b26abcfb6c993a82aecca644adfae8c7dff03c16171
6
+ metadata.gz: 6da6be8c4bd63955d1e2fd163b8300dc1f8de18c1cc2802195587a68d340dd3e997d5b41c3ef127b2944a55282805861a432731472e839387de28c9d8f9a3cd3
7
+ data.tar.gz: aef9d9d81706944fd4477ab55a388784e350bd5c978371945bb39848898569d1bff0684980f143e473bc7ce66bd326792a3b826abe72cc4bcd8e8b9c1e51a655
@@ -49,6 +49,10 @@ module ScopedAssociations
49
49
  def association_scope
50
50
  super.where(reflection.foreign_scope => reflection.name.to_s)
51
51
  end
52
+
53
+ def target_scope
54
+ super.where(reflection.foreign_scope => reflection.name.to_s)
55
+ end
52
56
  end
53
57
  end
54
58
  end
@@ -1,4 +1,4 @@
1
1
  module ScopedAssociations
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
4
4
 
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  describe 'ScopedAssociations' do
4
4
  let(:post) { Post.new }
5
5
 
6
+
6
7
  context "non polymorphic" do
8
+
7
9
  describe "has_one" do
8
10
  it "works with direct assignment" do
9
11
  post.secondary_comment = Comment.new(comment: "foo")
@@ -70,6 +72,27 @@ describe 'ScopedAssociations' do
70
72
  expect(post.secondary_comments.size).to eq 0
71
73
  end
72
74
  end
75
+
76
+ describe "using more relation" do
77
+ before do
78
+ post.primary_comment = Comment.new(comment: "foo")
79
+ post.primary_comments.build(comment: "bar")
80
+ post.save!
81
+ post.reload
82
+ end
83
+
84
+ it "has one element" do
85
+ expect(post.primary_comment).to be_present
86
+ end
87
+
88
+ it "has many has 1 elements" do
89
+ expect(post.primary_comments.size).to eq(1)
90
+ end
91
+
92
+ it "not contain the has_one element inside has_many elements" do
93
+ expect(post.primary_comments).to_not include(post.primary_comment)
94
+ end
95
+ end
73
96
  end
74
97
 
75
98
  context "polymorphic" do
@@ -139,6 +162,26 @@ describe 'ScopedAssociations' do
139
162
  expect(post.secondary_tags.size).to eq 0
140
163
  end
141
164
  end
165
+
166
+ describe "using more relation" do
167
+ before do
168
+ post.primary_tag = Tag.new(name: "foo")
169
+ post.primary_tags.build(name: "bar")
170
+ post.save!
171
+ post.reload
172
+ end
173
+
174
+ it "has one element" do
175
+ expect(post.primary_tag).to be_present
176
+ end
177
+
178
+ it "has many has 1 elements" do
179
+ expect(post.primary_tags.size).to eq(1)
180
+ end
181
+
182
+ it "not contain the has_one element inside has_many elements" do
183
+ expect(post.primary_tags).to_not include(post.primary_tag)
184
+ end
185
+ end
142
186
  end
143
187
  end
144
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoped_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-22 00:00:00.000000000 Z
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler