card 1.16.8 → 1.16.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/db/migrate_core_cards/{20150611203506_rails_inflection_updates.rb → 20120611203506_rails_inflection_updates.rb} +0 -0
  4. data/db/migrate_core_cards/20150326205655_bootswatch_themes.rb +0 -1
  5. data/db/migrate_core_cards/20150429090551_search_card_context.rb +1 -1
  6. data/db/migrate_core_cards/20150708224756_add_list_cards.rb +22 -0
  7. data/db/seed/new/card_actions.yml +789 -509
  8. data/db/seed/new/card_acts.yml +1 -1
  9. data/db/seed/new/card_changes.yml +2618 -1920
  10. data/db/seed/new/card_references.yml +1034 -901
  11. data/db/seed/new/cards.yml +2303 -1675
  12. data/db/seed/test/fixtures/card_actions.yml +1926 -1606
  13. data/db/seed/test/fixtures/card_acts.yml +354 -324
  14. data/db/seed/test/fixtures/card_changes.yml +5950 -5175
  15. data/db/seed/test/fixtures/card_references.yml +1861 -1630
  16. data/db/seed/test/fixtures/cards.yml +3768 -3048
  17. data/db/seed/test/seed.rb +121 -107
  18. data/lib/card.rb +2 -3
  19. data/lib/card/active_record_helper.rb +44 -0
  20. data/lib/card/auth.rb +51 -47
  21. data/lib/card/cache.rb +7 -3
  22. data/lib/card/codename.rb +7 -7
  23. data/lib/card/format.rb +2 -1
  24. data/lib/card/migration.rb +17 -16
  25. data/lib/card/name.rb +71 -20
  26. data/lib/card/set.rb +202 -166
  27. data/lib/card/simplecov_helper.rb +11 -7
  28. data/lib/card/subcards.rb +249 -0
  29. data/mod/01_core/set/all/collection.rb +1 -2
  30. data/mod/01_core/set/all/fetch.rb +167 -92
  31. data/mod/01_core/set/all/initialize.rb +8 -22
  32. data/mod/01_core/set/all/name.rb +128 -79
  33. data/mod/01_core/set/all/phases.rb +93 -95
  34. data/mod/01_core/set/all/subcards.rb +70 -0
  35. data/mod/01_core/set/all/tracked_attributes.rb +83 -59
  36. data/mod/01_core/set/all/trash.rb +14 -12
  37. data/mod/01_core/set/all/type.rb +3 -24
  38. data/mod/01_core/spec/set/all/initialize_spec.rb +44 -14
  39. data/mod/01_core/spec/set/all/permissions_spec.rb +206 -185
  40. data/mod/01_core/spec/set/all/tracked_attributes_spec.rb +0 -10
  41. data/mod/01_core/spec/set/all/trash_spec.rb +38 -13
  42. data/mod/01_core/spec/set/all/type_spec.rb +0 -19
  43. data/mod/01_history/set/all/content_history.rb +5 -3
  44. data/mod/01_history/set/all/history.rb +117 -82
  45. data/mod/02_basic_types/set/all/base.rb +50 -49
  46. data/mod/03_machines/lib/card/machine.rb +2 -1
  47. data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +55 -17
  48. data/mod/03_machines/spec/set/type/javascript_spec.rb +18 -12
  49. data/mod/05_email/set/right/followers.rb +5 -5
  50. data/mod/05_email/set/right/following.rb +1 -1
  51. data/mod/05_email/set/type_plus_right/user/follow.rb +1 -1
  52. data/mod/05_standard/lib/carrier_wave/cardmount.rb +19 -11
  53. data/mod/05_standard/lib/file_uploader.rb +1 -1
  54. data/mod/05_standard/set/abstract/attachment.rb +20 -8
  55. data/mod/05_standard/set/all/list_changes.rb +43 -0
  56. data/mod/05_standard/set/all/rich_html/form.rb +21 -11
  57. data/mod/05_standard/set/all/rich_html/menu.rb +1 -1
  58. data/mod/05_standard/set/right/account.rb +5 -5
  59. data/mod/05_standard/set/self/head.rb +0 -1
  60. data/mod/05_standard/set/self/signin.rb +43 -35
  61. data/mod/05_standard/set/type/file.rb +9 -2
  62. data/mod/05_standard/set/type/list.rb +134 -0
  63. data/mod/05_standard/set/type/listed_by.rb +94 -0
  64. data/mod/05_standard/set/type/search_type.rb +62 -61
  65. data/mod/05_standard/set/type/signup.rb +94 -63
  66. data/mod/05_standard/set/type/user.rb +48 -39
  67. data/mod/05_standard/spec/set/all/account_spec.rb +1 -1
  68. data/mod/05_standard/spec/set/all/rich_html/form_spec.rb +2 -2
  69. data/mod/05_standard/spec/set/self/signin_spec.rb +23 -27
  70. data/mod/05_standard/spec/set/type/email_template_spec.rb +0 -2
  71. data/mod/05_standard/spec/set/type/list_spec.rb +140 -0
  72. data/mod/05_standard/spec/set/type/listed_by_spec.rb +157 -0
  73. data/mod/05_standard/spec/set/type/signup_spec.rb +38 -32
  74. data/spec/lib/card/subcards_spec.rb +126 -0
  75. metadata +14 -3
@@ -1,54 +1,52 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  class ::Card
4
- def writeable_by(user)
4
+ def writeable_by user
5
5
  Card::Auth.as(user.id) do
6
- #warn "writeable #{Card::Auth.as_id}, #{user.inspect}"
6
+ # warn "writeable #{Card::Auth.as_id}, #{user.inspect}"
7
7
  ok? :update
8
8
  end
9
9
  end
10
10
 
11
- def readable_by(user)
11
+ def readable_by user
12
12
  Card::Auth.as(user.id) do
13
13
  ok? :read
14
14
  end
15
15
  end
16
16
  end
17
17
 
18
-
19
18
  module PermissionSpecHelper
20
-
21
- def assert_hidden_from( user, card, msg='')
22
- Card::Auth.as(user.id) { assert_hidden( card, msg ) }
19
+ def assert_hidden_from user, card, msg=''
20
+ Card::Auth.as(user.id) { assert_hidden(card, msg) }
23
21
  end
24
22
 
25
- def assert_not_hidden_from( user, card, msg='')
26
- Card::Auth.as(user.id) { assert_not_hidden( card, msg ) }
23
+ def assert_not_hidden_from user, card, msg=''
24
+ Card::Auth.as(user.id) { assert_not_hidden(card, msg) }
27
25
  end
28
26
 
29
- def assert_locked_from( user, card, msg='')
30
- Card::Auth.as(user.id) { assert_locked( card, msg ) }
27
+ def assert_locked_from user, card, msg=''
28
+ Card::Auth.as(user.id) { assert_locked(card, msg) }
31
29
  end
32
30
 
33
- def assert_not_locked_from( user, card, msg='')
34
- Card::Auth.as(user.id) { assert_not_locked( card, msg ) }
31
+ def assert_not_locked_from user, card, msg=''
32
+ Card::Auth.as(user.id) { assert_not_locked(card, msg) }
35
33
  end
36
34
 
37
- def assert_hidden( card, msg='' )
35
+ def assert_hidden card, msg=''
38
36
  assert !card.ok?(:read)
39
37
  assert_equal [], Card.search(id: card.id).map(&:name), msg
40
38
  end
41
39
 
42
- def assert_not_hidden( card, msg='' )
40
+ def assert_not_hidden card, msg=''
43
41
  assert card.ok?(:read)
44
42
  assert_equal [card.name], Card.search(id: card.id).map(&:name), msg
45
43
  end
46
44
 
47
- def assert_locked( card, msg='' )
45
+ def assert_locked card, msg=''
48
46
  assert_equal false, card.ok?(:update), msg
49
47
  end
50
48
 
51
- def assert_not_locked( card, msg='' )
49
+ def assert_not_locked card, msg=''
52
50
  assert_equal true, card.ok?(:update), msg
53
51
  end
54
52
  end
@@ -56,35 +54,34 @@ end
56
54
  include PermissionSpecHelper
57
55
 
58
56
  describe Card::Set::All::Permissions do
57
+ # FIXME: lots of good tests here, butmysql generally disorganized.
59
58
 
60
- #FIXME - lots of good tests here, but generally disorganized.
61
-
62
- describe "reader rules" do
59
+ describe 'reader rules' do
63
60
  before do
64
- @perm_card = Card.new(name: 'Home+*self+*read', type: 'Pointer', content: '[[Anyone Signed In]]')
61
+ @perm_card = Card.new name: 'Home+*self+*read', type: 'Pointer',
62
+ content: '[[Anyone Signed In]]'
65
63
  end
66
64
 
67
- it "should be *all+*read by default" do
65
+ it 'is *all+*read by default' do
68
66
  card = Card.fetch('Home')
69
67
  expect(card.read_rule_id).to eq(Card.fetch('*all+*read').id)
70
68
  expect(card.who_can(:read)).to eq([Card::AnyoneID])
71
- Card::Auth.as(:anonymous){ expect(card.ok?(:read)).to be_truthy }
69
+ Card::Auth.as(:anonymous) { expect(card.ok?(:read)).to be_truthy }
72
70
  end
73
71
 
74
- it "should update to role ('Anyone Signed In')" do
75
-
72
+ it "updates to role ('Anyone Signed In')" do
76
73
  name = @perm_card.name
77
74
  Card::Auth.as_bot { @perm_card.save! }
78
75
  pc = Card[name]
79
76
  card = Card['Home']
80
- #warn "card #{name}, #{card.inspect}, #{pc.inspect}"
77
+ # warn "card #{name}, #{card.inspect}, #{pc.inspect}"
81
78
  expect(pc).to be
82
79
  expect(card.read_rule_id).to eq(pc.id)
83
80
  expect(card.who_can(:read)).to eq([Card::AnyoneSignedInID])
84
- Card::Auth.as(:anonymous){ expect(card.ok?(:read)).to be_falsey }
81
+ Card::Auth.as(:anonymous) { expect(card.ok?(:read)).to be_falsey }
85
82
  end
86
83
 
87
- it "should update to user ('Joe Admin')" do
84
+ it "updates to user ('Joe Admin')" do
88
85
  @perm_card.content = '[[Joe Admin]]'
89
86
  Card::Auth.as_bot { @perm_card.save! }
90
87
 
@@ -97,57 +94,67 @@ describe Card::Set::All::Permissions do
97
94
  Card::Auth.as_bot { expect(card.ok?(:read)).to be_truthy }
98
95
  end
99
96
 
100
- it "should revert to more general rule when more specific (self) rule is deleted" do
101
- Card::Auth.as_bot do
102
- @perm_card.save!
103
- @perm_card.delete!
97
+ context 'when more specific (self) rule is deleted' do
98
+ it 'reverts to more general rule' do
99
+ Card::Auth.as_bot do
100
+ @perm_card.save!
101
+ @perm_card.delete!
102
+ end
103
+ card = Card.fetch('Home')
104
+ expect(card.read_rule_id).to eq(Card.fetch('*all+*read').id)
104
105
  end
105
- card = Card.fetch('Home')
106
- expect(card.read_rule_id).to eq(Card.fetch('*all+*read').id)
107
106
  end
108
107
 
109
- it "should revert to more general rule when more specific (right) rule is deleted" do
110
- pc = nil
111
- Card::Auth.as_bot do
112
- pc=Card.create(name: 'B+*right+*read', type: 'Pointer', content: '[[Anyone Signed In]]')
108
+ context 'when more specific (right) rule is deleted' do
109
+ it 'reverts to more general rule' do
110
+ pc = nil
111
+ Card::Auth.as_bot do
112
+ pc = Card.create name: 'B+*right+*read', type: 'Pointer',
113
+ content: '[[Anyone Signed In]]'
114
+ end
115
+ expect(pc).to be
116
+ card = Card.fetch('A+B')
117
+ expect(card.read_rule_id).to eq(pc.id)
118
+ # important to re-fetch to catch issues
119
+ # with detecting change in trash status.
120
+ pc = Card.fetch(pc.name)
121
+ Card::Auth.as_bot { pc.delete }
122
+ card = Card.fetch('A+B')
123
+ expect(card.read_rule_id).to eq(Card.fetch('*all+*read').id)
113
124
  end
114
- expect(pc).to be
115
- card = Card.fetch('A+B')
116
- expect(card.read_rule_id).to eq(pc.id)
117
- pc = Card.fetch(pc.name) #important to re-fetch to catch issues with detecting change in trash status.
118
- Card::Auth.as_bot { pc.delete }
119
- card = Card.fetch('A+B')
120
- expect(card.read_rule_id).to eq(Card.fetch('*all+*read').id)
121
125
  end
122
126
 
123
- it "should revert to more general rule when more specific rule is renamed" do
127
+ context 'when more specific rule is renamed' do
128
+ it 'reverts to more general rule' do
129
+ Card::Auth.as_bot do
130
+ @perm_card.save!
131
+ @perm_card = Card[@perm_card.name]
132
+ @perm_card.name = 'Something else+*self+*read'
133
+ @perm_card.save!
134
+ end
124
135
 
125
- Card::Auth.as_bot do
126
- @perm_card.save!
127
- @perm_card = Card[@perm_card.name]
128
- @perm_card.name = 'Something else+*self+*read'
129
- @perm_card.save!
136
+ card = Card.fetch('Home')
137
+ expect(card.read_rule_id).to eq(Card.fetch('*all+*read').id)
130
138
  end
131
-
132
- card = Card.fetch('Home')
133
- expect(card.read_rule_id).to eq(Card.fetch('*all+*read').id)
134
139
  end
135
140
 
136
- it "should not be overruled by a more general rule added later" do
141
+ it 'gets not overruled by a more general rule added later' do
137
142
  Card::Auth.as_bot do
138
143
  @perm_card.save!
139
- c= Card.fetch('Home')
144
+ c = Card.fetch('Home')
140
145
  c.type_id = Card::PhraseID
141
146
  c.save!
