Commit 1479f1722702c955ed3ee9456107c6a1a7277c7b

Authored by Dan Knox
1 parent ea9b3687

Add Spinach coverage for Gollum Wiki system and correct the Delete link.

The previously failing Spinach steps have been fixed with this commit.
I have also added new steps that cover the entire usage of the Wiki
system.

The new Spinach steps revealed a minor bug in the Delete page process.
The path for the "Delete this page" button was previously set to
`project_wikis_page(@project, @wiki)` when it should have been
using the singular `project_wiki_page(@project, @wiki)` path helper.

The link has been corrected and all steps are now passing.
app/views/wikis/edit.html.haml
... ... @@ -5,6 +5,6 @@
5 5 = render 'form'
6 6  
7 7 .pull-right
8   - - if can? current_user, :admin_wiki, @project
9   - = link_to project_wikis_path(@project, @wiki), confirm: "Are you sure you want to delete this page?", method: :delete, class: "btn btn-small btn-remove" do
  8 + - if @wiki.persisted? && can?(current_user, :admin_wiki, @project)
  9 + = link_to project_wiki_path(@project, @wiki), confirm: "Are you sure you want to delete this page?", method: :delete, class: "btn btn-small btn-remove" do
10 10 Delete this page
... ...
features/project/wiki.feature
... ... @@ -5,5 +5,32 @@ Feature: Project Wiki
5 5 Given I visit project wiki page
6 6  
7 7 Scenario: Add new page
8   - Given I create Wiki page
9   - Then I should see newly created wiki page
  8 + Given I create the Wiki Home page
  9 + Then I should see the newly created wiki page
  10 +
  11 + Scenario: Edit existing page
  12 + Given I have an existing Wiki page
  13 + And I browse to that Wiki page
  14 + And I click on the Edit button
  15 + And I change the content
  16 + Then I should see the updated content
  17 +
  18 + Scenario: View page history
  19 + Given I have an existing wiki page
  20 + And That page has two revisions
  21 + And I browse to that Wiki page
  22 + And I click the History button
  23 + Then I should see both revisions
  24 +
  25 + Scenario: Destroy Wiki page
  26 + Given I have an existing wiki page
  27 + And I browse to that Wiki page
  28 + And I click on the Edit button
  29 + And I click on the "Delete this page" button
  30 + Then The page should be deleted
  31 +
  32 + Scenario: View all pages
  33 + Given I have an existing wiki page
  34 + And I browse to that Wiki page
  35 + And I click on the "Pages" button
  36 + Then I should see the existing page in the pages list
... ...
features/steps/project/project_wiki.rb
... ... @@ -4,17 +4,73 @@ class ProjectWiki < Spinach::FeatureSteps
4 4 include SharedNote
5 5 include SharedPaths
6 6  
7   - Given 'I create Wiki page' do
8   - fill_in "Title", :with => 'Test title'
  7 + Given 'I create the Wiki Home page' do
9 8 fill_in "Content", :with => '[link test](test)'
10 9 click_on "Save"
11 10 end
12 11  
13   - Then 'I should see newly created wiki page' do
14   - page.should have_content "Test title"
  12 + Then 'I should see the newly created wiki page' do
  13 + page.should have_content "Home"
15 14 page.should have_content "link test"
16 15  
17 16 click_link "link test"
18 17 page.should have_content "Editing page"
19 18 end
  19 +
  20 + Given 'I have an existing Wiki page' do
  21 + wiki.create_page("existing", "content", :markdown, "first commit")
  22 + @page = wiki.find_page("existing")
  23 + end
  24 +
  25 + And 'I browse to that Wiki page' do
  26 + visit project_wiki_path(project, @page)
  27 + end
  28 +
  29 + And 'I click on the Edit button' do
  30 + click_on "Edit"
  31 + end
  32 +
  33 + And 'I change the content' do
  34 + fill_in "Content", :with => 'Updated Wiki Content'
  35 + click_on "Save"
  36 + end
  37 +
  38 + Then 'I should see the updated content' do
  39 + page.should have_content "Updated Wiki Content"
  40 + end
  41 +
  42 + And 'That page has two revisions' do
  43 + @page.update("new content", :markdown, "second commit")
  44 + end
  45 +
  46 + And 'I click the History button' do
  47 + click_on "History"
  48 + end
  49 +
  50 + Then 'I should see both revisions' do
  51 + page.should have_content current_user.name
  52 + page.should have_content "first commit"
  53 + page.should have_content "second commit"
  54 + end
  55 +
  56 + And 'I click on the "Delete this page" button' do
  57 + click_on "Delete this page"
  58 + end
  59 +
  60 + Then 'The page should be deleted' do
  61 + page.should have_content "Page was successfully deleted"
  62 + end
  63 +
  64 + And 'I click on the "Pages" button' do
  65 + click_on "Pages"
  66 + end
  67 +
  68 + Then 'I should see the existing page in the pages list' do
  69 + page.should have_content current_user.name
  70 + page.should have_content @page.title.titleize
  71 + end
  72 +
  73 + def wiki
  74 + @gollum_wiki = GollumWiki.new(project, current_user)
  75 + end
20 76 end
... ...
features/steps/shared/paths.rb
... ... @@ -161,7 +161,7 @@ module SharedPaths
161 161 end
162 162  
163 163 Given "I visit my project's wiki page" do
164   - visit project_wiki_path(@project, :index)
  164 + visit project_wiki_path(@project, :home)
165 165 end
166 166  
167 167 When 'I visit project hooks page' do
... ... @@ -256,7 +256,7 @@ module SharedPaths
256 256 end
257 257  
258 258 Given 'I visit project wiki page' do
259   - visit project_wiki_path(@project, :index)
  259 + visit project_wiki_path(@project, :home)
260 260 end
261 261  
262 262 def root_ref
... ...
features/support/env.rb
... ... @@ -32,6 +32,9 @@ DatabaseCleaner.strategy = :truncation
32 32 Spinach.hooks.before_scenario do
33 33 # Use tmp dir for FS manipulations
34 34 Gitlab.config.gitlab_shell.stub(repos_path: Rails.root.join('tmp', 'test-git-base-path'))
  35 + Gitlab::Shell.any_instance.stub(:add_repository) do |path|
  36 + create_temp_repo("#{Rails.root}/tmp/test-git-base-path/#{path}.git")
  37 + end
35 38 FileUtils.rm_rf Gitlab.config.gitlab_shell.repos_path
36 39 FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path
37 40 DatabaseCleaner.start
... ... @@ -46,3 +49,9 @@ Spinach.hooks.before_run do
46 49  
47 50 include FactoryGirl::Syntax::Methods
48 51 end
  52 +
  53 +def create_temp_repo(path)
  54 + FileUtils.mkdir_p path
  55 + command = "git init --quiet --bare #{path};"
  56 + system(command)
  57 +end
... ...