card 1.16.10 → 1.16.11
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/VERSION +1 -1
- data/db/migrate/20151105225559_more_space_for_db_content.rb +6 -0
- data/db/migrate_core_cards/20150708224756_add_list_cards.rb +19 -12
- data/db/schema.rb +11 -11
- data/db/version.txt +1 -1
- data/lib/card/active_record_helper.rb +9 -11
- data/lib/card/cache.rb +18 -18
- data/mod/01_core/set/all/fetch.rb +14 -15
- data/mod/01_core/set/all/name.rb +46 -38
- data/mod/01_core/set/all/references.rb +1 -1
- data/mod/01_core/set/all/subcards.rb +1 -1
- data/mod/01_core/set/all/tracked_attributes.rb +4 -6
- data/mod/01_core/set/all/trash.rb +4 -1
- data/mod/01_core/spec/set/all/fetch_spec.rb +12 -11
- data/mod/01_core/spec/set/all/tracked_attributes_spec.rb +145 -143
- data/mod/03_machines/lib/card/machine.rb +0 -1
- data/mod/05_standard/set/all/rich_html/editing.rb +38 -30
- data/mod/05_standard/set/right/account.rb +41 -22
- data/spec/models/card/cardtype_spec.rb +11 -27
- metadata +3 -2
@@ -143,12 +143,10 @@ event :expire_related, after: :store do
|
|
143
143
|
Card.expire name, true
|
144
144
|
end
|
145
145
|
end
|
146
|
+
end
|
146
147
|
|
147
|
-
|
148
|
-
#
|
149
|
-
|
150
|
-
dependents.each { |c| c.expire(true) }
|
151
|
-
# self.referencers.each { |c| c.expire(true) }
|
148
|
+
event :expire_related_names, before: :expire_related, changed: :name do
|
149
|
+
# FIXME: look for opportunities to avoid instantiating the following
|
150
|
+
descendants.each { |c| c.expire(true) }
|
152
151
|
name_referencers.each { |c| c.expire(true) }
|
153
|
-
# FIXME: this will need review when we do the new defaults/templating system
|
154
152
|
end
|
@@ -28,7 +28,10 @@ event :validate_delete, before: :approve, on: :delete do
|
|
28
28
|
errors.add :delete, "#{name} is is a system card. (#{codename})"
|
29
29
|
end
|
30
30
|
|
31
|
-
undeletable_all_rules_tags =
|
31
|
+
undeletable_all_rules_tags =
|
32
|
+
%w{ default style layout create read update delete }
|
33
|
+
# FIXME: HACK! should be configured in the rule
|
34
|
+
|
32
35
|
if junction? && (l = left) && l.codename == 'all' &&
|
33
36
|
undeletable_all_rules_tags.member?(right.codename)
|
34
37
|
errors.add :delete, "#{name} is an indestructible rule"
|
@@ -79,20 +79,21 @@ describe Card::Set::All::Fetch do
|
|
79
79
|
|
80
80
|
# expires the saved card
|
81
81
|
expect(Card.cache).to receive(:delete).with('a').and_call_original
|
82
|
-
expect(Card.cache).to receive(:delete).with(/~\d+/).at_least(
|
82
|
+
expect(Card.cache).to receive(:delete).with(/~\d+/).at_least(1)
|
83
83
|
# expires plus cards
|
84
|
-
expect(Card.cache).to receive(:delete).with('c+a')
|
85
|
-
expect(Card.cache).to receive(:delete).with('d+a')
|
86
|
-
expect(Card.cache).to receive(:delete).with('f+a')
|
87
|
-
expect(Card.cache).to receive(:delete).with('a+b')
|
88
|
-
expect(Card.cache).to receive(:delete).with('a+c')
|
89
|
-
expect(Card.cache).to receive(:delete).with('a+d')
|
90
|
-
expect(Card.cache).to receive(:delete).with('a+e')
|
91
|
-
expect(Card.cache).to receive(:delete).with('a+b+c')
|
84
|
+
#expect(Card.cache).to receive(:delete).with('c+a')
|
85
|
+
#expect(Card.cache).to receive(:delete).with('d+a')
|
86
|
+
#expect(Card.cache).to receive(:delete).with('f+a')
|
87
|
+
#expect(Card.cache).to receive(:delete).with('a+b')
|
88
|
+
#expect(Card.cache).to receive(:delete).with('a+c')
|
89
|
+
#expect(Card.cache).to receive(:delete).with('a+d')
|
90
|
+
#expect(Card.cache).to receive(:delete).with('a+e')
|
91
|
+
#expect(Card.cache).to receive(:delete).with('a+b+c')
|
92
92
|
|
93
93
|
# expired including? cards
|
94
|
-
expect(Card.cache).to receive(:delete).with('x').exactly(2).times
|
95
|
-
expect(Card.cache).to receive(:delete).with('y').exactly(2).times
|
94
|
+
#expect(Card.cache).to receive(:delete).with('x').exactly(2).times
|
95
|
+
#expect(Card.cache).to receive(:delete).with('y').exactly(2).times
|
96
|
+
|
96
97
|
a.save!
|
97
98
|
end
|
98
99
|
end
|
@@ -1,44 +1,39 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
|
4
3
|
module RenameMethods
|
5
4
|
def name_invariant_attributes card
|
6
5
|
{
|
7
6
|
content: card.content,
|
8
|
-
#updater_id: card.updater_id,
|
9
|
-
#revisions: card.actions.count,
|
7
|
+
# updater_id: card.updater_id,
|
8
|
+
# revisions: card.actions.count,
|
10
9
|
referencers: card.referencers.map(&:name).sort,
|
11
10
|
referees: card.referees.map(&:name).sort,
|
12
|
-
|
11
|
+
descendants: card.descendants.map(&:id).sort
|
13
12
|
}
|
14
13
|
end
|
15
14
|
|
16
15
|
def assert_rename card, new_name
|
17
|
-
attrs_before = name_invariant_attributes(
|
16
|
+
attrs_before = name_invariant_attributes(card)
|
18
17
|
actions_count_before = card.actions.count
|
19
|
-
card.name=new_name
|
18
|
+
card.name = new_name
|
20
19
|
card.update_referencers = true
|
21
20
|
card.save!
|
22
|
-
expect(card.actions.count).to eq(actions_count_before+1)
|
21
|
+
expect(card.actions.count).to eq(actions_count_before + 1)
|
23
22
|
assert_equal attrs_before, name_invariant_attributes(card)
|
24
23
|
assert_equal new_name, card.name
|
25
24
|
assert Card[new_name]
|
26
25
|
end
|
27
26
|
|
28
27
|
def card name
|
29
|
-
Card[name].refresh
|
28
|
+
Card[name].refresh || raise("Couldn't find card named #{name}")
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
include RenameMethods
|
34
33
|
|
35
|
-
|
36
34
|
describe Card::Set::All::TrackedAttributes do
|
37
|
-
|
38
|
-
|
39
35
|
describe 'set_name' do
|
40
|
-
|
41
|
-
it "should handle case variants" do
|
36
|
+
it 'should handle case variants' do
|
42
37
|
@c = Card.create! name: 'chump'
|
43
38
|
expect(@c.name).to eq('chump')
|
44
39
|
@c.name = 'Chump'
|
@@ -46,7 +41,7 @@ describe Card::Set::All::TrackedAttributes do
|
|
46
41
|
expect(@c.name).to eq('Chump')
|
47
42
|
end
|
48
43
|
|
49
|
-
it
|
44
|
+
it 'should handle changing from plus card to simple' do
|
50
45
|
c = Card.create! name: 'four+five'
|
51
46
|
c.name = 'nine'
|
52
47
|
c.save!
|
@@ -55,43 +50,44 @@ describe Card::Set::All::TrackedAttributes do
|
|
55
50
|
expect(c.right_id).to eq(nil)
|
56
51
|
end
|
57
52
|
|
58
|
-
#FIXME - following tests more about fetch than set_name.
|
53
|
+
# FIXME: - following tests more about fetch than set_name.
|
54
|
+
# this spec still needs lots of cleanup
|
59
55
|
|
60
|
-
it
|
61
|
-
Card.create!(name:
|
56
|
+
it 'test fetch with new when present' do
|
57
|
+
Card.create!(name: 'Carrots')
|
62
58
|
cards_should_be_added 0 do
|
63
|
-
c=Card.fetch
|
59
|
+
c = Card.fetch 'Carrots', new: {}
|
64
60
|
c.save
|
65
61
|
expect(c).to be_instance_of(Card)
|
66
|
-
expect(Card.fetch(
|
62
|
+
expect(Card.fetch('Carrots')).to be_instance_of(Card)
|
67
63
|
end
|
68
64
|
end
|
69
65
|
|
70
|
-
it
|
66
|
+
it 'test_simple' do
|
71
67
|
cards_should_be_added 1 do
|
72
68
|
expect(Card['Boo!']).to be_nil
|
73
|
-
expect(Card.create(name:
|
69
|
+
expect(Card.create(name: 'Boo!')).to be_instance_of(Card)
|
74
70
|
expect(Card['Boo!']).to be_instance_of(Card)
|
75
71
|
end
|
76
72
|
end
|
77
73
|
|
78
|
-
|
79
|
-
it "test fetch with new when not present" do
|
74
|
+
it 'test fetch with new when not present' do
|
80
75
|
cards_should_be_added 1 do
|
81
|
-
c=Card.fetch(
|
76
|
+
c = Card.fetch('Tomatoes', new: {})
|
82
77
|
c.save
|
83
78
|
expect(c).to be_instance_of(Card)
|
84
|
-
expect(Card.fetch(
|
79
|
+
expect(Card.fetch('Tomatoes')).to be_instance_of(Card)
|
85
80
|
end
|
86
81
|
end
|
87
82
|
|
88
|
-
it
|
83
|
+
it 'test_create_junction' do
|
89
84
|
cards_should_be_added 3 do
|
90
|
-
|
85
|
+
pearch = Card.create name: 'Peach+Pear', content: 'juicy'
|
86
|
+
expect(pearch).to be_instance_of(Card)
|
91
87
|
end
|
92
|
-
expect(Card[
|
93
|
-
expect(Card[
|
94
|
-
assert_equal
|
88
|
+
expect(Card['Peach']).to be_instance_of(Card)
|
89
|
+
expect(Card['Pear']).to be_instance_of(Card)
|
90
|
+
assert_equal 'juicy', Card['Peach+Pear'].content
|
95
91
|
end
|
96
92
|
|
97
93
|
private
|
@@ -101,121 +97,121 @@ describe Card::Set::All::TrackedAttributes do
|
|
101
97
|
yield
|
102
98
|
expect(Card.all.count).to eq(number)
|
103
99
|
end
|
104
|
-
|
105
100
|
end
|
106
101
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
# FIXME: these tests are TOO SLOW! 8s against server, 12s from command line.
|
102
|
+
describe 'renaming' do
|
103
|
+
# FIXME: these tests are TOO SLOW!
|
104
|
+
# 8s against server, 12s from command line.
|
113
105
|
# not sure if it's the card creation or the actual renaming process.
|
114
106
|
# Card#save needs optimized in general.
|
115
107
|
# Can't we just move this data to fixtures?
|
116
108
|
|
117
|
-
|
118
|
-
|
119
|
-
assert_rename card("A+B"), "A+B+T"
|
109
|
+
it 'renaming plus card to its own child' do
|
110
|
+
assert_rename card('A+B'), 'A+B+T'
|
120
111
|
end
|
121
112
|
|
122
|
-
it
|
113
|
+
it 'clears cache for old name' do
|
123
114
|
assert_rename Card['Menu'], 'manure'
|
124
115
|
expect(Card['Menu']).to be_nil
|
125
116
|
end
|
126
117
|
|
127
|
-
it
|
118
|
+
it 'wipes old references by default' do
|
128
119
|
c = Card['Menu']
|
129
120
|
c.name = 'manure'
|
130
121
|
c.save!
|
131
122
|
expect(Card['manure'].references_from.size).to eq(0)
|
132
123
|
end
|
133
124
|
|
134
|
-
it
|
125
|
+
it 'picks up new references' do
|
135
126
|
Card.create name: 'kinds of poop', content: '[[manure]]'
|
136
127
|
assert_rename Card['Menu'], 'manure'
|
137
128
|
expect(Card['manure'].references_from.size).to eq(2)
|
138
129
|
end
|
139
130
|
|
140
|
-
it
|
141
|
-
assert_rename card(
|
131
|
+
it 'handles name variants' do
|
132
|
+
assert_rename card('B'), 'b'
|
142
133
|
end
|
143
134
|
|
144
|
-
it
|
145
|
-
assert_rename card(
|
135
|
+
it 'handles plus cards renamed to simple' do
|
136
|
+
assert_rename card('A+B'), 'K'
|
146
137
|
end
|
147
138
|
|
148
|
-
|
149
|
-
|
150
|
-
assert_rename card("A+B"), "B+A"
|
139
|
+
it 'handles flipped parts' do
|
140
|
+
assert_rename card('A+B'), 'B+A'
|
151
141
|
end
|
152
142
|
|
153
|
-
it
|
154
|
-
@t=card
|
155
|
-
|
156
|
-
assert
|
143
|
+
it 'test_should_error_card_exists' do
|
144
|
+
@t = card 'T'
|
145
|
+
@t.name = 'A+B'
|
146
|
+
assert !@t.save, 'save should fail'
|
147
|
+
assert @t.errors[:name], 'should have errors on key'
|
157
148
|
end
|
158
149
|
|
159
|
-
it
|
160
|
-
@b=card
|
150
|
+
it 'test_used_as_tag' do
|
151
|
+
@b = card 'B'
|
152
|
+
@b.name = 'A+D'
|
153
|
+
@b.save
|
161
154
|
assert @b.errors[:name]
|
162
155
|
end
|
163
156
|
|
164
|
-
it
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
157
|
+
it 'test_update_descendants' do
|
158
|
+
card_list = [
|
159
|
+
Card['One+Two'],
|
160
|
+
Card['One+Two+Three'],
|
161
|
+
Card['Four+One'],
|
162
|
+
Card['Four+One+Five']
|
163
|
+
]
|
164
|
+
|
165
|
+
old_names = %w{ One+Two One+Two+Three Four+One Four+One+Five }
|
166
|
+
new_names = %w{ Uno+Two Uno+Two+Three Four+Uno Four+Uno+Five }
|
167
|
+
|
168
|
+
assert_equal old_names, card_list.map(&:name)
|
169
|
+
Card['One'].update_attributes! name: 'Uno'
|
170
|
+
assert_equal new_names, card_list.map(&:reload).map(&:name)
|
175
171
|
end
|
176
172
|
|
177
|
-
it
|
178
|
-
@t=card
|
173
|
+
it 'test_should_error_invalid_name' do
|
174
|
+
@t = card 'T'
|
175
|
+
@t.name = 'YT_o~Yo'
|
176
|
+
@t.save
|
179
177
|
assert @t.errors[:name]
|
180
178
|
end
|
181
179
|
|
182
|
-
it
|
183
|
-
assert_rename card(
|
180
|
+
it 'test_simple_to_simple' do
|
181
|
+
assert_rename card('A'), 'Alephant'
|
184
182
|
end
|
185
183
|
|
186
|
-
it
|
187
|
-
assert_rename card(
|
184
|
+
it 'test_simple_to_junction_with_create' do
|
185
|
+
assert_rename card('T'), 'C+J'
|
188
186
|
end
|
189
187
|
|
190
|
-
it
|
191
|
-
c = Card[
|
192
|
-
c.name=
|
188
|
+
it 'test_reset_key' do
|
189
|
+
c = Card['Basic Card']
|
190
|
+
c.name = 'banana card'
|
193
191
|
c.save!
|
194
|
-
|
195
|
-
|
192
|
+
expect(c.key).to eq('banana_card')
|
193
|
+
expect(Card['Banana Card']).not_to be_nil
|
196
194
|
end
|
197
195
|
|
198
|
-
|
199
|
-
|
200
|
-
it "test_rename_should_not_fail_when_updating_inaccessible_referencer" do
|
201
|
-
Card.create! name: "Joe Card", content: "Whattup"
|
196
|
+
it 'test_rename_should_not_fail_when_updating_inaccessible_referencer' do
|
197
|
+
Card.create! name: 'Joe Card', content: 'Whattup'
|
202
198
|
Card::Auth.as :joe_admin do
|
203
|
-
Card.create! name:
|
199
|
+
Card.create! name: 'Admin Card', content: '[[Joe Card]]'
|
204
200
|
end
|
205
|
-
c = Card[
|
206
|
-
c.update_attributes! name:
|
207
|
-
assert_equal
|
201
|
+
c = Card['Joe Card']
|
202
|
+
c.update_attributes! name: 'Card of Joe', update_referencers: true
|
203
|
+
assert_equal '[[Card of Joe]]', Card['Admin Card'].content
|
208
204
|
end
|
209
205
|
|
210
|
-
it
|
206
|
+
it 'test_rename_should_update_structured_referencer' do
|
211
207
|
Card::Auth.as_bot do
|
212
|
-
c=Card.create! name:
|
213
|
-
Card.create! name:
|
214
|
-
Card.create! name:
|
208
|
+
c = Card.create! name: 'Pit'
|
209
|
+
Card.create! name: 'Orange', type: 'Fruit', content: '[[Pit]]'
|
210
|
+
Card.create! name: 'Fruit+*type+*structure', content: 'this [[Pit]]'
|
215
211
|
|
216
|
-
assert_equal
|
217
|
-
c.update_attributes! name:
|
218
|
-
assert_equal
|
212
|
+
assert_equal 'this [[Pit]]', Card['Orange'].raw_content
|
213
|
+
c.update_attributes! name: 'Seed', update_referencers: true
|
214
|
+
assert_equal 'this [[Seed]]', Card['Orange'].raw_content
|
219
215
|
end
|
220
216
|
end
|
221
217
|
|
@@ -227,92 +223,98 @@ describe Card::Set::All::TrackedAttributes do
|
|
227
223
|
end
|
228
224
|
end
|
229
225
|
|
230
|
-
|
231
|
-
context "chuck" do
|
226
|
+
context 'chuck' do
|
232
227
|
before do
|
233
228
|
Card::Auth.as_bot do
|
234
|
-
Card.create! name:
|
229
|
+
Card.create! name: 'chuck_wagn+chuck'
|
235
230
|
end
|
236
231
|
end
|
237
232
|
|
238
|
-
it
|
239
|
-
c1
|
240
|
-
|
241
|
-
|
233
|
+
it 'test_rename_name_substitution' do
|
234
|
+
c1 = Card['chuck_wagn+chuck']
|
235
|
+
c2 = Card['chuck']
|
236
|
+
assert_rename c2, 'buck'
|
237
|
+
assert_equal 'chuck_wagn+buck', Card.find(c1.id).name
|
242
238
|
end
|
243
239
|
|
244
|
-
it
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
240
|
+
it 'test_reference_updates_plus_to_simple' do
|
241
|
+
c1 = Card::Auth.as_bot do
|
242
|
+
Card.create! name: 'Huck', content: '[[chuck wagn+chuck]]'
|
243
|
+
end
|
244
|
+
c2 = Card['chuck_wagn+chuck']
|
245
|
+
assert_rename c2, 'schmuck'
|
246
|
+
c1 = Card.find(c1.id)
|
247
|
+
assert_equal '[[schmuck]]', c1.content
|
252
248
|
end
|
253
249
|
end
|
254
250
|
|
255
|
-
context
|
251
|
+
context 'dairy' do
|
256
252
|
before do
|
257
253
|
Card::Auth.as_bot do
|
258
|
-
Card.create!
|
254
|
+
Card.create! name: 'Dairy',
|
255
|
+
type: 'Cardtype',
|
256
|
+
content: '[[/new/{{_self|name}}|new]]'
|
259
257
|
end
|
260
258
|
end
|
261
259
|
|
262
|
-
it
|
263
|
-
c = Card[
|
264
|
-
c.name =
|
260
|
+
it 'test_renaming_card_with_self_link_should_not_hang' do
|
261
|
+
c = Card['Dairy']
|
262
|
+
c.name = 'Buttah'
|
265
263
|
c.update_referencers = true
|
266
264
|
c.save!
|
267
|
-
assert_equal
|
265
|
+
assert_equal '[[/new/{{_self|name}}|new]]', Card['Buttah'].content
|
268
266
|
end
|
269
267
|
|
270
|
-
it
|
271
|
-
c = Card[
|
272
|
-
c.update_attributes
|
273
|
-
assert_equal
|
268
|
+
it 'should rename card without updating references' do
|
269
|
+
c = Card['Dairy']
|
270
|
+
c.update_attributes name: 'Newt', update_referencers: false
|
271
|
+
assert_equal '[[/new/{{_self|name}}|new]]', Card['Newt'].content
|
274
272
|
end
|
275
273
|
end
|
276
274
|
|
277
275
|
|
278
|
-
context
|
276
|
+
context 'blues' do
|
279
277
|
before do
|
280
278
|
Card::Auth.as_bot do
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
279
|
+
[['Blue', ''],
|
280
|
+
['blue includer 1', '{{Blue}}'],
|
281
|
+
['blue includer 2', '{{blue|closed;other:stuff}}'],
|
282
|
+
['blue linker 1', '[[Blue]]'],
|
283
|
+
['blue linker 2', '[[blue]]']
|
284
|
+
].each do |name, content|
|
285
|
+
Card.create! name: name, content: content
|
286
|
+
end
|
288
287
|
end
|
289
288
|
end
|
290
289
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
290
|
+
it 'test_updates_inclusions_when_renaming' do
|
291
|
+
c1 = Card['Blue']
|
292
|
+
c2 = Card['blue includer 1']
|
293
|
+
c3 = Card['blue includer 2']
|
294
|
+
c1.update_attributes name: 'Red', update_referencers: true
|
295
|
+
assert_equal '{{Red}}', Card.find(c2.id).content
|
296
296
|
# NOTE these attrs pass through a hash stage that may not preserve order
|
297
|
-
assert_equal
|
297
|
+
assert_equal '{{Red|closed;other:stuff}}', Card.find(c3.id).content
|
298
298
|
end
|
299
299
|
|
300
|
-
it
|
301
|
-
c1
|
302
|
-
|
303
|
-
|
300
|
+
it 'test_updates_inclusions_when_renaming_to_plus' do
|
301
|
+
c1 = Card['Blue']
|
302
|
+
c2 = Card['blue includer 1']
|
303
|
+
c1.update_attributes name: 'blue includer 1+color',
|
304
|
+
update_referencers: true
|
305
|
+
assert_equal '{{blue includer 1+color}}', Card.find(c2.id).content
|
304
306
|
end
|
305
307
|
|
306
|
-
it
|
307
|
-
c1
|
308
|
-
|
308
|
+
it 'test_reference_updates_on_case_variants' do
|
309
|
+
c1 = Card['Blue']
|
310
|
+
c2 = Card['blue linker 1']
|
311
|
+
c3 = Card['blue linker 2']
|
312
|
+
c1.reload.name = 'Red'
|
309
313
|
c1.update_referencers = true
|
310
314
|
c1.save!
|
311
|
-
assert_equal
|
312
|
-
assert_equal
|
315
|
+
assert_equal '[[Red]]', Card.find(c2.id).content
|
316
|
+
assert_equal '[[Red]]', Card.find(c3.id).content
|
313
317
|
end
|
314
318
|
end
|
315
|
-
|
316
319
|
end
|
317
|
-
|
318
320
|
end
|