142
- Card.create(name: 'Phrase+*type+*read', type: 'Pointer', content: '[[Joe User]]')
147
+ Card.create name: 'Phrase+*type+*read', type: 'Pointer',
148
+ content: '[[Joe User]]'
143
149
  end
144
150
 
145
151
  card = Card.fetch('Home')
146
152
  expect(card.read_rule_id).to eq(@perm_card.id)
147
153
  end
148
154
 
149
- it "should get updated when trunk type change makes type-plus-right apply / unapply" do
150
- @perm_card.name = "Phrase+B+*type plus right+*read"
155
+ it 'gets updated when trunk type change makes ' \
156
+ 'type-plus-right apply / unapply' do
157
+ @perm_card.name = 'Phrase+B+*type plus right+*read'
151
158
  Card::Auth.as_bot { @perm_card.save! }
152
159
  expect(Card.fetch('A+B').read_rule_id).to eq(Card.fetch('*all+*read').id)
153
160
  c = Card.fetch('A')
@@ -156,10 +163,10 @@ describe Card::Set::All::Permissions do
156
163
  expect(Card.fetch('A+B').read_rule_id).to eq(@perm_card.id)
157
164
  end
158
165
 
159
- it "should work with relative settings" do
166
+ it 'works with relative settings' do
160
167
  Card::Auth.as_bot do
161
168
  @perm_card.save!
162
- all_plus = Card.fetch '*all plus+*read', new: {content: '_left'}
169
+ all_plus = Card.fetch '*all plus+*read', new: { content: '_left' }
163
170
  all_plus.save
164
171
  end
165
172
  c = Card.new(name: 'Home+Heart')
@@ -169,58 +176,61 @@ describe Card::Set::All::Permissions do
169
176
  expect(c.read_rule_id).to eq(@perm_card.id)
170
177
  end
171
178
 
172
- it "should get updated when relative settings change" do
179
+ it 'should get updated when relative settings change' do
173
180
  Card::Auth.as_bot do
174
- all_plus = Card.fetch '*all plus+*read', new: {content: '_left'}
181
+ all_plus = Card.fetch '*all plus+*read', new: { content: '_left' }
175
182
  all_plus.save
176
183
  end
177
184
  c = Card.new(name: 'Home+Heart')
178
185
  expect(c.who_can(:read)).to eq([Card::AnyoneID])
179
- expect(c.permission_rule_card(:read).first.id).to eq(Card.fetch('*all+*read').id)
186
+ expect(c.permission_rule_card(:read).first.id).to(
187
+ eq(Card.fetch('*all+*read').id)
188
+ )
180
189
  c.save
181
190
  expect(c.read_rule_id).to eq(Card.fetch('*all+*read').id)
182
191
  Card::Auth.as_bot { @perm_card.save! }
183
192
  c2 = Card.fetch('Home+Heart')
184
193
  expect(c2.who_can(:read)).to eq([Card::AnyoneSignedInID])
185
194
  expect(c2.read_rule_id).to eq(@perm_card.id)
186
- expect(Card.fetch('Home+Heart').read_rule_id).to eq(@perm_card.id)
187
- Card::Auth.as_bot{ @perm_card.delete }
195
+ expect(Card.fetch('Home+Heart').read_rule_id).to(
196
+ eq(@perm_card.id)
197
+ )
198
+ Card::Auth.as_bot { @perm_card.delete }
188
199
  expect(Card.fetch('Home').read_rule_id).to eq(Card.fetch('*all+*read').id)
189
- expect(Card.fetch('Home+Heart').read_rule_id).to eq(Card.fetch('*all+*read').id)
200
+ expect(Card.fetch('Home+Heart').read_rule_id).to(
201
+ eq(Card.fetch('*all+*read').id)
202
+ )
190
203
  end
191
204
 
192
- it "should insure that class overrides work with relative settings" do
205
+ it 'should insure that class overrides work with relative settings' do
193
206
  Card::Auth.as_bot do
194
207
  all_plus = Card.fetch '*all plus+*read', new: { content: '_left' }
195
208
  all_plus.save
196
209
  Card::Auth.as_bot { @perm_card.save! }
197
210
  c = Card.create(name: 'Home+Heart')
198
211
  expect(c.read_rule_id).to eq(@perm_card.id)
199
- r = Card.create(name: 'Heart+*right+*read', type: 'Pointer', content: '[[Administrator]]')
212
+ r = Card.create name: 'Heart+*right+*read', type: 'Pointer',
213
+ content: '[[Administrator]]'
200
214
  expect(Card.fetch('Home+Heart').read_rule_id).to eq(r.id)
201
215
  end
202
216
  end
203
217
 
204
- it "should work on virtual+virtual cards" do
218
+ it 'should work on virtual+virtual cards' do
205
219
  c = Card.fetch('Number+*type+by name')
206
220
  expect(c.ok?(:read)).to be_truthy
207
221
  end
208
-
209
222
  end
210
223
 
211
-
212
-
213
224
  context '??' do
214
225
  before do
215
226
  Card::Auth.as_bot do
216
- # Card::Auth.cache.reset
227
+ # Card::Auth.cache.reset
217
228
  @u1, @u2, @u3, @r1, @r2, @r3, @c1, @c2, @c3 =
218
- %w( u1 u2 u3 r1 r2 r3 c1 c2 c3 ).map do |x| Card[x] end
229
+ %w( u1 u2 u3 r1 r2 r3 c1 c2 c3 ).map { |x| Card[x] }
219
230
  end
220
231
  end
221
232
 
222
-
223
- it "checking ok read should not add to errors" do
233
+ it 'checking ok read should not add to errors' do
224
234
  Card::Auth.as_bot do
225
235
  expect(Card::Auth.always_ok?).to eq(true)
226
236
  end
@@ -229,8 +239,9 @@ describe Card::Set::All::Permissions do
229
239
  end
230
240
  Card::Auth.as(:joe_admin) do
231
241
  expect(Card::Auth.always_ok?).to eq(true)
232
- Card.create! name: "Hidden"
233
- Card.create(name: 'Hidden+*self+*read', type: 'Pointer', content: '[[Anyone Signed In]]')
242
+ Card.create! name: 'Hidden'
243
+ Card.create name: 'Hidden+*self+*read', type: 'Pointer',
244
+ content: '[[Anyone Signed In]]'
234
245
  end
235
246
 
236
247
  Card::Auth.as(:anonymous) do
@@ -240,70 +251,75 @@ describe Card::Set::All::Permissions do
240
251
  end
241
252
  end
242
253
 
243
- it "should be granted to admin if to anybody" do
254
+ it 'should be granted to admin if to anybody' do
244
255
  Card::Auth.as_bot do
245
256
  c1 = Card['c1']
246
- Card.create! name: 'c1+*self+*comment', type: 'Pointer', content: '[[r1]]'
247
- expect(c1.who_can( :comment )).to eq([Card['r1'].id])
257
+ Card.create! name: 'c1+*self+*comment', type: 'Pointer',
258
+ content: '[[r1]]'
259
+ expect(c1.who_can(:comment)).to eq([Card['r1'].id])
248
260
  expect(c1.ok?(:comment)).to be_truthy
249
261
  end
250
262
  end
251
263
 
252
- it "reader setting" do
253
- Card.where(trash: false).each do |c|
254
- prc = c.permission_rule_card(:read)
255
- #warn "C #{c.inspect}, #{c.read_rule_id}, #{prc.first.id}, #{c.read_rule_class}, #{prc.second}, #{prc.first.inspect}" unless prc.last == c.read_rule_class && prc.first.id == c.read_rule_id
256
- expect(prc.last).to eq(c.read_rule_class)
257
- expect(prc.first.id).to eq(c.read_rule_id)
264
+ it 'reader setting' do
265
+ Card.where(trash: false).each do |ca|
266
+ rule_card, rule_class = ca.permission_rule_card(:read)
267
+ # warn "C #{c.inspect}, #{c.read_rule_id}, #{prc.first.id},
268
+ # {c.read_rule_class}, #{prc.second}, #{prc.first.inspect}" unless
269
+ # prc.last == c.read_rule_class && prc.first.id == c.read_rule_id
270
+ expect(rule_class).to eq(ca.read_rule_class)
271
+ expect(rule_card.id).to eq(ca.read_rule_id)
258
272
  end
259
273
  end
260
274
 
261
-
262
- it "write user permissions" do
275
+ it 'write user permissions' do
263
276
  Card::Auth.as_bot do
264
277
  @u1.fetch(trait: :roles, new: {}).items = [@r1, @r2]
265
278
  @u2.fetch(trait: :roles, new: {}).items = [@r1, @r3]
266
279
  @u3.fetch(trait: :roles, new: {}).items = [@r1, @r2, @r3]
267
280
 
268
- cards=[1,2,3].map do |num|
269
- Card.create(name: "c#{num}+*self+*update", type: 'Pointer', content: "[[u#{num}]]")
281
+ (1..3).map do |num|
282
+ Card.create name: "c#{num}+*self+*update", type: 'Pointer',
283
+ content: "[[u#{num}]]"
270
284
  end
271
285
  end
272
286
 
273
287
  @c1 = Card['c1']
274
- assert_not_locked_from( @u1, @c1 )
275
- assert_locked_from( @u2, @c1 )
276
- assert_locked_from( @u3, @c1 )
288
+ assert_not_locked_from(@u1, @c1)
289
+ assert_locked_from(@u2, @c1)
290
+ assert_locked_from(@u3, @c1)
277
291
 
278
292
  @c2 = Card['c2']
279
- assert_locked_from( @u1, @c2 )
280
- assert_not_locked_from( @u2, @c2 )
281
- assert_locked_from( @u3, @c2 )
293
+ assert_locked_from(@u1, @c2)
294
+ assert_not_locked_from(@u2, @c2)
295
+ assert_locked_from(@u3, @c2)
282
296
  end
283
297
 
284
- it "read group permissions" do
298
+ it 'read group permissions' do
285
299
  Card::Auth.as_bot do
286
300
  @u1.fetch(trait: :roles).items = [@r1, @r2]
287
301
  @u2.fetch(trait: :roles).items = [@r1, @r3]
288
302
 
289
- [1,2,3].each do |num|
290
- Card.create(name: "c#{num}+*self+*read", type: 'Pointer', content: "[[r#{num}]]")
303
+ (1..3).each do |num|
304
+ Card.create name: "c#{num}+*self+*read", type: 'Pointer',
305
+ content: "[[r#{num}]]"
291
306
  end
292
307
  end
293
308
 
294
- assert_not_hidden_from( @u1, @c1 )
295
- assert_not_hidden_from( @u1, @c2 )
296
- assert_hidden_from( @u1, @c3 )
309
+ assert_not_hidden_from(@u1, @c1)
310
+ assert_not_hidden_from(@u1, @c2)
311
+ assert_hidden_from(@u1, @c3)
297
312
 
298
- assert_not_hidden_from( @u2, @c1 )
299
- assert_hidden_from( @u2, @c2 )
300
- assert_not_hidden_from( @u2, @c3 )
313
+ assert_not_hidden_from(@u2, @c1)
314
+ assert_hidden_from(@u2, @c2)
315
+ assert_not_hidden_from(@u2, @c3)
301
316
  end
302
317
 
303
- it "write group permissions" do
318
+ it 'write group permissions' do
304
319
  Card::Auth.as_bot do
305
- [1,2,3].each do |num|
306
- Card.create(name: "c#{num}+*self+*update", type: 'Pointer', content: "[[r#{num}]]")
320
+ (1..3).each do |num|
321
+ Card.create name: "c#{num}+*self+*update", type: 'Pointer',
322
+ content: "[[r#{num}]]"
307
323
  end
308
324
 
309
325
  @u3.fetch(trait: :roles, new: {}).items = [@r1]
@@ -315,94 +331,110 @@ describe Card::Set::All::Permissions do
315
331
  c3(r3) T F F
316
332
  }
317
333
 
318
- assert_equal true, @c1.writeable_by(@u1), "c1 writeable by u1"
319
- assert_equal true, @c1.writeable_by(@u2), "c1 writeable by u2"
320
- assert_equal true, @c1.writeable_by(@u3), "c1 writeable by u3"
321
- assert_equal true, @c2.writeable_by(@u1), "c2 writeable by u1"
322
- assert_equal true, @c2.writeable_by(@u2), "c2 writeable by u2"
323
- assert_equal false, @c2.writeable_by(@u3), "c2 writeable by u3"
324
- assert_equal true, @c3.writeable_by(@u1), "c3 writeable by u1"
325
- assert_equal false, @c3.writeable_by(@u2), "c3 writeable by u2"
326
- assert_equal false, @c3.writeable_by(@u3), "c3 writeable by u3"
334
+ assert_equal true, @c1.writeable_by(@u1), 'c1 writeable by u1'
335
+ assert_equal true, @c1.writeable_by(@u2), 'c1 writeable by u2'
336
+ assert_equal true, @c1.writeable_by(@u3), 'c1 writeable by u3'
337
+ assert_equal true, @c2.writeable_by(@u1), 'c2 writeable by u1'
338
+ assert_equal true, @c2.writeable_by(@u2), 'c2 writeable by u2'
339
+ assert_equal false, @c2.writeable_by(@u3), 'c2 writeable by u3'
340
+ assert_equal true, @c3.writeable_by(@u1), 'c3 writeable by u1'
341
+ assert_equal false, @c3.writeable_by(@u2), 'c3 writeable by u2'
342
+ assert_equal false, @c3.writeable_by(@u3), 'c3 writeable by u3'
327
343
  end
328
344
 
329
- it "read user permissions" do
330
- Card::Auth.as_bot {
345
+ it 'read user permissions' do
346
+ Card::Auth.as_bot do
331
347
  @u1.fetch(trait: :roles, new: {}).items = [@r1, @r2]
332
348
  @u2.fetch(trait: :roles, new: {}).items = [@r1, @r3]
333
349
  @u3.fetch(trait: :roles, new: {}).items = [@r1, @r2, @r3]
334
350
 
335
- [1,2,3].each do |num|
336
- Card.create(name: "c#{num}+*self+*read", type: 'Pointer', content: "[[u#{num}]]")
351
+ (1..3).each do |num|
352
+ Card.create name: "c#{num}+*self+*read", type: 'Pointer',
353
+ content: "[[u#{num}]]"
337
354
  end
338
- }
339
-
355
+ end
340
356
 
341
357
  # NOTE: retrieving private cards is known not to work now.
342
- # assert_not_hidden_from( @u1, @c1 )
343
- # assert_not_hidden_from( @u2, @c2 )
358
+ # assert_not_hidden_from(@u1, @c1)
359
+ # assert_not_hidden_from(@u2, @c2)
344
360
 
345
- assert_hidden_from( @u2, @c1 )
346
- assert_hidden_from( @u3, @c1 )
347
- assert_hidden_from( @u1, @c2 )
348
- assert_hidden_from( @u3, @c2 )
361
+ assert_hidden_from(@u2, @c1)
362
+ assert_hidden_from(@u3, @c1)
363
+ assert_hidden_from(@u1, @c2)
364
+ assert_hidden_from(@u3, @c2)
349
365
  end
350
366
 
351
- context "create permissions" do
367
+ context 'create permissions' do
352
368
  before do
353
369
  Card::Auth.as_bot do
354
- Card.create! name: '*structure+*right+*create', type: 'Pointer', content: '[[Anyone Signed In]]'
355
- Card.create! name: '*self+*right+*create', type: 'Pointer', content: '[[Anyone Signed In]]'
370
+ Card.create! name: '*structure+*right+*create', type: 'Pointer',
371
+ content: '[[Anyone Signed In]]'
372
+ Card.create! name: '*self+*right+*create', type: 'Pointer',
373
+ content: '[[Anyone Signed In]]'
356
374
  end
357
375
  end
358
376
 
359
- it "should inherit" do
377
+ it 'inherits' do
360
378
  Card::Auth.as(:anyone_signed_in) do
361
- expect(Card.fetch( 'A+*self' ).ok?(:create)).to be_truthy #explicitly granted above
362
- expect(Card.fetch( 'A+*right').ok?(:create)).to be_falsey #by default restricted
363
-
364
- expect(Card.fetch( 'A+*self+*structure', new: {} ).ok?(:create)).to be_truthy # +*structure granted;
365
- expect(Card.fetch( 'A+*right+*structure', new: {} ).ok?(:create)).to be_falsey # can't create A+B, therefore can't create A+B+C
379
+ # explicitly granted above
380
+ expect(Card.fetch('A+*self').ok?(:create)).to be_truthy
381
+ # by default restricted
382
+ expect(Card.fetch('A+*right').ok?(:create)).to be_falsey
383
+
384
+ expect(Card.fetch('A+*self+*structure', new: {}).ok?(:create)).to(
385
+ be_truthy # +*structure granted;
386
+ )
387
+ expect(Card.fetch('A+*right+*structure', new: {}).ok?(:create)).to(
388
+ be_falsey # can't create A+B, therefore can't create A+B+C
389
+ )
366
390
  end
367
391
  end
368
-
369
392
  end
370
393
 
371
-
372
- it "private wql" do
394
+ it 'private wql' do
373
395
  # set up cards of type TestType, 2 with nil reader, 1 with role1 reader
374
- Card::Auth.as_bot do
375
- [@c1,@c2,@c3].each do |c|
376
- c.update_attributes content: 'WeirdWord'
377
- end
378
- Card.create(name: "c1+*self+*read", type: 'Pointer', content: "[[u1]]")
379
- end
396
+ Card::Auth.as_bot do
397
+ [@c1, @c2, @c3].each do |c|
398
+ c.update_attributes content: 'WeirdWord'
399
+ end
400
+ Card.create(name: 'c1+*self+*read', type: 'Pointer', content: '[[u1]]')
401
+ end
380
402
 
381
- Card::Auth.as(@u1) do
382
- expect(Card.search(content: 'WeirdWord').map(&:name).sort).to eq(%w( c1 c2 c3 ))
383
- end
384
- Card::Auth.as(@u2) do
385
- expect(Card.search(content: 'WeirdWord').map(&:name).sort).to eq(%w( c2 c3 ))
386
- end
403
+ Card::Auth.as(@u1) do
404
+ expect(Card.search(content: 'WeirdWord').map(&:name).sort).to(
405
+ eq %w( c1 c2 c3 )
406
+ )
407
+ end
408
+ Card::Auth.as(@u2) do
409
+ expect(Card.search(content: 'WeirdWord').map(&:name).sort).to(
410
+ eq %w( c2 c3 )
411
+ )
412
+ end
387
413
  end
388
414
 
389
- it "role wql" do
390
- #warn "u1 roles #{Card[ @u1.id ].fetch(trait: :roles).item_names.inspect}"
415
+ it 'role wql' do
416
+ # warn "u1 roles #{Card[ @u1.id ].fetch(trait:
417
+ # :roles).item_names.inspect}"
391
418
 
392
419
  # set up cards of type TestType, 2 with nil reader, 1 with role1 reader
393
420
  Card::Auth.as_bot do
394
- [@c1,@c2,@c3].each do |c|
421
+ [@c1, @c2, @c3].each do |c|
395
422
  c.update_attributes content: 'WeirdWord'
396
423
  end
397
- Card.create(name: "c1+*self+*read", type: 'Pointer', content: "[[r3]]")
424
+ Card.create(name: 'c1+*self+*read', type: 'Pointer', content: '[[r3]]')
398
425
  end
399
426
 
400
427
  Card::Auth.as(@u1) do
401
- expect(Card.search(content: 'WeirdWord').map(&:name).sort).to eq(%w( c1 c2 c3 ))
428
+ expect(Card.search(content: 'WeirdWord').map(&:name).sort).to(
429
+ eq(%w( c1 c2 c3 ))
430
+ )
402
431
  end
403
- Card::Auth.current_id =nil # for Card::Auth.as to be effective, you can't have a logged in user
432
+ # for Card::Auth.as to be effective, you can't have a logged in user
433
+ Card::Auth.current_id = nil
404
434
  Card::Auth.as(@u2) do
405
- expect(Card.search(content: 'WeirdWord').map(&:name).sort).to eq(%w( c2 c3 ))
435
+ expect(Card.search(content: 'WeirdWord').map(&:name).sort).to(
436
+ eq(%w( c2 c3 ))
437
+ )
406
438
  end
407
439
  end
408
440
 
@@ -423,50 +455,42 @@ describe Card::Set::All::Permissions do
423
455
  J * * . . .
424
456
  G * . . . .
425
457
  }
426
-
427
458
  end
428
-
429
459
  end
430
460
 
431
-
432
-
433
-
434
- it "should let joe view new cards" do
461
+ it 'should let joe view new cards' do
435
462
  expect(Card.new.ok?(:read)).to be_truthy
436
463
  end
437
464
 
438
-
439
- context "default permissions" do
465
+ context 'default permissions' do
440
466
  before do
441
- @c = Card.create! name: "sky blue"
467
+ @c = Card.create! name: 'sky blue'
442
468
  end
443
469
 
444
- it "should let anonymous users view basic cards" do
470
+ it 'should let anonymous users view basic cards' do
445
471
  Card::Auth.as :anonymous do
446
472
  expect(@c.ok?(:read)).to be_truthy
447
473
  end
448
474
  end
449
475
 
450
- it "should let joe user basic cards" do
476
+ it 'should let joe user basic cards' do
451
477
  Card::Auth.as :joe_user do
452
478
  expect(@c.ok?(:read)).to be_truthy
453
479
  end
454
480
  end
455
481
  end
456
482
 
457
- it "should allow anyone signed in to create Basic Cards" do
483
+ it 'should allow anyone signed in to create Basic Cards' do
458
484
  expect(Card.new.ok?(:create)).to be_truthy
459
485
  end
460
486
 
461
- it "should not allow someone not signed in to create Basic Cards" do
487
+ it 'should not allow someone not signed in to create Basic Cards' do
462
488
  Card::Auth.as :anonymous do
463
489
  expect(Card.new.ok?(:create)).not_to be_truthy
464
490
  end
465
491
  end
466
492
 
467
-
468
-
469
- context "settings based permissions" do
493
+ context 'settings based permissions' do
470
494
  before do
471
495
  Card::Auth.as_bot do
472
496
  @delete_rule_card = Card.fetch '*all+*delete', new: {}
@@ -476,7 +500,7 @@ describe Card::Set::All::Permissions do
476
500
  end
477
501
  end
478
502
 
479
- it "should handle delete as a setting" do
503
+ it 'should handle delete as a setting' do
480
504
  c = Card.new name: 'whatever'
481
505
  expect(c.who_can(:delete)).to eq([Card['joe_user'].id])
482
506
  Card::Auth.as(:joe_user) do
@@ -489,17 +513,14 @@ describe Card::Set::All::Permissions do
489
513
  expect(c.ok?(:delete)).to eq(false)
490
514
  end
491
515
  Card::Auth.as_bot do
492
- expect(c.ok?(:delete)).to eq(true) #because administrator
516
+ expect(c.ok?(:delete)).to eq(true) # because administrator
493
517
  end
494
518
  end
495
519
  end
496
-
497
-
498
-
499
520
  end
500
521
 
501
-
502
522
  # FIXME-perm
503
523
 
504
524
  # need test for
505
- # changing cardtypes gives you correct permissions (changing cardtype in general...)
525
+ # changing cardtypes gives you correct permissions
526
+ # (changing cardtype in general...)