radiant-forum-extension 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/README.md +37 -56
  2. data/VERSION +1 -1
  3. data/app/controllers/forum_base_controller.rb +78 -0
  4. data/app/controllers/forums_controller.rb +5 -34
  5. data/app/controllers/posts_controller.rb +61 -153
  6. data/app/controllers/topics_controller.rb +6 -63
  7. data/app/helpers/forum_helper.rb +24 -48
  8. data/app/models/forum.rb +5 -18
  9. data/app/models/post.rb +53 -55
  10. data/app/models/post_attachment.rb +9 -6
  11. data/app/models/topic.rb +20 -113
  12. data/app/views/admin/reader_configuration/_edit_forum.html.haml +4 -2
  13. data/app/views/admin/reader_configuration/_forum.html.haml +6 -2
  14. data/app/views/forums/_forum.html.haml +14 -20
  15. data/app/views/forums/_latest.html.haml +12 -0
  16. data/app/views/forums/_standard_parts.html.haml +49 -0
  17. data/app/views/forums/index.html.haml +16 -24
  18. data/app/views/forums/show.html.haml +18 -28
  19. data/app/views/pages/_comment.html.haml +1 -1
  20. data/app/views/posts/_attachments.html.haml +13 -0
  21. data/app/views/posts/_confirm_delete.html.haml +10 -0
  22. data/app/views/posts/_context.html.haml +16 -0
  23. data/app/views/posts/_edit_links.html.haml +11 -0
  24. data/app/views/posts/_form.html.haml +40 -2
  25. data/app/views/posts/_latest.html.haml +10 -17
  26. data/app/views/posts/_new_attachment.html.haml +2 -0
  27. data/app/views/posts/_post.html.haml +25 -60
  28. data/app/views/posts/{_search.html.haml → _search_form.html.haml} +1 -1
  29. data/app/views/posts/_uploader.html.haml +2 -2
  30. data/app/views/posts/edit.html.haml +26 -13
  31. data/app/views/posts/index.html.haml +19 -27
  32. data/app/views/posts/new.html.haml +27 -7
  33. data/app/views/posts/remove.html.haml +27 -0
  34. data/app/views/posts/show.html.haml +20 -7
  35. data/app/views/readers/_forum_messages.html.haml +20 -0
  36. data/app/views/readers/_messages_summary.html.haml +3 -0
  37. data/app/views/topics/_context.html.haml +12 -0
  38. data/app/views/topics/_latest.html.haml +14 -16
  39. data/app/views/topics/_locked.html.haml +1 -1
  40. data/app/views/topics/_replies.html.haml +6 -0
  41. data/app/views/topics/_reply.html.haml +23 -0
  42. data/app/views/topics/_topic.html.haml +14 -43
  43. data/app/views/topics/_voices.html.haml +5 -0
  44. data/app/views/topics/index.html.haml +11 -24
  45. data/app/views/topics/show.html.haml +25 -38
  46. data/config/initializers/radiant_config.rb +5 -1
  47. data/config/locales/en.yml +73 -27
  48. data/config/routes.rb +3 -4
  49. data/db/migrate/20101222160900_page_posts.rb +21 -0
  50. data/db/migrate/20101222163605_no_comment_forum.rb +10 -0
  51. data/db/migrate/20110105103827_topic_merely_associative.rb +23 -0
  52. data/db/migrate/20110111080550_detach_observer.rb +11 -0
  53. data/db/migrate/20110127113852_import_attachments.rb +9 -0
  54. data/forum_extension.rb +12 -13
  55. data/lib/commentable_model.rb +98 -0
  56. data/lib/forum_page.rb +2 -22
  57. data/lib/forum_reader_sessions_controller.rb +14 -0
  58. data/lib/forum_readers_controller.rb +2 -9
  59. data/lib/forum_red_cloth3.rb +23 -4
  60. data/lib/forum_red_cloth4.rb +23 -4
  61. data/lib/forum_tags.rb +298 -194
  62. data/lib/sanitize/config/forum.rb +47 -0
  63. data/public/images/furniture/blank.png +0 -0
  64. data/public/images/furniture/emoticons.png +0 -0
  65. data/public/javascripts/forum.js +349 -93
  66. data/public/javascripts/jquery.tools.min.js +195 -0
  67. data/public/punymce/blank.htm +1 -0
  68. data/public/punymce/css/content.css +4 -0
  69. data/public/punymce/css/editor.css +58 -0
  70. data/public/punymce/i18n/sv.js +28 -0
  71. data/public/punymce/img/icons.gif +0 -0
  72. data/public/punymce/img/icons_uncompressed.png +0 -0
  73. data/public/punymce/plugins/bbcode.js +1 -0
  74. data/public/punymce/plugins/bbcode_src.js +50 -0
  75. data/public/punymce/plugins/editsource/css/editor.css +3 -0
  76. data/public/punymce/plugins/editsource/editsource.js +1 -0
  77. data/public/punymce/plugins/editsource/editsource_src.js +81 -0
  78. data/public/punymce/plugins/editsource/img/icons.gif +0 -0
  79. data/public/punymce/plugins/emoticons/css/content.css +13 -0
  80. data/public/punymce/plugins/emoticons/css/editor.css +17 -0
  81. data/public/punymce/plugins/emoticons/emoticons.js +1 -0
  82. data/public/punymce/plugins/emoticons/emoticons_src.js +303 -0
  83. data/public/punymce/plugins/emoticons/img/emoticons.gif +0 -0
  84. data/public/punymce/plugins/emoticons/img/emoticons.png +0 -0
  85. data/public/punymce/plugins/emoticons/img/trans.gif +0 -0
  86. data/public/punymce/plugins/entities.js +1 -0
  87. data/public/punymce/plugins/entities_src.js +37 -0
  88. data/public/punymce/plugins/forceblocks.js +1 -0
  89. data/public/punymce/plugins/forceblocks_src.js +465 -0
  90. data/public/punymce/plugins/forcenl.js +1 -0
  91. data/public/punymce/plugins/forcenl_src.js +26 -0
  92. data/public/punymce/plugins/image/css/editor.css +1 -0
  93. data/public/punymce/plugins/image/image.js +1 -0
  94. data/public/punymce/plugins/image/image_src.js +30 -0
  95. data/public/punymce/plugins/image/img/icons.gif +0 -0
  96. data/public/punymce/plugins/link/css/editor.css +2 -0
  97. data/public/punymce/plugins/link/img/icons.gif +0 -0
  98. data/public/punymce/plugins/link/link.js +1 -0
  99. data/public/punymce/plugins/link/link_src.js +36 -0
  100. data/public/punymce/plugins/paste.js +1 -0
  101. data/public/punymce/plugins/paste_src.js +169 -0
  102. data/public/punymce/plugins/protect.js +1 -0
  103. data/public/punymce/plugins/protect_src.js +30 -0
  104. data/public/punymce/plugins/safari2x.js +1 -0
  105. data/public/punymce/plugins/safari2x_src.js +284 -0
  106. data/public/punymce/plugins/tabfocus.js +1 -0
  107. data/public/punymce/plugins/tabfocus_src.js +45 -0
  108. data/public/punymce/plugins/textcolor/css/editor.css +7 -0
  109. data/public/punymce/plugins/textcolor/img/icons.gif +0 -0
  110. data/public/punymce/plugins/textcolor/textcolor.js +1 -0
  111. data/public/punymce/plugins/textcolor/textcolor_src.js +73 -0
  112. data/public/punymce/puny_mce.js +1 -0
  113. data/public/punymce/puny_mce_full.js +1 -0
  114. data/public/punymce/puny_mce_src.js +1460 -0
  115. data/public/stylesheets/sass/forum.sass +175 -169
  116. data/radiant-forum-extension.gemspec +81 -19
  117. data/spec/controllers/admin/forums_controller_spec.rb +2 -2
  118. data/spec/controllers/forums_controller_spec.rb +3 -6
  119. data/spec/controllers/posts_controller_spec.rb +76 -59
  120. data/spec/controllers/topics_controller_spec.rb +4 -95
  121. data/spec/datasets/forum_readers_dataset.rb +1 -0
  122. data/spec/datasets/forums_dataset.rb +91 -10
  123. data/spec/lib/commentable_model_spec.rb +88 -0
  124. data/spec/lib/forum_page_spec.rb +2 -34
  125. data/spec/lib/forum_site_spec.rb +2 -3
  126. data/spec/lib/forum_tags_spec.rb +35 -0
  127. data/spec/models/forum_spec.rb +31 -20
  128. data/spec/models/post_spec.rb +40 -39
  129. data/spec/models/topic_spec.rb +29 -71
  130. data/spec/spec_helper.rb +10 -1
  131. metadata +84 -22
  132. data/app/views/posts/_reply.html.haml +0 -35
  133. data/app/views/posts/_upload.html.haml +0 -2
  134. data/app/views/posts/preview.html.haml +0 -32
  135. data/app/views/posts/search.html.haml +0 -63
  136. data/app/views/posts/search.rss.builder +0 -14
  137. data/app/views/topics/_form.html.haml +0 -30
  138. data/app/views/topics/_help.html.haml +0 -8
  139. data/app/views/topics/comments.html.haml +0 -6
  140. data/app/views/topics/edit.html.haml +0 -26
  141. data/app/views/topics/new.html.haml +0 -56
  142. data/spec/datasets/forum_pages_dataset.rb +0 -11
  143. data/spec/datasets/posts_dataset.rb +0 -31
  144. data/spec/datasets/topics_dataset.rb +0 -37
@@ -34,7 +34,7 @@ describe Admin::ForumsController do
34
34
  it "should deny you access to #{action} action if you are not an admin" do
35
35
  lambda {
36
36
  send(method, action, :id => forum_id(:public))
37
- }.should restrict_access(:deny => [users(:developer), users(:existing)],
37
+ }.should restrict_access(:deny => [users(:designer), users(:existing)],
38
38
  :url => '/admin/page')
39
39
  end
40
40
  end
@@ -47,7 +47,7 @@ describe Admin::ForumsController do
47
47
  it "should allow you to access to #{action} action even if you are not an admin" do
48
48
  lambda {
49
49
  send(method, action, :id => forum_id(:public))
50
- }.should restrict_access(:allow => [users(:developer), users(:admin), users(:existing)], :url => '/admin/pages')
50
+ }.should restrict_access(:allow => [users(:designer), users(:admin), users(:existing)], :url => '/admin/pages')
51
51
  end
52
52
  end
53
53
  end
@@ -1,8 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
- Radiant::Config['reader.layout'] = 'Main'
3
2
 
4
3
  describe ForumsController do
5
- dataset :forum_readers
6
4
  dataset :forums
7
5
 
8
6
  before do
@@ -33,10 +31,9 @@ describe ForumsController do
33
31
  end
34
32
 
35
33
  [:new, :edit, :update, :create, :destroy].each do |action|
36
- it "should redirect #{action} requests to admin login" do
37
- get action, :id => forum_id(:public)
38
- response.should be_redirect
39
- response.should redirect_to(admin_forums_url)
34
+ it "should fail #{action} requests" do
35
+ lambda { get action, :id => forum_id(:public) }.should raise_error ActionController::RoutingError
40
36
  end
41
37
  end
38
+
42
39
  end
@@ -1,9 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
- Radiant::Config['reader.layout'] = 'Main'
3
2
 
4
3
  describe PostsController do
5
- dataset :layouts
6
- dataset :posts
4
+ dataset :forums
7
5
 
8
6
  before do
9
7
  Page.current_site = sites(:test) if defined? Site
@@ -24,41 +22,45 @@ describe PostsController do
24
22
  response.should render_template("index")
25
23
  end
26
24
  end
27
-
28
- describe "on get to search" do
29
- before do
30
- get :search
31
- end
32
-
33
- it "should redirect to login" do
34
- response.should be_redirect
35
- response.should redirect_to(reader_login_url)
36
- end
37
- end
38
25
 
39
26
  describe "on get to show" do
40
27
 
41
28
  describe "for a page comment" do
42
29
  before do
30
+ Radiant::Config['forum.public?'] = true
43
31
  @comment = posts(:comment)
44
32
  @page = pages(:commentable)
45
- get :show, :id => post_id(:comment), :topic_id => topic_id(:comments), :forum_id => forum_id(:comments)
33
+ get :show, :id => post_id(:comment)
46
34
  end
47
35
  it "should redirect to the page address and post anchor" do
48
36
  response.should be_redirect
49
- response.should redirect_to(@page.url + "##{@comment.dom_id}")
37
+ response.should redirect_to(@page.url + "?page=1##{@comment.dom_id}")
50
38
  end
51
39
  end
52
40
 
53
- describe "for a normal post" do
41
+ describe "for a first post" do
42
+ before do
43
+ Radiant::Config['forum.public?'] = true
44
+ get :show, :id => post_id(:first)
45
+ end
46
+ it "should redirect to the topic" do
47
+ response.should be_redirect
48
+ response.should redirect_to(forum_topic_url(@topic.forum, @topic))
49
+ end
50
+ end
51
+
52
+ describe "for a reply" do
54
53
  before do
55
- get :show, :id => @post.id, :topic_id => @topic.id, :forum_id => @forum.id
54
+ Radiant::Config['forum.public?'] = true
55
+ get :show, :id => post_id(:second)
56
56
  end
57
- it "should redirect to the topic address, post page and post anchor" do
57
+ it "should redirect to the topic with the page and anchor of the post" do
58
58
  response.should be_redirect
59
- response.should redirect_to(forum_topic_url(@topic.forum, @topic, {:page => @post.topic_page, :anchor => "post_#{@post.id}"}))
59
+ response.should redirect_to(forum_topic_url(@topic.forum, @topic, {:page => posts(:second).page_when_paginated, :anchor => "post_#{posts(:second).id}"}))
60
60
  end
61
61
  end
62
+
63
+
62
64
  end
63
65
 
64
66
  describe "on get to new" do
@@ -82,12 +84,12 @@ describe PostsController do
82
84
  end
83
85
  end
84
86
 
85
- describe "by xmlhttprequest" do
87
+ describe "over xmlhttp" do
86
88
  before do
87
89
  xhr :get, :new, {:topic_id => topic_id(:older), :forum_id => forum_id(:public)}
88
90
  end
89
91
 
90
- it "should render a bare login form for inclusion in the page" do
92
+ it "should render a bare login form" do
91
93
  response.should be_success
92
94
  response.should render_template('reader_sessions/_login_form')
93
95
  response.layout.should be_nil
@@ -125,19 +127,19 @@ describe PostsController do
125
127
 
126
128
  it "should render the new post form in the normal way" do
127
129
  response.should be_success
128
- response.should render_template("new")
130
+ response.should render_template("posts/new")
129
131
  response.layout.should == 'layouts/radiant'
130
132
  end
131
133
  end
132
134
 
133
- describe "by xmlhttprequest" do
135
+ describe "over xmlhttp" do
134
136
  before do
135
137
  xhr :get, :new, :topic_id => @topic.id, :forum_id => forum_id(:public)
136
138
  end
137
139
 
138
- it "should render a bare comment form for inclusion in the page" do
140
+ it "should render a bare post form" do
139
141
  response.should be_success
140
- response.should render_template('posts/_reply')
142
+ response.should render_template('posts/_form')
141
143
  response.layout.should be_nil
142
144
  end
143
145
  end
@@ -182,12 +184,12 @@ describe PostsController do
182
184
  flash[:error].should =~ /locked/
183
185
  end
184
186
  end
185
- describe "by xmlhttprequest" do
187
+ describe "over xmlhttp" do
186
188
  before do
187
189
  xhr :post, :create, :post => {:body => 'otherwise complete'}, :topic_id => @topic.id, :forum_id => forum_id(:public)
188
190
  end
189
191
 
190
- it "should render a bare 'locked' template for inclusion in the page" do
192
+ it "should render a bare 'locked' template" do
191
193
  response.should be_success
192
194
  response.should render_template('topics/_locked')
193
195
  response.layout.should be_nil
@@ -219,7 +221,7 @@ describe PostsController do
219
221
 
220
222
  it "should re-render the bare post form" do
221
223
  response.should be_success
222
- response.should render_template('new')
224
+ response.should render_template('posts/_form')
223
225
  response.layout.should be_nil
224
226
  end
225
227
 
@@ -232,58 +234,58 @@ describe PostsController do
232
234
  login_as_reader(:normal)
233
235
  end
234
236
 
235
- it "should create the post" do
236
- post :create, :post => {:body => 'test post body'}, :topic_id => @topic.id, :forum_id => forum_id(:public)
237
- topic = Topic.find(@topic.id)
238
- topic.should_not be_nil
239
- topic.posts[-1].body.should == 'test post body'
240
- end
241
-
242
- describe "over xmlhttp" do
237
+ describe "over normal http" do
243
238
  before do
244
- xhr :post, :create, :post => {:body => 'test post body'}, :topic_id => @topic.id, :forum_id => forum_id(:public)
239
+ alphabet = ("a".."z").to_a
240
+ @body = Array.new(64, '').collect{alphabet[rand(alphabet.size)]}.join
241
+ post :create, :post => {:body => @body}, :topic_id => @topic.id, :forum_id => forum_id(:public)
242
+ @post = Post.find_by_body(@body)
245
243
  end
246
- it "should return the formatted message for inclusion in the page" do
247
- response.should be_success
248
- response.should render_template('show')
249
- response.layout.should be_nil
244
+
245
+ it "should create the post" do
246
+ @post.should_not be_nil
250
247
  end
251
- end
252
248
 
253
- describe "over normal http" do
254
- before do
255
- alphabet = ("a".."z").to_a
256
- body = Array.new(64, '').collect{alphabet[rand(alphabet.size)]}.join
257
- post :create, :post => {:body => body}, :topic_id => @topic.id, :forum_id => forum_id(:public)
258
- @post = Post.find_by_body(body)
249
+ it "should associate the post with its topic" do
250
+ @post.topic.should == @topic
259
251
  end
260
252
 
261
253
  it "should redirect to the right topic and page" do
262
254
  response.should be_redirect
263
- response.should redirect_to(forum_topic_url(@forum, @topic, {:page => @post.topic_page, :anchor => "post_#{@post.id}"}))
255
+ response.should redirect_to(forum_topic_url(@forum, @topic, {:page => @post.page_when_paginated, :anchor => "post_#{@post.id}"}))
256
+ end
257
+ end
258
+
259
+ describe "over xmlhttp" do
260
+ before do
261
+ xhr :post, :create, :post => {:body => 'test post body'}, :topic_id => @topic.id, :forum_id => forum_id(:public)
262
+ end
263
+
264
+ it "should return the formatted message for inclusion in the page" do
265
+ response.should be_success
266
+ response.should render_template('posts/_post')
267
+ response.layout.should be_nil
264
268
  end
265
269
  end
266
270
 
267
271
  describe "to attach a comment to a page" do
268
272
  before do
269
273
  login_as_reader(:normal)
270
- post :create, :post => {:body => "I ain't getting in no plane."}, :page_id => page_id(:commentable)
271
- @topic = pages(:commentable).topic
274
+ post :create, :post => {:body => "I ain't getting in no plane.", :page_id => page_id(:commentable)}
272
275
  @post = Post.find_by_body("I ain't getting in no plane.")
273
276
  end
274
277
 
275
- it "should create a page topic" do
276
- @topic.should_not be_nil
277
- end
278
-
279
- it "should reuse the page topic if it already exists" do
280
- post :create, :post => {:body => 'barbecue'}, :page_id => page_id(:commentable)
281
- Post.find_by_body('barbecue').topic.should == @topic
278
+ it "should create the post" do
279
+ @post.should_not be_nil
282
280
  end
283
281
 
284
282
  it "should attach the post to the page" do
285
283
  @post.page.should == pages(:commentable)
286
284
  end
285
+
286
+ it "should not associate the post with a topic" do
287
+ @post.topic.should be_nil
288
+ end
287
289
 
288
290
  it "should clear the cache" do
289
291
  Radiant::Cache.should_receive(:clear)
@@ -305,6 +307,21 @@ describe PostsController do
305
307
  end
306
308
  end
307
309
 
310
+ describe "to start a new topic" do
311
+ before do
312
+ login_as_reader(:normal)
313
+ post :create, :post => {:body => "Madam, I would drink it.", :topic_attributes => {:name => "Winston, I would poison your tea.", :forum_id => forum_id(:public)}}
314
+ @topic = Topic.find_by_name("Winston, I would poison your tea.")
315
+ @post = Post.find_by_body("Madam, I would drink it.")
316
+ end
317
+
318
+ it "should create the joined topic and post" do
319
+ @topic.should_not be_nil
320
+ @post.should_not be_nil
321
+ @post.topic.should == @topic
322
+ @topic.posts.first.should == @post
323
+ end
324
+ end
308
325
  end
309
326
  end
310
327
  end
@@ -1,10 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
- Radiant::Config['reader.layout'] = 'Main'
3
2
 
4
3
  describe TopicsController do
5
- dataset :forum_readers
6
- dataset :layouts
7
- dataset :topics
4
+ dataset :forums
8
5
 
9
6
  before do
10
7
  Page.current_site = sites(:test) if defined? Site
@@ -35,99 +32,11 @@ describe TopicsController do
35
32
  response.should render_template("show")
36
33
  end
37
34
  end
38
-
39
- describe "on get to new" do
40
- describe "without a logged-in reader" do
41
- before do
42
- logout_reader
43
- get :new, :forum_id => forum_id(:public)
44
- end
45
- it "should redirect to login" do
46
- response.should be_redirect
47
- response.should redirect_to(reader_login_url)
48
- end
49
- it "should store the return address in the session" do
50
- request.session[:return_to].should == request.request_uri
51
- end
52
- end
53
35
 
54
- describe "with a logged-in reader" do
55
- before do
56
- login_as_reader(:normal)
57
- get :new, :forum_id => forum_id(:public)
58
- end
59
- it "should render the new topic form" do
60
- response.should be_success
61
- response.should render_template("new")
62
- end
36
+ [:new, :edit, :update, :create, :destroy].each do |action|
37
+ it "should fail #{action} requests" do
38
+ lambda { get action, :id => forum_id(:public) }.should raise_error ActionController::RoutingError
63
39
  end
64
40
  end
65
41
 
66
- describe "on post to create" do
67
- describe "without a logged-in reader" do
68
- before do
69
- logout_reader
70
- post :create, :forum_id => forum_id(:public), :topic => {:name => 'another test topic', :body => 'topic body'}
71
- end
72
- it "should redirect to login" do
73
- response.should be_redirect
74
- response.should redirect_to(reader_login_url)
75
- end
76
- end
77
-
78
- describe "with a logged-in reader" do
79
- before do
80
- Page.current_site = sites(:test) if defined? Site
81
- login_as_reader(:normal)
82
- end
83
- describe "but an invalid topic field" do
84
- before do
85
- post :create, :forum_id => forum_id(:public), :topic => {:name => '', :body => 'topic body'}
86
- end
87
- it "should rerender the topic form" do
88
- response.should be_success
89
- response.should render_template("new")
90
- end
91
- end
92
-
93
- describe "but an invalid post" do
94
- before do
95
- post :create, :forum_id => forum_id(:public), :topic => {:name => 'topic name', :body => ''}
96
- end
97
- it "should rerender the topic form" do
98
- response.should be_success
99
- response.should render_template("new")
100
- end
101
- end
102
-
103
- describe "and a valid request" do
104
- before do
105
- post :create, :forum_id => forum_id(:public), :topic => {:name => 'another test topic', :body => 'topic body'}
106
- @topic = Topic.find_by_name('another test topic')
107
- end
108
- it "should create the topic" do
109
- @topic.should_not be_nil
110
- @topic.forum.should == forums(:public)
111
- @topic.posts.first.should_not be_nil
112
- @topic.posts.first.body.should == 'topic body'
113
- end
114
- it "should assign the topic to the current reader" do
115
- @topic.reader.should_not be_nil
116
- @topic.reader.should == readers(:normal)
117
- end
118
- it "should create the topic's first post" do
119
- @topic.first_post.should_not be_nil
120
- @topic.first_post.body.should == 'topic body'
121
- @topic.first_post.topic.should == @topic
122
- end
123
- it "should redirect to the topic page" do
124
- response.should be_redirect
125
- response.should redirect_to(forum_topic_url(@topic.forum, @topic))
126
- end
127
- end
128
- end
129
- end
130
-
131
-
132
-
133
42
  end
@@ -7,6 +7,7 @@ class ForumReadersDataset < Dataset::Base
7
7
  def load
8
8
  create_reader "Normal"
9
9
  create_reader "Idle"
10
+ create_reader "Notable"
10
11
  create_reader "Activated"
11
12
  create_reader "User", :user_id => user_id(:existing)
12
13
  create_reader "Admin", :user_id => user_id(:admin)
@@ -1,28 +1,109 @@
1
1
  class ForumsDataset < Dataset::Base
2
- uses :forum_sites if defined? Site
2
+ uses :forum_readers, :home_page, :users
3
3
 
4
- def load
5
- create_forum "Public"
6
- create_forum "Private"
7
- create_forum "Misc"
8
- create_forum "Comments", :for_comments => true
4
+ def load
5
+ create_layout "Forum"
6
+
7
+ create_forum "Public" do
8
+ create_topic "older", :reader => readers(:normal), :replied_at => 2.days.ago do
9
+ add_post "First", :created_at => 2.days.ago, :body => 'original topic message'
10
+ add_post "Second", :created_at => 1.day.ago, :body => 'first reply to public topic'
11
+ end
12
+ create_topic "newer", :reader => readers(:normal), :replied_at => 1.day.ago
13
+ end
14
+
15
+ create_forum "Private" do
16
+ create_topic "sticky", :reader => readers(:normal), :replied_at => 3.days.ago, :sticky => true
17
+ create_topic "locked", :reader => readers(:normal), :locked => true, :replied_at => 1.year.ago
18
+ create_topic "private", :reader => readers(:normal), :replied_at => 1.day.ago do
19
+ add_post "Third", :created_at => 4.hours.ago, :body => 'Reply to private topic'
20
+ end
21
+ end
22
+
23
+ create_forum "Misc" do
24
+ create_topic "empty", :reader => readers(:notable)
25
+ end
26
+
27
+ create_page "Commentable", :commentable => true, :comments_closed => false, :created_by => users(:admin) do
28
+ add_post "Comment", :created_at => 2.days.ago, :body => 'first comment on page'
29
+ add_post "Recomment", :created_at => 1.day.ago, :body => 'second comment on page'
30
+ end
31
+
32
+ create_page "Uncommented", :commentable => true, :comments_closed => false, :created_by => users(:admin)
33
+ create_page "Uncommentable", :commentable => false, :comments_closed => false, :created_by => users(:admin)
34
+ create_page "Comments closed", :commentable => true, :comments_closed => true, :created_by => users(:admin)
9
35
  end
10
36
 
11
37
  helpers do
38
+ def create_layout(name, attributes={})
39
+ create_model :layout, name.symbolize, attributes.update(:name => name)
40
+ end
41
+
12
42
  def create_forum(name, attributes={})
13
- create_model :forum, name.symbolize, attributes.update(:name => name)
43
+ attributes = forum_attributes(attributes.update(:name => name))
44
+ symbol = name.symbolize
45
+ create_model :forum, symbol, attributes
46
+ if block_given?
47
+ @forum_id = forum_id(symbol)
48
+ yield
49
+ @forum_id = nil
50
+ end
14
51
  end
15
52
 
53
+ def create_topic(name, attributes={})
54
+ attributes = topic_attributes(attributes.update(:name => name))
55
+ symbol = name.symbolize
56
+ reader = attributes.delete(:reader)
57
+ create_model :topic, symbol, attributes
58
+ @topic_id = topic_id(symbol)
59
+ add_post("#{name}_first_post", :reader => reader)
60
+ yield if block_given?
61
+ @topic_id = nil
62
+ end
63
+
64
+ def add_post(name, attributes={})
65
+ attributes = post_attributes(attributes)
66
+ symbol = name.symbolize
67
+ create_model :post, symbol, attributes
68
+ if block_given?
69
+ @post_id = post_id(symbol)
70
+ yield
71
+ @post_id = nil
72
+ end
73
+ end
74
+
16
75
  def forum_attributes(attributes={})
17
76
  name = attributes[:name] || "Forum"
18
77
  symbol = name.symbolize
19
78
  attributes = {
20
79
  :name => name,
80
+ :created_at => Time.now
21
81
  }.merge(attributes)
22
- attributes[:site] = sites(:test) if defined? Site
82
+ attributes[:site_id] = site_id(:test) if Forum.reflect_on_association(:site)
23
83
  attributes
24
84
  end
25
-
85
+
86
+ def topic_attributes(attributes={})
87
+ name = attributes[:name] || "A topic"
88
+ att = {
89
+ :name => name,
90
+ :forum_id => @forum_id
91
+ }.merge(attributes)
92
+ attributes[:site_id] ||= site_id(:test) if Topic.reflect_on_association(:site)
93
+ att
94
+ end
95
+
96
+ def post_attributes(attributes={})
97
+ att = {
98
+ :body => "Message body",
99
+ :reader => readers(:normal),
100
+ :created_at => 1.day.ago,
101
+ :topic_id => @topic_id,
102
+ :page_id => @current_page_id
103
+ }.merge(attributes)
104
+ att[:site_id] ||= site_id(:test) if Post.reflect_on_association(:site)
105
+ att
106
+ end
26
107
  end
27
-
108
+
28
109
  end