summaryrefslogtreecommitdiff
path: root/features/steps/snippets/snippets.rb
blob: 0b3e942a4fd3cad4b152ba73802a08de718aaf64 (plain)
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
class Spinach::Features::Snippets < Spinach::FeatureSteps
  include SharedAuthentication
  include SharedPaths
  include SharedProject
  include SharedSnippet
  include WaitForAjax

  step 'I click link "Personal snippet one"' do
    click_link "Personal snippet one"
  end

  step 'I should not see "Personal snippet one" in snippets' do
    expect(page).not_to have_content "Personal snippet one"
  end

  step 'I click link "Edit"' do
    page.within ".detail-page-header" do
      first(:link, "Edit").click
    end
  end

  step 'I click link "Delete"' do
    first(:link, "Delete").click
  end

  step 'I submit new snippet "Personal snippet three"' do
    fill_in "personal_snippet_title", with: "Personal snippet three"
    fill_in "personal_snippet_file_name", with: "my_snippet.rb"
    page.within('.file-editor') do
      find('.ace_editor').native.send_keys 'Content of snippet three'
    end
    click_button "Create snippet"
    wait_for_ajax
  end

  step 'I submit new internal snippet' do
    fill_in "personal_snippet_title", with: "Internal personal snippet one"
    fill_in "personal_snippet_file_name", with: "my_snippet.rb"
    choose 'personal_snippet_visibility_level_10'

    page.within('.file-editor') do
      find(:xpath, "//input[@id='personal_snippet_content']").set 'Content of internal snippet'
    end

    click_button "Create snippet"
  end

  step 'I should see snippet "Personal snippet three"' do
    expect(page).to have_content "Personal snippet three"
    expect(page).to have_content "Content of snippet three"
  end

  step 'I submit new title "Personal snippet new title"' do
    fill_in "personal_snippet_title", with: "Personal snippet new title"
    click_button "Save"
  end

  step 'I should see "Personal snippet new title"' do
    expect(page).to have_content "Personal snippet new title"
  end

  step 'I uncheck "Private" checkbox' do
    choose "Internal"
    click_button "Save"
  end

  step 'I should see "Personal snippet one" public' do
    expect(page).to have_no_xpath("//i[@class='public-snippet']")
  end

  step 'I visit snippet page "Personal snippet one"' do
    visit snippet_path(snippet)
  end

  step 'I visit snippet page "Internal personal snippet one"' do
    visit snippet_path(internal_snippet)
  end

  def snippet
    @snippet ||= PersonalSnippet.find_by!(title: "Personal snippet one")
  end

  def internal_snippet
    @snippet ||= PersonalSnippet.find_by!(title: "Internal personal snippet one")
  end
end