snippets.rb 2.57 KB
Newer Older
1
class Spinach::Features::ProjectSnippets < Spinach::FeatureSteps
2 3 4 5 6
  include SharedAuthentication
  include SharedProject
  include SharedNote
  include SharedPaths

7
  step 'project "Shop" have "Snippet one" snippet' do
8 9 10 11 12 13 14 15
    create(:project_snippet,
           title: "Snippet one",
           content: "Test content",
           file_name: "snippet.rb",
           project: project,
           author: project.users.first)
  end

16
  step 'project "Shop" have no "Snippet two" snippet' do
17 18 19 20 21 22 23
    create(:snippet,
           title: "Snippet two",
           content: "Test content",
           file_name: "snippet.rb",
           author: project.users.first)
  end

24
  step 'I click link "New Snippet"' do
25 26 27
    click_link "Add new snippet"
  end

28
  step 'I click link "Snippet one"' do
29 30 31
    click_link "Snippet one"
  end

32
  step 'I should see "Snippet one" in snippets' do
33
    expect(page).to have_content "Snippet one"
34 35
  end

36
  step 'I should not see "Snippet two" in snippets' do
37
    expect(page).not_to have_content "Snippet two"
38 39
  end

40
  step 'I should not see "Snippet one" in snippets' do
41
    expect(page).not_to have_content "Snippet one"
42 43
  end

44
  step 'I click link "Edit"' do
45
    page.within ".file-title" do
46 47 48 49
      click_link "Edit"
    end
  end

50
  step 'I click link "Remove Snippet"' do
51
    click_link "remove"
52 53
  end

54
  step 'I submit new snippet "Snippet three"' do
55 56
    fill_in "project_snippet_title", :with => "Snippet three"
    fill_in "project_snippet_file_name", :with => "my_snippet.rb"
57
    page.within('.file-editor') do
58 59
      find(:xpath, "//input[@id='project_snippet_content']").set 'Content of snippet three'
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
60
    click_button "Create snippet"
61 62
  end

63
  step 'I should see snippet "Snippet three"' do
64 65
    expect(page).to have_content "Snippet three"
    expect(page).to have_content "Content of snippet three"
66 67
  end

68
  step 'I submit new title "Snippet new title"' do
69 70 71 72
    fill_in "project_snippet_title", :with => "Snippet new title"
    click_button "Save"
  end

73
  step 'I should see "Snippet new title"' do
74
    expect(page).to have_content "Snippet new title"
75 76
  end

77
  step 'I leave a comment like "Good snippet!"' do
78
    page.within('.js-main-target-form') do
79 80 81 82 83
      fill_in "note_note", with: "Good snippet!"
      click_button "Add Comment"
    end
  end

84
  step 'I should see comment "Good snippet!"' do
85
    expect(page).to have_content "Good snippet!"
86 87
  end

88
  step 'I visit snippet page "Snippet one"' do
Vinnie Okada's avatar
Vinnie Okada committed
89
    visit namespace_project_snippet_path(project.namespace, project, project_snippet)
90 91 92
  end

  def project_snippet
skv's avatar
skv committed
93
    @project_snippet ||= ProjectSnippet.find_by!(title: "Snippet one")
94 95
  end
end