Welcome to mirror list, hosted at ThFree Co, Russian Federation.

snippets_spec.rb « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ef217ba62c4fc182a0859b49171a42e099bc7c8 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require 'spec_helper'

describe "Snippets" do
  let(:project) { create(:project) }

  before do
    login_as :user
    project.add_access(@user, :read, :write)
  end

  describe "GET /snippets" do
    before do
      @snippet = create(:snippet,
                        author: @user,
                        project: project)

      visit project_snippets_path(project)
    end

    subject { page }

    it { should have_content(@snippet.title[0..10]) }
    it { should have_content(@snippet.project.name) }

    describe "Destroy" do
      before do
        # admin access to remove snippet
        @user.users_projects.destroy_all
        project.add_access(@user, :read, :write, :admin)
        visit edit_project_snippet_path(project, @snippet)
      end

      it "should remove entry" do
        expect {
          click_link "destroy_snippet_#{@snippet.id}"
        }.to change { Snippet.count }.by(-1)
      end
    end
  end

  describe "New snippet" do
    before do
      visit project_snippets_path(project)
      click_link "New Snippet"
    end

    it "should open new snippet popup" do
      page.current_path.should == new_project_snippet_path(project)
    end

    describe "fill in" do
      before do
        fill_in "snippet_title", with: "login function"
        fill_in "snippet_file_name", with: "test.rb"
        fill_in "snippet_content", with: "def login; end"
      end

      it { expect { click_button "Save" }.to change {Snippet.count}.by(1) }

      it "should add new snippet to table" do
        click_button "Save"
        page.current_path.should == project_snippet_path(project, Snippet.last)
        page.should have_content "login function"
        page.should have_content "test.rb"
      end
    end
  end

  describe "Edit snippet" do
    before do
      @snippet = create(:snippet,
                        author: @user,
                        project: project)
      visit project_snippet_path(project, @snippet)
      click_link "Edit"
    end

    it "should open edit page" do
      page.current_path.should == edit_project_snippet_path(project, @snippet)
    end

    describe "fill in" do
      before do
        fill_in "snippet_title", with: "login function"
        fill_in "snippet_file_name", with: "test.rb"
        fill_in "snippet_content", with: "def login; end"
      end

      it { expect { click_button "Save" }.to_not change {Snippet.count} }

      it "should update snippet fields" do
        click_button "Save"

        page.current_path.should == project_snippet_path(project, @snippet)
        page.should have_content "login function"
        page.should have_content "test.rb"
      end
    end
  end
end