deferring 0.1.0 → 0.1.1
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/lib/deferring.rb +3 -0
- data/lib/deferring/version.rb +1 -1
- data/spec/lib/deferring_habtm_spec.rb +56 -5
- 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: 0807e9de82ca4e5593921580b87eaa83bc6ed3b5
|
4
|
+
data.tar.gz: cba881489e3cbb1e43a6b87e617eb4a28a3f83ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3250b185fc57e85c66a1b25b84ad111a1d98b31a76fa434e6587c16a52551d0cc9b43a2ea2abd4b7f963ad723edfe8cbb1807e12e10010d5f37865b8e9d1b198
|
7
|
+
data.tar.gz: 137c400ee0f8270e69951d5e49c6c61ee5849285983c8121a0dd1fa2aba9692a84d340bd063719445630ed92144268c4ab1fd782b4777306bed47af8618da1cb
|
data/lib/deferring.rb
CHANGED
@@ -175,8 +175,10 @@ module Deferring
|
|
175
175
|
define_method :"#{association_name.singularize}_ids=" do |ids|
|
176
176
|
find_or_create_deferred_association(association_name, listeners, inverse_association_name)
|
177
177
|
|
178
|
+
ids ||= []
|
178
179
|
klass = self.class.reflect_on_association(:"#{association_name}").klass
|
179
180
|
objects = klass.find(ids.reject(&:blank?))
|
181
|
+
|
180
182
|
send(:"deferred_#{association_name}").objects = objects
|
181
183
|
end
|
182
184
|
|
@@ -192,6 +194,7 @@ module Deferring
|
|
192
194
|
attr_accessor :"#{association_name}_checked"
|
193
195
|
# collection_singular_checked=
|
194
196
|
define_method(:"#{association_name}_checked=") do |ids|
|
197
|
+
ids ||= ''
|
195
198
|
send(:"#{association_name.singularize}_ids=", ids.split(','))
|
196
199
|
end
|
197
200
|
|
data/lib/deferring/version.rb
CHANGED
@@ -101,14 +101,65 @@ RSpec.describe 'deferred has_and_belongs_to_many associations' do
|
|
101
101
|
expect{ bob.save }.to change{ Person.where(name: 'Bob').first.teams.size }.from(0).to(1)
|
102
102
|
end
|
103
103
|
|
104
|
-
|
104
|
+
it 'unlinks all records when assigning empty array' do
|
105
|
+
bob.team_ids = [dba.id, operations.id]
|
106
|
+
bob.save
|
107
|
+
|
108
|
+
bob.team_ids = []
|
109
|
+
expect(bob.teams.length).to eq(0)
|
110
|
+
|
111
|
+
expect{ bob.save }.to change{ Person.where(name: 'Bob').first.teams.size }.from(2).to(0)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'unlinks all records when assigning nil' do
|
115
|
+
bob.team_ids = [dba.id, operations.id]
|
116
|
+
bob.save
|
117
|
+
|
118
|
+
bob.team_ids = nil
|
119
|
+
expect(bob.teams.length).to eq(0)
|
120
|
+
|
121
|
+
expect{ bob.save }.to change{ Person.where(name: 'Bob').first.teams.size }.from(2).to(0)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#collection_checked=' do
|
126
|
+
|
127
|
+
it 'set associated records' do
|
128
|
+
bob.teams_checked = "#{dba.id},#{operations.id}"
|
129
|
+
expect{ bob.save }.to change{ Person.where(name: 'Bob').first.teams.size }.from(0).to(2)
|
130
|
+
end
|
105
131
|
|
106
|
-
|
107
|
-
|
132
|
+
it 'replace existing records when assigning a new set of ids of records' do
|
133
|
+
bob.team_ids = [dba.id, operations.id]
|
134
|
+
bob.save
|
135
|
+
|
136
|
+
# Replace DBA and Operations by Support.
|
137
|
+
bob.teams_checked = "#{support.id}"
|
138
|
+
|
139
|
+
expect{ bob.save }.to change{ Person.where(name: 'Bob').first.teams.size }.from(2).to(1)
|
140
|
+
expect(bob.teams.first).to eq(support)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'unlinks all records when assigning empty string' do
|
144
|
+
bob.team_ids = [dba.id, operations.id]
|
145
|
+
bob.save
|
146
|
+
|
147
|
+
# Unlinks DBA and Operations.
|
148
|
+
bob.teams_checked = ""
|
149
|
+
expect(bob.teams.length).to eq(0)
|
150
|
+
|
151
|
+
expect{ bob.save }.to change{ Person.where(name: 'Bob').first.teams.size }.from(2).to(0)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'unlinks all records when assigning nil' do
|
155
|
+
bob.team_ids = [dba.id, operations.id]
|
156
|
+
bob.save
|
108
157
|
|
109
|
-
|
110
|
-
|
158
|
+
# Unlinks DBA and Operations.
|
159
|
+
bob.teams_checked = nil
|
160
|
+
expect(bob.teams.length).to eq(0)
|
111
161
|
|
162
|
+
expect{ bob.save }.to change{ Person.where(name: 'Bob').first.teams.size }.from(2).to(0)
|
112
163
|
end
|
113
164
|
|
114
165
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deferring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robin Roestenburg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|