Skip to content
Snippets Groups Projects
Commit 9265de3d authored by gitlabhq's avatar gitlabhq
Browse files

snippets are ready

parent 526ad466
No related branches found
No related tags found
No related merge requests found
class CreateSnippets < ActiveRecord::Migration
def change
create_table :snippets do |t|
t.string :title
t.text :content
t.integer :author_id, :null => false
t.integer :project_id, :null => false
t.timestamps
end
end
end
class AddContentTypeToSnippets < ActiveRecord::Migration
def change
add_column :snippets, :content_type, :string, :null => false, :default => "txt"
end
end
class AddFileNameToSnippets < ActiveRecord::Migration
def change
add_column :snippets, :file_name, :string
remove_column :snippets, :content_type
end
end
Loading
Loading
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
 
ActiveRecord::Schema.define(:version => 20111015154310) do
ActiveRecord::Schema.define(:version => 20111016195506) do
 
create_table "issues", :force => true do |t|
t.string "title"
Loading
Loading
@@ -56,6 +56,16 @@ ActiveRecord::Schema.define(:version => 20111015154310) do
t.integer "owner_id"
end
 
create_table "snippets", :force => true do |t|
t.string "title"
t.text "content"
t.integer "author_id", :null => false
t.integer "project_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "file_name"
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
Loading
Loading
Loading
Loading
@@ -35,6 +35,12 @@ Factory.add(:issue, Issue) do |obj|
obj.content = Faker::Lorem.sentences
end
 
Factory.add(:snippet, Snippet) do |obj|
obj.title = Faker::Lorem.sentence
obj.file_name = Faker::Lorem.sentence
obj.content = Faker::Lorem.sentences
end
Factory.add(:note, Note) do |obj|
obj.note = Faker::Lorem.sentence
end
Loading
Loading
require 'spec_helper'
describe Snippet do
describe "Associations" do
it { should belong_to(:project) }
it { should belong_to(:author) }
end
describe "Validation" do
it { should validate_presence_of(:title) }
it { should validate_presence_of(:author_id) }
it { should validate_presence_of(:project_id) }
it { should validate_presence_of(:file_name) }
it { should validate_presence_of(:content) }
end
end
Loading
Loading
@@ -107,5 +107,14 @@ describe "Projects" do
it { project_issues_path(@project).should be_denied_for :user }
it { project_issues_path(@project).should be_denied_for :visitor }
end
describe "GET /project_code/snippets" do
it { project_snippets_path(@project).should be_allowed_for @u1 }
it { project_snippets_path(@project).should be_allowed_for @u3 }
it { project_snippets_path(@project).should be_denied_for :admin }
it { project_snippets_path(@project).should be_denied_for @u2 }
it { project_snippets_path(@project).should be_denied_for :user }
it { project_snippets_path(@project).should be_denied_for :visitor }
end
end
end
require 'spec_helper'
describe "Snippets" do
let(:project) { Factory :project }
before do
login_as :user
project.add_access(@user, :read, :write)
end
describe "GET /snippets" do
before do
@snippet = Factory :snippet,
:author => @user,
:project => project
visit project_snippets_path(project)
end
subject { page }
it { should have_content(@snippet.title) }
it { should have_content(@snippet.project.name) }
it { should have_content(@snippet.author.name) }
describe "Destroy" do
before do
# admin access to remove snippet
@user.users_projects.destroy_all
project.add_access(@user, :read, :write, :admin)
visit project_snippets_path(project)
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 = Factory :snippet,
:author => @user,
:project => project
visit project_snippets_path(project)
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment