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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e953ea9f7439ad1d939a2c065d03e5510e04c65d
4
- data.tar.gz: b0a96975541b75458b1e9837c1cc91c53ac57ef9
3
+ metadata.gz: ba01b13afb1f06c09c3d48017a45b21a005b84a5
4
+ data.tar.gz: 5e497437e5ffbbc5d4aa7da4526fbf4a4cd10b93
5
5
  SHA512:
6
- metadata.gz: 10bb7e01b55aadeb1ed1e9fcc95a5ffe453a1bc6a57a0a0a05cfceb074cad179ff8ed81e0ad88a4cf5d3a3657b2aa7042e561529541518fe137f0f9c155477f9
7
- data.tar.gz: 9e8a1cd7323123abb4d1cb3d224e5457a9d57878cf7bcbb2c719e3f9eccba9c6f92cd0caef102b44627292cdce475afd2f7e2ea937fc980ba6571c65dbe16f56
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,3]
33
- parent.child_ids #=> [1,2,3]
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
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module JsonHasMany
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-json_has_many
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel