radiant-forum-extension 2.1.6 → 3.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/README.md +20 -16
  2. data/Rakefile +0 -16
  3. data/app/controllers/forum_base_controller.rb +32 -10
  4. data/app/controllers/posts_controller.rb +37 -14
  5. data/app/helpers/forum_helper.rb +23 -16
  6. data/app/models/forum.rb +11 -7
  7. data/app/models/post.rb +53 -14
  8. data/app/models/post_attachment.rb +1 -1
  9. data/app/models/topic.rb +21 -8
  10. data/app/views/admin/dashboard/_forum_dashboard.html.haml +51 -0
  11. data/app/views/admin/forums/_form.html.haml +12 -0
  12. data/app/views/admin/forums/edit.html.haml +1 -1
  13. data/app/views/admin/forums/index.html.haml +16 -20
  14. data/app/views/admin/posts/_form.html.haml +2 -2
  15. data/app/views/admin/posts/edit.html.haml +1 -1
  16. data/app/views/admin/posts/index.html.haml +5 -5
  17. data/app/views/admin/reader_configuration/_edit_forum.html.haml +6 -0
  18. data/app/views/admin/reader_configuration/_forum.html.haml +5 -1
  19. data/app/views/admin/topics/_form.html.haml +3 -5
  20. data/app/views/admin/topics/edit.html.haml +1 -1
  21. data/app/views/admin/topics/index.html.haml +5 -5
  22. data/app/views/forums/_forum.html.haml +6 -5
  23. data/app/views/forums/_latest.html.haml +14 -12
  24. data/app/views/forums/_statistics.html.haml +4 -4
  25. data/app/views/forums/index.html.haml +8 -10
  26. data/app/views/forums/index.rss.builder +2 -2
  27. data/app/views/forums/show.html.haml +12 -15
  28. data/app/views/pages/_add_comment.html.haml +9 -8
  29. data/app/views/pages/_comments.html.haml +3 -3
  30. data/app/views/posts/_attachments.html.haml +1 -1
  31. data/app/views/posts/_confirm_delete.html.haml +7 -2
  32. data/app/views/posts/_context.html.haml +5 -5
  33. data/app/views/posts/_edit_links.html.haml +4 -4
  34. data/app/views/posts/_form.html.haml +15 -12
  35. data/app/views/posts/_ineditable.html.haml +7 -0
  36. data/app/views/posts/_latest.html.haml +3 -8
  37. data/app/views/posts/_minimal.html.haml +7 -0
  38. data/app/views/posts/_post.html.haml +20 -17
  39. data/app/views/posts/_post.rss.builder +2 -2
  40. data/app/views/posts/_search_form.html.haml +13 -13
  41. data/app/views/posts/_search_results.html.haml +15 -0
  42. data/app/views/posts/_search_summary.html.haml +13 -0
  43. data/app/views/posts/_uploader.html.haml +1 -1
  44. data/app/views/posts/edit.html.haml +22 -21
  45. data/app/views/posts/index.html.haml +12 -19
  46. data/app/views/posts/index.rss.builder +6 -6
  47. data/app/views/posts/new.html.haml +19 -22
  48. data/app/views/posts/remove.html.haml +15 -15
  49. data/app/views/posts/show.html.haml +16 -10
  50. data/app/views/readers/_forum_messages.html.haml +9 -6
  51. data/app/views/readers/_messages_summary.html.haml +1 -1
  52. data/app/views/shared/_standard_forum_parts.html.haml +41 -0
  53. data/app/views/topics/_busiest.html.haml +9 -8
  54. data/app/views/topics/_context.html.haml +11 -8
  55. data/app/views/topics/_latest.html.haml +2 -2
  56. data/app/views/topics/_locked.html.haml +1 -1
  57. data/app/views/topics/_minimal.html.haml +2 -2
  58. data/app/views/topics/_replies.html.haml +4 -3
  59. data/app/views/topics/_reply.html.haml +13 -8
  60. data/app/views/topics/_topic.html.haml +5 -9
  61. data/app/views/topics/_topic.rss.builder +1 -1
  62. data/app/views/topics/index.html.haml +14 -10
  63. data/app/views/topics/index.rss.builder +2 -2
  64. data/app/views/topics/show.html.haml +20 -19
  65. data/app/views/topics/show.rss.builder +3 -3
  66. data/config/initializers/radiant_config.rb +4 -1
  67. data/config/locales/en.yml +202 -178
  68. data/db/migrate/002_pages_commentable.rb +1 -2
  69. data/db/migrate/004_sample_layout.rb +38 -15
  70. data/db/migrate/20110111080550_detach_observer.rb +4 -4
  71. data/db/migrate/20110613112823_search_text.rb +9 -0
  72. data/db/migrate/20110613130230_tidy_up.rb +27 -0
  73. data/db/migrate/20110630083446_page_replied_at.rb +11 -0
  74. data/forum_extension.rb +13 -11
  75. data/lib/commentable_model.rb +13 -9
  76. data/lib/forum_admin_ui.rb +6 -6
  77. data/lib/forum_page.rb +5 -3
  78. data/lib/forum_reader.rb +7 -1
  79. data/lib/forum_reader_sessions_controller.rb +2 -3
  80. data/lib/forum_tags.rb +126 -11
  81. data/lib/radiant-forum-extension.rb +8 -0
  82. data/public/cleditor/images/buttons.gif +0 -0
  83. data/public/cleditor/images/icons/1.gif +0 -0
  84. data/public/cleditor/images/icons/10.gif +0 -0
  85. data/public/cleditor/images/icons/11.gif +0 -0
  86. data/public/cleditor/images/icons/12.gif +0 -0
  87. data/public/cleditor/images/icons/2.gif +0 -0
  88. data/public/cleditor/images/icons/3.gif +0 -0
  89. data/public/cleditor/images/icons/4.gif +0 -0
  90. data/public/cleditor/images/icons/5.gif +0 -0
  91. data/public/cleditor/images/icons/6.gif +0 -0
  92. data/public/cleditor/images/icons/7.gif +0 -0
  93. data/public/cleditor/images/icons/8.gif +0 -0
  94. data/public/cleditor/images/icons/9.gif +0 -0
  95. data/public/cleditor/images/icons/icons.gif +0 -0
  96. data/public/cleditor/images/toolbar.gif +0 -0
  97. data/public/cleditor/jquery.cleditor.css +24 -0
  98. data/public/cleditor/jquery.cleditor.icon.js +65 -0
  99. data/public/cleditor/jquery.cleditor.js +1132 -0
  100. data/public/cleditor/jquery.cleditor.xhtml.js +230 -0
  101. data/public/javascripts/forum.js +146 -107
  102. data/public/stylesheets/sass/forum.sass +94 -58
  103. data/radiant-forum-extension.gemspec +25 -276
  104. data/spec/controllers/forums_controller_spec.rb +0 -7
  105. data/spec/controllers/posts_controller_spec.rb +20 -37
  106. data/spec/controllers/topics_controller_spec.rb +1 -7
  107. data/spec/datasets/forums_dataset.rb +38 -40
  108. data/spec/lib/commentable_model_spec.rb +26 -38
  109. data/spec/lib/forum_reader_spec.rb +0 -4
  110. data/spec/models/forum_spec.rb +46 -16
  111. data/spec/models/post_spec.rb +10 -6
  112. data/spec/models/topic_spec.rb +26 -17
  113. data/spec/spec_helper.rb +1 -0
  114. metadata +66 -99
  115. data/VERSION +0 -1
  116. data/app/views/forums/_standard_parts.html.haml +0 -59
  117. data/lib/sanitize/config/forum.rb +0 -49
  118. data/public/javascripts/gallery.js +0 -275
  119. data/public/punymce/blank.htm +0 -1
  120. data/public/punymce/css/content.css +0 -4
  121. data/public/punymce/css/editor.css +0 -58
  122. data/public/punymce/i18n/sv.js +0 -28
  123. data/public/punymce/img/icons.gif +0 -0
  124. data/public/punymce/img/icons_uncompressed.png +0 -0
  125. data/public/punymce/plugins/bbcode.js +0 -1
  126. data/public/punymce/plugins/bbcode_src.js +0 -50
  127. data/public/punymce/plugins/editsource/css/editor.css +0 -3
  128. data/public/punymce/plugins/editsource/editsource.js +0 -1
  129. data/public/punymce/plugins/editsource/editsource_src.js +0 -81
  130. data/public/punymce/plugins/editsource/img/icons.gif +0 -0
  131. data/public/punymce/plugins/emoticons/css/content.css +0 -13
  132. data/public/punymce/plugins/emoticons/css/editor.css +0 -17
  133. data/public/punymce/plugins/emoticons/emoticons.js +0 -1
  134. data/public/punymce/plugins/emoticons/emoticons_src.js +0 -303
  135. data/public/punymce/plugins/emoticons/img/emoticons.gif +0 -0
  136. data/public/punymce/plugins/emoticons/img/emoticons.png +0 -0
  137. data/public/punymce/plugins/emoticons/img/trans.gif +0 -0
  138. data/public/punymce/plugins/entities.js +0 -1
  139. data/public/punymce/plugins/entities_src.js +0 -37
  140. data/public/punymce/plugins/forceblocks.js +0 -1
  141. data/public/punymce/plugins/forceblocks_src.js +0 -465
  142. data/public/punymce/plugins/forcenl.js +0 -1
  143. data/public/punymce/plugins/forcenl_src.js +0 -26
  144. data/public/punymce/plugins/image/css/editor.css +0 -1
  145. data/public/punymce/plugins/image/image.js +0 -1
  146. data/public/punymce/plugins/image/image_src.js +0 -30
  147. data/public/punymce/plugins/image/img/icons.gif +0 -0
  148. data/public/punymce/plugins/link/css/editor.css +0 -2
  149. data/public/punymce/plugins/link/img/icons.gif +0 -0
  150. data/public/punymce/plugins/link/link.js +0 -1
  151. data/public/punymce/plugins/link/link_src.js +0 -36
  152. data/public/punymce/plugins/paste.js +0 -1
  153. data/public/punymce/plugins/paste_src.js +0 -169
  154. data/public/punymce/plugins/protect.js +0 -1
  155. data/public/punymce/plugins/protect_src.js +0 -30
  156. data/public/punymce/plugins/safari2x.js +0 -1
  157. data/public/punymce/plugins/safari2x_src.js +0 -284
  158. data/public/punymce/plugins/tabfocus.js +0 -1
  159. data/public/punymce/plugins/tabfocus_src.js +0 -45
  160. data/public/punymce/plugins/textcolor/css/editor.css +0 -7
  161. data/public/punymce/plugins/textcolor/img/icons.gif +0 -0
  162. data/public/punymce/plugins/textcolor/textcolor.js +0 -1
  163. data/public/punymce/plugins/textcolor/textcolor_src.js +0 -73
  164. data/public/punymce/puny_mce.js +0 -1
  165. data/public/punymce/puny_mce_full.js +0 -1
  166. data/public/punymce/puny_mce_src.js +0 -1460
