public
Description: The easy to use rails wiki
Homepage: http://signalwiki.com
Clone URL: git://github.com/queso/signal-wiki.git
Search Repo:
Adding the patches from ENTP.  Also fixed some bad page locking logic and 
tests.
queso (author)
Wed Apr 16 23:51:16 -0700 2008
commit  97e1874d38dc94079b9205b3cba0b341b3085fc5
tree    2acd64707634af291fae9a4b9e198c65760ec840
parent  ef22344ab94f249f9318c5e5bf5d93e436364d38
...
15
16
17
 
 
 
 
18
...
15
16
17
18
19
20
21
22
0
@@ -15,5 +15,9 @@
0
     @site ||= Site.find(:first)
0
   end
0
   
0
+ def require_admin
0
+ redirect_to(page_path('home')) unless logged_in? && current_user.admin?
0
+ end
0
+
0
 end
...
5
6
7
8
 
9
10
11
...
13
14
15
16
 
17
18
19
...
5
6
7
 
8
9
10
11
...
13
14
15
 
16
17
18
19
0
@@ -5,7 +5,7 @@
0
   before_filter :admin_required, :only => :index
0
 protected
0
   def admin_required
0
- raise AccessDenied unless current_user.admin?
0
+ redirect_to new_session_path unless current_user.admin?
0
   end
0
 
0
 public
0
@@ -13,7 +13,7 @@
0
   # collection methods
0
 
0
   def create
0
- flag = current_user.flags.create! params[:flag]
0
+ flag = current_user.flags.create!(params[:flag])
0
     flash[:notice] = if flag.new_record?
0
       "You already flagged this content!"
0
     else # success
...
1
2
 
 
3
4
5
...
1
 
2
3
4
5
6
0
@@ -1,5 +1,6 @@
0
 class PagesController < ApplicationController
0
- before_filter :require_login, :except => [:index, :show, :revision]
0
+ before_filter :require_login, :except => [:index, :show, :revision, :search]
0
+ before_filter :require_admin, :only => [:lock]
0
   before_filter :check_private, :only => [:show, :revision]
0
   caches_page :show
0
   cache_sweeper :page_sweeper, :only => [:create, :update]
...
2
3
4
5
6
 
 
7
8
9
10
11
...
20
21
22
 
 
 
 
23
24
 
25
26
 
27
28
29
...
2
3
4
 
 
5
6
7
8
9
10
11
...
20
21
22
23
24
25
26
27
 
28
29
 
30
31
32
33
0
@@ -2,8 +2,8 @@
0
   
0
   def wikified_body(body)
0
     r = RedCloth.new(body)
0
- r.gsub!(/\[\[(.*)(\|(.*))?\]\]/) {wiki_link(*$1.split("|")[0..1])}
0
- r.to_html
0
+ r.gsub!(/\[\[(.*?)(\|(.*?))?\]\]/) { wiki_link($1, $3) }
0
+ sanitize r.to_html
0
   end
0
   
0
   def wiki_link(wiki_words, link_text = nil)
0
0
0
@@ -20,10 +20,14 @@
0
   end
0
   
0
   def body_input(f)
0
+ text_input(f, 'body')
0
+ end
0
+
0
+ def text_input(f, attr)
0
     if site.disable_teh
0
- f.text_area :body
0
+ f.text_area attr.to_sym
0
     else
0
- textile_editor 'page', 'body'
0
+ textile_editor 'page', attr
0
     end
0
   end
0
   
...
89
90
91
92
 
 
 
 
 
93
94
95
...
89
90
91
 
92
93
94
95
96
97
98
99
0
@@ -89,7 +89,11 @@
0
   end
0
   
0
   def locked?
0
- locked_at.nil? or locked_at > Time.now
0
+ if locked_at.nil?
0
+ return false
0
+ else
0
+ locked_at < Time.now
0
+ end
0
   end
0
   
0
   def unlock
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@
0
   <tbody>
0
     <% @flags.each do |flag| %>
0
     <tr class="<%= cycle('alternate','') %>">
0
- <td><%=h flag.created_at.to_s :short %></td>
0
+ <td><%=h flag.created_at.to_s(:short) %></td>
0
       <td><%=h flag.user.login %> (<%=h flag.user.flags.size %>)</td>
0
       <td><%= link_to h('%s %i' % [flag.flaggable_type, flag.flaggable_id]), flag.flaggable %></td>
0
       <td><%= flag.owner ? (link_to h(flag.owner.login), flag.owner) : "Anonymous" %></td>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
 
0
   <p>
0
     <label for="body">Body</label><br />
0
- <%= body_input(f) %>
0
+ <%= body_input(f) %>
0
   </p>
0
 
0
   <p>
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@
0
 <ul class="meta_info">
0
   <li><%= link_to('View previous revision', revision_page_url(:id => @page.permalink, :version => (@page.previous.version))) if @page.previous %></li>
0
   <li><%= link_to('View next revision', revision_page_url(:id => @page.permalink, :version => (@page.next.version))) if @page.next %></li>
0
- <li><%= link_to "Rollback to this revision", rollback_page_url(:id => @page.permalink, :version => (@page.version)) unless current_revision(@page.page_id, @page.version) || (Page.find(@page.page_id).locked? && !current_user.admin?) %></li>
0
+ <li><%= link_to "Rollback to this revision", rollback_page_url(:id => @page.permalink, :version => (@page.version)) unless current_revision(@page.page_id, @page.version) || (Page.find(@page.page_id).locked? && (logged_in? && !current_user.admin?)) %></li>
0
   <%# FIXME Clean up this revision link logic %>
0
   <li><%= link_to 'Return to current revision', wiki_page_url(@page.permalink) %></li>
0
 </ul>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
0
@@ -1 +1,75 @@
0
+require File.dirname(__FILE__) + "/../spec_helper"
0
+
0
+describe FlagsController, "a user not logged in" do
0
+ fixtures :sites, :users, :pages
0
+ integrate_views
0
+
0
+ before do
0
+ controller.stub!(:logged_in?).and_return false
0
+ controller.stub!(:current_user).and_return :false
0
+ end
0
+
0
+ it "does not render 'index'" do
0
+ get :index
0
+ response.should redirect_to('session/new')
0
+ end
0
+
0
+ it 'can not flag something' do
0
+ post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated' }
0
+ response.should redirect_to('session/new')
0
+ end
0
+end
0
+
0
+describe FlagsController, "a user logged in as normal user" do
0
+ fixtures :sites, :pages, :page_versions, :users
0
+ integrate_views
0
+
0
+ before do
0
+ # Mocking this was a bitch.
0
+ @user = users(:jeremy)
0
+
0
+ controller.stub!(:require_login)
0
+ controller.stub!(:logged_in?).and_return true
0
+ controller.stub!(:current_user).and_return @user
0
+ end
0
+
0
+ it "does not render 'index'" do
0
+ get :index
0
+ response.should redirect_to('session/new')
0
+ end
0
+
0
+ it 'can flag something' do
0
+ lambda {
0
+ post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id }
0
+ response.should redirect_to('pages/hai')
0
+ }.should change(Flag, :count).by(1)
0
+ end
0
+end
0
+
0
+
0
+describe FlagsController, "a user logged in as admin" do
0
+ fixtures :sites, :pages, :page_versions, :users
0
+ integrate_views
0
+
0
+ before do
0
+ @user = users(:admin)
0
+ controller.stub!(:require_login)
0
+ controller.stub!(:logged_in?).and_return true
0
+ controller.stub!(:current_user).and_return @user
0
+ end
0
+
0
+ it "renders 'index'" do
0
+ get :index
0
+ response.should be_success
0
+ response.should render_template("index")
0
+ end
0
+
0
+ it 'can flag something' do
0
+ lambda {
0
+ post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id }
0
+ response.should redirect_to('pages/hai')
0
+ }.should change(Flag, :count).by(1)
0
+ end
0
+
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
0
@@ -1 +1,260 @@
0
+require File.dirname(__FILE__) + "/../spec_helper"
0
+
0
+def create_page
0
+ Page.create(:title => "hee haw", :body => "moop", :site_id => 1)
0
+end
0
+
0
+describe PagesController, " with site that requires login, a user not logged in" do
0
+ fixtures :sites, :pages, :page_versions, :users
0
+ integrate_views
0
+ before do
0
+ controller.stub!(:logged_in?).and_return false
0
+ controller.stub!(:current_user).and_return :false
0
+ end
0
+
0
+ it "does not render 'new'" do
0
+ get :new
0
+ response.should redirect_to('session/new')
0
+ end
0
+
0
+ it "renders 'revision'" do
0
+ page = create_page
0
+ page.body = "MEEP"
0
+ page.save!
0
+
0
+ get :revision, :id => page.permalink, :version => page.version - 1
0
+ response.should be_success
0
+ response.should render_template("revision")
0
+ end
0
+
0
+ it "searches for pages" do
0
+ get :search, :query => "home"
0
+ response.should be_success
0
+ end
0
+
0
+ it "can not lock a page" do
0
+ get :lock, :id => 'hai'
0
+ response.should redirect_to('session/new')
0
+ end
0
+
0
+ it "can not rollback a page" do
0
+ page = create_page
0
+ page.body = "MEEP"
0
+ page.save!
0
+ current_version = page.version
0
+
0
+ get :rollback, :id => page.permalink, :version => 1
0
+ response.should redirect_to('session/new')
0
+
0
+ page = page.reload
0
+ page.version.should be == current_version
0
+ end
0
+
0
+ it "can not edit a page" do
0
+ page = create_page
0
+
0
+ lambda do
0
+ post :update, :id => page.permalink, :page => {:body => "hehehe"}
0
+ response.should redirect_to('session/new')
0
+ end.should_not change(page, :body)
0
+ end
0
+
0
+ it "can not create a page" do
0
+ lambda do
0
+ post :create, :page => { :site_id => 1, :title => "o hai", :body => "meeg000!!" }
0
+ response.should redirect_to('session/new')
0
+ end.should_not change(Page, :count)
0
+ end
0
+end
0
+
0
+describe PagesController, " with site that does not require login, a user not logged in" do
0
+ fixtures :sites, :pages, :page_versions, :users
0
+ integrate_views
0
+ before do
0
+ site = Site.find(:first)
0
+ site.require_login_to_post = false
0
+ site.save!
0
+
0
+ controller.stub!(:logged_in?).and_return false
0
+ controller.stub!(:current_user).and_return :false
0
+ end
0
+
0
+ it "renders 'new'" do
0
+ get :new
0
+ response.should be_success
0
+ end
0
+
0
+ it "can rollback a page" do
0
+ page = create_page
0
+ page.body = "MEEP"
0
+ page.save!
0
+ current_version = page.version
0
+
0
+ get :rollback, :id => page.permalink, :version => 1
0
+ response.should redirect_to(page.permalink)
0
+
0
+ page = page.reload
0
+ page.version.should be < current_version
0
+ end
0
+
0
+ it "can edit a page" do
0
+ page = create_page
0
+
0
+ lambda do
0
+ post :update, :id => page.permalink, :page => {:body => "hehehe"}
0
+ response.should redirect_to(page.permalink)
0
+ page.reload
0
+ end.should change(page, :body)
0
+ end
0
+
0
+ it "can create a page" do
0
+ lambda do
0
+ post :create, :page => { :site_id => 1, :title => "o hai", :body => "meeg000!!" }
0
+ response.should redirect_to('o-hai')
0
+ end.should change(Page, :count)
0
+ end
0
+end
0
+
0
+describe PagesController, "a user logged in as normal user" do
0
+ fixtures :sites, :pages, :page_versions, :users
0
+ integrate_views
0
+
0
+ before do
0
+ controller.stub!(:require_login)
0
+ controller.stub!(:logged_in?).and_return true
0
+ controller.stub!(:current_user).and_return users(:jeremy)
0
+ end
0
+
0
+
0
+ it "renders 'new'" do
0
+ get :new
0
+ response.should be_success
0
+ response.should render_template("new")
0
+ end
0
+
0
+ it "renders 'revision'" do
0
+ page = create_page
0
+ page.body = "MEEP"
0
+ page.save!
0
+
0
+ get :revision, :id => page.permalink, :version => page.version - 1
0
+ response.should be_success
0
+ response.should render_template("revision")
0
+ end
0
+
0
+ it "searches for pages" do
0
+ get :search, :query => "home"
0
+ response.should be_success
0
+ end
0
+
0
+ it "can edit a page" do
0
+ page = create_page
0
+
0
+ lambda do
0
+ post :update, :id => page.permalink, :page => {:body => "hehehe"}
0
+ response.should redirect_to(page.permalink)
0
+ page = page.reload
0
+ end.should change(page, :body)
0
+ end
0
+
0
+ it "can create a page" do
0
+ lambda do
0
+ post :create, :page => { :site_id => 1, :title => "o hai", :body => "meeg000!!" }
0
+ response.should redirect_to('o-hai')
0
+ end.should change(Page, :count)
0
+ end
0
+
0
+ it "can rollback a page" do
0
+ page = Page.create(:title => "hee haw", :body => "moop", :site_id => 1)
0
+ page.body = "MEEP"
0
+ page.save!
0
+ current_version = page.version
0
+
0
+ get :rollback, :id => page.permalink, :version => 1
0
+ response.should redirect_to(page.permalink)
0
+
0
+ page = page.reload
0
+ page.version.should be < current_version
0
+ end
0
+
0
+ it "can not lock a page" do
0
+ get :lock, :id => 'hai'
0
+ response.should redirect_to('pages/home')
0
+ end
0
+end
0
+
0
+describe PagesController, "a user logged in as admin" do
0
+ fixtures :sites, :pages, :page_versions, :users
0
+ integrate_views
0
+ before do
0
+ controller.stub!(:require_login)
0
+ controller.stub!(:logged_in?).and_return true
0
+ controller.stub!(:current_user).and_return users(:admin)
0
+ end
0
+
0
+ it "renders 'new'" do
0
+ get :new
0
+ response.should be_success
0
+ response.should render_template("new")
0
+ end
0
+
0
+ it "renders 'revision'" do
0
+ page = create_page
0
+ page.body = "MEEP"
0
+ page.save!
0
+
0
+ get :revision, :id => page.permalink, :version => page.version - 1
0
+ response.should be_success
0
+ response.should render_template("revision")
0
+ end
0
+
0
+ it "searches for pages" do
0
+ get :search, :query => "home"
0
+ response.should be_success
0
+ end
0
+
0
+ it "can edit a page" do
0
+ page = create_page
0
+
0
+ lambda do
0
+ post :update, :id => page.permalink, :page => {:body => "hehehe"}
0
+ response.should redirect_to(page.permalink)
0
+ page = page.reload
0
+ end.should change(page, :body)
0
+ end
0
+
0
+ it "can create a page" do
0
+ lambda do
0
+ post :create, :page => { :site_id => 1, :title => "o hai", :body => "meeg000!!" }
0
+ response.should redirect_to('o-hai')
0
+ end.should change(Page, :count)
0
+ end
0
+
0
+ it "can rollback a page" do
0
+ page = Page.create(:title => "hee haw", :body => "moop", :site_id => 1)
0
+ page.body = "MEEP"
0
+ page.save!
0
+ current_version = page.version
0
+
0
+ get :rollback, :id => page.permalink, :version => 1
0
+ response.should redirect_to(page.permalink)
0
+
0
+ page = page.reload
0
+ page.version.should be < current_version
0
+ end
0
+
0
+ it "can lock a page" do
0
+ get :lock, :id => 'hai'
0
+ response.should redirect_to('hai')
0
+ end
0
+
0
+ it "can unlock a page" do
0
+ page = create_page
0
+ page.lock
0
+
0
+ get :lock, :id => page.permalink
0
+ page.reload
0
+ page.should_not be_locked
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
0
@@ -1 +1,10 @@
0
+one_old:
0
+ id: 1
0
+ title: hai
0
+ permalink: hai
0
+ body: there, i fixed ur ram
0
+ site_id: 1
0
+ version: 1
0
+ created_at: <%= 1.day.ago.to_s :db %>
0
+ page_id: <%= Fixtures.identify :one %>
...
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
0
@@ -1 +1,9 @@
0
+one:
0
+ id: 1
0
+ title: hai
0
+ permalink: hai
0
+ body: there
0
+ site_id: 1
0
+ version: 1
0
+ locked_at:
...
2
3
4
 
5
6
...
2
3
4
5
6
7
0
@@ -2,6 +2,7 @@
0
 first:
0
   id: 1
0
   title: RoR
0
+ require_login_to_post: 1
0
   created_at: 2008-03-15 10:28:00
0
   updated_at: 2008-03-15 10:28:00
...
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1 +1,12 @@
0
+jeremy:
0
+ id: 1
0
+ login: jeremy
0
+ email: hai@ohai.com
0
+ admin: 0
0
+
0
+admin:
0
+ id: 2
0
+ login: admin
0
+ email: hai@ohai.com
0
+ admin: 1
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -1 +1,18 @@
0
+require File.dirname(__FILE__) + '/../spec_helper'
0
+
0
+describe PagesHelper do
0
+
0
+ it "has the right amount of greediness on parsing wiki links" do
0
+ self.stub!(:wiki_link).and_return "MONKEYS"
0
+ wikified_body("hello[[there]]whats[[up]]").should == "<p>helloMONKEYSwhatsMONKEYS</p>"
0
+ wikified_body("hello[[there|hai]]whats[[up|doc]]").should == "<p>helloMONKEYSwhatsMONKEYS</p>"
0
+ end
0
+
0
+ it "parses wiki links" do
0
+ self.should_receive(:wiki_link).with("up", nil).and_return("MONKEYS")
0
+ self.should_receive(:wiki_link).with("there", "hai").and_return("MONKEYS")
0
+ wikified_body("hello[[there|hai]]whats[[up]]").should == "<p>helloMONKEYSwhatsMONKEYS</p>"
0
+ end
0
+
0
+end
...
46
47
48
49
 
50
51
52
 
53
54
55
56
57
58
59
 
 
 
 
 
 
 
 
60
61
62
...
46
47
48
 
49
50
51
 
52
53
54
55
56
57
58
 
59
60
61
62
63
64
65
66
67
68
69
0
@@ -46,17 +46,24 @@
0
   fixtures :sites
0
   
0
   before do
0
- @page1 = Page.create! :title => "outbound", :permalink => "outbound", :body => "empty", :site_id => 1
0
+ @page1 = Page.create! :title => "outbound", :permalink => "outbound", :body => "empty", :site_id => sites(:first).id
0
   end
0
   
0
- it "edit a locked page" do
0
+ it "edits a locked page" do
0
     @page1.lock
0
     @page1.body = "Blah blah"
0
     @page1.save
0
     @page1.should_not be_valid
0
   end
0
   
0
- it "edit a previous locked but now unlocked page" do
0
+ it "sets locked correctly" do
0
+ @page1.lock
0
+ @page1.should be_locked
0
+ @page1.unlock
0
+ @page1.should_not be_locked
0
+ end
0
+
0
+ it "edits a previous locked but now unlocked page" do
0
     @page1.lock
0
     @page1.unlock
0
     @page1.body = "Blah blah"

Comments

    No one has commented yet.