summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew8xx8 <avk@8xx8.ru>2013-03-24 19:12:28 +0400
committerAndrew8xx8 <avk@8xx8.ru>2013-03-24 19:12:28 +0400
commit7d2fbe6bd880b001857a373500e4fae31d43060a (patch)
treedc4789ae249951407ad349ab8a3ceacfcf0e866c
parent617239000762a01c57b35cbb699f155622ae921a (diff)
downloadgitlab-ce-7d2fbe6bd880b001857a373500e4fae31d43060a.tar.gz
Project Snippets now part of project
-rw-r--r--app/controllers/projects/application_controller.rb3
-rw-r--r--app/controllers/projects/snippets_controller.rb2
-rw-r--r--app/helpers/tab_helper.rb2
-rw-r--r--spec/features/projects/snippets_spec.rb101
4 files changed, 106 insertions, 2 deletions
diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb
index 49e514a228e..86e4a7cbd6b 100644
--- a/app/controllers/projects/application_controller.rb
+++ b/app/controllers/projects/application_controller.rb
@@ -1,3 +1,4 @@
class Projects::ApplicationController < ApplicationController
-
+ before_filter :project
+ before_filter :repository
end
diff --git a/app/controllers/projects/snippets_controller.rb b/app/controllers/projects/snippets_controller.rb
index 7c3281084f7..4602fbb989a 100644
--- a/app/controllers/projects/snippets_controller.rb
+++ b/app/controllers/projects/snippets_controller.rb
@@ -14,6 +14,8 @@ class Projects::SnippetsController < Projects::ApplicationController
# Allow destroy snippet
before_filter :authorize_admin_snippet!, only: [:destroy]
+ layout 'project_resource'
+
respond_to :html
def index
diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb
index d2be4b1a7e6..19aba0f5f6d 100644
--- a/app/helpers/tab_helper.rb
+++ b/app/helpers/tab_helper.rb
@@ -73,7 +73,7 @@ module TabHelper
end
def project_tab_class
- return "active" if current_page?(controller: "projects", action: :edit, id: @project)
+ return "active" if current_page?(controller: "/projects", action: :edit, id: @project)
if ['services', 'hooks', 'deploy_keys', 'team_members'].include? controller.controller_name
"active"
diff --git a/spec/features/projects/snippets_spec.rb b/spec/features/projects/snippets_spec.rb
new file mode 100644
index 00000000000..3c85359ee06
--- /dev/null
+++ b/spec/features/projects/snippets_spec.rb
@@ -0,0 +1,101 @@
+require 'spec_helper'
+
+describe "Project::Snippets" do
+ let(:project) { create(:project) }
+
+ before do
+ login_as :user
+ project.team << [@user, :developer]
+ end
+
+ describe "GET /:project/snippets" do
+ before do
+ @snippet = create(:snippet,
+ author: @user,
+ project: project)
+
+ visit project_snippets_path(project)
+ p 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.team << [@user, :master]
+ 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 project 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", js: true do
+ before do
+ fill_in "snippet_title", with: "login function"
+ fill_in "snippet_file_name", with: "test.rb"
+ page.execute_script("editor.insert('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 project snippet" do
+ before do
+ @snippet = create(:snippet,
+ author: @user,
+ project: project)
+ visit project_snippet_path(project, @snippet)
+ click_link "Edit Snippet"
+ 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"
+ 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