@@ -1,48 +1,57 @@
1
1
  class ForumsDataset < Dataset::Base
2
- uses :forum_readers, :home_page, :users
2
+ uses :readers
3
3
 
4
4
  def load
5
5
  create_layout "Forum"
6
6
 
7
7
  create_forum "Public" do
8
+ create_topic "sticky", :reader => readers(:normal), :replied_at => 3.days.ago, :sticky => true
8
9
  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'
10
+ create_post "First", :created_at => 2.days.ago, :body => 'original topic message'
11
+ create_post "Second", :created_at => 1.day.ago, :body => 'first reply to public topic'
11
12
  end
12
13
  create_topic "newer", :reader => readers(:normal), :replied_at => 1.day.ago
13
14
  end
14
15
 
15
- create_forum "Private" do
16
- create_topic "sticky", :reader => readers(:normal), :replied_at => 3.days.ago, :sticky => true
16
+ create_forum "Other" do
17
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'
18
+ create_topic "another", :reader => readers(:normal), :replied_at => 1.day.ago do
19
+ create_post "Third", :created_at => 4.hours.ago, :body => 'Reply to another topic'
20
20
  end
21
21
  end
22
22
 
23
23
  create_forum "Misc" do
24
- create_topic "empty", :reader => readers(:notable)
24
+ create_topic "empty", :reader => readers(:another)
25
+ create_topic "busy", :reader => readers(:another) do
26
+ 60.times do |i|
27
+ create_post "test_#{i}", :body => "test #{i}", :reader => readers(:normal), :created_at => (100-i).minutes.ago
28
+ end
29
+ create_post "nearly", :body => "test by visible", :reader => readers(:visible)
30
+ create_post "finally", :body => "test by another", :reader => readers(:another)
31
+ end
32
+ end
33
+
34
+ create_forum "Grouped" do
35
+ create_topic "grouped", :reader => readers(:another)
25
36
  end
26
37
 
27
38
  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'
39
+ create_post "Comment", :created_at => 2.days.ago, :body => 'first comment on page'
40
+ create_post "Recomment", :created_at => 1.day.ago, :body => 'second comment on page'
30
41
  end
31
42
 
32
43
  create_page "Uncommented", :commentable => true, :comments_closed => false, :created_by => users(:admin)
33
44
  create_page "Uncommentable", :commentable => false, :comments_closed => false, :created_by => users(:admin)
34
45
  create_page "Comments closed", :commentable => true, :comments_closed => true, :created_by => users(:admin)
46
+
47
+
48
+ restrict_to_group :special, [forums(:grouped)]
35
49
  end
36
50
 
37
51
  helpers do
38
- def create_layout(name, attributes={})
39
- create_model :layout, name.symbolize, attributes.update(:name => name)
40
- end
41
-
42
52
  def create_forum(name, attributes={})
43
- attributes = forum_attributes(attributes.update(:name => name))
44
53
  symbol = name.symbolize
45
- create_model :forum, symbol, attributes
54
+ create_model :forum, symbol, default_forum_attributes(name).merge(attributes)
46
55
  if block_given?
47
56
  @forum_id = forum_id(symbol)
48
57
  yield
@@ -51,20 +60,18 @@ class ForumsDataset < Dataset::Base
51
60
  end
52
61
 
53
62
  def create_topic(name, attributes={})
54
- attributes = topic_attributes(attributes.update(:name => name))
55
63
  symbol = name.symbolize
56
64
  reader = attributes.delete(:reader)
57
- create_model :topic, symbol, attributes
65
+ create_model :topic, symbol, default_topic_attributes(name).merge(attributes)
58
66
  @topic_id = topic_id(symbol)
59
- add_post("#{name}_first_post", :reader => reader)
67
+ create_post("#{name}_first_post", :reader => reader)
60
68
  yield if block_given?
61
69
  @topic_id = nil
62
70
  end
63
71
 
64
- def add_post(name, attributes={})
65
- attributes = post_attributes(attributes)
72
+ def create_post(name, attributes={})
66
73
  symbol = name.symbolize
67
- create_model :post, symbol, attributes
74
+ create_model :post, name.symbolize, default_post_attributes.merge(attributes)
68
75
  if block_given?
69
76
  @post_id = post_id(symbol)
70
77
  yield
@@ -72,37 +79,28 @@ class ForumsDataset < Dataset::Base
72
79
  end
73
80
  end
74
81
 
75
- def forum_attributes(attributes={})
76
- name = attributes[:name] || "Forum"
77
- symbol = name.symbolize
78
- attributes = {
82
+ def default_forum_attributes(name="Forum")
83
+ {
79
84
  :name => name,
80
85
  :created_at => Time.now
81
- }.merge(attributes)
82
- attributes[:site_id] = site_id(:test) if Forum.reflect_on_association(:site)
83
- attributes
86
+ }
84
87
  end
85
88
 
86
- def topic_attributes(attributes={})
87
- name = attributes[:name] || "A topic"
88
- att = {
89
+ def default_topic_attributes(name="A topic")
90
+ {
89
91
  :name => name,
90
92
  :forum_id => @forum_id
91
- }.merge(attributes)
92
- attributes[:site_id] ||= site_id(:test) if Topic.reflect_on_association(:site)
93
- att
93
+ }
94
94
  end
95
95
 
96
- def post_attributes(attributes={})
97
- att = {
96
+ def default_post_attributes
97
+ {
98
98
  :body => "Message body",
99
99
  :reader => readers(:normal),
100
100
  :created_at => 1.day.ago,
101
101
  :topic_id => @topic_id,
102
102
  :page_id => @current_page_id
103
- }.merge(attributes)
104
- att[:site_id] ||= site_id(:test) if Post.reflect_on_association(:site)
105
- att
103
+ }
106
104
  end
107
105
  end
108
106
 
@@ -1,88 +1,76 @@
1
1
  require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
+ # NB post-holder may be Page or Topic (or whatever else has been made commentable)
4
+
3
5
  describe 'Post-holder' do
4
6
  dataset :forums
5
7
 
6
8
  before do
7
9
  Radiant::Config['forum.paginate_posts?'] = true
8
- @topic = topics(:empty)
9
10
  end
11
+
12
+ let(:topic) { topics(:empty) }
13
+ let(:busy_topic) { topics(:busy) }
10
14
 
11
15
  describe "without replies" do
12
16
  it "should announce posts but not replies" do
13
- @topic.posts.count.should == 1
14
- @topic.has_posts?.should be_true
15
- @topic.has_replies?.should be_false
17
+ topic.posts.count.should == 1
18
+ topic.has_posts?.should be_true
19
+ topic.has_replies?.should be_false
16
20
  end
17
21
  end
18
22
 
19
23
  describe "with replies" do
20
- before do
21
- 60.times do |i|
22
- @topic.posts.create!(:body => "test #{i}", :reader => readers(:normal), :created_at => (100-i).minutes.ago)
23
- end
24
- @topic.posts.create!(:body => "test by another", :reader => readers(:idle))
25
- @topic.reload
26
- end
27
-
28
24
  it "should have many posts" do
29
- @topic.posts.count.should == 62
25
+ busy_topic.posts.count.should == 63
30
26
  end
31
27
 
32
28
  it "should report the number of replies to the original post" do
33
- @topic.reply_count.should == 61
34
- @topic.replies.length.should == @topic.reply_count
29
+ busy_topic.reply_count.should == 62
30
+ busy_topic.replies.length.should == busy_topic.reply_count
35
31
  end
36
32
 
37
33
  it "should report the number of readers taking part" do
38
- calculated = @topic.posts.map(&:reader).uniq
39
- Rails.logger.warn ">>"
40
- @topic.voice_count.should == calculated.length
41
- Rails.logger.warn "<<"
34
+ calculated = busy_topic.posts.map(&:reader).uniq
35
+ busy_topic.voice_count.should == calculated.length
42
36
  end
43
37
 
44
38
  it "should report the number of readers replying" do
45
- calculated = @topic.posts.map(&:reader).uniq - [@topic.posts.first.reader]
46
- @topic.other_voice_count.should == calculated.length
39
+ calculated = busy_topic.posts.map(&:reader).uniq - [topic.posts.first.reader]
40
+ busy_topic.other_voice_count.should == calculated.length
47
41
  end
48
42
 
49
43
  it "should report the list of readers taking part" do
50
- @topic.voices.length.should == 3
51
- @topic.voices.include?(readers(:notable)).should be_true
52
- @topic.voices.include?(readers(:normal)).should be_true
53
- @topic.voices.include?(readers(:idle)).should be_true
44
+ busy_topic.voices.should =~ [readers(:normal), readers(:another), readers(:visible)]
54
45
  end
55
46
 
56
47
  it "should report the list of readers replying" do
57
- @topic.other_voices.length.should == 2
58
- @topic.other_voices.include?(readers(:notable)).should be_false
59
- @topic.other_voices.include?(readers(:normal)).should be_true
60
- @topic.other_voices.include?(readers(:idle)).should be_true
48
+ busy_topic.other_voices.should =~ [readers(:visible), readers(:normal)]
61
49
  end
62
50
 
63
51
  it "should paginate its posts" do
64
- @topic.paged?.should be_true
52
+ busy_topic.paged?.should be_true
65
53
  end
66
54
 
67
55
  it "should know on which page to find a given post" do
68
- @topic.page_for(Post.find_by_body("test 16")).should == 1
69
- @topic.page_for(Post.find_by_body("test 36")).should == 2
70
- @topic.page_for(Post.find_by_body("test 56")).should == 3
56
+ busy_topic.page_for(Post.find_by_body("test 16")).should == 1
57
+ busy_topic.page_for(Post.find_by_body("test 36")).should == 2
58
+ busy_topic.page_for(Post.find_by_body("test 56")).should == 3
71
59
  end
72
60
 
73
61
  it "should read config to find the number of posts per page" do
74
62
  Radiant::Config['forum.posts_per_page'] = 15
75
- @topic.page_for(Post.find_by_body("test 16")).should == 2
76
- @topic.page_for(Post.find_by_body("test 36")).should == 3
77
- @topic.page_for(Post.find_by_body("test 56")).should == 4
63
+ busy_topic.page_for(Post.find_by_body("test 16")).should == 2
64
+ busy_topic.page_for(Post.find_by_body("test 36")).should == 3
65
+ busy_topic.page_for(Post.find_by_body("test 56")).should == 4
78
66
  end
79
67
 
80
68
  it "should know when it was last replied to" do
81
- @topic.replied_at.should == @topic.posts.last.created_at
69
+ busy_topic.replied_at.should == posts(:finally).created_at
82
70
  end
83
71
 
84
72
  it "should know by whom it was last replied to" do
85
- @topic.replied_by.should == readers(:idle)
73
+ busy_topic.replied_by.should == posts(:finally).reader
86
74
  end
87
75
  end
88
76
  end
@@ -2,10 +2,6 @@ require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
3
  describe 'Forum reader' do
4
4
 
5
- it "should have a topics association" do
6
- Reader.reflect_on_association(:topics).should_not be_nil
7
- end
8
-
9
5
  it "should have a posts association" do
10
6
  Reader.reflect_on_association(:posts).should_not be_nil
11
7
  end
@@ -2,29 +2,26 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Forum do
4
4
  dataset :forums
5
-
6
- before do
7
- @site = Page.current_site = sites(:test) if defined? Site
8
- @forum = forums(:public)
9
- @reader = Reader.current = readers(:normal)
10
- end
5
+ let(:forum) {forums(:public)}
6
+ let(:group_forum) {forums(:grouped)}
7
+ let(:reader) {readers(:normal)}
8
+ let(:unrestricted) {[forums(:public), forums(:other), forums(:misc)]}
11
9
 
12
10
  it "should require a name" do
13
- @forum.name = nil
14
- @forum.should_not be_valid
15
- @forum.errors.on(:name).should_not be_empty
11
+ forum.name = nil
12
+ forum.should_not be_valid
13
+ forum.errors.on(:name).should_not be_empty
16
14
  end
17
15
 
18
16
  describe "topics.bydate" do
19
17
  it "should list its topics in descending date order" do
20
- forums(:public).topics.bydate.first.should == topics(:newer)
21
- forums(:private).topics.bydate.first.should == topics(:private)
18
+ forum.topics.bydate.first.should == topics(:newer)
22
19
  end
23
20
  end
24
21
 
25
22
  describe "topics.stickyfirst" do
26
23
  it "should list its topics with the sticky first" do
27
- forums(:private).topics.stickyfirst.first.should == topics(:sticky)
24
+ forum.topics.stickyfirst.first.should == topics(:sticky)
28
25
  end
29
26
  end
30
27
 
@@ -34,11 +31,11 @@ describe Forum do
34
31
  end
35
32
 
36
33
  it "should be visible to a reader" do
37
- forums(:public).visible_to?(@reader).should be_true
34
+ forum.visible_to?(reader).should be_true
38
35
  end
39
36
 
40
37
  it "should be visible when there is no reader" do
41
- forums(:public).visible_to?(nil).should be_true
38
+ forum.visible_to?(nil).should be_true
42
39
  end
43
40
  end
44
41
 
@@ -48,11 +45,44 @@ describe Forum do
48
45
  end
49
46
 
50
47
  it "should be visible to a reader" do
51
- forums(:public).visible_to?(@reader).should be_true
48
+ forum.visible_to?(reader).should be_true
52
49
  end
53
50
 
54
51
  it "should not be visible when there is no reader" do
55
- forums(:public).visible_to?(nil).should be_false
52
+ forum.visible_to?(nil).should be_false
53
+ end
54
+ end
55
+
56
+ it "should have a groups association" do
57
+ Forum.reflect_on_association(:groups).should_not be_nil
58
+ end
59
+
60
+ describe "when a reader is not grouped" do
61
+ it "should list only the ungrouped forums" do
62
+ Forum.visible.should =~ unrestricted
63
+ Forum.visible_to(readers(:ungrouped)).should =~ unrestricted
64
+ end
65
+ end
66
+
67
+ describe "to a grouped reader" do
68
+ it "should list also the forums of that group" do
69
+ Forum.visible_to(readers(:another)).should =~ unrestricted + [group_forum]
70
+ end
71
+ end
72
+
73
+ describe "with a group" do
74
+ it "should report itself visible to a reader who is a group member" do
75
+ group_forum.visible_to?(readers(:another)).should be_true
76
+ end
77
+ it "should report itself invisible to a reader who is not a group member" do
78
+ group_forum.visible_to?(readers(:normal)).should be_false
79
+ end
80
+ end
81
+
82
+ describe "without a group" do
83
+ it "should report itself visible to everyone" do
84
+ forum.visible_to?(readers(:normal)).should be_true
85
+ forum.visible_to?(readers(:another)).should be_true
56
86
  end
57
87
  end
58
88
 
@@ -23,12 +23,16 @@ describe Post do
23
23
  describe "when added to a topic" do
24
24
  before do
25
25
  Rails.logger.warn ">>"
26
- post = topics(:older).posts.create!(:body => 'newly added', :reader => readers(:idle))
26
+ @post = topics(:older).posts.create!(:body => 'and its my post about new marmalade', :reader => readers(:normal))
27
27
  end
28
28
 
29
+ it "should update its indexable form" do
30
+ @post.search_text.should == "older post new marmalade"
31
+ end
32
+
29
33
  it "should update topic reply data" do
30
34
  topic = Topic.find(topic_id(:older))
31
- topic.replied_by.should == readers(:idle)
35
+ topic.replied_by.should == readers(:normal)
32
36
  topic.replied_at.should be_close(Time.now, 10.seconds)
33
37
  end
34
38
  end
@@ -45,7 +49,7 @@ describe Post do
45
49
  end
46
50
 
47
51
  it "should not be editable by anyone else" do
48
- @post.editable_by?(readers(:idle)).should be_false
52
+ @post.editable_by?(readers(:another)).should be_false
49
53
  end
50
54
  end
51
55
 
@@ -60,14 +64,14 @@ describe Post do
60
64
  end
61
65
 
62
66
  it "should not be editable by anyone else" do
63
- @post.editable_by?(readers(:idle)).should be_false
67
+ @post.editable_by?(readers(:another)).should be_false
64
68
  end
65
69
  end
66
70
 
67
71
  describe "on removal" do
68
72
  before do
69
73
  @last = topics(:older).posts.last
70
- @post = topics(:older).posts.create!(:body => 'uh oh', :reader => readers(:idle))
74
+ @post = topics(:older).posts.create!(:body => 'uh oh', :reader => readers(:normal))
71
75
  end
72
76
  it "should revert topic reply data" do
73
77
  @post.destroy
@@ -84,7 +88,7 @@ describe Post do
84
88
  55.times do |i|
85
89
  topics(:older).posts.create!(:body => 'rhubarb', :reader => readers(:normal))
86
90
  end
87
- lastpost = topics(:older).posts.create!(:body => 'bar', :reader => readers(:idle))
91
+ lastpost = topics(:older).posts.create!(:body => 'bar', :reader => readers(:normal))
88
92
  firstpost.page_when_paginated.should == 1
89
93
  lastpost.page_when_paginated.should == 3
90
94
  end
@@ -4,30 +4,29 @@ describe Topic do
4
4
  dataset :forums
5
5
 
6
6
  describe "on creation" do
7
- before do
8
- @post = Post.create!(
7
+ let(:topic) {
8
+ Post.create!(
9
9
  :body => "first post body",
10
10
  :reader_id => reader_id(:normal),
11
11
  :topic_attributes => {
12
12
  :name => 'testing',
13
13
  :forum_id => forum_id(:public)
14
14
  }
15
- )
16
- @topic = @post.topic
17
- end
18
-
15
+ ).topic
16
+
17
+ }
19
18
  it "should set default values" do
20
- @topic.sticky?.should be_false
21
- @topic.locked?.should be_false
22
- @topic.replied_by.should == readers(:normal)
23
- @topic.replied_at.should be_close(Time.now, 1.minute)
19
+ topic.sticky?.should be_false
20
+ topic.locked?.should be_false
21
+ topic.replied_by.should == readers(:normal)
22
+ topic.replied_at.should be_close(Time.now, 1.minute)
24
23
  end
25
24
 
26
25
  [:name].each do |field|
27
26
  it "should require a #{field}" do
28
- @topic.send("#{field}=".intern, nil)
29
- @topic.should_not be_valid
30
- @topic.errors.on(field).should_not be_empty
27
+ topic.send("#{field}=".intern, nil)
28
+ topic.should_not be_valid
29
+ topic.errors.on(field).should_not be_empty
31
30
  end
32
31
  end
33
32
 
@@ -37,11 +36,11 @@ describe Topic do
37
36
  end
38
37
 
39
38
  it "should be visible to a reader" do
40
- @topic.visible_to?(@reader).should be_true
39
+ topic.visible_to?(@reader).should be_true
41
40
  end
42
41
 
43
42
  it "should be visible when there is no reader" do
44
- @topic.visible_to?(nil).should be_true
43
+ topic.visible_to?(nil).should be_true
45
44
  end
46
45
  end
47
46
 
@@ -51,11 +50,21 @@ describe Topic do
51
50
  end
52
51
 
53
52
  it "should be visible to a reader" do
54
- @topic.visible_to?(readers(:idle)).should be_true
53
+ topic.visible_to?(readers(:normal)).should be_true
55
54
  end
56
55
 
57
56
  it "should not be visible when there is no reader" do
58
- @topic.visible_to?(nil).should be_false
57
+ topic.visible_to?(nil).should be_false
58
+ end
59
+ end
60
+
61
+ describe "in a grouped forum" do
62
+ it "should be visible to a group member" do
63
+ topics(:grouped).visible_to?(readers(:another)).should be_true
64
+ end
65
+
66
+ it "should not be visible to a non group member" do
67
+ topics(:grouped).visible_to?(readers(:normal)).should be_false
59
68
  end
60
69
  end
61
70
  end
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,7 @@ Radiant::Config['site.title'] = 'Test Site'
20
20
  Radiant::Config['site.url'] = 'www.example.com'
21
21
  Radiant::Config['readers.layout'] = 'Main'
22
22
  Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
23
+ Dataset::Resolver.default << (ReaderExtension.root + "/spec/datasets")
23
24
 
24
25
  if File.directory?(File.dirname(__FILE__) + "/matchers")
25
26
  Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }