Commit 7d2fbe6bd880b001857a373500e4fae31d43060a
1 parent
61723900
Exists in
master
and in
4 other branches
Project Snippets now part of project
Showing
4 changed files
with
106 additions
and
2 deletions
Show diff stats
app/controllers/projects/application_controller.rb
app/controllers/projects/snippets_controller.rb
app/helpers/tab_helper.rb
| ... | ... | @@ -73,7 +73,7 @@ module TabHelper |
| 73 | 73 | end |
| 74 | 74 | |
| 75 | 75 | def project_tab_class |
| 76 | - return "active" if current_page?(controller: "projects", action: :edit, id: @project) | |
| 76 | + return "active" if current_page?(controller: "/projects", action: :edit, id: @project) | |
| 77 | 77 | |
| 78 | 78 | if ['services', 'hooks', 'deploy_keys', 'team_members'].include? controller.controller_name |
| 79 | 79 | "active" | ... | ... |
| ... | ... | @@ -0,0 +1,101 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe "Project::Snippets" do | |
| 4 | + let(:project) { create(:project) } | |
| 5 | + | |
| 6 | + before do | |
| 7 | + login_as :user | |
| 8 | + project.team << [@user, :developer] | |
| 9 | + end | |
| 10 | + | |
| 11 | + describe "GET /:project/snippets" do | |
| 12 | + before do | |
| 13 | + @snippet = create(:snippet, | |
| 14 | + author: @user, | |
| 15 | + project: project) | |
| 16 | + | |
| 17 | + visit project_snippets_path(project) | |
| 18 | + p project_snippets_path(project) | |
| 19 | + | |
| 20 | + end | |
| 21 | + | |
| 22 | + subject { page } | |
| 23 | + | |
| 24 | + it { should have_content(@snippet.title[0..10]) } | |
| 25 | + it { should have_content(@snippet.project.name) } | |
| 26 | + | |
| 27 | + describe "Destroy" do | |
| 28 | + before do | |
| 29 | + # admin access to remove snippet | |
| 30 | + @user.users_projects.destroy_all | |
| 31 | + project.team << [@user, :master] | |
| 32 | + visit edit_project_snippet_path(project, @snippet) | |
| 33 | + end | |
| 34 | + | |
| 35 | + it "should remove entry" do | |
| 36 | + expect { | |
| 37 | + click_link "destroy_snippet_#{@snippet.id}" | |
| 38 | + }.to change { Snippet.count }.by(-1) | |
| 39 | + end | |
| 40 | + end | |
| 41 | + end | |
| 42 | + | |
| 43 | + describe "New project snippet" do | |
| 44 | + before do | |
| 45 | + visit project_snippets_path(project) | |
| 46 | + click_link "New Snippet" | |
| 47 | + end | |
| 48 | + | |
| 49 | + it "should open new snippet popup" do | |
| 50 | + page.current_path.should == new_project_snippet_path(project) | |
| 51 | + end | |
| 52 | + | |
| 53 | + describe "fill in", js: true do | |
| 54 | + before do | |
| 55 | + fill_in "snippet_title", with: "login function" | |
| 56 | + fill_in "snippet_file_name", with: "test.rb" | |
| 57 | + page.execute_script("editor.insert('def login; end');") | |
| 58 | + end | |
| 59 | + | |
| 60 | + it { expect { click_button "Save" }.to change {Snippet.count}.by(1) } | |
| 61 | + | |
| 62 | + it "should add new snippet to table" do | |
| 63 | + click_button "Save" | |
| 64 | + page.current_path.should == project_snippet_path(project, Snippet.last) | |
| 65 | + page.should have_content "login function" | |
| 66 | + page.should have_content "test.rb" | |
| 67 | + end | |
| 68 | + end | |
| 69 | + end | |
| 70 | + | |
| 71 | + describe "Edit project snippet" do | |
| 72 | + before do | |
| 73 | + @snippet = create(:snippet, | |
| 74 | + author: @user, | |
| 75 | + project: project) | |
| 76 | + visit project_snippet_path(project, @snippet) | |
| 77 | + click_link "Edit Snippet" | |
| 78 | + end | |
| 79 | + | |
| 80 | + it "should open edit page" do | |
| 81 | + page.current_path.should == edit_project_snippet_path(project, @snippet) | |
| 82 | + end | |
| 83 | + | |
| 84 | + describe "fill in" do | |
| 85 | + before do | |
| 86 | + fill_in "snippet_title", with: "login function" | |
| 87 | + fill_in "snippet_file_name", with: "test.rb" | |
| 88 | + end | |
| 89 | + | |
| 90 | + it { expect { click_button "Save" }.to_not change {Snippet.count} } | |
| 91 | + | |
| 92 | + it "should update snippet fields" do | |
| 93 | + click_button "Save" | |
| 94 | + | |
| 95 | + page.current_path.should == project_snippet_path(project, @snippet) | |
| 96 | + page.should have_content "login function" | |
| 97 | + page.should have_content "test.rb" | |
| 98 | + end | |
| 99 | + end | |
| 100 | + end | |
| 101 | +end | ... | ... |