active_record-json_has_many 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/active_record/json_has_many.rb +5 -0
- data/lib/active_record/json_has_many/version.rb +1 -1
- data/spec/json_has_many_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba01b13afb1f06c09c3d48017a45b21a005b84a5
|
4
|
+
data.tar.gz: 5e497437e5ffbbc5d4aa7da4526fbf4a4cd10b93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee28c7c0cdf75ab5000d5f957579811c687530a97f893483e546a2a4f14d3565106cb2482987a4ddd5bd9a128f97948a5ed66b62f3fc447bec5a47dcb0af576
|
7
|
+
data.tar.gz: 79221239f336dd334931a12ba5592213f3157607f3d9185be4f225f96f978acdab937eac3dc70c237f34de99ee0deb40db1f2ea9fa9555fc59d04e6815bca609
|
data/README.md
CHANGED
@@ -26,11 +26,15 @@ end
|
|
26
26
|
This will add some familiar `has_many`-style methods:
|
27
27
|
|
28
28
|
```ruby
|
29
|
+
parent.children? #=> false
|
30
|
+
|
29
31
|
parent.children = [Child.create!, Child.create!, Child.create!]
|
30
32
|
parent.children #=> [#<Child id: 1>, #<Child id: 2>, #<Child id: 3>]
|
31
33
|
|
32
|
-
parent.child_ids = [1,2
|
33
|
-
parent.child_ids #=> [1,2
|
34
|
+
parent.child_ids = [1,2]
|
35
|
+
parent.child_ids #=> [1,2]
|
36
|
+
|
37
|
+
parent.children? #=> true
|
34
38
|
```
|
35
39
|
|
36
40
|
## Requirements
|
@@ -10,6 +10,7 @@ module ActiveRecord
|
|
10
10
|
one_ids_equals = :"#{one_ids}="
|
11
11
|
class_name ||= one.classify
|
12
12
|
many_equals = :"#{many}="
|
13
|
+
many_eh = :"#{many}?"
|
13
14
|
|
14
15
|
serialize one_ids, JSON
|
15
16
|
|
@@ -25,6 +26,10 @@ module ActiveRecord
|
|
25
26
|
define_method many_equals do |collection|
|
26
27
|
send one_ids_equals, collection.map(&:id)
|
27
28
|
end
|
29
|
+
|
30
|
+
define_method many_eh do
|
31
|
+
send(one_ids).any?
|
32
|
+
end
|
28
33
|
}
|
29
34
|
end
|
30
35
|
end
|
data/spec/json_has_many_spec.rb
CHANGED
@@ -61,6 +61,19 @@ describe ActiveRecord::JsonHasMany do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
describe "#children?" do
|
65
|
+
let(:children) { [Child.create!, Child.create!, Child.create!] }
|
66
|
+
|
67
|
+
it "returns false when there are no children" do
|
68
|
+
expect(subject.children?).to be_falsey
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns true when there are children" do
|
72
|
+
subject.children = children
|
73
|
+
expect(subject.children?).to be_truthy
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
64
77
|
context "when overriding class name" do
|
65
78
|
let(:pets) { [Pet.create!, Pet.create!, Pet.create!] }
|
66
79
|
|