public
Description: The easy to use rails wiki
Homepage: http://signalwiki.com
Clone URL: git://github.com/queso/signal-wiki.git
improve rspec coverage, and fixed several minor bugs
Ping Yu (author)
Sat Apr 19 15:08:12 -0700 2008
queso (committer)
Sun Apr 20 20:13:15 -0700 2008
commit  46d4cabb2f4308f3a0a596a974ea379de13d10c1
tree    645877510119deea3520e83d430be5d5b6b5b043
parent  780fd0bb35138e2b9de47f37e8db0cd0b5b9a8e8
...
11
12
13
 
 
...
11
12
13
14
15
0
@@ -11,3 +11,5 @@ db/*.sqlite3
0
 index/*
0
 public/javascripts/signal.js
0
 public/stylesheets/signal.css
0
+.project
0
+.loadpath
...
13
14
15
16
 
17
18
19
...
13
14
15
 
16
17
18
19
0
@@ -13,7 +13,7 @@ public
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
...
91
92
93
94
 
95
96
97
...
1
2
3
4
5
6
...
92
93
94
 
95
96
97
98
0
@@ -1,5 +1,6 @@
0
 class PagesController < ApplicationController
0
   before_filter :require_login, :except => [:index, :show, :revision, :search]
0
+  before_filter :login_required, :only => [:destroy]
0
   before_filter :require_admin, :only => [:lock]
0
   before_filter :check_private, :only => [:show, :revision]
0
   caches_page :show
0
@@ -91,7 +92,7 @@ class PagesController < ApplicationController
0
         format.html { redirect_to(wiki_page_url(@page)) }
0
         format.xml  { render :xml => @page, :status => :created, :location => @page }
0
       else
0
-        format.html { render :action => "new" }
0
+        format.html { puts @page.errors.inspect; render :action => "new" }
0
         format.xml  { render :xml => @page.errors, :status => :unprocessable_entity }
0
       end
0
     end
...
17
18
19
20
 
 
21
22
23
...
17
18
19
 
20
21
22
23
24
0
@@ -17,7 +17,8 @@ module PagesHelper
0
   end
0
   
0
   def current_revision(id, version)
0
-    version == Page.find(id).version
0
+    page = Page.find(id)
0
+    page ? (version == page.version) : false
0
   end
0
   
0
   def body_input(f)
...
43
44
45
46
47
 
 
48
49
50
...
104
105
106
 
 
 
107
108
109
...
43
44
45
 
 
46
47
48
49
50
...
104
105
106
107
108
109
110
111
112
0
@@ -43,8 +43,8 @@ class Page < ActiveRecord::Base
0
   
0
   def is_spam?(site)
0
     v = Viking.connect("akismet", {:api_key => site.akismet_key, :blog => site.akismet_url})
0
-    response = v.check_comment(:comment_content => body.to_s, :comment_author => user.login.to_s, :user_ip => ip.to_s, :user_agent => agent.to_s, :referrer => referrer.to_s)
0
-    logger.info "Calling Akismet for page #{permalink} by #{user.login.to_s} using ip #{ip}:  #{response[:spam]}"
0
+    response = v.check_comment(:comment_content => body.to_s, :comment_author => username.to_s, :user_ip => ip.to_s, :user_agent => agent.to_s, :referrer => referrer.to_s)
0
+    logger.info "Calling Akismet for page #{permalink} by #{username.to_s} using ip #{ip}:  #{response[:spam]}"
0
     return response[:spam]
0
   end
0
   
0
@@ -104,6 +104,9 @@ class Page < ActiveRecord::Base
0
     RAILS_DEFAULT_LOGGER.info "UNLOCKED #{self.permalink}"
0
   end
0
   
0
+  def username
0
+    user.blank? ? "anonymous" : user.login
0
+  end
0
   def self.find_all_by_wiki_word(wiki_word, site = nil)
0
     site ||= Site.find(:first)
0
     pages = site.pages.find(:all)
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 Comparing 
0
-<span style="background-color: #cfc; padding: 1px 4px;">version <%= @v2.version %></span> 
0
+<span style="background-color: #cfc; padding: 1px 4px;">version <%= @v1.version %></span> 
0
 and
0
 <span style="background-color: #ddd; padding: 1px 4px;">version <%= @v2.version %></span>
0
 <pre class="diff">
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@
0
       updated <%= time_ago_in_words(rev.updated_at) %> ago 
0
       by <%= author(rev.user_id)  %>
0
       <% if rev.respond_to?(:previous) && !rev.previous.nil? %>
0
-      <%= link_to "(Diff)", diff_page_url(@page.permalink, :v1 => rev.version, :v2 => rev.previous) %>
0
+      <%= link_to "(Diff)", diff_page_url(@page.permalink, :v1 => rev.version, :v2 => rev.previous.version) %>
0
       <% end %>
0
   </li>
0
 <% end %>
...
9
10
11
12
13
 
 
 
 
 
 
 
 
 
14
15
16
17
18
 
 
 
19
20
21
...
38
39
40
41
 
42
43
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
48
49
...
71
72
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
75
...
9
10
11
 
 
12
13
14
15
16
17
18
19
20
21
22
23
 
 
24
25
26
27
28
29
...
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
...
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
0
@@ -9,13 +9,21 @@ describe FlagsController, "a user not logged in" do
0
     controller.stub!(:current_user).and_return :false
0
   end
0
   
0
-  it "does not render 'index'" do
0
-    get :index
0
+  %w[index new].each do |action|
0
+     it "#{action} should redirect to login" do
0
+       get action
0
+       response.should redirect_to('session/new')
0
+     end
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
   
0
-  it 'can not flag something' do
0
-    post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated' }
0
+  it 'can not delete' do
0
+    delete :destroy, :id => "1"
0
+    response.should_not be_success
0
     response.should redirect_to('session/new')
0
   end
0
 end
0
@@ -38,12 +46,40 @@ describe FlagsController, "a user logged in as normal user" do
0
     response.should redirect_to('session/new')
0
   end
0
   
0
-  it 'can flag something' do
0
+  it 'canflag 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
+  it 'can not flag same page twice' do
0
+    post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id }
0
+    lambda {
0
+      post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id }
0
+      #flash[:notice].should == "You already flagged this content!"
0
+    }.should_not change(Flag, :count)
0
+  end
0
+  
0
+  it "render 'new'" do
0
+    get :new, :flaggable_type => 'Page', :flaggable_id => 1
0
+    response.should be_success
0
+    response.should render_template('new')
0
+  end
0
+  
0
+  it "render / with error if flaggable_type is not found" do
0
+    get :new, :flaggable_type => 'NotFound', :flaggable_id => 1
0
+    response.should_not be_success
0
+    response.should redirect_to('/')
0
+    #flash[:error].should_not be_empty
0
+  end
0
+
0
+  it "can delete a page" do
0
+    flag = @user.flags.create({ :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id })
0
+    lambda do
0
+      delete :destroy, :id => flag
0
+      response.should redirect_to('flags')
0
+    end.should change(Flag, :count)
0
+  end
0
 end
0
 
0
 
0
@@ -71,5 +107,31 @@ describe FlagsController, "a user logged in as admin" do
0
     }.should change(Flag, :count).by(1)
0
   end
0
   
0
+  it "render 'new'" do
0
+    get :new, :flaggable_type => 'Page', :flaggable_id => 1
0
+    response.should be_success
0
+    response.should render_template("new")
0
+  end
0
+  it 'can not flag same page twice' do
0
+    post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id }
0
+    lambda {
0
+      post :create, :flag => { :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id }
0
+      #flash[:notice].should == "You already flagged this content!"
0
+    }.should_not change(Flag, :count)
0
+  end
0
+  it "render / with error if flaggable_type is not found" do
0
+    get :new, :flaggable_type => 'NotFound', :flaggable_id => 1
0
+    response.should_not be_success
0
+    response.should redirect_to('/')
0
+    #flash[:error].should_not be_empty
0
+  end
0
+  it "can delete a page" do
0
+    flag = @user.flags.create({ :flaggable_type => 'Page', :flaggable_id => 1, :reason => 'outdated', :user_id => @user.id })
0
+    lambda do
0
+      delete :destroy, :id => flag
0
+      response.should redirect_to('flags')
0
+    end.should change(Flag, :count)
0
+  end
0
+  
0
 end
0
 
...
3
4
5
6
 
 
 
7
8
9
...
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
16
17
18
19
20
 
21
22
23
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
26
27
...
65
66
67
 
 
 
 
 
 
 
 
 
68
69
70
...
79
80
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
83
84
85
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
88
89
...
113
114
115
 
 
 
 
 
 
 
 
 
 
116
117
118
...
125
126
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
 
 
 
 
129
130
131
132
133
 
 
 
 
 
 
 
 
134
135
136
...
141
142
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
145
146
...
181
182
183
 
 
 
 
 
 
 
 
 
184
185
186
...
191
192
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
 
 
 
 
195
196
197
198
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
201
202
...
208
209
210
 
 
 
 
 
 
 
 
 
 
 
211
212
213
...
256
257
258
 
 
 
 
 
 
 
 
 
259
260
...
3
4
5
 
6
7
8
9
10
11
...
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
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
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
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
...
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
...
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
...
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
0
@@ -3,7 +3,9 @@ require File.dirname(__FILE__) + "/../spec_helper"
0
 def create_page
0
   Page.create(:title => "hee haw", :body => "moop", :site_id => 1)
0
 end
0
-
0
+def create_delete_page
0
+  Page.create(:title => "to be delete", :body => "moop", :site_id => 1)
0
+end
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
@@ -12,16 +14,68 @@ describe PagesController, " with site that requires login, a user not logged in"
0
     controller.stub!(:current_user).and_return :false
0
   end
0
   
0
+  it "show all pages" do
0
+    get :index
0
+    response.should be_success
0
+    response.should render_template("index")
0
+  end
0
+    
0
+  it "shows page if it exists" do
0
+    page = create_page
0
+    page.body = "MEEP"
0
+    page.save!
0
+
0
+    get :show, :id => page.permalink
0
+    response.should be_success
0
+    response.should render_template("show")      
0
+  end
0
+  
0
+  it "redirect to session/new if page is a private page" do
0
+    page = create_page
0
+    page.private_page = true
0
+    page.save!
0
+
0
+    get :show, :id => page.permalink
0
+    response.should_not be_success
0
+    response.should redirect_to("session/new")      
0
+    
0
+  end
0
+  it "redirect to page/new (and it will in turn redirect to session/new) if showing a page that does not exist" do
0
+    get :show, :id => "unavailable"
0
+    response.should redirect_to("pages/new")      
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
+  it "does not render 'diff'" do
0
     page = create_page
0
     page.body = "MEEP"
0
     page.save!
0
 
0
+    get :diff, :id => page.permalink, :v1 => page.version, :v2 => page.version - 1
0
+    response.should redirect_to('session/new')
0
+  end
0
+  
0
+  it "does not render 'revisions'" do
0
+    page = create_page
0
+    get :revisions, :id => page.permalink
0
+    response.should redirect_to('session/new')
0
+  end
0
+
0
+  it "does not render 'edit'" do
0
+    page = create_page
0
+    get :edit, :id => page.permalink
0
+    response.should redirect_to('session/new')
0
+  end
0
+
0
+  it "renders 'revision'" do
0
+    page = create_page
0
+    page.body = "moep MEEPp"
0
+    page.save!
0
+
0
     get :revision, :id => page.permalink, :version => page.version - 1
0
     response.should be_success
0
     response.should render_template("show")    
0
@@ -65,6 +119,15 @@ describe PagesController, " with site that requires login, a user not logged in"
0
       response.should redirect_to('session/new')
0
     end.should_not change(Page, :count)
0
   end
0
+   it "can not delete a page" do
0
+    page = create_delete_page
0
+    
0
+    lambda do
0
+    delete :destroy, :id => page.permalink
0
+    response.should_not be_success
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
@@ -79,11 +142,60 @@ describe PagesController, " with site that does not require login, a user not lo
0
     controller.stub!(:current_user).and_return :false
0
   end
0
   
0
+  it "show all pages" do
0
+    get :index
0
+    response.should be_success
0
+    response.should render_template("index")
0
+  end
0
+    
0
+  it "shows page if it exists" do
0
+    page = create_page
0
+    page.body = "MEEP"
0
+    page.save!
0
+
0
+    get :show, :id => page.permalink
0
+    response.should be_success
0
+    response.should render_template("show")      
0
+  end
0
+  
0
+  it "shows new page if it does not exist" do
0
+    get :show, :id => "unavailable"
0
+    response.should redirect_to("pages/new")      
0
+  end
0
+  
0
   it "renders 'new'" do
0
     get :new
0
     response.should be_success
0
   end
0
   
0
+  it "shows 'diff'" do
0
+    page = create_page
0
+    page.body = "MEEP"
0
+    page.save!
0
+
0
+    get :diff, :id => page.permalink, :v1 => page.version, :v2 => page.version - 1
0
+    assigns(:v1).should == page.versions.find_by_version(params[:v1])
0
+    assigns(:v2).should == page.versions.find_by_version(params[:v2])
0
+    response.should be_success
0
+    response.should render_template("diff")
0
+  end
0
+  
0
+  it "shows 'revisions'" do
0
+    page = create_page
0
+    get :revisions, :id => page.permalink
0
+    assigns(:revisions).should == page.versions
0
+    response.should be_success
0
+    response.should render_template("revisions")   
0
+  end
0
+  
0
+  it "shows 'edit'" do
0
+    page = create_page
0
+    get :edit, :id => page.permalink
0
+    assigns(:page).should == page
0
+    response.should be_success
0
+    response.should render_template("edit")   
0
+  end
0
+
0
   it "can rollback a page" do
0
     page = create_page
0
     page.body = "MEEP"
0
@@ -113,6 +225,16 @@ describe PagesController, " with site that does not require login, a user not lo
0
       response.should redirect_to('o-hai')
0
     end.should change(Page, :count)
0
   end
0
+  
0
+  it "cannot delete a page" do
0
+    page = create_delete_page
0
+    lambda do
0
+      delete :destroy, :id => page.permalink
0
+      response.should_not be_success
0
+      response.should redirect_to('session/new')
0
+    end.should_not change(Page, :count)
0
+  end
0
+
0
 end
0
 
0
 describe PagesController, "a user logged in as normal user" do
0
@@ -125,12 +247,40 @@ describe PagesController, "a user logged in as normal user" do
0
     controller.stub!(:current_user).and_return users(:jeremy)
0
   end
0
   
0
+  it "show all pages" do
0
+    get :index
0
+    response.should be_success
0
+    response.should render_template("index")
0
+  end
0
+    
0
+  it "shows page if it exists" do
0
+    page = create_page
0
+    page.body = "MEEP"
0
+    page.save!
0
+
0
+    get :show, :id => page.permalink
0
+    response.should be_success
0
+    response.should render_template("show")      
0
+  end
0
   
0
+  it "shows new page if it does not exist" do
0
+    get :show, :id => "unavailable"
0
+    response.should redirect_to("pages/new")      
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 "shows 'revisions'" do
0
+    page = create_page
0
+    get :revisions, :id => page.permalink
0
+    assigns(:revisions).should == page.versions
0
+    response.should be_success
0
+    response.should render_template("revisions")   
0
+  end
0
   
0
   it "renders 'revision'" do
0
     page = create_page
0
@@ -141,6 +291,25 @@ describe PagesController, "a user logged in as normal user" do
0
     response.should be_success
0
     response.should render_template("show")   
0
   end
0
+  it "shows 'edit'" do
0
+    page = create_page
0
+    get :edit, :id => page.permalink
0
+    assigns(:page).should == page
0
+    response.should be_success
0
+    response.should render_template("edit")   
0
+  end
0
+  
0
+  it "shows 'diff'" do
0
+    page = create_page
0
+    page.body = "MEEP"
0
+    page.save!
0
+
0
+    get :diff, :id => page.permalink, :v1 => page.version, :v2 => page.version - 1
0
+    assigns(:v1).should == page.versions.find_by_version(params[:v1])
0
+    assigns(:v2).should == page.versions.find_by_version(params[:v2])
0
+    response.should be_success
0
+    response.should render_template("diff")
0
+  end
0
   
0
   it "searches for pages" do
0
     get :search, :query => "home"
0
@@ -181,6 +350,15 @@ describe PagesController, "a user logged in as normal user" do
0
     get :lock, :id => 'hai'
0
     response.should redirect_to('pages/home')
0
   end
0
+  it "can delete a page" do
0
+    page = create_delete_page
0
+    page.title = "to be delete"
0
+    page.save
0
+    lambda do
0
+      delete :destroy, :id => page.permalink
0
+      response.should redirect_to('pages')
0
+    end.should change(Page, :count)
0
+  end
0
 end
0
 
0
 describe PagesController, "a user logged in as admin" do
0
@@ -191,12 +369,48 @@ describe PagesController, "a user logged in as admin" do
0
     controller.stub!(:logged_in?).and_return true
0
     controller.stub!(:current_user).and_return users(:admin)
0
   end
0
+
0
+  it "show all pages" do
0
+    get :index
0
+    response.should be_success
0
+    response.should render_template("index")
0
+  end
0
+    
0
+  it "shows page if it exists" do
0
+    page = create_page
0
+    page.body = "MEEP"
0
+    page.save!
0
+
0
+    get :show, :id => page.permalink
0
+    response.should be_success
0
+    response.should render_template("show")      
0
+  end
0
   
0
+  it "shows new page if it does not exist" do
0
+    get :show, :id => "unavailable"
0
+    response.should redirect_to("pages/new")      
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 "shows 'revisions'" do
0
+    page = create_page
0
+    get :revisions, :id => page.permalink
0
+    assigns(:revisions).should == page.versions
0
+    response.should be_success
0
+    response.should render_template("revisions")   
0
+  end
0
+  it "shows 'edit'" do
0
+    page = create_page
0
+    get :edit, :id => page.permalink
0
+    assigns(:page).should == page
0
+    response.should be_success
0
+    response.should render_template("edit")   
0
+  end
0
   
0
   it "renders 'revision'" do
0
     page = create_page
0
@@ -208,6 +422,17 @@ describe PagesController, "a user logged in as admin" do
0
     response.should render_template("show")   
0
   end
0
   
0
+  it "shows 'diff'" do
0
+    page = create_page
0
+    page.body = "MEEP"
0
+    page.save!
0
+
0
+    get :diff, :id => page.permalink, :v1 => page.version, :v2 => page.version - 1
0
+    assigns(:v1).should == page.versions.find_by_version(params[:v1])
0
+    assigns(:v2).should == page.versions.find_by_version(params[:v2])
0
+    response.should be_success
0
+    response.should render_template("diff")
0
+  end
0
   it "searches for pages" do
0
     get :search, :query => "home"
0
     response.should be_success
0
@@ -256,5 +481,14 @@ describe PagesController, "a user logged in as admin" do
0
     page.reload
0
     page.should_not be_locked
0
   end
0
+  it "can delete a page" do
0
+    page = create_delete_page
0
+    page.title = "to be delete"
0
+    page.save
0
+    lambda do
0
+      delete :destroy, :id => page.permalink
0
+      response.should redirect_to('pages')
0
+    end.should change(Page, :count)
0
+  end
0
 end
0
 
...
14
15
16
17
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
...
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
0
@@ -14,4 +14,72 @@ describe PagesHelper do
0
     wikified_body("hello[[there|hai]]whats[[up]]").should == "<p>helloMONKEYSwhatsMONKEYS</p>"
0
   end
0
   
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+describe PagesHelper do
0
+  before do
0
+    @wiki_word = "o hai"
0
+    @link_text = "test"
0
+    @perma_link = {:permalink => "o-hai"}
0
+    @class_str = "class=\"new_wiki_link\""
0
+  end
0
+    it "links to wiki permalink if page exists" do
0
+      
0
+    Page.should_receive(:exists?).with(@perma_link).and_return true
0
+    link = wiki_link(@wiki_word, @link_text)
0
+    link.should include(@link_text)
0
+    link.should_not include(@wiki_word)
0
+    link.should_not include(@class_str)
0
+    
0
+    end
0
+    it "links to wiki permalink with proper style if page doesnot exist" do
0
+      
0
+    Page.should_receive(:exists?).with(@perma_link).and_return false
0
+    link = wiki_link(@wiki_word, @link_text)
0
+    link.should include(@link_text)
0
+    link.should_not include(@wiki_word)
0
+    link.should include(@class_str)
0
+    end
0
+  end
0
+  
0
+describe PagesHelper do
0
+  before do
0
+    @site = mock_model(Site)
0
+    @form = mock_model(Object)
0
+    @attr = :body
0
+      self.should_receive(:site).and_return @site
0
+  end
0
+    it "should render textarea if site disable teh" do
0
+      @site.should_receive(:disable_teh).and_return true
0
+      @form.should_receive(:text_area)
0
+      text_input(@form, @attr)
0
+    end
0
+    it "should render tech if site enable teh" do
0
+      @site.should_receive(:disable_teh).and_return false
0
+      @form.should_not_receive(:text_area)
0
+      self.should_receive(:textile_editor)
0
+      text_input(@form, @attr)
0
+    end
0
+ end
0
+describe PagesHelper do
0
+  before do
0
+    @id = 1
0
+    @page = mock_model(Page)
0
+    @version = mock_model(Page)
0
+    @version2 = mock_model(Page)
0
+  end
0
+    it "checks existing page with same version" do
0
+      Page.should_receive(:find).with(@id).and_return @page
0
+      @page.should_receive(:version).and_return @version
0
+      current_revision(@id, @version).should == true
0
+    end
0
+    it "checks existing page with different version" do
0
+      Page.should_receive(:find).with(@id).and_return @page
0
+      @page.should_receive(:version).and_return @version2
0
+      current_revision(@id, @version).should == false
0
+    end
0
+    it "checks non-existing page version" do
0
+      Page.should_receive(:find).with(@id).and_return nil
0
+      current_revision(@id, @version).should == false
0
+    end
0
+ end
0
\ No newline at end of file
...
5
6
7
 
8
9
10
...
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
...
5
6
7
8
9
10
11
...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
0
@@ -5,6 +5,7 @@ describe Page, "validity" do
0
   
0
   before(:each) do
0
     @page = Page.new :site_id => 1
0
+    @site = mock_model(Site)
0
   end
0
 
0
   it "should not be valid" do
0
@@ -17,6 +18,19 @@ describe Page, "validity" do
0
     @page.should be_valid
0
   end
0
   
0
+  it "should not be valid if site is spam" do
0
+    @page.stub!(:is_spam?).and_return true
0
+    @page.stub!(:site).and_return @site
0
+    @site.should_receive(:akismet_key?).and_return true
0
+    @page.should_not be_valid
0
+  end
0
+  
0
+  it "should connect to viking for spam info" do
0
+    @v = mock_model(Object)
0
+    Viking.should_receive(:connect).and_return @v
0
+    @v.should_receive(:check_comment).and_return :spam => true
0
+    @page.is_spam?(@page.site).should == true
0
+  end
0
 end
0
 
0
 describe Page, "creating links" do

Comments