card 1.16.15 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/recaptcha.rb +21 -4
  4. data/db/migrate_core_cards/20130823192433_add_style_cards.rb +1 -1
  5. data/db/migrate_core_cards/20140512155840_add_script_cards.rb +1 -1
  6. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +2 -2
  7. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
  8. data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +1 -1
  9. data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +63 -0
  10. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
  11. data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +1 -1
  12. data/db/schema.rb +1 -1
  13. data/db/seed/new/card_actions.yml +602 -394
  14. data/db/seed/new/card_acts.yml +595 -1
  15. data/db/seed/new/card_changes.yml +26282 -10262
  16. data/db/seed/new/card_references.yml +1252 -1084
  17. data/db/seed/new/cards.yml +1899 -1423
  18. data/db/seed/test/fixtures/card_actions.yml +1653 -1413
  19. data/db/seed/test/fixtures/card_acts.yml +1063 -445
  20. data/db/seed/test/fixtures/card_changes.yml +29674 -13637
  21. data/db/seed/test/fixtures/card_references.yml +1976 -1815
  22. data/db/seed/test/fixtures/cards.yml +3194 -2719
  23. data/lib/card.rb +14 -13
  24. data/lib/card/auth.rb +10 -6
  25. data/lib/card/cache.rb +58 -120
  26. data/lib/card/cache/persistent.rb +50 -0
  27. data/lib/card/cache/temporary.rb +38 -0
  28. data/lib/card/chunk.rb +34 -25
  29. data/lib/card/content.rb +3 -3
  30. data/lib/card/env.rb +3 -0
  31. data/lib/card/format.rb +56 -53
  32. data/lib/card/migration.rb +6 -2
  33. data/lib/card/name.rb +9 -1
  34. data/lib/card/query.rb +1 -1
  35. data/lib/card/reference.rb +17 -11
  36. data/lib/card/set.rb +1 -1
  37. data/lib/card/subcards.rb +6 -6
  38. data/lib/card/view_cache.rb +45 -28
  39. data/lib/generators/card/migration/templates/card_migration.erb +1 -2
  40. data/mod/01_core/chunk/include.rb +71 -48
  41. data/mod/01_core/chunk/link.rb +6 -3
  42. data/mod/01_core/chunk/query_reference.rb +38 -29
  43. data/mod/01_core/chunk/reference.rb +23 -24
  44. data/mod/01_core/set/all/collection.rb +1 -1
  45. data/mod/01_core/set/all/fetch.rb +39 -12
  46. data/mod/01_core/set/all/permissions.rb +2 -4
  47. data/mod/01_core/set/all/references.rb +50 -75
  48. data/mod/01_core/set/all/rules.rb +19 -18
  49. data/mod/01_core/set/all/subcards.rb +1 -1
  50. data/mod/01_core/set/all/templating.rb +31 -88
  51. data/mod/01_core/set/all/tracked_attributes.rb +7 -14
  52. data/mod/01_core/set/all/utils.rb +77 -66
  53. data/mod/01_core/set_pattern/07_type_plus_right.rb +6 -3
  54. data/mod/01_core/spec/set/all/fetch_spec.rb +148 -96
  55. data/mod/01_core/spec/set/all/templating_spec.rb +49 -40
  56. data/mod/01_core/spec/set/all/trash_spec.rb +1 -1
  57. data/mod/01_history/set/all/actions.rb +1 -1
  58. data/mod/02_basic_types/set/all/base.rb +13 -7
  59. data/mod/02_basic_types/set/all/rss.rb +17 -22
  60. data/mod/02_basic_types/set/type/plain_text.rb +5 -2
  61. data/mod/02_basic_types/spec/set/all/base_spec.rb +1 -0
  62. data/mod/02_basic_types/spec/set/all/rss_spec.rb +7 -6
  63. data/mod/03_machines/lib/javascript/wagn.js.coffee +22 -9
  64. data/mod/03_machines/set/right/machine_output.rb +1 -1
  65. data/mod/04_settings/lib/card/setting.rb +45 -31
  66. data/mod/04_settings/set/right/structure.rb +47 -1
  67. data/mod/04_settings/set/self/default_html_view.rb +2 -0
  68. data/mod/04_settings/set/self/follow_fields.rb +2 -0
  69. data/mod/04_settings/set/self/recent_settings.rb +1 -1
  70. data/mod/05_standard/file/favicon/image-icon.png +0 -0
  71. data/mod/05_standard/file/favicon/image-large.png +0 -0
  72. data/mod/05_standard/file/favicon/image-medium.png +0 -0
  73. data/mod/05_standard/file/favicon/image-original.png +0 -0
  74. data/mod/05_standard/file/favicon/image-small.png +0 -0
  75. data/mod/05_standard/set/all/links.rb +27 -26
  76. data/mod/05_standard/set/all/rich_html/editing.rb +1 -1
  77. data/mod/05_standard/set/all/rich_html/toolbar.rb +1 -1
  78. data/mod/05_standard/set/rstar/rules.rb +20 -325
  79. data/mod/05_standard/set/rstar/rules_editor.rb +362 -0
  80. data/mod/05_standard/set/self/admin_info.rb +82 -0
  81. data/mod/05_standard/set/self/all.rb +16 -10
  82. data/mod/05_standard/set/self/head.rb +20 -19
  83. data/mod/05_standard/set/type/signup.rb +0 -1
  84. data/mod/05_standard/spec/set/all/account_spec.rb +44 -43
  85. data/mod/05_standard/spec/set/right/account_spec.rb +4 -2
  86. data/mod/05_standard/spec/set/type/search_type_spec.rb +8 -0
  87. data/mod/05_standard/spec/set/type/signup_spec.rb +24 -17
  88. data/mod/06_bootstrap/set/all/bootstrap/helper.rb +1 -1
  89. data/spec/lib/card/cache_spec.rb +64 -70
  90. data/spec/lib/card/content_spec.rb +236 -150
  91. data/spec/lib/card/reference_spec.rb +22 -38
  92. data/spec/lib/card/subcards_spec.rb +38 -0
  93. data/spec/lib/card/view_cache_spec.rb +8 -0
  94. data/spec/spec_helper.rb +1 -1
  95. data/tmpsets/set/mod001-01_core/all/collection.rb +77 -74
  96. data/tmpsets/set/mod001-01_core/all/content.rb +14 -16
  97. data/tmpsets/set/mod001-01_core/all/fetch.rb +137 -110
  98. data/tmpsets/set/mod001-01_core/all/name.rb +58 -40
  99. data/tmpsets/set/mod001-01_core/all/pattern.rb +12 -11
  100. data/tmpsets/set/mod001-01_core/all/permissions.rb +125 -117
  101. data/tmpsets/set/mod001-01_core/all/phases.rb +2 -1
  102. data/tmpsets/set/mod001-01_core/all/references.rb +52 -77
  103. data/tmpsets/set/mod001-01_core/all/rules.rb +47 -53
  104. data/tmpsets/set/mod001-01_core/all/templating.rb +31 -87
  105. data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +12 -21
  106. data/tmpsets/set/mod001-01_core/all/trash.rb +4 -1
  107. data/tmpsets/set/mod001-01_core/all/type.rb +23 -21
  108. data/tmpsets/set/mod001-01_core/all/utils.rb +80 -64
  109. data/tmpsets/set/mod002-01_history/all/actions.rb +20 -16
  110. data/tmpsets/set/mod002-01_history/all/history.rb +18 -13
  111. data/tmpsets/set/mod003-02_basic_types/all/base.rb +37 -10
  112. data/tmpsets/set/mod003-02_basic_types/all/rss.rb +17 -22
  113. data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +5 -2
  114. data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +51 -39
  115. data/tmpsets/set/mod004-03_machines/right/machine_output.rb +10 -6
  116. data/tmpsets/set/mod005-04_settings/abstract/permission.rb +10 -5
  117. data/tmpsets/set/mod005-04_settings/right/structure.rb +47 -1
  118. data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +1 -0
  119. data/tmpsets/set/mod005-04_settings/type/setting.rb +4 -1
  120. data/tmpsets/set/mod006-05_email/all/follow.rb +45 -54
  121. data/tmpsets/set/mod006-05_email/all/notify.rb +88 -73
  122. data/tmpsets/set/mod006-05_email/right/followers.rb +17 -14
  123. data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +22 -18
  124. data/tmpsets/set/mod006-05_email/type/email_template.rb +1 -1
  125. data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +94 -67
  126. data/tmpsets/set/mod007-05_standard/all/account.rb +18 -20
  127. data/tmpsets/set/mod007-05_standard/all/comment.rb +51 -29
  128. data/tmpsets/set/mod007-05_standard/all/error.rb +129 -99
  129. data/tmpsets/set/mod007-05_standard/all/links.rb +27 -26
  130. data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +115 -103
  131. data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +112 -78
  132. data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +123 -81
  133. data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +15 -58
  134. data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -2
  135. data/tmpsets/set/mod007-05_standard/right/account.rb +71 -75
  136. data/tmpsets/set/mod007-05_standard/right/email.rb +16 -13
  137. data/tmpsets/set/mod007-05_standard/right/password.rb +20 -12
  138. data/tmpsets/set/mod007-05_standard/right/status.rb +2 -2
  139. data/tmpsets/set/mod007-05_standard/right/token.rb +49 -2
  140. data/tmpsets/set/mod007-05_standard/rstar/rules.rb +20 -325
  141. data/tmpsets/set/mod007-05_standard/self/all.rb +16 -10
  142. data/tmpsets/set/mod007-05_standard/self/head.rb +76 -62
  143. data/tmpsets/set/mod007-05_standard/self/search.rb +45 -22
  144. data/tmpsets/set/mod007-05_standard/self/signin.rb +14 -12
  145. data/tmpsets/set/mod007-05_standard/type/cardtype.rb +13 -11
  146. data/tmpsets/set/mod007-05_standard/type/file.rb +1 -1
  147. data/tmpsets/set/mod007-05_standard/type/search_type.rb +3 -2
  148. data/tmpsets/set/mod007-05_standard/type/set.rb +20 -16
  149. data/tmpsets/set/mod007-05_standard/type/signup.rb +19 -25
  150. data/tmpsets/set/mod007-05_standard/type/user.rb +1 -1
  151. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +1 -1
  152. data/tmpsets/set_pattern/106-type_plus_right.rb +6 -3
  153. metadata +11 -2
@@ -21,8 +21,8 @@ format :html do
21
21
  def head_title
22
22
  title = root.card && root.card.name
23
23
  title = nil if title.blank?
24
- title = params[:action] if title == '*placeholder'
25
- %(<title>#{title ? "#{title} - " : ''}#{ Card.setting :title }</title>)
24
+ title = params[:action] if title=='*placeholder'
25
+ %(<title>#{title ? "#{title} - " : ''}#{ Card.global_setting :title }</title>)
26
26
  end
27
27
 
28
28
  def head_buttons
@@ -101,7 +101,7 @@ format :html do
101
101
  #{ javascript_tag do varvals * ';' end }
102
102
  #{ @js_tag if @js_tag }
103
103
  <!--[if lt IE 9]>#{ javascript_include_tag ie9_card.machine_output_url if ie9_card }<![endif]-->
104
- #{ javascript_tag { "wagn.setTinyMCEConfig('#{ escape_javascript Card.setting(:tiny_mce).to_s }')" } }
104
+ #{ javascript_tag { "wagn.setTinyMCEConfig('#{ escape_javascript Card.global_setting(:tiny_mce).to_s }')" } }
105
105
  #{ google_analytics_head_javascript }
106
106
  <script type="text/javascript">
107
107
  $('document').ready(function() {
@@ -111,22 +111,23 @@ format :html do
111
111
  HTML
112
112
  end
113
113
 
114
+
114
115
  def google_analytics_head_javascript
115
- if (ga_key = Card.setting("*google analytics key")) # FIXME: escape this?
116
- <<-HTML
117
- <script type="text/javascript">
118
- var _gaq = _gaq || [];
119
- _gaq.push(['_setAccount', '#{ga_key}']);
120
- _gaq.push(['_trackPageview']);
121
- (function() {
122
- var ga = document.createElement('script');
123
- ga.type = 'text/javascript'; ga.async = true;
124
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
125
- var s = document.getElementsByTagName('script')[0];
126
- s.parentNode.insertBefore(ga, s);
127
- })();
128
- </script>
129
- HTML
130
- end
116
+ return unless (ga_key = Card.global_setting(:google_analytics_key))
117
+ <<-JAVASCRIPT
118
+ <script type="text/javascript">
119
+ var _gaq = _gaq || [];
120
+ _gaq.push(['_setAccount', '#{ga_key}']);
121
+ _gaq.push(['_trackPageview']);
122
+ (function() {
123
+ var ga = document.createElement('script');
124
+ ga.type = 'text/javascript'; ga.async = true;
125
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
126
+ var s = document.getElementsByTagName('script')[0];
127
+ s.parentNode.insertBefore(ga, s);
128
+ s.parentNode.insertBefore(ga, s);
129
+ })();
130
+ </script>
131
+ JAVASCRIPT
131
132
  end
132
133
  end
@@ -1,4 +1,3 @@
1
-
2
1
  format :html do
3
2
  def default_new_args args
4
3
  super args
@@ -2,7 +2,6 @@
2
2
 
3
3
  describe Card::Set::All::Account do
4
4
  describe 'accountable?' do
5
-
6
5
  it 'should be false for cards with *accountable rule off' do
7
6
  expect(Card['A'].accountable?).to eq(false)
8
7
  end
@@ -10,21 +9,22 @@ describe Card::Set::All::Account do
10
9
  it 'should be true for cards with *accountable rule on' do
11
10
  Card::Auth.as_bot do
12
11
  Card.create name: 'A+*self+*accountable', content: '1'
13
- Card.create name: '*account+*right+*create', content: '[[Anyone Signed In]]'
12
+ Card.create name: '*account+*right+*create',
13
+ content: '[[Anyone Signed In]]'
14
14
  end
15
15
  expect(Card['A'].accountable?).to eq(true)
16
16
  end
17
-
18
17
  end
19
18
 
20
- describe "parties" do
21
-
22
- it "for Wagn Bot" do
19
+ describe 'parties' do
20
+ it 'for Wagn Bot' do
23
21
  Card::Auth.current_id = Card::WagnBotID
24
- expect(Card::Auth.current.parties.sort).to eq([Card::WagnBotID, Card::AnyoneSignedInID, Card::AdministratorID])
22
+ expect(Card::Auth.current.parties.sort).to eq(
23
+ [Card::WagnBotID, Card::AnyoneSignedInID, Card::AdministratorID]
24
+ )
25
25
  end
26
26
 
27
- it "for Anonymous" do
27
+ it 'for Anonymous' do
28
28
  Card::Auth.current_id = Card::AnonymousID
29
29
  expect(Card::Auth.current.parties.sort).to eq([Card::AnonymousID])
30
30
  end
@@ -35,7 +35,7 @@ describe Card::Set::All::Account do
35
35
  @parties = @joe_user_card.parties # note: must be called to test resets
36
36
  end
37
37
 
38
- it "should initially have only auth and self " do
38
+ it 'should initially have only auth and self ' do
39
39
  expect(@parties).to eq([Card::AnyoneSignedInID, @joe_user_card.id])
40
40
  end
41
41
 
@@ -43,20 +43,28 @@ describe Card::Set::All::Account do
43
43
  roles_card = @joe_user_card.fetch trait: :roles, new: {}
44
44
  r1 = Card['r1']
45
45
 
46
- Card::Auth.as_bot { roles_card.items = [ r1.id ] }
47
- expect(Card['Joe User'].parties).to eq(@parties) # local cache still has old parties (permission does not change mid-request)
46
+ Card::Auth.as_bot { roles_card.items = [r1.id] }
47
+ expect(Card['Joe User'].parties).to eq(@parties)
48
+ # local cache still has old parties
49
+ # (permission does not change mid-request)
48
50
 
49
- Card::Cache.restore # simulate new request -- clears local cache, where, eg, @parties would still be cached on card
50
- Card::Auth.current_id = Card::Auth.current_id # simulate new request -- current_id assignment clears several class variables
51
+ Card::Cache.restore
52
+ # simulate new request
53
+ # clears local cache, where, eg, @parties would still be cached on card
51
54
 
52
- new_parties = [ Card::AnyoneSignedInID, r1.id, @joe_user_card.id ]
53
- expect(Card['Joe User'].parties).to eq(new_parties) # @parties regenerated, now with correct values
54
- expect(Card::Auth.current. parties).to eq(new_parties)
55
+ Card::Auth.current_id = Card::Auth.current_id
56
+ # simulate new request
57
+ # current_id assignment clears several class variables
55
58
 
56
- # @joe_user_card.refresh(force=true).parties.should == new_parties # should work, but now superfluous?
59
+ new_parties = [Card::AnyoneSignedInID, r1.id, @joe_user_card.id]
60
+ expect(Card['Joe User'].parties).to eq(new_parties)
61
+ # @parties regenerated, now with correct values
62
+
63
+ expect(Card::Auth.current. parties).to eq(new_parties)
64
+ # @joe_user_card.refresh(force=true).parties.should == new_parties
65
+ # should work, but now superfluous?
57
66
  end
58
67
  end
59
-
60
68
  end
61
69
 
62
70
  describe 'among?' do
@@ -65,27 +73,23 @@ describe Card::Set::All::Account do
65
73
  end
66
74
  end
67
75
 
68
-
69
- describe "'+*email'" do
76
+ describe '+*email' do
70
77
  it 'should create a card and account card' do
71
78
  jadmin = Card['joe admin']
72
- Card::Auth.current_id = jadmin.id #simulate login to get correct from address
73
- ja_email = jadmin.account.email
79
+ Card::Auth.current_id = jadmin.id
80
+ # simulate login to get correct from address
74
81
 
75
- Card::Env[:params] = { email: {subject: 'Hey Joe!', message: 'Come on in.'} }
76
- Card.create! name: 'Joe New', type_id: Card::UserID, '+*account'=>{ '+*email'=> 'joe@new.com' }
82
+ Card::Env[:params] = { email: { subject: 'Hey Joe!',
83
+ message: 'Come on in.' } }
84
+ Card.create! name: 'Joe New',
85
+ type_id: Card::UserID,
86
+ '+*account' => { '+*email' => 'joe@new.com' }
77
87
 
78
88
  c = Card['Joe New']
79
- u = Card::Auth[ 'joe@new.com' ]
89
+ u = Card::Auth['joe@new.com']
80
90
 
81
91
  expect(c.account).to eq(u)
82
92
  expect(c.type_id).to eq(Card::UserID)
83
- =begin
84
- email = ActionMailer::Base.deliveries.last
85
- email.to.should == ['joe@new.com']
86
- email.subject.should == 'Hey Joe!'
87
- email.from.should == [ ja_email ]
88
- =end
89
93
  end
90
94
  end
91
95
 
@@ -93,20 +97,20 @@ describe Card::Set::All::Account do
93
97
  before do
94
98
  @card = Card['Joe User']
95
99
  end
96
- it "should handle email updates" do
97
- @card.update_attributes! '+*account'=>{ '+*email'=>'joe@user.co.uk' }
100
+
101
+ it 'should handle email updates' do
102
+ @card.update_attributes! '+*account' => { '+*email' => 'joe@user.co.uk' }
98
103
  expect(@card.account.email).to eq('joe@user.co.uk')
99
104
  end
100
105
 
101
- it "should let Wagn Bot block accounts" do
106
+ it 'should let Wagn Bot block accounts' do
102
107
  Card::Auth.as_bot do
103
108
  @card.account.status_card.update_attributes! content: 'blocked'
104
109
  expect(@card.account.blocked?).to be_truthy
105
110
  end
106
111
  end
107
112
 
108
-
109
- it "should not allow a user to block or unblock himself" do
113
+ it 'should not allow a user to block or unblock himself' do
110
114
  expect do
111
115
  @card.account.status_card.update_attributes! content: 'blocked'
112
116
  end.to raise_error
@@ -114,24 +118,21 @@ describe Card::Set::All::Account do
114
118
  end
115
119
  end
116
120
 
117
- describe "#read_rules" do
121
+ describe '#read_rules' do
118
122
  before(:all) do
119
123
  @read_rules = Card['joe_user'].read_rules
120
124
  end
121
125
 
122
-
123
- it "*all+*read should apply to Joe User" do
126
+ it '*all+*read should apply to Joe User' do
124
127
  expect(@read_rules.member?(Card.fetch('*all+*read').id)).to be_truthy
125
128
  end
126
129
 
127
- it "9 more should apply to Joe Admin" do
130
+ it '13 more should apply to Joe Admin' do
128
131
  # includes lots of account rules...
129
132
  Card::Auth.as('joe_admin') do
130
133
  ids = Card::Auth.as_card.read_rules
131
- expect(ids.length).to eq(@read_rules.size + 9)
134
+ expect(ids.length).to eq(@read_rules.size + 13)
132
135
  end
133
136
  end
134
-
135
137
  end
136
-
137
138
  end
@@ -58,7 +58,8 @@ describe Card::Set::Right::Account do
58
58
  end
59
59
 
60
60
  it 'contains deck title' do
61
- expect(@mail.parts[0].body.raw_source).to match(Card.setting(:title))
61
+ body = @mail.parts[0].body.raw_source
62
+ expect(body).to match(Card.global_setting(:title))
62
63
  end
63
64
 
64
65
  it 'contains link to verify account' do
@@ -82,7 +83,8 @@ describe Card::Set::Right::Account do
82
83
  end
83
84
 
84
85
  it 'contains deck title' do
85
- expect(@mail.parts[0].body.raw_source).to match(Card.setting(:title))
86
+ body = @mail.parts[0].body.raw_source
87
+ expect(body).to match(Card.global_setting(:title))
86
88
  end
87
89
 
88
90
  it 'contains password resset link' do
@@ -49,4 +49,12 @@ describe Card::Set::Type::SearchType do
49
49
  end
50
50
 
51
51
  end
52
+ context 'rss format' do
53
+ it 'render rss without errors' do
54
+ search_card = Card.create type: 'Search', name: 'Asearch',
55
+ content: %{{"id":"1"}}
56
+ rss = search_card.format(:rss).render_feed
57
+ expect(rss).to have_tag('title', text: 'Wagn Bot')
58
+ end
59
+ end
52
60
  end
@@ -47,7 +47,8 @@ describe Card::Set::Type::Signup do
47
47
 
48
48
  it 'sends email with an appropriate link' do
49
49
  @mail = ActionMailer::Base.deliveries.last
50
- expect(@mail.parts[0].body.raw_source).to match(Card.setting(:title))
50
+ body = @mail.parts[0].body.raw_source
51
+ expect(body).to match(Card.global_setting(:title))
51
52
  end
52
53
 
53
54
  it 'creates an authenticable token' do
@@ -90,21 +91,25 @@ describe Card::Set::Type::Signup do
90
91
 
91
92
  context 'signup (with approval)' do
92
93
  before do
93
- # NOTE: by default Anonymous does not have permission to create User cards.
94
+ # NOTE: by default Anonymous does not have permission
95
+ # to create User cards.
94
96
  Mail::TestMailer.deliveries.clear
95
97
  Card::Auth.current_id = Card::AnonymousID
96
- @signup = Card.create! name: 'Big Bad Wolf', type_id: Card::SignupID,
97
- '+*account'=>{ '+*email'=>'wolf@wagn.org', '+*password'=>'wolf' }
98
+ @signup = Card.create! name: 'Big Bad Wolf',
99
+ type_id: Card::SignupID,
100
+ '+*account' => {
101
+ '+*email' => 'wolf@wagn.org',
102
+ '+*password' => 'wolf'
103
+ }
98
104
  @account = @signup.account
99
105
  end
100
106
 
101
-
102
107
  it 'should create all the necessary cards, but no token' do
103
108
  expect(@signup.type_id).to eq(Card::SignupID)
104
109
  expect(@account.email).to eq('wolf@wagn.org')
105
110
  expect(@account.status).to eq('pending')
106
111
  expect(@account.salt).not_to eq('')
107
- expect(@account.password.length).to be > 10 #encrypted
112
+ expect(@account.password.length).to be > 10 # encrypted
108
113
  end
109
114
 
110
115
  it 'should not create a token' do
@@ -119,16 +124,13 @@ describe Card::Set::Type::Signup do
119
124
  expect(body).to include(@signup.name)
120
125
  expect(body).to include('wolf@wagn.org')
121
126
  end
122
-
123
127
  end
124
128
 
125
129
  it 'does not send verification email' do
126
130
  expect(Mail::TestMailer.deliveries[-2]).to be_nil
127
131
  end
128
132
 
129
-
130
133
  context 'approval with token' do
131
-
132
134
  it 'should create token' do
133
135
  Card::Env.params[:approve_with_token] = true
134
136
  Card::Auth.as 'joe_admin'
@@ -137,11 +139,9 @@ describe Card::Set::Type::Signup do
137
139
  @signup.save!
138
140
  expect(@signup.account.token).to be_present
139
141
  end
140
-
141
142
  end
142
143
 
143
144
  context 'approval without token' do
144
-
145
145
  it 'should create token' do
146
146
  Card::Env.params[:approve_without_token] = true
147
147
  Card::Auth.as 'joe_admin'
@@ -153,20 +153,27 @@ describe Card::Set::Type::Signup do
153
153
  expect(@signup.account.status).to eq('active')
154
154
  end
155
155
  end
156
-
157
156
  end
158
157
 
159
158
  context 'a welcome email card exists' do
160
159
  before do
161
160
  Card::Auth.as_bot do
162
- Card.create! name: 'welcome email', subcards: {'+*subject'=>'welcome',
163
- '+*html_message'=>'Welcome {{_self|name}}'}, type_id: Card::EmailTemplateID
161
+ Card.create! name: 'welcome email',
162
+ type_id: Card::EmailTemplateID,
163
+ subcards: {
164
+ '+*subject' => 'welcome',
165
+ '+*html_message' => 'Welcome {{_self|name}}'
166
+ }
164
167
  end
165
168
  Mail::TestMailer.deliveries.clear
166
- @signup = Card.create! name: 'Big Bad Sheep', type_id: Card::SignupID,
167
- '+*account'=>{'+*email'=>'sheep@wagn.org', '+*password'=>'sheep'}
168
-
169
+ @signup = Card.create! name: 'Big Bad Sheep',
170
+ type_id: Card::SignupID,
171
+ '+*account' => {
172
+ '+*email' => 'sheep@wagn.org',
173
+ '+*password' => 'sheep'
174
+ }
169
175
  end
176
+
170
177
  it 'sends welcome email when account is activated' do
171
178
  @signup.run_phase :approve do
172
179
  @signup.activate_account
@@ -137,7 +137,7 @@ format :html do
137
137
  item_options = options.delete(:items) || {}
138
138
  wrap_with :ul, options do
139
139
  content.map do |item|
140
- content_tag :li, item, item_options
140
+ content_tag :li, item.html_safe, item_options
141
141
  end.join "\n"
142
142
  end
143
143
  end
@@ -1,121 +1,115 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  describe Card::Cache do
4
- describe "with nil store" do
4
+ describe 'with nil store' do
5
5
  before do
6
- expect(Card::Cache).to receive(:generate_cache_id).exactly(2).times.and_return("cache_id")
7
- @cache = Card::Cache.new prefix: "prefix"
6
+ @cache = Card::Cache.new prefix: 'prefix'
8
7
  end
9
8
 
10
- describe "#basic operations" do
11
- it "should work" do
12
- @cache.write("a", "foo")
13
- expect(@cache.read("a")).to eq("foo")
14
- @cache.fetch("b") { "bar" }
15
- expect(@cache.read("b")).to eq("bar")
9
+ describe '#basic operations' do
10
+ it 'should work' do
11
+ @cache.write('a', 'foo')
12
+ expect(@cache.read('a')).to eq('foo')
13
+ @cache.fetch('b') { 'bar' }
14
+ expect(@cache.read('b')).to eq('bar')
16
15
  @cache.reset
17
16
  end
18
17
  end
19
18
  end
20
19
 
21
- describe "with same cache_id" do
20
+ describe 'with same cache_id' do
22
21
  before :each do
23
- @store = ActiveSupport::Cache::MemoryStore.new
24
- expect(Card::Cache).to receive(:generate_cache_id).and_return("cache_id")
25
- @cache = Card::Cache.new store: @store, prefix: "prefix"
22
+ @hard = ActiveSupport::Cache::MemoryStore.new
23
+ @cache = Card::Cache.new store: @hard, prefix: 'prefix'
26
24
  end
27
25
 
28
- it "#read" do
29
- expect(@store).to receive(:read).with("prefix/cache_id/foo")
30
- @cache.read("foo")
26
+ it '#read' do
27
+ expect(@hard).to receive(:read).with('prefix/foo')
28
+ @cache.read('foo')
31
29
  end
32
30
 
33
- it "#write" do
34
- expect(@store).to receive(:write).with("prefix/cache_id/foo", "val")
35
- @cache.write("foo", "val")
36
- expect(@cache.read('foo')).to eq("val")
31
+ it '#write' do
32
+ expect(@hard).to receive(:write).with('prefix/foo', 'val')
33
+ @cache.write('foo', 'val')
34
+ expect(@cache.read('foo')).to eq('val')
37
35
  end
38
36
 
39
- it "#fetch" do
40
- block = Proc.new { "hi" }
41
- expect(@store).to receive(:fetch).with("prefix/cache_id/foo", &block)
42
- @cache.fetch("foo", &block)
37
+ it '#fetch' do
38
+ block = Proc.new { 'hi' }
39
+ expect(@hard).to receive(:fetch).with('prefix/foo', &block)
40
+ @cache.fetch('foo', &block)
43
41
  end
44
42
 
45
- it "#delete" do
46
- expect(@store).to receive(:delete).with("prefix/cache_id/foo")
47
- @cache.delete "foo"
43
+ it '#delete' do
44
+ expect(@hard).to receive(:delete).with('prefix/foo')
45
+ @cache.delete 'foo'
48
46
  end
49
47
 
50
- it "#write_local" do
51
- @cache.write_local('a', 'foo')
52
- expect(@cache.read("a")).to eq('foo')
53
- expect(@store).not_to receive(:write)
54
- expect(@cache.store.read("a")).to eq(nil)
48
+ it '#soft.write' do
49
+ @cache.soft.write('a', 'foo')
50
+ expect(@cache.read('a')).to eq('foo')
51
+ expect(@hard).not_to receive(:write)
52
+ expect(@cache.hard.read('a')).to eq(nil)
55
53
  end
56
54
  end
57
55
 
58
- it "#reset" do
59
- expect(Card::Cache).to receive(:generate_cache_id).and_return("cache_id1")
60
- @store = ActiveSupport::Cache::MemoryStore.new
61
- @cache = Card::Cache.new store: @store, prefix: "prefix"
62
- expect(@cache.prefix).to eq("prefix/cache_id1/")
63
- @cache.write("foo","bar")
64
- expect(@cache.read("foo")).to eq("bar")
56
+ it '#reset' do
57
+ @hard = ActiveSupport::Cache::MemoryStore.new
58
+ @cache = Card::Cache.new store: @hard, prefix: 'prefix'
59
+ expect(@cache.hard.prefix).to eq('prefix/')
60
+ @cache.write('foo','bar')
61
+ expect(@cache.read('foo')).to eq('bar')
65
62
 
66
63
  # reset
67
- expect(Card::Cache).to receive(:generate_cache_id).and_return("cache_id2")
68
64
  @cache.reset
69
- expect(@cache.prefix).to eq("prefix/cache_id2/")
70
- expect(@cache.store.read("prefix/cache_id")).to eq("cache_id2")
71
- expect(@cache.read("foo")).to be_nil
65
+ expect(@cache.hard.prefix).to eq('prefix/')
66
+ expect(@cache.read('foo')).to be_nil
72
67
 
73
- cache2 = Card::Cache.new store: @store, prefix: "prefix"
74
- expect(cache2.prefix).to eq("prefix/cache_id2/")
68
+ cache2 = Card::Cache.new store: @hard, prefix: 'prefix'
69
+ expect(cache2.hard.prefix).to eq('prefix/')
75
70
  end
76
71
 
77
- describe "with file store" do
72
+ describe 'with file store' do
78
73
  before do
79
74
  cache_path = "#{Wagn.root}/tmp/cache"
80
75
  unless File.directory?(cache_path)
81
76
  FileUtils.mkdir_p(cache_path)
82
77
  end
83
- @store = ActiveSupport::Cache::FileStore.new cache_path
78
+ @hard = ActiveSupport::Cache::FileStore.new cache_path
84
79
 
85
- @store.clear
86
- #cache_path = cache_path + "/prefix"
87
- #p = Pathname.new(cache_path)
88
- #p.mkdir if !p.exist?
80
+ @hard.clear
81
+ # cache_path = cache_path + '/prefix'
82
+ # p = Pathname.new(cache_path)
83
+ # p.mkdir if !p.exist?
89
84
  #
90
- #root_dirs = Dir.entries(cache_path).reject{|f| ['.', '..'].include?(f)}
91
- #files_to_remove = root_dirs.collect{|f| File.join(cache_path, f)}
92
- #FileUtils.rm_r(files_to_remove)
93
-
94
- expect(Card::Cache).to receive(:generate_cache_id).exactly(2).times.and_return("cache_id1")
95
- @cache = Card::Cache.new store: @store, prefix: "prefix"
85
+ # root_dirs = Dir.entries(cache_path).reject{|f| ['.', '..'].include?(f)}
86
+ # files_to_remove = root_dirs.collect{|f| File.join(cache_path, f)}
87
+ # FileUtils.rm_r(files_to_remove)
88
+ @cache = Card::Cache.new store: @hard, prefix: 'prefix'
96
89
  end
97
90
 
98
- describe "#basic operations with special symbols" do
99
- it "should work" do
100
- @cache.write('%\\/*:?"<>|', "foo")
101
- cache2 = Card::Cache.new store: @store, prefix: "prefix"
102
- expect(cache2.read('%\\/*:?"<>|')).to eq("foo")
91
+ describe '#basic operations with special symbols' do
92
+ it 'should work' do
93
+ @cache.write('%\\/*:?"<>|', 'foo')
94
+ cache2 = Card::Cache.new store: @hard, prefix: 'prefix'
95
+ expect(cache2.read('%\\/*:?"<>|')).to eq('foo')
103
96
  @cache.reset
104
97
  end
105
98
  end
106
99
 
107
- describe "#basic operations with non-latin symbols" do
108
- it "should work" do
109
- @cache.write('(汉语漢語 Hànyǔ; 华语華語 Huáyǔ; 中文 Zhōngwén', "foo")
110
- @cache.write('русский', "foo")
111
- cache3 = Card::Cache.new store: @store, prefix: "prefix"
112
- expect(cache3.read('(汉语漢語 Hànyǔ; 华语華語 Huáyǔ; 中文 Zhōngwén')).to eq("foo")
113
- expect(cache3.read('русский')).to eq("foo")
100
+ describe '#basic operations with non-latin symbols' do
101
+ it 'should work' do
102
+ @cache.write('(汉语漢語 Hànyǔ; 华语華語 Huáyǔ; 中文 Zhōngwén', 'foo')
103
+ @cache.write('русский', 'foo')
104
+ cache3 = Card::Cache.new store: @hard, prefix: 'prefix'
105
+ cached = cache3.read '(汉语漢語 Hànyǔ; 华语華語 Huáyǔ; 中文 Zhōngwén'
106
+ expect(cached).to eq('foo')
107
+ expect(cache3.read('русский')).to eq('foo')
114
108
  @cache.reset
115
109
  end
116
110
  end
117
111
 
118
- describe "#tempfile" do
112
+ describe '#tempfile' do
119
113
  # TODO
120
114
  end
121
115
  end