wiki.rb 3.61 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
  Given 'I click on the Cancel button' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8
    within(:css, ".form-actions") do
9 10 11 12 13 14 15 16 17
      click_on "Cancel"
    end
  end

  Then 'I should be redirected back to the Edit Home Wiki page' do
    url = URI.parse(current_url)
    url.path.should == project_wiki_path(project, :home)
  end

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

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

    click_link "link test"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
28
    page.should have_content "Editing"
Nihad Abbasov's avatar
Nihad Abbasov committed
29
  end
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

  Given 'I have an existing Wiki page' do
    wiki.create_page("existing", "content", :markdown, "first commit")
    @page = wiki.find_page("existing")
  end

  And 'I browse to that Wiki page' do
    visit project_wiki_path(project, @page)
  end

  And 'I click on the Edit button' do
    click_on "Edit"
  end

  And 'I change the content' do
45
    fill_in "Content", with: 'Updated Wiki Content'
46
    click_on "Save changes"
47 48 49 50 51 52
  end

  Then 'I should see the updated content' do
    page.should have_content "Updated Wiki Content"
  end

53 54 55 56 57
  Then 'I should be redirected back to that Wiki page' do
    url = URI.parse(current_url)
    url.path.should == project_wiki_path(project, @page)
  end

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
  And 'That page has two revisions' do
    @page.update("new content", :markdown, "second commit")
  end

  And 'I click the History button' do
    click_on "History"
  end

  Then 'I should see both revisions' do
    page.should have_content current_user.name
    page.should have_content "first commit"
    page.should have_content "second commit"
  end

  And 'I click on the "Delete this page" button' do
    click_on "Delete this page"
  end

  Then 'The page should be deleted' do
    page.should have_content "Page was successfully deleted"
  end

  And 'I click on the "Pages" button' do
    click_on "Pages"
  end

  Then 'I should see the existing page in the pages list' do
    page.should have_content current_user.name
86
    page.should have_content @page.title
87 88
  end

89 90 91 92 93 94 95 96 97 98
  Given 'I have an existing Wiki page with images linked on page' do
    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

  And 'I browse to wiki page with images' do
    visit project_wiki_path(project, @wiki_page)
  end

  And 'I click on existing image link' do
Marin Jankovski's avatar
Marin Jankovski committed
99 100 101
    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")
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
    page.should have_link('image', href: "image.jpg")
    click_on "image"
  end

  Then 'I should see the image from wiki repo' do
    url = URI.parse(current_url)
    url.path.should match("wikis/image.jpg")
    page.should_not have_xpath('/html') # Page should render the image which means there is no html involved
  end

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

  And 'I click on image link' do
    page.should have_link('image', href: "image.jpg")
    click_on "image"
  end

  Then 'I should see the new wiki page form' do
    url = URI.parse(current_url)
    url.path.should match("wikis/image.jpg")
    page.should have_content('New Wiki Page')
    page.should have_content('Editing - image.jpg')
  end

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