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
|
# encoding: utf-8
#--
# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
require File.dirname(__FILE__) + '/../test_helper'
class PagesControllerTest < ActionController::TestCase
should_render_in_site_specific_context
def setup
@project = projects(:johans)
@repo = @project.wiki_repository
end
context "repository readyness" do
should " be ready on #index" do
Repository.any_instance.stubs(:ready?).returns(false)
get :index, :project_id => @project.to_param
assert_redirected_to(project_path(@project))
assert_match(/is being created/, flash[:notice])
end
should " be ready on #show" do
Repository.any_instance.stubs(:ready?).returns(false)
get :show, :project_id => @project.to_param, :id => "Home"
assert_redirected_to(project_path(@project))
assert_match(/is being created/, flash[:notice])
end
end
context "index" do
should "renders an index" do
git_stub = stub("git", {
:tree => stub(:contents => [mock("node", :name => "Foo"), mock("node", :name => "Bar")])
})
Repository.any_instance.stubs(:git).returns(git_stub)
get :index, :project_id => @project.to_param
assert_response :success
end
should "redirects to the project if wiki is disabled for this projcet" do
@project.update_attribute(:wiki_enabled, false)
get :index, :project_id => @project.to_param
assert_redirected_to(project_path(@project))
end
should "render the history atom feed" do
grit = Grit::Repo.new(grit_test_repo("dot_git"), :is_bare => true)
Repository.any_instance.stubs(:git).returns(grit)
get :index, :project_id => @project.to_param, :format => "atom"
assert_response :success
assert_equal grit.commits("master", 30), assigns(:commits)
assert_template "index.atom.builder"
assert_equal "max-age=1800, private", @response.headers['Cache-Control']
end
end
context "show" do
should "redirects to edit if the page is new, and user is logged in" do
login_as nil
page_stub = mock("page stub")
page_stub.expects(:new?).returns(true)
page_stub.expects(:title).at_least_once.returns("Home")
Repository.any_instance.expects(:git).returns(mock("git"))
Page.expects(:find).returns(page_stub)
get :show, :project_id => @project.to_param, :id => "Home"
assert_response :success
assert_select ".help-box p", /page "Home" doesn't exist yet/
end
should "redirects to the project if wiki is disabled for this projcet" do
@project.update_attribute(:wiki_enabled, false)
get :show, :project_id => @project.to_param, :id => "Foo"
assert_redirected_to(project_path(@project))
end
end
context 'Preview' do
setup do
page_stub = mock("page stub")
page_stub.expects(:content=)
page_stub.expects(:content).returns("Messing around with wiki markup")
page_stub.expects(:save).never
Repository.any_instance.expects(:git).returns(mock("git"))
Page.expects(:find).returns(page_stub)
end
should 'render the preview for an existing page' do
login_as :johan
put :preview, :project_id => @project.to_param, :id => "Sandbox", :format => 'js', :page => {:content => 'Foo'}
assert_response :success
end
end
context "write permissions restricted to project members" do
setup do
@repo.update_attribute(:wiki_permissions, Repository::WIKI_WRITABLE_PROJECT_MEMBERS)
end
should "redirect back for non-projectmembers" do
assert !@project.member?(users(:mike))
login_as :mike
get :edit, :project_id => @project.to_param, :id => "NotHere"
assert_response :redirect
assert_match(/restricted wiki editing to project members/, flash[:error])
assert_redirected_to project_pages_path(@project)
end
end
end
|