summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects_controller_spec.rb3
-rw-r--r--spec/features/lint_spec.rb9
-rw-r--r--spec/lib/gitlab_ci_yaml_processor_spec.rb179
-rw-r--r--spec/models/commit_spec.rb2
-rw-r--r--spec/models/project_services/hip_chat_message_spec.rb2
-rw-r--r--spec/models/project_services/slack_message_spec.rb2
-rw-r--r--spec/services/create_commit_service_spec.rb50
-rw-r--r--spec/support/gitlab_stubs/gitlab_ci.yml57
8 files changed, 119 insertions, 185 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 455a213..0069a78 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -12,7 +12,8 @@ describe ProjectsController do
before: '2aa371379db71ac89ae20843fcff3b3477cf1a1d',
after: '1c8a9df454ef68c22c2a33cca8232bb50849e5c5',
token: @project.token,
- ci_yaml_file: gitlab_ci_yaml
+ ci_yaml_file: gitlab_ci_yaml,
+ commits: [ { message: "Message" } ]
expect(response).to be_success
diff --git a/spec/features/lint_spec.rb b/spec/features/lint_spec.rb
index 4a1ea26..1160f24 100644
--- a/spec/features/lint_spec.rb
+++ b/spec/features/lint_spec.rb
@@ -11,11 +11,10 @@ describe "Lint" do
fill_in "content", with: content
click_on "Validate"
within "table" do
- page.should have_content("Skip Refs")
- page.should have_content("Job - Rspec")
- page.should have_content("Job - Spinach")
- page.should have_content("Deploy Job - cap deploy")
- page.should have_content("Deploy Job - Deploy to staging")
+ page.should have_content("Job - rspec")
+ page.should have_content("Job - spinach")
+ page.should have_content("Deploy Job - staging")
+ page.should have_content("Deploy Job - production")
end
end
diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb
index 22d0d6b..96dcf64 100644
--- a/spec/lib/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb
@@ -2,217 +2,120 @@ require 'spec_helper'
describe GitlabCiYamlProcessor do
- describe "#builds" do
- it "returns builds from string" do
- config = YAML.dump({
- jobs: ["ls"]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.builds.size.should == 1
- config_processor.builds.first.should == {
- branches: true,
- commands: "\nls",
- name: "ls",
- tag_list: "",
- tags: nil
- }
- end
-
- it "returns builds from string including before_script" do
+ describe "#builds_for_ref" do
+ it "returns builds if no branch specified" do
config = YAML.dump({
before_script: ["pwd"],
- jobs: ["ls"]
+ rspec: {test: "rspec"}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.builds.first.should == {
- branches: true,
- commands: "pwd\nls",
- name: "ls",
- tag_list: "",
- tags: nil
+ config_processor.builds_for_ref("master").size.should == 1
+ config_processor.builds_for_ref("master").first.should == {
+ except: nil,
+ name: :rspec,
+ only: nil,
+ script: "pwd\nrspec",
+ tags: []
}
end
- it "returns builds from job hash" do
+ it "does not return builds if only has another branch" do
config = YAML.dump({
before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runner: "mysql,ruby"}]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.builds.first.should == {
- branches: true,
- commands: "pwd\nls",
- name: "Rspec",
- tag_list: "mysql,ruby",
- tags: nil
- }
- end
- end
-
- describe "#deploy_builds" do
- it "returns deploy builds from string" do
- config = YAML.dump({
- deploy_jobs: ["ls"]
+ rspec: {test: "rspec", only: ["deploy"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds.size.should == 1
- config_processor.deploy_builds.first.should == {
- commands: "\nls",
- name: "ls",
- deploy: true,
- refs: "",
- tag_list: ""
- }
+ config_processor.builds_for_ref("master").size.should == 0
end
- it "returns deploy builds from string including before_script" do
+ it "does not return builds if only has regexp with another branch" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: ["ls"]
+ rspec: {test: "rspec", only: ["/^deploy$/"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds.first.should == {
- commands: "pwd\nls",
- name: "ls",
- deploy: true,
- refs: "",
- tag_list: ""
- }
+ config_processor.builds_for_ref("master").size.should == 0
end
- it "returns deploy builds from job hash" do
+ it "returns builds if only has specified this branch" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: [{script: "ls", name: "Rspec", refs: "master,deploy"}]
+ rspec: {test: "rspec", only: ["master"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds.first.should == {
- commands: "pwd\nls",
- name: "Rspec",
- deploy: true,
- refs: "master,deploy",
- tag_list: ""
- }
+ config_processor.builds_for_ref("master").size.should == 1
end
- end
- describe "create_commit_for_tag?" do
- it "returns true because there is a job for tags" do
+ it "does not build tags" do
config = YAML.dump({
before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runners: "mysql,ruby", tags: true}],
- deploy_jobs: ["ls"]
+ rspec: {test: "rspec", exclude: ["tags"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.create_commit_for_tag?("deploy").should be_true
- end
-
- it "returns true because there is a deploy job for this tag" do
- config = YAML.dump({
- before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runner: "mysql,ruby", tags: false}],
- deploy_jobs: [{script: "ls", refs: "deploy"}]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.create_commit_for_tag?("deploy").should be_true
- end
-
- it "returns true because there is a deploy job without tag specified" do
- config = YAML.dump({
- before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runner: "mysql,ruby", tags: false}],
- deploy_jobs: ["ls"]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.create_commit_for_tag?("deploy").should be_true
- end
-
- it "returns false because there is no deploy job for this ref nor job for tags" do
- config = YAML.dump({
- before_script: ["pwd"],
- jobs: [{script: "ls", name: "Rspec", runner: "mysql,ruby", tags: false}],
- deploy_jobs: [{script: "ls", refs: "master"}]
- })
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.create_commit_for_tag?("deploy").should be_false
+ config_processor.builds_for_ref("0-1", true).size.should == 1
end
end
describe "#deploy_builds_for_ref" do
- it "returns deploy job for ref" do
+ it "returns builds if no branch specified" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: [{script: "ls", name: "Deploy!1", refs: "deploy"}, {script: "pwd", refs: "staging"}]
+ rspec: {deploy: "rspec"}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds_for_ref("deploy").size.should == 1
- config_processor.deploy_builds_for_ref("deploy").first[:name].should == 'Deploy!1'
+ config_processor.deploy_builds_for_ref("master").size.should == 1
+ config_processor.deploy_builds_for_ref("master").first.should == {
+ except: nil,
+ name: :rspec,
+ only: nil,
+ script: "pwd\nrspec",
+ tags: []
+ }
end
- it "returns deploy job for ref including job without ref specified" do
+ it "does not return builds if only has another branch" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: [{script: "ls", name: "Deploy!1", refs: "deploy"}, "pwd"]
+ rspec: {deploy: "rspec", only: ["deploy"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.deploy_builds_for_ref("deploy").size.should == 2
+ config_processor.deploy_builds_for_ref("master").size.should == 0
end
- it "returns empty array because there is no deploy job for this ref" do
+ it "does not return builds if only has regexp with another branch" do
config = YAML.dump({
before_script: ["pwd"],
- deploy_jobs: [{script: "ls", name: "Deploy!1", refs: "deploy"}]
+ rspec: {deploy: "rspec", only: ["/^deploy$/"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.deploy_builds_for_ref("master").size.should == 0
end
- end
- describe "skip_ref?" do
- it "skips ref" do
+ it "returns builds if only has specified this branch" do
config = YAML.dump({
- skip_refs: "master"
+ before_script: ["pwd"],
+ rspec: {deploy: "rspec", only: ["master"]}
})
config_processor = GitlabCiYamlProcessor.new(config)
- config_processor.skip_ref?("master").should be_true
- config_processor.skip_ref?("deploy").should be_false
- end
-
- it "does not skip ref if no refs specified" do
- config = YAML.dump({})
-
- config_processor = GitlabCiYamlProcessor.new(config)
-
- config_processor.skip_ref?("master").should be_false
+ config_processor.deploy_builds_for_ref("master").size.should == 1
end
end
-
end \ No newline at end of file
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 1658ae6..8c0073e 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -138,7 +138,7 @@ describe Commit do
commit.create_deploy_builds
commit.builds.reload
- commit.builds.size.should == 1
+ commit.builds.size.should == 2
end
end
diff --git a/spec/models/project_services/hip_chat_message_spec.rb b/spec/models/project_services/hip_chat_message_spec.rb
index d4bfb31..5fa5549 100644
--- a/spec/models/project_services/hip_chat_message_spec.rb
+++ b/spec/models/project_services/hip_chat_message_spec.rb
@@ -8,7 +8,7 @@ describe HipChatMessage do
context "One build" do
let(:commit) do
commit = FactoryGirl.create(:commit, project: project)
- commit.push_data[:ci_yaml_file] = YAML.dump({jobs: ["ls"]})
+ commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { test: 'pwd' }})
commit.save
commit
end
diff --git a/spec/models/project_services/slack_message_spec.rb b/spec/models/project_services/slack_message_spec.rb
index 03c0cd3..857935d 100644
--- a/spec/models/project_services/slack_message_spec.rb
+++ b/spec/models/project_services/slack_message_spec.rb
@@ -8,7 +8,7 @@ describe SlackMessage do
context "One build" do
let(:commit) do
commit = FactoryGirl.create(:commit, project: project)
- commit.push_data[:ci_yaml_file] = YAML.dump({jobs: ["ls"]})
+ commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { test: "ls" }})
commit.save
commit
end
diff --git a/spec/services/create_commit_service_spec.rb b/spec/services/create_commit_service_spec.rb
index ae118e4..c04aaa6 100644
--- a/spec/services/create_commit_service_spec.rb
+++ b/spec/services/create_commit_service_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe CreateCommitService do
let(:service) { CreateCommitService.new }
let(:project) { FactoryGirl.create(:project) }
-
+
describe :execute do
context 'valid params' do
let(:commit) do
@@ -11,8 +11,9 @@ describe CreateCommitService do
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
- ci_yaml_file: gitlab_ci_yaml
- )
+ ci_yaml_file: gitlab_ci_yaml,
+ commits: [ { message: "Message" } ]
+ )
end
it { commit.should be_kind_of(Commit) }
@@ -24,15 +25,27 @@ describe CreateCommitService do
context "deploy builds" do
it "calls create_deploy_builds if there are no builds" do
- config = YAML.dump({jobs: [], build_jobs: ["ls"]})
+ config = YAML.dump({production: {deploy: "ls"}})
Commit.any_instance.should_receive(:create_deploy_builds)
- service.execute(project, ref: 'refs/heads/master', before: '00000000', after: '31das312', ci_yaml_file: config)
+ service.execute(project,
+ ref: 'refs/heads/master',
+ before: '00000000',
+ after: '31das312',
+ ci_yaml_file: config,
+ commits: [ { message: "Message" } ]
+ )
end
it "does not call create_deploy_builds if there is build" do
- config = YAML.dump({jobs: ["ls"], build_jobs: ["ls"]})
+ config = YAML.dump({rspec: {test: "ls"},production: {deploy: "ls"}})
Commit.any_instance.should_not_receive(:create_deploy_builds)
- service.execute(project, ref: 'refs/heads/master', before: '00000000', after: '31das312', ci_yaml_file: config)
+ service.execute(project,
+ ref: 'refs/heads/master',
+ before: '00000000',
+ after: '31das312',
+ ci_yaml_file: config,
+ commits: [ { message: "Message" } ]
+ )
end
end
@@ -42,7 +55,8 @@ describe CreateCommitService do
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
- ci_yaml_file: gitlab_ci_yaml
+ ci_yaml_file: gitlab_ci_yaml,
+ commits: [ { message: "Message" } ]
)
result.should be_persisted
end
@@ -52,41 +66,43 @@ describe CreateCommitService do
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
- ci_yaml_file: YAML.dump({})
+ ci_yaml_file: YAML.dump({}),
+ commits: [ { message: "Message" } ]
)
result.should be_false
end
it "creates commit if there is no appropriate job but deploy job has right ref setting" do
- config = YAML.dump({deploy_jobs: [{script: "ls", refs: "0_1"}]})
+ config = YAML.dump({deploy: {deploy: "ls", only: ["0_1"]}})
result = service.execute(project,
ref: 'refs/heads/0_1',
before: '00000000',
after: '31das312',
- ci_yaml_file: config
+ ci_yaml_file: config,
+ commits: [ { message: "Message" } ]
)
result.should be_persisted
end
end
describe :ci_skip? do
- it "skips commit creation if there is [ci skip] tag in commit message" do
+ it "skips builds creation if there is [ci skip] tag in commit message" do
commits = [{message: "some message[ci skip]"}]
- result = service.execute(project,
+ commit = service.execute(project,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits,
ci_yaml_file: gitlab_ci_yaml
)
- result.should be_false
+ commit.builds.any?.should be_false
end
- it "does not skips commit creation if there is no [ci skip] tag in commit message" do
+ it "does not skips builds creation if there is no [ci skip] tag in commit message" do
commits = [{message: "some message"}]
- result = service.execute(project,
+ commit = service.execute(project,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
@@ -94,7 +110,7 @@ describe CreateCommitService do
ci_yaml_file: gitlab_ci_yaml
)
- result.should be_persisted
+ commit.builds.first.name.should == "staging"
end
end
diff --git a/spec/support/gitlab_stubs/gitlab_ci.yml b/spec/support/gitlab_stubs/gitlab_ci.yml
index 4f76e36..bf09f73 100644
--- a/spec/support/gitlab_stubs/gitlab_ci.yml
+++ b/spec/support/gitlab_stubs/gitlab_ci.yml
@@ -1,24 +1,39 @@
-# Refs to skip
-skip_refs: “deploy-*”
-
-# Run before each script
before_script:
- - ls
+ - gem install bundler
+ - bundle install
+ - bundle exec rake db:create
+
+rspec:
+ test: "rake spec"
+ tags:
+ - ruby
+ - postgres
+ only:
+ - branches
+
+spinach:
+ test: "rake spinach"
+ tags:
+ - ruby
+ - mysql
+ except:
+ - tags
-# Parallel jobs, each line is parallel build
-jobs:
- - script: "rake spec"
- runner: "ruby,postgres"
- name: "Rspec"
- - script: "rake spinach"
- runner: "ruby,mysql"
- name: "Spinach"
- tags: true
- branches: true
+staging:
+ deploy: "cap deploy stating"
+ tags:
+ - capistrano
+ - debian
+ except:
+ - stable
-# Parallel deploy jobs
-deploy_jobs:
- - "cap deploy production"
- - script: "cap deploy staging"
- refs: staging
- name: "Deploy to staging"
+production:
+ deploy:
+ - cap deploy production
+ - cap notify
+ tags:
+ - capistrano
+ - debian
+ only:
+ - master
+ - /^deploy-.*$/ \ No newline at end of file