Commit 7d2fbe6bd880b001857a373500e4fae31d43060a

Authored by Andrew8xx8
1 parent 61723900

Project Snippets now part of project

app/controllers/projects/application_controller.rb
1 class Projects::ApplicationController < ApplicationController 1 class Projects::ApplicationController < ApplicationController
2 - 2 + before_filter :project
  3 + before_filter :repository
3 end 4 end
app/controllers/projects/snippets_controller.rb
@@ -14,6 +14,8 @@ class Projects::SnippetsController &lt; Projects::ApplicationController @@ -14,6 +14,8 @@ class Projects::SnippetsController &lt; Projects::ApplicationController
14 # Allow destroy snippet 14 # Allow destroy snippet
15 before_filter :authorize_admin_snippet!, only: [:destroy] 15 before_filter :authorize_admin_snippet!, only: [:destroy]
16 16
  17 + layout 'project_resource'
  18 +
17 respond_to :html 19 respond_to :html
18 20
19 def index 21 def index
app/helpers/tab_helper.rb
@@ -73,7 +73,7 @@ module TabHelper @@ -73,7 +73,7 @@ module TabHelper
73 end 73 end
74 74
75 def project_tab_class 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 if ['services', 'hooks', 'deploy_keys', 'team_members'].include? controller.controller_name 78 if ['services', 'hooks', 'deploy_keys', 'team_members'].include? controller.controller_name
79 "active" 79 "active"
spec/features/projects/snippets_spec.rb 0 → 100644
@@ -0,0 +1,101 @@ @@ -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