-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex_spec.rb
More file actions
141 lines (124 loc) · 4.61 KB
/
index_spec.rb
File metadata and controls
141 lines (124 loc) · 4.61 KB
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
# -*- coding: utf-8 -*-
require_relative 'ramaziki'
require 'mechanize'
require 'nokogiri'
describe "index.cgi は、" do
Home = "http://localhost:7000/"
DataDir = "data"
before(:all) do
Dir.chdir(DataDir) {
Dir['*'].each { |f| File.unlink f }
}
end
before do
@wiki = Ramaziki.new(DataDir)
@wiki["test"] = "テスト"
@wiki["テスト"] = "test"
@agent = Mechanize.new
end
it "home はトップページを表示する" do
page = @agent.get(URI.join(Home, "home"))
page.title.should == "Home"
page.at('h1').inner_text.should == "Ramaziki Home"
end
it "index はページ一覧(名前順)を表示する" do
page = @agent.get(URI.join(Home, "index"))
lists = page.at('ul').search('li')
lists[0].inner_text.should == "test"
lists[1].inner_text.should == "テスト"
end
it "show はページを表示する。" do
page = @agent.get(URI.join(Home, "show/test"))
page.title.should == "test"
href = page.at('div#edit>a').attributes["href"]
href.value.should == "/edit/test"
page.at('div#content/pre').text.should =~ /テスト/
page = @agent.get(URI.join(Home, URI::encode("show/テスト")))
page.title.should == "テスト"
href = page.at('div#edit>a').attributes["href"]
href.value.should == URI.encode("/edit/テスト")
page.at('pre').text.should =~ /test/
end
it "create は新しいページの名前を入力する。" do
page = @agent.get(URI.join(Home, "create"))
@agent.page.form_with(:name => 'create') { |form|
form["page"].should be_empty
form.field_with(:name => "page").value = "createtest"
form.click_button
}
@agent.page.form_with(:name => "edit") { |form|
form.action.should == "/modify/createtest"
form["text"].should be_empty
}
end
it "edit でページ内容がフォームで編集できる。" do
@agent.get(URI.join(Home, "edit/test"))
@agent.page.title.should == "test の編集"
@agent.page.form_with(:name => "edit") { |form|
form.action.should == "/modify/test"
form["text"].should == "テスト"
form.field_with(:name => "text").value = "試験"
form.click_button
}
page = @agent.page
page.title.should == "test"
page.at('pre').text.should =~ /試験/
end
it "edit でページ内容が変更されてなければ、警告を出す。" do
@agent.get(URI.join(Home, "edit/test"))
@agent.page.title.should == "test の編集"
@agent.page.form_with(:name => "edit") { |form|
form.action.should == "/modify/test"
form["text"].should == "テスト"
form.click_button
}
page = @agent.page
page.title.should == "test"
page.at('h1').inner_text.should == "test"
page.at('div#flash_notice').text.should =~ /内容が変更されていません/
page.at('pre').text.should =~ /テスト/
end
it "日本語のページ名でも ちゃんと編集できる。" do
@agent.get(URI.join(Home, URI.encode("edit/テスト")))
@agent.page.title.should == "テスト の編集"
@agent.page.form_with(:name => "edit") { |form|
form.action.should == URI.encode("/modify/テスト")
#form["page"].should == URI.encode("テスト")
form["text"].should == "test"
form.field_with(:name => "text").value = "試験"
form.click_button
}
page = @agent.page
page.title.should == "テスト"
page.at('pre').text.should =~ /試験/
end
it "edit のフォームが空だったら、ページを削除する。" do
@agent.get(URI.join(Home, "edit/test"))
page = @agent.page
page.form_with(:name => "edit") { |form|
form.field_with(:name => "text").value = ""
form.click_button
}
@agent.page.title.should == "Home"
@wiki.exists?("test").should_not be_true
@agent.get(URI.join(Home, URI.encode("edit/テスト")))
page = @agent.page
page.form_with(:name => "edit") { |form|
form.field_with(:name => "text").value = ""
form.click_button
}
@agent.page.at('div#flash_notice').text.should =~ /テスト を削除しました/
@wiki.exists?("テスト").should_not be_true
end
# it "modify でテキストが存在しない場合、削除しない。" do
# @agent.get(URI.join(Home, "modify/test"))
# @wiki.exists?("test").should be_true
#
# end
it "edit のページ名が空だったら、メッセージを出してHomeに戻る。" do
page = @agent.get(URI.join(Home, "edit"))
page.title.should == "Home"
page.at('h1').inner_text.should == "Ramaziki Home"
page.at('div#flash_error').text.should =~ /ページが指定されていません/
end
end