passive_record 0.3.8 → 0.3.9

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: f8aef98c4504dee98e437999a2fbfc3fb087363a
4
- data.tar.gz: 737920031f79621eff0163e2547a93a86cc2829b
3
+ metadata.gz: 4f7bcf7c09ce2830df7940f8241d34b3dd79f3b0
4
+ data.tar.gz: 5d9844ff88d1aa22fc003765a4746ff1918d1e1b
5
5
  SHA512:
6
- metadata.gz: 619873a35e03b3c0ed16ae23e9f28ff97abcbe2525a581beaa91889c508c77ad74565d043d10f619ffedf44f7c7828a6e1a65374f01ca849b8c0d7b8c61cbbd2
7
- data.tar.gz: f3c817c0b0a99a41063969946f6420fce4847379f5d6bce11e431996a8ff6978846bfe2347b67db0a22d82ff0882fb53ab4bc215711dc627f94d2cb74d981c75
6
+ metadata.gz: ea71ea386493db3d619f9cb1fa58d738004622a822e31c309b730d2742e5585728c2e9a59f44e4d44b3bc31bfd0728c1b09808089fc9dd539ff3f27a9fdc63e8
7
+ data.tar.gz: 92042f4052e8e79780bdcc182fc8b784d60aad57b435c7acd0cd5324683df34b38e9472dba3b86f24f50eeaf76ba21a7498f015d54e29421186c4f92cb79b566
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # passive_record
2
2
 
