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 +4 -4
- data/README.md +14 -10
- data/lib/passive_record/class_methods.rb +1 -1
- data/lib/passive_record/version.rb +1 -1
- data/spec/passive_record_spec.rb +18 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f7bcf7c09ce2830df7940f8241d34b3dd79f3b0
|
4
|
+
data.tar.gz: 5d9844ff88d1aa22fc003765a4746ff1918d1e1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea71ea386493db3d619f9cb1fa58d738004622a822e31c309b730d2742e5585728c2e9a59f44e4d44b3bc31bfd0728c1b09808089fc9dd539ff3f27a9fdc63e8
|
7
|
+
data.tar.gz: 92042f4052e8e79780bdcc182fc8b784d60aad57b435c7acd0cd5324683df34b38e9472dba3b86f24f50eeaf76ba21a7498f015d54e29421186c4f92cb79b566
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# passive_record
|
2
2
|
|
3
|
-
* [
|
4
|
-
* [
|
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
|
[](https://codeclimate.com/github/deepcerulean/passive_record)
|
8
7
|
[](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.
|
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`)
|
data/spec/passive_record_spec.rb
CHANGED
@@ -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')}.
|
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
|
-
|
42
|
+
doomed_id = doomed.id
|
43
|
+
expect(SimpleModel.find(doomed_id)).to eq(doomed)
|
42
44
|
doomed.destroy
|
43
|
-
expect(SimpleModel.find(
|
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).
|
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).
|
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).
|
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.
|
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-
|
11
|
+
date: 2016-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|