2011-10-16 23:07:10 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe "Snippets" do
|
2012-11-06 04:31:55 +01:00
|
|
|
let(:project) { create(:project) }
|
2011-10-16 23:07:10 +02:00
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
before do
|
2011-10-16 23:07:10 +02:00
|
|
|
login_as :user
|
2013-01-04 17:50:31 +01:00
|
|
|
project.team << [@user, :developer]
|
2011-10-16 23:07:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /snippets" do
|
2011-10-26 15:46:25 +02:00
|
|
|
before do
|
2012-11-06 04:31:55 +01:00
|
|
|
@snippet = create(:snippet,
|
|
|
|
author: @user,
|
|
|
|
project: project)
|
2011-10-16 23:07:10 +02:00
|
|
|
|
|
|
|
visit project_snippets_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { page }
|
|
|
|
|
2011-12-22 20:52:57 +01:00
|
|
|
it { should have_content(@snippet.title[0..10]) }
|
2011-10-16 23:07:10 +02:00
|
|
|
it { should have_content(@snippet.project.name) }
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
describe "Destroy" do
|
|
|
|
before do
|
2011-10-16 23:07:10 +02:00
|
|
|
# admin access to remove snippet
|
|
|
|
@user.users_projects.destroy_all
|
2013-01-04 17:50:31 +01:00
|
|
|
project.team << [@user, :master]
|
2011-12-15 22:21:29 +01:00
|
|
|
visit edit_project_snippet_path(project, @snippet)
|
2011-10-16 23:07:10 +02:00
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should remove entry" do
|
2011-10-16 23:07:10 +02:00
|
|
|
expect {
|
|
|
|
click_link "destroy_snippet_#{@snippet.id}"
|
|
|
|
}.to change { Snippet.count }.by(-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
describe "New snippet" do
|
|
|
|
before do
|
2011-10-16 23:07:10 +02:00
|
|
|
visit project_snippets_path(project)
|
|
|
|
click_link "New Snippet"
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should open new snippet popup" do
|
2011-10-16 23:07:10 +02:00
|
|
|
page.current_path.should == new_project_snippet_path(project)
|
|
|
|
end
|
|
|
|
|
2012-12-12 18:42:08 +01:00
|
|
|
describe "fill in", js: true do
|
2011-10-16 23:07:10 +02:00
|
|
|
before do
|
2012-08-11 00:07:50 +02:00
|
|
|
fill_in "snippet_title", with: "login function"
|
|
|
|
fill_in "snippet_file_name", with: "test.rb"
|
2012-12-12 18:42:08 +01:00
|
|
|
page.execute_script("editor.insert('def login; end');")
|
2011-10-16 23:07:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { click_button "Save" }.to change {Snippet.count}.by(1) }
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should add new snippet to table" do
|
2011-10-16 23:07:10 +02:00
|
|
|
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
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
describe "Edit snippet" do
|
|
|
|
before do
|
2012-11-06 04:31:55 +01:00
|
|
|
@snippet = create(:snippet,
|
|
|
|
author: @user,
|
|
|
|
project: project)
|
2011-12-15 22:21:29 +01:00
|
|
|
visit project_snippet_path(project, @snippet)
|
2013-02-21 12:09:47 +01:00
|
|
|
click_link "Edit Snippet"
|
2011-10-16 23:07:10 +02:00
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should open edit page" do
|
2011-10-16 23:07:10 +02:00
|
|
|
page.current_path.should == edit_project_snippet_path(project, @snippet)
|
|
|
|
end
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
describe "fill in" do
|
2011-10-16 23:07:10 +02:00
|
|
|
before do
|
2012-08-11 00:07:50 +02:00
|
|
|
fill_in "snippet_title", with: "login function"
|
|
|
|
fill_in "snippet_file_name", with: "test.rb"
|
2011-10-16 23:07:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { click_button "Save" }.to_not change {Snippet.count} }
|
|
|
|
|
2011-10-26 15:46:25 +02:00
|
|
|
it "should update snippet fields" do
|
2011-10-16 23:07:10 +02:00
|
|
|
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
|