3
- * [Homepage](https://rubygems.org/gems/passive_record)
4
- * [Documentation](http://rubydoc.info/gems/passive_record/frames)
5
- * [Email](mailto:jweissman1986 at gmail.com)
3
+ * [Documentation](https://rubygems.org/gems/passive_record)
4
+ * [Email](mailto:joe at deepc.io)
6
5
 
7
6
  [![Code Climate GPA](https://codeclimate.com/github/deepcerulean/passive_record/badges/gpa.svg)](https://codeclimate.com/github/deepcerulean/passive_record)
8
7
  [![Codeship Status for deepcerulean/passive_record](https://www.codeship.io/projects/66bb2d90-ba61-0133-af95-025ac38368ea/status)](https://codeship.com/projects/128700)
@@ -87,10 +86,12 @@ PassiveRecord may be right for you!
87
86
 
88
87
  ## PassiveRecord API
89
88
 
89
+
90
90
  A class including PassiveRecord will gain the following new instance and class methods.
91
91
 
92
92
  ### Instance Methods
93
93
 
94
+
94
95
  A class `Role` which is declared to `include PassiveRecord` will gain the following instance methods:
95
96
  - `role.update(attrs_hash)`
96
97
  - `role.to_h`
@@ -98,16 +99,19 @@ PassiveRecord may be right for you!
98
99
 
99
100
  ### Class Methods
100
101
 
102
+
101
103
  A class `User` which is declared to `include PassiveRecord` will gain the following class methods:
104
+
105
+ - `User.all` and `User.each`
102
106
  - `User.create(attrs_hash)`
107
+ - `User.descendants`
108
+ - `User.destroy(id)`
109
+ - `User.destroy_all`
110
+ - `User.each` enumerates over `User.all`, giving `User.count`, `User.first`, etc.
103
111
  - `User.find(id_or_ids)`
104
- - `User.find_by(conditions_hash)`
105
112
  - `User.find_all_by(conditions_hash)`
106
- - `User.all` and `User.each`
107
- - `User.each` enumerates over `User.all`, giving `User.count`, `User.first`, etc.
113
+ - `User.find_by(conditions_hash)`
108
114
  - `User.where(conditions_hash)` (returns a `PassiveRecord::Query` object)
109
- - `User.descendants`
110
- - `User.destroy_all`
111
115
 
112
116
  ### Belongs To
113
117
 
@@ -133,11 +137,11 @@ PassiveRecord may be right for you!
133
137
  A model `Parent` which declares `has_many :children` or `has_and_belongs_to_many :children` will gain:
134
138
 
135
139
  - `parent.children` (returns a `Relation`, documented below)
136
- - `parent.children_ids`
137
140
  - `parent.children=`
141
+ - `parent.children_ids`
138
142
  - `parent.children_ids=`
143
+ - `parent.children<<`
139
144
  - `parent.create_child(attrs)`
140
- - `parent.children<<` (insert a related model)
141
145
  - `parent.children.all?(&predicate)`
142
146
  - `parent.children.empty?`
143
147
  - `parent.children.where(conditions)` (returns a `Core::Query`)
@@ -73,7 +73,7 @@ module PassiveRecord
73
73
  end
74
74
 
75
75
  def destroy(id)
76
- @instances.delete(id)
76
+ @instances = instances_by_id.reject{|k,_| id == k }
77
77
  end
78
78
 
79
79
  def destroy_all
@@ -1,4 +1,4 @@
1
1
  module PassiveRecord
2
2
  # passive_record version
3
- VERSION = "0.3.8"
3
+ VERSION = "0.3.9"
4
4
  end
@@ -26,7 +26,8 @@ describe "passive record models" do
26
26
  describe "instance methods" do
27
27
  describe "#update" do
28
28
  it 'should update attrs' do
29
- expect {model.update(foo: '123')}.to change {model.foo}.from(value).to('123')
29
+ expect {model.update(foo: '123')}.
30
+ to change {model.foo}.from(value).to('123')
30
31
  end
31
32
 
32
33
  it 'should invoke callbacks' do
@@ -38,9 +39,12 @@ describe "passive record models" do
38
39
  describe "#destroy" do
39
40
  it 'should remove the entity and freeze it' do
40
41
  doomed = SimpleModel.create
41
- expect(SimpleModel.find(doomed.id)).to eq(doomed)
42
+ doomed_id = doomed.id
43
+ expect(SimpleModel.find(doomed_id)).to eq(doomed)
42
44
  doomed.destroy
43
- expect(SimpleModel.find(doomed.id)).to eq(nil)
45
+ expect(SimpleModel.find(doomed_id)).to eq(nil)
46
+
47
+ expect{10.times{SimpleModel.create}}.to change{SimpleModel.count}.by(10)
44
48
  end
45
49
  end
46
50
 
@@ -51,13 +55,16 @@ describe "passive record models" do
51
55
 
52
56
  it 'should report relations' do
53
57
  dog = Dog.create
54
- expect(dog.inspect).to eq("Family::Dog (id: #{dog.id.inspect}, breed: \"#{dog.breed}\", created_at: #{dog.created_at}, sound: \"bark\", child_id: nil)")
58
+ expect(dog.inspect).
59
+ to eq("Family::Dog (id: #{dog.id.inspect}, breed: \"#{dog.breed}\", created_at: #{dog.created_at}, sound: \"bark\", child_id: nil)")
55
60
 
56
61
  child = Child.create
57
62
  child.dogs << dog
58
- expect(dog.inspect).to eq("Family::Dog (id: #{dog.id.inspect}, breed: \"#{dog.breed}\", created_at: #{dog.created_at}, sound: \"bark\", child_id: #{child.id.inspect})")
63
+ expect(dog.inspect).
64
+ to eq("Family::Dog (id: #{dog.id.inspect}, breed: \"#{dog.breed}\", created_at: #{dog.created_at}, sound: \"bark\", child_id: #{child.id.inspect})")
59
65
 
60
- expect(child.inspect).to eq("Family::Child (id: #{child.id.inspect}, created_at: #{child.created_at}, name: \"Alice\", toy_id: nil, dog_ids: [#{dog.id.inspect}], parent_id: nil)")
66
+ expect(child.inspect).
67
+ to eq("Family::Child (id: #{child.id.inspect}, created_at: #{child.created_at}, name: \"Alice\", toy_id: nil, dog_ids: [#{dog.id.inspect}], parent_id: nil)")
61
68
  end
62
69
  end
63
70
 
@@ -395,6 +402,7 @@ describe "passive record models" do
395
402
  end
396
403
 
397
404
  context 'direct habtm' do
405
+ before(:each) { PassiveRecord.drop_all }
398
406
  let!(:user) { User.create roles: [role] }
399
407
  let(:role) { Role.create }
400
408
  let(:another_user) { User.create }
@@ -404,9 +412,12 @@ describe "passive record models" do
404
412
  expect(user.roles).to include(role)
405
413
  expect(role.user_ids).to eq([user.id])
406
414
  expect(user.role_ids).to eq([role.id])
407
-
408
415
  expect {role.users << another_user}.to change{role.users.count}.by(1)
409
416
  end
417
+
418
+ it 'should handle inverse relations' do
419
+ expect {role.users << another_user}.to change{another_user.roles.count}.by(1)
420
+ end
410
421
  end
411
422
  end
412
423
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passive_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-26 00:00:00.000000000 Z
11
+ date: 2016-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport