wiki.rb 3.7 KB
Newer Older
1
class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
Nihad Abbasov's avatar
Nihad Abbasov committed
2 3 4 5 6
  include SharedAuthentication
  include SharedProject
  include SharedNote
  include SharedPaths

7
  step 'I click on the Cancel button' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8
    within(:css, ".form-actions") do
9 10 11 12
      click_on "Cancel"
    end
  end

13
  step 'I should be redirected back to the Edit Home Wiki page' do
Vinnie Okada's avatar
Vinnie Okada committed
14
    current_path.should == namespace_project_wiki_path(project.namespace, project, :home)
15 16
  end

17
  step 'I create the Wiki Home page' do
18
    fill_in "wiki_content", with: '[link test](test)'
19
    click_on "Create page"
Nihad Abbasov's avatar
Nihad Abbasov committed
20 21
  end

22
  step 'I should see the newly created wiki page' do
23
    page.should have_content "Home"
Nihad Abbasov's avatar
Nihad Abbasov committed
24 25 26
    page.should have_content "link test"

    click_link "link test"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
27
    page.should have_content "Editing"
Nihad Abbasov's avatar
Nihad Abbasov committed
28
  end
29

30
  step 'I have an existing Wiki page' do
31 32 33 34
    wiki.create_page("existing", "content", :markdown, "first commit")
    @page = wiki.find_page("existing")
  end

35
  step 'I browse to that Wiki page' do
Vinnie Okada's avatar
Vinnie Okada committed
36
    visit namespace_project_wiki_path(project.namespace, project, @page)
37 38
  end

39
  step 'I click on the Edit button' do
40 41 42
    click_on "Edit"
  end

43
  step 'I change the content' do
44
    fill_in "Content", with: 'Updated Wiki Content'
45
    click_on "Save changes"
46 47
  end

48
  step 'I should see the updated content' do
49 50 51
    page.should have_content "Updated Wiki Content"
  end

52
  step 'I should be redirected back to that Wiki page' do
Vinnie Okada's avatar
Vinnie Okada committed
53
    current_path.should == namespace_project_wiki_path(project.namespace, project, @page)
54 55
  end

56
  step 'That page has two revisions' do
57 58 59
    @page.update("new content", :markdown, "second commit")
  end

60
  step 'I click the History button' do
61 62 63
    click_on "History"
  end

64
  step 'I should see both revisions' do
65 66 67 68 69
    page.should have_content current_user.name
    page.should have_content "first commit"
    page.should have_content "second commit"
  end

70
  step 'I click on the "Delete this page" button' do
71 72 73
    click_on "Delete this page"
  end

74
  step 'The page should be deleted' do
75 76 77
    page.should have_content "Page was successfully deleted"
  end

78
  step 'I click on the "Pages" button' do
79 80 81
    click_on "Pages"
  end

82
  step 'I should see the existing page in the pages list' do
83
    page.should have_content current_user.name
84
    page.should have_content @page.title
85 86
  end

87
  step 'I have an existing Wiki page with images linked on page' do
88 89 90 91
    wiki.create_page("pictures", "Look at this [image](image.jpg)\n\n ![image](image.jpg)", :markdown, "first commit")
    @wiki_page = wiki.find_page("pictures")
  end

92
  step 'I browse to wiki page with images' do
Vinnie Okada's avatar
Vinnie Okada committed
93
    visit namespace_project_wiki_path(project.namespace, project, @wiki_page)
94 95
  end

96
  step 'I click on existing image link' do
Marin Jankovski's avatar
Marin Jankovski committed
97 98 99
    file = Gollum::File.new(wiki.wiki)
    Gollum::Wiki.any_instance.stub(:file).with("image.jpg", "master", true).and_return(file)
    Gollum::File.any_instance.stub(:mime_type).and_return("image/jpeg")
100 101 102 103
    page.should have_link('image', href: "image.jpg")
    click_on "image"
  end

104
  step 'I should see the image from wiki repo' do
105
    current_path.should match('wikis/image.jpg')
106
    page.should_not have_xpath('/html') # Page should render the image which means there is no html involved
107 108
    Gollum::Wiki.any_instance.unstub(:file)
    Gollum::File.any_instance.unstub(:mime_type)
109 110
  end

111
  step 'Image should be shown on the page' do
112 113 114
    page.should have_xpath("//img[@src=\"image.jpg\"]")
  end

115
  step 'I click on image link' do
116 117 118 119
    page.should have_link('image', href: "image.jpg")
    click_on "image"
  end

120
  step 'I should see the new wiki page form' do
121
    current_path.should match('wikis/image.jpg')
122 123 124 125
    page.should have_content('New Wiki Page')
    page.should have_content('Editing - image.jpg')
  end

126
  def wiki
127
    @project_wiki = ProjectWiki.new(project, current_user)
128
  end
Nihad Abbasov's avatar
Nihad Abbasov committed
129
end