From 4eafc188437e0214c09d59083586ea871b625b14 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 28 Jan 2015 23:08:28 -0500 Subject: Refactor Repository to use new RepositoryCache class Abstracts away the lower-level implementation details from the Repository model. --- spec/lib/repository_cache_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/lib/repository_cache_spec.rb (limited to 'spec') diff --git a/spec/lib/repository_cache_spec.rb b/spec/lib/repository_cache_spec.rb new file mode 100644 index 00000000000..af399f3a731 --- /dev/null +++ b/spec/lib/repository_cache_spec.rb @@ -0,0 +1,34 @@ +require 'rspec' +require_relative '../../lib/repository_cache' + +describe RepositoryCache do + let(:backend) { double('backend').as_null_object } + let(:cache) { RepositoryCache.new('example', backend) } + + describe '#cache_key' do + it 'includes the namespace' do + expect(cache.cache_key(:foo)).to eq 'foo:example' + end + end + + describe '#expire' do + it 'expires the given key from the cache' do + cache.expire(:foo) + expect(backend).to have_received(:delete).with('foo:example') + end + end + + describe '#fetch' do + it 'fetches the given key from the cache' do + cache.fetch(:bar) + expect(backend).to have_received(:fetch).with('bar:example') + end + + it 'accepts a block' do + p = -> {} + + cache.fetch(:baz, &p) + expect(backend).to have_received(:fetch).with('baz:example', &p) + end + end +end -- cgit v1.2.1 From 9de4e696a68b7a0fb4d1e04becac24813fc4c922 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 29 Jan 2015 12:01:27 -0500 Subject: Remove errant print statements from votes spec This caused those random "true" outputs in the rspec output. --- spec/lib/votes_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/lib/votes_spec.rb b/spec/lib/votes_spec.rb index 2c01a34756d..a88a10d927f 100644 --- a/spec/lib/votes_spec.rb +++ b/spec/lib/votes_spec.rb @@ -161,8 +161,8 @@ describe Issue, 'Votes' do add_note '+1 I still like this' add_note '+1 I really like this' add_note '+1 Give me this now!!!!' - p issue.downvotes.should == 0 - p issue.upvotes.should == 1 + issue.downvotes.should == 0 + issue.upvotes.should == 1 end it 'should count a users vote only once without caring about comments' do @@ -171,8 +171,8 @@ describe Issue, 'Votes' do add_note 'Another comment' add_note '+1 vote' add_note 'final comment' - p issue.downvotes.should == 0 - p issue.upvotes.should == 1 + issue.downvotes.should == 0 + issue.upvotes.should == 1 end end -- cgit v1.2.1 From ed17adfbcd7f279747ac8f23da079808299b06e6 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 29 Jan 2015 12:15:15 -0500 Subject: Update shoulda-matchers This outdated gem was the cause of those annoying MiniTest errors. Also updates one use of `ensure_inclusion_of` which was deprecated in favor of `validate_inclusion_of`. --- spec/models/members_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/models/members_spec.rb b/spec/models/members_spec.rb index 6866c4794c2..cea653ec285 100644 --- a/spec/models/members_spec.rb +++ b/spec/models/members_spec.rb @@ -10,7 +10,7 @@ describe Member do it { should validate_presence_of(:user) } it { should validate_presence_of(:source) } - it { should ensure_inclusion_of(:access_level).in_array(Gitlab::Access.values) } + it { should validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) } end describe "Delegate methods" do -- cgit v1.2.1 From c47328948b5fff218c68279260a57ab6b03e7423 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 30 Jan 2015 00:22:51 -0800 Subject: Fix specs for icons --- spec/helpers/notifications_helper_spec.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'spec') diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb index 31ecdacf28e..dcc3318e4f9 100644 --- a/spec/helpers/notifications_helper_spec.rb +++ b/spec/helpers/notifications_helper_spec.rb @@ -1,6 +1,9 @@ require 'spec_helper' describe NotificationsHelper do + include FontAwesome::Rails::IconHelper + include IconsHelper + describe 'notification_icon' do let(:notification) { double(disabled?: false, participating?: false, watch?: false) } -- cgit v1.2.1 From ab6f7164e03139889c09a6a207e9df3481e57b3b Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 30 Jan 2015 15:40:04 -0500 Subject: Make the structure of spec/models match app/models --- spec/models/assembla_service_spec.rb | 48 ---------- spec/models/buildbox_service_spec.rb | 73 --------------- spec/models/flowdock_service_spec.rb | 47 ---------- spec/models/gemnasium_service_spec.rb | 43 --------- spec/models/gitlab_ci_service_spec.rb | 44 --------- spec/models/group_member_spec.rb | 46 ---------- spec/models/hooks/project_hook_spec.rb | 36 ++++++++ spec/models/hooks/service_hook_spec.rb | 24 +++++ spec/models/hooks/system_hook_spec.rb | 100 +++++++++++++++++++++ spec/models/hooks/web_hook_spec.rb | 74 +++++++++++++++ spec/models/jira_service_spec.rb | 83 ----------------- spec/models/members/group_member_spec.rb | 46 ++++++++++ spec/models/members/project_member_spec.rb | 92 +++++++++++++++++++ spec/models/project_hook_spec.rb | 36 -------- spec/models/project_member_spec.rb | 92 ------------------- .../project_services/assembla_service_spec.rb | 48 ++++++++++ .../project_services/buildbox_service_spec.rb | 73 +++++++++++++++ .../project_services/flowdock_service_spec.rb | 47 ++++++++++ .../project_services/gemnasium_service_spec.rb | 43 +++++++++ .../project_services/gitlab_ci_service_spec.rb | 44 +++++++++ spec/models/project_services/jira_service_spec.rb | 83 +++++++++++++++++ .../project_services/pushover_service_spec.rb | 69 ++++++++++++++ spec/models/project_services/slack_message_spec.rb | 65 ++++++++++++++ spec/models/project_services/slack_service_spec.rb | 57 ++++++++++++ spec/models/pushover_service_spec.rb | 69 -------------- spec/models/service_hook_spec.rb | 24 ----- spec/models/slack_message_spec.rb | 65 -------------- spec/models/slack_service_spec.rb | 57 ------------ spec/models/system_hook_spec.rb | 100 --------------------- spec/models/web_hook_spec.rb | 74 --------------- 30 files changed, 901 insertions(+), 901 deletions(-) delete mode 100644 spec/models/assembla_service_spec.rb delete mode 100644 spec/models/buildbox_service_spec.rb delete mode 100644 spec/models/flowdock_service_spec.rb delete mode 100644 spec/models/gemnasium_service_spec.rb delete mode 100644 spec/models/gitlab_ci_service_spec.rb delete mode 100644 spec/models/group_member_spec.rb create mode 100644 spec/models/hooks/project_hook_spec.rb create mode 100644 spec/models/hooks/service_hook_spec.rb create mode 100644 spec/models/hooks/system_hook_spec.rb create mode 100644 spec/models/hooks/web_hook_spec.rb delete mode 100644 spec/models/jira_service_spec.rb create mode 100644 spec/models/members/group_member_spec.rb create mode 100644 spec/models/members/project_member_spec.rb delete mode 100644 spec/models/project_hook_spec.rb delete mode 100644 spec/models/project_member_spec.rb create mode 100644 spec/models/project_services/assembla_service_spec.rb create mode 100644 spec/models/project_services/buildbox_service_spec.rb create mode 100644 spec/models/project_services/flowdock_service_spec.rb create mode 100644 spec/models/project_services/gemnasium_service_spec.rb create mode 100644 spec/models/project_services/gitlab_ci_service_spec.rb create mode 100644 spec/models/project_services/jira_service_spec.rb create mode 100644 spec/models/project_services/pushover_service_spec.rb create mode 100644 spec/models/project_services/slack_message_spec.rb create mode 100644 spec/models/project_services/slack_service_spec.rb delete mode 100644 spec/models/pushover_service_spec.rb delete mode 100644 spec/models/service_hook_spec.rb delete mode 100644 spec/models/slack_message_spec.rb delete mode 100644 spec/models/slack_service_spec.rb delete mode 100644 spec/models/system_hook_spec.rb delete mode 100644 spec/models/web_hook_spec.rb (limited to 'spec') diff --git a/spec/models/assembla_service_spec.rb b/spec/models/assembla_service_spec.rb deleted file mode 100644 index 005dd41fea9..00000000000 --- a/spec/models/assembla_service_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe AssemblaService, models: true do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Execute" do - let(:user) { create(:user) } - let(:project) { create(:project) } - - before do - @assembla_service = AssemblaService.new - @assembla_service.stub( - project_id: project.id, - project: project, - service_hook: true, - token: 'verySecret', - subdomain: 'project_name' - ) - @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) - @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret' - WebMock.stub_request(:post, @api_url) - end - - it "should call Assembla API" do - @assembla_service.execute(@sample_data) - WebMock.should have_requested(:post, @api_url).with( - body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ - ).once - end - end -end diff --git a/spec/models/buildbox_service_spec.rb b/spec/models/buildbox_service_spec.rb deleted file mode 100644 index 1d9ca51be16..00000000000 --- a/spec/models/buildbox_service_spec.rb +++ /dev/null @@ -1,73 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe BuildboxService do - describe 'Associations' do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe 'commits methods' do - before do - @project = Project.new - @project.stub( - default_branch: 'default-brancho' - ) - - @service = BuildboxService.new - @service.stub( - project: @project, - service_hook: true, - project_url: 'https://buildbox.io/account-name/example-project', - token: 'secret-sauce-webhook-token:secret-sauce-status-token' - ) - end - - describe :webhook_url do - it 'returns the webhook url' do - @service.webhook_url.should == - 'https://webhook.buildbox.io/deliver/secret-sauce-webhook-token' - end - end - - describe :commit_status_path do - it 'returns the correct status page' do - @service.commit_status_path('2ab7834c').should == - 'https://gitlab.buildbox.io/status/secret-sauce-status-token.json?commit=2ab7834c' - end - end - - describe :build_page do - it 'returns the correct build page' do - @service.build_page('2ab7834c').should == - 'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c' - end - end - - describe :builds_page do - it 'returns the correct path to the builds page' do - @service.builds_path.should == - 'https://buildbox.io/account-name/example-project/builds?branch=default-brancho' - end - end - - describe :status_img_path do - it 'returns the correct path to the status image' do - @service.status_img_path.should == 'https://badge.buildbox.io/secret-sauce-status-token.svg' - end - end - end -end diff --git a/spec/models/flowdock_service_spec.rb b/spec/models/flowdock_service_spec.rb deleted file mode 100644 index ac156719b43..00000000000 --- a/spec/models/flowdock_service_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe FlowdockService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Execute" do - let(:user) { create(:user) } - let(:project) { create(:project) } - - before do - @flowdock_service = FlowdockService.new - @flowdock_service.stub( - project_id: project.id, - project: project, - service_hook: true, - token: 'verySecret' - ) - @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) - @api_url = 'https://api.flowdock.com/v1/git/verySecret' - WebMock.stub_request(:post, @api_url) - end - - it "should call FlowDock API" do - @flowdock_service.execute(@sample_data) - WebMock.should have_requested(:post, @api_url).with( - body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ - ).once - end - end -end diff --git a/spec/models/gemnasium_service_spec.rb b/spec/models/gemnasium_service_spec.rb deleted file mode 100644 index 2c560c11dac..00000000000 --- a/spec/models/gemnasium_service_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe GemnasiumService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Execute" do - let(:user) { create(:user) } - let(:project) { create(:project) } - - before do - @gemnasium_service = GemnasiumService.new - @gemnasium_service.stub( - project_id: project.id, - project: project, - service_hook: true, - token: 'verySecret', - api_key: 'GemnasiumUserApiKey' - ) - @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) - end - it "should call Gemnasium service" do - Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once - @gemnasium_service.execute(@sample_data) - end - end -end diff --git a/spec/models/gitlab_ci_service_spec.rb b/spec/models/gitlab_ci_service_spec.rb deleted file mode 100644 index 83277058fbb..00000000000 --- a/spec/models/gitlab_ci_service_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe GitlabCiService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Mass assignment" do - end - - describe 'commits methods' do - before do - @service = GitlabCiService.new - @service.stub( - service_hook: true, - project_url: 'http://ci.gitlab.org/projects/2', - token: 'verySecret' - ) - end - - describe :commit_status_path do - it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret"} - end - - describe :build_page do - it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c"} - end - end -end diff --git a/spec/models/group_member_spec.rb b/spec/models/group_member_spec.rb deleted file mode 100644 index 38657de6793..00000000000 --- a/spec/models/group_member_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# == Schema Information -# -# Table name: members -# -# id :integer not null, primary key -# access_level :integer not null -# source_id :integer not null -# source_type :string(255) not null -# user_id :integer not null -# notification_level :integer not null -# type :string(255) -# created_at :datetime -# updated_at :datetime -# - -require 'spec_helper' - -describe GroupMember do - context 'notification' do - describe "#after_create" do - it "should send email to user" do - membership = build(:group_member) - membership.stub(notification_service: double('NotificationService').as_null_object) - membership.should_receive(:notification_service) - membership.save - end - end - - describe "#after_update" do - before do - @membership = create :group_member - @membership.stub(notification_service: double('NotificationService').as_null_object) - end - - it "should send email to user" do - @membership.should_receive(:notification_service) - @membership.update_attribute(:access_level, GroupMember::MASTER) - end - - it "does not send an email when the access level has not changed" do - @membership.should_not_receive(:notification_service) - @membership.update_attribute(:access_level, GroupMember::OWNER) - end - end - end -end diff --git a/spec/models/hooks/project_hook_spec.rb b/spec/models/hooks/project_hook_spec.rb new file mode 100644 index 00000000000..4e0d50d7f3f --- /dev/null +++ b/spec/models/hooks/project_hook_spec.rb @@ -0,0 +1,36 @@ +# == Schema Information +# +# Table name: web_hooks +# +# id :integer not null, primary key +# url :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# type :string(255) default("ProjectHook") +# service_id :integer +# push_events :boolean default(TRUE), not null +# issues_events :boolean default(FALSE), not null +# merge_requests_events :boolean default(FALSE), not null +# tag_push_events :boolean default(FALSE) +# + +require 'spec_helper' + +describe ProjectHook do + describe '.push_hooks' do + it 'should return hooks for push events only' do + hook = create(:project_hook, push_events: true) + hook2 = create(:project_hook, push_events: false) + expect(ProjectHook.push_hooks).to eq([hook]) + end + end + + describe '.tag_push_hooks' do + it 'should return hooks for tag push events only' do + hook = create(:project_hook, tag_push_events: true) + hook2 = create(:project_hook, tag_push_events: false) + expect(ProjectHook.tag_push_hooks).to eq([hook]) + end + end +end diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb new file mode 100644 index 00000000000..6ec82438dfe --- /dev/null +++ b/spec/models/hooks/service_hook_spec.rb @@ -0,0 +1,24 @@ +# == Schema Information +# +# Table name: web_hooks +# +# id :integer not null, primary key +# url :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# type :string(255) default("ProjectHook") +# service_id :integer +# push_events :boolean default(TRUE), not null +# issues_events :boolean default(FALSE), not null +# merge_requests_events :boolean default(FALSE), not null +# tag_push_events :boolean default(FALSE) +# + +require "spec_helper" + +describe ServiceHook do + describe "Associations" do + it { should belong_to :service } + end +end diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb new file mode 100644 index 00000000000..8deb732de9c --- /dev/null +++ b/spec/models/hooks/system_hook_spec.rb @@ -0,0 +1,100 @@ +# == Schema Information +# +# Table name: web_hooks +# +# id :integer not null, primary key +# url :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# type :string(255) default("ProjectHook") +# service_id :integer +# push_events :boolean default(TRUE), not null +# issues_events :boolean default(FALSE), not null +# merge_requests_events :boolean default(FALSE), not null +# tag_push_events :boolean default(FALSE) +# + +require "spec_helper" + +describe SystemHook do + describe "execute" do + before(:each) do + @system_hook = create(:system_hook) + WebMock.stub_request(:post, @system_hook.url) + end + + it "project_create hook" do + Projects::CreateService.new(create(:user), name: 'empty').execute + WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once + end + + it "project_destroy hook" do + user = create(:user) + project = create(:empty_project, namespace: user.namespace) + Projects::DestroyService.new(project, user, {}).execute + WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once + end + + it "user_create hook" do + create(:user) + WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once + end + + it "user_destroy hook" do + user = create(:user) + user.destroy + WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once + end + + it "project_create hook" do + user = create(:user) + project = create(:project) + project.team << [user, :master] + WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once + end + + it "project_destroy hook" do + user = create(:user) + project = create(:project) + project.team << [user, :master] + project.project_members.destroy_all + WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once + end + + it 'group create hook' do + create(:group) + WebMock.should have_requested(:post, @system_hook.url).with( + body: /group_create/ + ).once + end + + it 'group destroy hook' do + group = create(:group) + group.destroy + WebMock.should have_requested(:post, @system_hook.url).with( + body: /group_destroy/ + ).once + end + + it 'group member create hook' do + group = create(:group) + user = create(:user) + group.add_user(user, Gitlab::Access::MASTER) + WebMock.should have_requested(:post, @system_hook.url).with( + body: /user_add_to_group/ + ).once + end + + it 'group member destroy hook' do + group = create(:group) + user = create(:user) + group.add_user(user, Gitlab::Access::MASTER) + group.group_members.destroy_all + WebMock.should have_requested(:post, @system_hook.url).with( + body: /user_remove_from_group/ + ).once + end + + end +end diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb new file mode 100644 index 00000000000..e9c04ee89cb --- /dev/null +++ b/spec/models/hooks/web_hook_spec.rb @@ -0,0 +1,74 @@ +# == Schema Information +# +# Table name: web_hooks +# +# id :integer not null, primary key +# url :string(255) +# project_id :integer +# created_at :datetime +# updated_at :datetime +# type :string(255) default("ProjectHook") +# service_id :integer +# push_events :boolean default(TRUE), not null +# issues_events :boolean default(FALSE), not null +# merge_requests_events :boolean default(FALSE), not null +# tag_push_events :boolean default(FALSE) +# + +require 'spec_helper' + +describe ProjectHook do + describe "Associations" do + it { should belong_to :project } + end + + describe "Mass assignment" do + end + + describe "Validations" do + it { should validate_presence_of(:url) } + + context "url format" do + it { should allow_value("http://example.com").for(:url) } + it { should allow_value("https://excample.com").for(:url) } + it { should allow_value("http://test.com/api").for(:url) } + it { should allow_value("http://test.com/api?key=abc").for(:url) } + it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) } + + it { should_not allow_value("example.com").for(:url) } + it { should_not allow_value("ftp://example.com").for(:url) } + it { should_not allow_value("herp-and-derp").for(:url) } + end + end + + describe "execute" do + before(:each) do + @project_hook = create(:project_hook) + @project = create(:project) + @project.hooks << [@project_hook] + @data = { before: 'oldrev', after: 'newrev', ref: 'ref'} + + WebMock.stub_request(:post, @project_hook.url) + end + + it "POSTs to the web hook URL" do + @project_hook.execute(@data) + WebMock.should have_requested(:post, @project_hook.url).once + end + + it "POSTs the data as JSON" do + json = @data.to_json + + @project_hook.execute(@data) + WebMock.should have_requested(:post, @project_hook.url).with(body: json).once + end + + it "catches exceptions" do + WebHook.should_receive(:post).and_raise("Some HTTP Post error") + + lambda { + @project_hook.execute(@data) + }.should raise_error + end + end +end diff --git a/spec/models/jira_service_spec.rb b/spec/models/jira_service_spec.rb deleted file mode 100644 index 0c73a68c924..00000000000 --- a/spec/models/jira_service_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'spec_helper' - -describe JiraService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Validations" do - context "active" do - before do - subject.active = true - end - - it { should validate_presence_of :project_url } - it { should validate_presence_of :issues_url } - it { should validate_presence_of :new_issue_url } - end - end - - describe 'description and title' do - let(:project) { create(:project) } - - context 'when it is not set' do - before do - @service = project.create_jira_service(active: true) - end - - after do - @service.destroy! - end - - it 'should be initialized' do - expect(@service.title).to eq('JIRA') - expect(@service.description).to eq("Jira issue tracker") - end - end - - context 'when it is set' do - before do - properties = { 'title' => 'Jira One', 'description' => 'Jira One issue tracker' } - @service = project.create_jira_service(active: true, properties: properties) - end - - after do - @service.destroy! - end - - it "should be correct" do - expect(@service.title).to eq('Jira One') - expect(@service.description).to eq('Jira One issue tracker') - end - end - end - - describe 'project and issue urls' do - let(:project) { create(:project) } - - context 'when gitlab.yml was initialized' do - before do - settings = { "jira" => { - "title" => "Jira", - "project_url" => "http://jira.sample/projects/project_a", - "issues_url" => "http://jira.sample/issues/:id", - "new_issue_url" => "http://jira.sample/projects/project_a/issues/new" - } - } - Gitlab.config.stub(:issues_tracker).and_return(settings) - @service = project.create_jira_service(active: true) - end - - after do - @service.destroy! - end - - it 'should be prepopulated with the settings' do - expect(@service.properties[:project_url]).to eq('http://jira.sample/projects/project_a') - expect(@service.properties[:issues_url]).to eq("http://jira.sample/issues/:id") - expect(@service.properties[:new_issue_url]).to eq("http://jira.sample/projects/project_a/issues/new") - end - end - end -end diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb new file mode 100644 index 00000000000..38657de6793 --- /dev/null +++ b/spec/models/members/group_member_spec.rb @@ -0,0 +1,46 @@ +# == Schema Information +# +# Table name: members +# +# id :integer not null, primary key +# access_level :integer not null +# source_id :integer not null +# source_type :string(255) not null +# user_id :integer not null +# notification_level :integer not null +# type :string(255) +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe GroupMember do + context 'notification' do + describe "#after_create" do + it "should send email to user" do + membership = build(:group_member) + membership.stub(notification_service: double('NotificationService').as_null_object) + membership.should_receive(:notification_service) + membership.save + end + end + + describe "#after_update" do + before do + @membership = create :group_member + @membership.stub(notification_service: double('NotificationService').as_null_object) + end + + it "should send email to user" do + @membership.should_receive(:notification_service) + @membership.update_attribute(:access_level, GroupMember::MASTER) + end + + it "does not send an email when the access level has not changed" do + @membership.should_not_receive(:notification_service) + @membership.update_attribute(:access_level, GroupMember::OWNER) + end + end + end +end diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb new file mode 100644 index 00000000000..9b5f89b6d7d --- /dev/null +++ b/spec/models/members/project_member_spec.rb @@ -0,0 +1,92 @@ +# == Schema Information +# +# Table name: members +# +# id :integer not null, primary key +# access_level :integer not null +# source_id :integer not null +# source_type :string(255) not null +# user_id :integer not null +# notification_level :integer not null +# type :string(255) +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe ProjectMember do + describe :import_team do + before do + @abilities = Six.new + @abilities << Ability + + @project_1 = create :project + @project_2 = create :project + + @user_1 = create :user + @user_2 = create :user + + @project_1.team << [ @user_1, :developer ] + @project_2.team << [ @user_2, :reporter ] + + @status = @project_2.team.import(@project_1) + end + + it { @status.should be_true } + + describe 'project 2 should get user 1 as developer. user_2 should not be changed' do + it { @project_2.users.should include(@user_1) } + it { @project_2.users.should include(@user_2) } + + it { @abilities.allowed?(@user_1, :write_project, @project_2).should be_true } + it { @abilities.allowed?(@user_2, :read_project, @project_2).should be_true } + end + + describe 'project 1 should not be changed' do + it { @project_1.users.should include(@user_1) } + it { @project_1.users.should_not include(@user_2) } + end + end + + describe :add_users_into_projects do + before do + @project_1 = create :project + @project_2 = create :project + + @user_1 = create :user + @user_2 = create :user + + ProjectMember.add_users_into_projects( + [@project_1.id, @project_2.id], + [@user_1.id, @user_2.id], + ProjectMember::MASTER + ) + end + + it { @project_1.users.should include(@user_1) } + it { @project_1.users.should include(@user_2) } + + + it { @project_2.users.should include(@user_1) } + it { @project_2.users.should include(@user_2) } + end + + describe :truncate_teams do + before do + @project_1 = create :project + @project_2 = create :project + + @user_1 = create :user + @user_2 = create :user + + @project_1.team << [ @user_1, :developer] + @project_2.team << [ @user_2, :reporter] + + ProjectMember.truncate_teams([@project_1.id, @project_2.id]) + end + + it { @project_1.users.should be_empty } + it { @project_2.users.should be_empty } + end +end diff --git a/spec/models/project_hook_spec.rb b/spec/models/project_hook_spec.rb deleted file mode 100644 index 4e0d50d7f3f..00000000000 --- a/spec/models/project_hook_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# == Schema Information -# -# Table name: web_hooks -# -# id :integer not null, primary key -# url :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# type :string(255) default("ProjectHook") -# service_id :integer -# push_events :boolean default(TRUE), not null -# issues_events :boolean default(FALSE), not null -# merge_requests_events :boolean default(FALSE), not null -# tag_push_events :boolean default(FALSE) -# - -require 'spec_helper' - -describe ProjectHook do - describe '.push_hooks' do - it 'should return hooks for push events only' do - hook = create(:project_hook, push_events: true) - hook2 = create(:project_hook, push_events: false) - expect(ProjectHook.push_hooks).to eq([hook]) - end - end - - describe '.tag_push_hooks' do - it 'should return hooks for tag push events only' do - hook = create(:project_hook, tag_push_events: true) - hook2 = create(:project_hook, tag_push_events: false) - expect(ProjectHook.tag_push_hooks).to eq([hook]) - end - end -end diff --git a/spec/models/project_member_spec.rb b/spec/models/project_member_spec.rb deleted file mode 100644 index 9b5f89b6d7d..00000000000 --- a/spec/models/project_member_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -# == Schema Information -# -# Table name: members -# -# id :integer not null, primary key -# access_level :integer not null -# source_id :integer not null -# source_type :string(255) not null -# user_id :integer not null -# notification_level :integer not null -# type :string(255) -# created_at :datetime -# updated_at :datetime -# - -require 'spec_helper' - -describe ProjectMember do - describe :import_team do - before do - @abilities = Six.new - @abilities << Ability - - @project_1 = create :project - @project_2 = create :project - - @user_1 = create :user - @user_2 = create :user - - @project_1.team << [ @user_1, :developer ] - @project_2.team << [ @user_2, :reporter ] - - @status = @project_2.team.import(@project_1) - end - - it { @status.should be_true } - - describe 'project 2 should get user 1 as developer. user_2 should not be changed' do - it { @project_2.users.should include(@user_1) } - it { @project_2.users.should include(@user_2) } - - it { @abilities.allowed?(@user_1, :write_project, @project_2).should be_true } - it { @abilities.allowed?(@user_2, :read_project, @project_2).should be_true } - end - - describe 'project 1 should not be changed' do - it { @project_1.users.should include(@user_1) } - it { @project_1.users.should_not include(@user_2) } - end - end - - describe :add_users_into_projects do - before do - @project_1 = create :project - @project_2 = create :project - - @user_1 = create :user - @user_2 = create :user - - ProjectMember.add_users_into_projects( - [@project_1.id, @project_2.id], - [@user_1.id, @user_2.id], - ProjectMember::MASTER - ) - end - - it { @project_1.users.should include(@user_1) } - it { @project_1.users.should include(@user_2) } - - - it { @project_2.users.should include(@user_1) } - it { @project_2.users.should include(@user_2) } - end - - describe :truncate_teams do - before do - @project_1 = create :project - @project_2 = create :project - - @user_1 = create :user - @user_2 = create :user - - @project_1.team << [ @user_1, :developer] - @project_2.team << [ @user_2, :reporter] - - ProjectMember.truncate_teams([@project_1.id, @project_2.id]) - end - - it { @project_1.users.should be_empty } - it { @project_2.users.should be_empty } - end -end diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb new file mode 100644 index 00000000000..005dd41fea9 --- /dev/null +++ b/spec/models/project_services/assembla_service_spec.rb @@ -0,0 +1,48 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe AssemblaService, models: true do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Execute" do + let(:user) { create(:user) } + let(:project) { create(:project) } + + before do + @assembla_service = AssemblaService.new + @assembla_service.stub( + project_id: project.id, + project: project, + service_hook: true, + token: 'verySecret', + subdomain: 'project_name' + ) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) + @api_url = 'https://atlas.assembla.com/spaces/project_name/github_tool?secret_key=verySecret' + WebMock.stub_request(:post, @api_url) + end + + it "should call Assembla API" do + @assembla_service.execute(@sample_data) + WebMock.should have_requested(:post, @api_url).with( + body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ + ).once + end + end +end diff --git a/spec/models/project_services/buildbox_service_spec.rb b/spec/models/project_services/buildbox_service_spec.rb new file mode 100644 index 00000000000..1d9ca51be16 --- /dev/null +++ b/spec/models/project_services/buildbox_service_spec.rb @@ -0,0 +1,73 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe BuildboxService do + describe 'Associations' do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe 'commits methods' do + before do + @project = Project.new + @project.stub( + default_branch: 'default-brancho' + ) + + @service = BuildboxService.new + @service.stub( + project: @project, + service_hook: true, + project_url: 'https://buildbox.io/account-name/example-project', + token: 'secret-sauce-webhook-token:secret-sauce-status-token' + ) + end + + describe :webhook_url do + it 'returns the webhook url' do + @service.webhook_url.should == + 'https://webhook.buildbox.io/deliver/secret-sauce-webhook-token' + end + end + + describe :commit_status_path do + it 'returns the correct status page' do + @service.commit_status_path('2ab7834c').should == + 'https://gitlab.buildbox.io/status/secret-sauce-status-token.json?commit=2ab7834c' + end + end + + describe :build_page do + it 'returns the correct build page' do + @service.build_page('2ab7834c').should == + 'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c' + end + end + + describe :builds_page do + it 'returns the correct path to the builds page' do + @service.builds_path.should == + 'https://buildbox.io/account-name/example-project/builds?branch=default-brancho' + end + end + + describe :status_img_path do + it 'returns the correct path to the status image' do + @service.status_img_path.should == 'https://badge.buildbox.io/secret-sauce-status-token.svg' + end + end + end +end diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb new file mode 100644 index 00000000000..ac156719b43 --- /dev/null +++ b/spec/models/project_services/flowdock_service_spec.rb @@ -0,0 +1,47 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe FlowdockService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Execute" do + let(:user) { create(:user) } + let(:project) { create(:project) } + + before do + @flowdock_service = FlowdockService.new + @flowdock_service.stub( + project_id: project.id, + project: project, + service_hook: true, + token: 'verySecret' + ) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) + @api_url = 'https://api.flowdock.com/v1/git/verySecret' + WebMock.stub_request(:post, @api_url) + end + + it "should call FlowDock API" do + @flowdock_service.execute(@sample_data) + WebMock.should have_requested(:post, @api_url).with( + body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/ + ).once + end + end +end diff --git a/spec/models/project_services/gemnasium_service_spec.rb b/spec/models/project_services/gemnasium_service_spec.rb new file mode 100644 index 00000000000..2c560c11dac --- /dev/null +++ b/spec/models/project_services/gemnasium_service_spec.rb @@ -0,0 +1,43 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe GemnasiumService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Execute" do + let(:user) { create(:user) } + let(:project) { create(:project) } + + before do + @gemnasium_service = GemnasiumService.new + @gemnasium_service.stub( + project_id: project.id, + project: project, + service_hook: true, + token: 'verySecret', + api_key: 'GemnasiumUserApiKey' + ) + @sample_data = Gitlab::PushDataBuilder.build_sample(project, user) + end + it "should call Gemnasium service" do + Gemnasium::GitlabService.should_receive(:execute).with(an_instance_of(Hash)).once + @gemnasium_service.execute(@sample_data) + end + end +end diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb new file mode 100644 index 00000000000..83277058fbb --- /dev/null +++ b/spec/models/project_services/gitlab_ci_service_spec.rb @@ -0,0 +1,44 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe GitlabCiService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Mass assignment" do + end + + describe 'commits methods' do + before do + @service = GitlabCiService.new + @service.stub( + service_hook: true, + project_url: 'http://ci.gitlab.org/projects/2', + token: 'verySecret' + ) + end + + describe :commit_status_path do + it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c/status.json?token=verySecret"} + end + + describe :build_page do + it { @service.build_page("2ab7834c").should == "http://ci.gitlab.org/projects/2/commits/2ab7834c"} + end + end +end diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb new file mode 100644 index 00000000000..0c73a68c924 --- /dev/null +++ b/spec/models/project_services/jira_service_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper' + +describe JiraService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Validations" do + context "active" do + before do + subject.active = true + end + + it { should validate_presence_of :project_url } + it { should validate_presence_of :issues_url } + it { should validate_presence_of :new_issue_url } + end + end + + describe 'description and title' do + let(:project) { create(:project) } + + context 'when it is not set' do + before do + @service = project.create_jira_service(active: true) + end + + after do + @service.destroy! + end + + it 'should be initialized' do + expect(@service.title).to eq('JIRA') + expect(@service.description).to eq("Jira issue tracker") + end + end + + context 'when it is set' do + before do + properties = { 'title' => 'Jira One', 'description' => 'Jira One issue tracker' } + @service = project.create_jira_service(active: true, properties: properties) + end + + after do + @service.destroy! + end + + it "should be correct" do + expect(@service.title).to eq('Jira One') + expect(@service.description).to eq('Jira One issue tracker') + end + end + end + + describe 'project and issue urls' do + let(:project) { create(:project) } + + context 'when gitlab.yml was initialized' do + before do + settings = { "jira" => { + "title" => "Jira", + "project_url" => "http://jira.sample/projects/project_a", + "issues_url" => "http://jira.sample/issues/:id", + "new_issue_url" => "http://jira.sample/projects/project_a/issues/new" + } + } + Gitlab.config.stub(:issues_tracker).and_return(settings) + @service = project.create_jira_service(active: true) + end + + after do + @service.destroy! + end + + it 'should be prepopulated with the settings' do + expect(@service.properties[:project_url]).to eq('http://jira.sample/projects/project_a') + expect(@service.properties[:issues_url]).to eq("http://jira.sample/issues/:id") + expect(@service.properties[:new_issue_url]).to eq("http://jira.sample/projects/project_a/issues/new") + end + end + end +end diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb new file mode 100644 index 00000000000..f2813d66c7d --- /dev/null +++ b/spec/models/project_services/pushover_service_spec.rb @@ -0,0 +1,69 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe PushoverService do + describe 'Associations' do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe 'Validations' do + context 'active' do + before do + subject.active = true + end + + it { should validate_presence_of :api_key } + it { should validate_presence_of :user_key } + it { should validate_presence_of :priority } + end + end + + describe 'Execute' do + let(:pushover) { PushoverService.new } + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } + + let(:api_key) { 'verySecret' } + let(:user_key) { 'verySecret' } + let(:device) { 'myDevice' } + let(:priority) { 0 } + let(:sound) { 'bike' } + let(:api_url) { 'https://api.pushover.net/1/messages.json' } + + before do + pushover.stub( + project: project, + project_id: project.id, + service_hook: true, + api_key: api_key, + user_key: user_key, + device: device, + priority: priority, + sound: sound + ) + + WebMock.stub_request(:post, api_url) + end + + it 'should call Pushover API' do + pushover.execute(sample_data) + + WebMock.should have_requested(:post, api_url).once + end + end +end diff --git a/spec/models/project_services/slack_message_spec.rb b/spec/models/project_services/slack_message_spec.rb new file mode 100644 index 00000000000..c530fad619b --- /dev/null +++ b/spec/models/project_services/slack_message_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe SlackMessage do + subject { SlackMessage.new(args) } + + let(:args) { + { + after: 'after', + before: 'before', + project_name: 'project_name', + ref: 'refs/heads/master', + user_name: 'user_name', + project_url: 'url' + } + } + + let(:color) { '#345' } + + context 'push' do + before do + args[:commits] = [ + { message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } }, + { message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } }, + ] + end + + it 'returns a message regarding pushes' do + subject.pretext.should == + 'user_name pushed to branch of '\ + ' ()' + subject.attachments.should == [ + { + text: ": message1 - author1\n"\ + ": message2 - author2", + color: color, + } + ] + end + end + + context 'new branch' do + before do + args[:before] = '000000' + end + + it 'returns a message regarding a new branch' do + subject.pretext.should == + 'user_name pushed new branch to '\ + '' + subject.attachments.should be_empty + end + end + + context 'removed branch' do + before do + args[:after] = '000000' + end + + it 'returns a message regarding a removed branch' do + subject.pretext.should == + 'user_name removed branch master from ' + subject.attachments.should be_empty + end + end +end diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb new file mode 100644 index 00000000000..34594072409 --- /dev/null +++ b/spec/models/project_services/slack_service_spec.rb @@ -0,0 +1,57 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + +require 'spec_helper' + +describe SlackService do + describe "Associations" do + it { should belong_to :project } + it { should have_one :service_hook } + end + + describe "Validations" do + context "active" do + before do + subject.active = true + end + + it { should validate_presence_of :webhook } + end + end + + describe "Execute" do + let(:slack) { SlackService.new } + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } + let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' } + + before do + slack.stub( + project: project, + project_id: project.id, + service_hook: true, + webhook: webhook_url + ) + + WebMock.stub_request(:post, webhook_url) + end + + it "should call Slack API" do + slack.execute(sample_data) + + WebMock.should have_requested(:post, webhook_url).once + end + end +end diff --git a/spec/models/pushover_service_spec.rb b/spec/models/pushover_service_spec.rb deleted file mode 100644 index f2813d66c7d..00000000000 --- a/spec/models/pushover_service_spec.rb +++ /dev/null @@ -1,69 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe PushoverService do - describe 'Associations' do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe 'Validations' do - context 'active' do - before do - subject.active = true - end - - it { should validate_presence_of :api_key } - it { should validate_presence_of :user_key } - it { should validate_presence_of :priority } - end - end - - describe 'Execute' do - let(:pushover) { PushoverService.new } - let(:user) { create(:user) } - let(:project) { create(:project) } - let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } - - let(:api_key) { 'verySecret' } - let(:user_key) { 'verySecret' } - let(:device) { 'myDevice' } - let(:priority) { 0 } - let(:sound) { 'bike' } - let(:api_url) { 'https://api.pushover.net/1/messages.json' } - - before do - pushover.stub( - project: project, - project_id: project.id, - service_hook: true, - api_key: api_key, - user_key: user_key, - device: device, - priority: priority, - sound: sound - ) - - WebMock.stub_request(:post, api_url) - end - - it 'should call Pushover API' do - pushover.execute(sample_data) - - WebMock.should have_requested(:post, api_url).once - end - end -end diff --git a/spec/models/service_hook_spec.rb b/spec/models/service_hook_spec.rb deleted file mode 100644 index 6ec82438dfe..00000000000 --- a/spec/models/service_hook_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -# == Schema Information -# -# Table name: web_hooks -# -# id :integer not null, primary key -# url :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# type :string(255) default("ProjectHook") -# service_id :integer -# push_events :boolean default(TRUE), not null -# issues_events :boolean default(FALSE), not null -# merge_requests_events :boolean default(FALSE), not null -# tag_push_events :boolean default(FALSE) -# - -require "spec_helper" - -describe ServiceHook do - describe "Associations" do - it { should belong_to :service } - end -end diff --git a/spec/models/slack_message_spec.rb b/spec/models/slack_message_spec.rb deleted file mode 100644 index c530fad619b..00000000000 --- a/spec/models/slack_message_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'spec_helper' - -describe SlackMessage do - subject { SlackMessage.new(args) } - - let(:args) { - { - after: 'after', - before: 'before', - project_name: 'project_name', - ref: 'refs/heads/master', - user_name: 'user_name', - project_url: 'url' - } - } - - let(:color) { '#345' } - - context 'push' do - before do - args[:commits] = [ - { message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } }, - { message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } }, - ] - end - - it 'returns a message regarding pushes' do - subject.pretext.should == - 'user_name pushed to branch of '\ - ' ()' - subject.attachments.should == [ - { - text: ": message1 - author1\n"\ - ": message2 - author2", - color: color, - } - ] - end - end - - context 'new branch' do - before do - args[:before] = '000000' - end - - it 'returns a message regarding a new branch' do - subject.pretext.should == - 'user_name pushed new branch to '\ - '' - subject.attachments.should be_empty - end - end - - context 'removed branch' do - before do - args[:after] = '000000' - end - - it 'returns a message regarding a removed branch' do - subject.pretext.should == - 'user_name removed branch master from ' - subject.attachments.should be_empty - end - end -end diff --git a/spec/models/slack_service_spec.rb b/spec/models/slack_service_spec.rb deleted file mode 100644 index 34594072409..00000000000 --- a/spec/models/slack_service_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -# == Schema Information -# -# Table name: services -# -# id :integer not null, primary key -# type :string(255) -# title :string(255) -# project_id :integer not null -# created_at :datetime -# updated_at :datetime -# active :boolean default(FALSE), not null -# properties :text -# - -require 'spec_helper' - -describe SlackService do - describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } - end - - describe "Validations" do - context "active" do - before do - subject.active = true - end - - it { should validate_presence_of :webhook } - end - end - - describe "Execute" do - let(:slack) { SlackService.new } - let(:user) { create(:user) } - let(:project) { create(:project) } - let(:sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } - let(:webhook_url) { 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685' } - - before do - slack.stub( - project: project, - project_id: project.id, - service_hook: true, - webhook: webhook_url - ) - - WebMock.stub_request(:post, webhook_url) - end - - it "should call Slack API" do - slack.execute(sample_data) - - WebMock.should have_requested(:post, webhook_url).once - end - end -end diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb deleted file mode 100644 index 8deb732de9c..00000000000 --- a/spec/models/system_hook_spec.rb +++ /dev/null @@ -1,100 +0,0 @@ -# == Schema Information -# -# Table name: web_hooks -# -# id :integer not null, primary key -# url :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# type :string(255) default("ProjectHook") -# service_id :integer -# push_events :boolean default(TRUE), not null -# issues_events :boolean default(FALSE), not null -# merge_requests_events :boolean default(FALSE), not null -# tag_push_events :boolean default(FALSE) -# - -require "spec_helper" - -describe SystemHook do - describe "execute" do - before(:each) do - @system_hook = create(:system_hook) - WebMock.stub_request(:post, @system_hook.url) - end - - it "project_create hook" do - Projects::CreateService.new(create(:user), name: 'empty').execute - WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once - end - - it "project_destroy hook" do - user = create(:user) - project = create(:empty_project, namespace: user.namespace) - Projects::DestroyService.new(project, user, {}).execute - WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once - end - - it "user_create hook" do - create(:user) - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once - end - - it "user_destroy hook" do - user = create(:user) - user.destroy - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once - end - - it "project_create hook" do - user = create(:user) - project = create(:project) - project.team << [user, :master] - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once - end - - it "project_destroy hook" do - user = create(:user) - project = create(:project) - project.team << [user, :master] - project.project_members.destroy_all - WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once - end - - it 'group create hook' do - create(:group) - WebMock.should have_requested(:post, @system_hook.url).with( - body: /group_create/ - ).once - end - - it 'group destroy hook' do - group = create(:group) - group.destroy - WebMock.should have_requested(:post, @system_hook.url).with( - body: /group_destroy/ - ).once - end - - it 'group member create hook' do - group = create(:group) - user = create(:user) - group.add_user(user, Gitlab::Access::MASTER) - WebMock.should have_requested(:post, @system_hook.url).with( - body: /user_add_to_group/ - ).once - end - - it 'group member destroy hook' do - group = create(:group) - user = create(:user) - group.add_user(user, Gitlab::Access::MASTER) - group.group_members.destroy_all - WebMock.should have_requested(:post, @system_hook.url).with( - body: /user_remove_from_group/ - ).once - end - - end -end diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb deleted file mode 100644 index e9c04ee89cb..00000000000 --- a/spec/models/web_hook_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -# == Schema Information -# -# Table name: web_hooks -# -# id :integer not null, primary key -# url :string(255) -# project_id :integer -# created_at :datetime -# updated_at :datetime -# type :string(255) default("ProjectHook") -# service_id :integer -# push_events :boolean default(TRUE), not null -# issues_events :boolean default(FALSE), not null -# merge_requests_events :boolean default(FALSE), not null -# tag_push_events :boolean default(FALSE) -# - -require 'spec_helper' - -describe ProjectHook do - describe "Associations" do - it { should belong_to :project } - end - - describe "Mass assignment" do - end - - describe "Validations" do - it { should validate_presence_of(:url) } - - context "url format" do - it { should allow_value("http://example.com").for(:url) } - it { should allow_value("https://excample.com").for(:url) } - it { should allow_value("http://test.com/api").for(:url) } - it { should allow_value("http://test.com/api?key=abc").for(:url) } - it { should allow_value("http://test.com/api?key=abc&type=def").for(:url) } - - it { should_not allow_value("example.com").for(:url) } - it { should_not allow_value("ftp://example.com").for(:url) } - it { should_not allow_value("herp-and-derp").for(:url) } - end - end - - describe "execute" do - before(:each) do - @project_hook = create(:project_hook) - @project = create(:project) - @project.hooks << [@project_hook] - @data = { before: 'oldrev', after: 'newrev', ref: 'ref'} - - WebMock.stub_request(:post, @project_hook.url) - end - - it "POSTs to the web hook URL" do - @project_hook.execute(@data) - WebMock.should have_requested(:post, @project_hook.url).once - end - - it "POSTs the data as JSON" do - json = @data.to_json - - @project_hook.execute(@data) - WebMock.should have_requested(:post, @project_hook.url).with(body: json).once - end - - it "catches exceptions" do - WebHook.should_receive(:post).and_raise("Some HTTP Post error") - - lambda { - @project_hook.execute(@data) - }.should raise_error - end - end -end -- cgit v1.2.1 From c0acb28c4ec710c90eb55dc996251a30001c8e79 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 2 Feb 2015 10:24:40 -0800 Subject: Annotate models --- spec/factories/projects.rb | 1 + spec/models/project_services/jira_service_spec.rb | 14 ++++++++++++++ spec/models/project_spec.rb | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 5ae57718c1a..0899a7603fc 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -26,6 +26,7 @@ # star_count :integer default(0), not null # import_type :string(255) # import_source :string(255) +# avatar :string(255) # FactoryGirl.define do diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 0c73a68c924..99ca04eff6e 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -1,3 +1,17 @@ +# == Schema Information +# +# Table name: services +# +# id :integer not null, primary key +# type :string(255) +# title :string(255) +# project_id :integer not null +# created_at :datetime +# updated_at :datetime +# active :boolean default(FALSE), not null +# properties :text +# + require 'spec_helper' describe JiraService do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 092c02d552e..4669a9fd87d 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -14,7 +14,7 @@ # merge_requests_enabled :boolean default(TRUE), not null # wiki_enabled :boolean default(TRUE), not null # namespace_id :integer -# issues_tracker :string(255) default('gitlab'), not null +# issues_tracker :string(255) default("gitlab"), not null # issues_tracker_id :string(255) # snippets_enabled :boolean default(TRUE), not null # last_activity_at :datetime -- cgit v1.2.1 From 4e97f26649a7756bef843fca74e3c58eadd117e1 Mon Sep 17 00:00:00 2001 From: jubianchi Date: Fri, 30 Jan 2015 10:46:08 +0100 Subject: Acces groups with their path in API --- spec/requests/api/groups_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'spec') diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index 95f82463367..8465d765294 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -73,6 +73,24 @@ describe API::API, api: true do response.status.should == 404 end end + + context 'when using group path in URL' do + it 'should return any existing group' do + get api("/groups/#{group1.path}", admin) + response.status.should == 200 + json_response['name'] == group2.name + end + + it 'should not return a non existing group' do + get api('/groups/unknown', admin) + response.status.should == 404 + end + + it 'should not return a group not attached to user1' do + get api("/groups/#{group2.path}", user1) + response.status.should == 403 + end + end end describe "POST /groups" do -- cgit v1.2.1 From 97d4ac40477788c1c43d2f32baefd1df1ceeb9f4 Mon Sep 17 00:00:00 2001 From: Jason Blanchard Date: Fri, 30 Jan 2015 23:21:31 -0500 Subject: Adds link to milestone and keeping resource context on smaller viewports for issues and merge requests --- spec/features/issues_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb index 26607b0090c..e6fa376f3eb 100644 --- a/spec/features/issues_spec.rb +++ b/spec/features/issues_spec.rb @@ -65,7 +65,7 @@ describe "Issues", feature: true do click_button "Save changes" - page.should have_content "Assignee: Select assignee" + page.should have_content 'Assignee: none' issue.reload.assignee.should be_nil end end @@ -249,6 +249,7 @@ describe "Issues", feature: true do click_button 'Update Issue' page.should have_content "Milestone changed to #{milestone.title}" + page.should have_content "Milestone: #{milestone.title}" has_select?('issue_assignee_id', :selected => milestone.title) end end @@ -287,7 +288,7 @@ describe "Issues", feature: true do sleep 2 # wait for ajax stuff to complete first('.user-result').click - page.should have_content "Assignee: Unassigned" + page.should have_content 'Assignee: none' sleep 2 # wait for ajax stuff to complete issue.reload.assignee.should be_nil end -- cgit v1.2.1 From ee955d7a125f9d18ac7ae334542ae68dd8d5114c Mon Sep 17 00:00:00 2001 From: Jason Blanchard Date: Fri, 30 Jan 2015 14:23:35 -0500 Subject: Adds persistent collapse button for left side bar --- spec/helpers/nav_helper_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spec/helpers/nav_helper_spec.rb (limited to 'spec') diff --git a/spec/helpers/nav_helper_spec.rb b/spec/helpers/nav_helper_spec.rb new file mode 100644 index 00000000000..e4d18d8bfc6 --- /dev/null +++ b/spec/helpers/nav_helper_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the NavHelper. For example: +# +# describe NavHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +describe NavHelper do + describe '#nav_menu_collapsed?' do + it 'returns true when the nav is collapsed in the cookie' do + helper.request.cookies[:collapsed_nav] = 'true' + expect(helper.nav_menu_collapsed?).to eq true + end + + it 'returns false when the nav is not collapsed in the cookie' do + helper.request.cookies[:collapsed_nav] = 'false' + expect(helper.nav_menu_collapsed?).to eq false + end + end +end -- cgit v1.2.1 From b9d9ac82a9d650b659866ea26dcb4e7987f10381 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Mon, 2 Feb 2015 21:30:11 -0800 Subject: Commit page: async load branches info Conflicts: config/routes.rb --- spec/controllers/commit_controller_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec') diff --git a/spec/controllers/commit_controller_spec.rb b/spec/controllers/commit_controller_spec.rb index f5822157ea4..cd8b46d7672 100644 --- a/spec/controllers/commit_controller_spec.rb +++ b/spec/controllers/commit_controller_spec.rb @@ -70,4 +70,13 @@ describe Projects::CommitController do end end end + + describe "#branches" do + it "contains branch and tags information" do + get :branches, project_id: project.to_param, id: commit.id + + expect(assigns(:branches)).to include("master", "feature_conflict") + expect(assigns(:tags)).to include("v1.1.0") + end + end end -- cgit v1.2.1