From b62cdc3c479365b2c96400c44b5e31eeb3d0c204 Mon Sep 17 00:00:00 2001 From: Tony Chu Date: Fri, 11 Dec 2015 21:47:57 +0800 Subject: Actually use the `skip_merges` option in Repository#commits --- spec/models/repository_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index c484ae8fc8c..db86f7032c6 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -239,4 +239,10 @@ describe Repository, models: true do it { is_expected.to eq(true) } end end + + describe :skip_merged_commit do + subject { repository.commits(Gitlab::Git::BRANCH_REF_PREFIX + "'test'", nil, 100, 0, true).map{ |k| k.id } } + + it { is_expected.not_to include('e56497bb5f03a90a51293fc6d516788730953899') } + end end -- cgit v1.2.3 From 2d59a0ff448cbb970db5754787753db810a9acc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 8 Feb 2016 15:54:34 +0100 Subject: Add a spec for setting/updating a MR's milestone via the API --- spec/requests/api/merge_requests_spec.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index d7bfa17b0b1..aa12d456aa9 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -10,6 +10,7 @@ describe API::API, api: true do let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds) } let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") } let!(:note2) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "another comment on a MR") } + let(:milestone) { create(:milestone, title: '1.0.0', project: project) } before do project.team << [user, :reporters] @@ -169,10 +170,12 @@ describe API::API, api: true do source_branch: 'feature_conflict', target_branch: 'master', author: user, - labels: 'label, label2' + labels: 'label, label2', + milestone_id: milestone.id expect(response.status).to eq(201) expect(json_response['title']).to eq('Test merge_request') expect(json_response['labels']).to eq(['label', 'label2']) + expect(json_response['milestone']['id']).to eq(milestone.id) end it "should return 422 when source_branch equals target_branch" do @@ -373,18 +376,24 @@ describe API::API, api: true do end describe "PUT /projects/:id/merge_requests/:merge_request_id" do - it "should return merge_request" do + it "updates title and returns merge_request" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), title: "New title" expect(response.status).to eq(200) expect(json_response['title']).to eq('New title') end - it "should return merge_request" do + it "updates description and returns merge_request" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), description: "New description" expect(response.status).to eq(200) expect(json_response['description']).to eq('New description') end + it "updates milestone_id and returns merge_request" do + put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), milestone_id: milestone.id + expect(response.status).to eq(200) + expect(json_response['milestone']['id']).to eq(milestone.id) + end + it "should return 400 when source_branch is specified" do put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), source_branch: "master", target_branch: "master" -- cgit v1.2.3 From b34963bc125d11af7b9c993d1233258f084e580d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 9 Feb 2016 15:51:06 +0100 Subject: Validate email addresses using Devise.email_regexp Also: - Get rid of legacy :strict_mode - Get rid of custom :email validator - Add some shared examples to spec emails validation --- spec/models/application_setting_spec.rb | 4 +++ spec/models/email_spec.rb | 22 ++++++++++++++ spec/models/member_spec.rb | 6 +++- spec/models/user_spec.rb | 36 +++++------------------ spec/support/email_format_shared_examples.rb | 44 ++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 30 deletions(-) create mode 100644 spec/models/email_spec.rb create mode 100644 spec/support/email_format_shared_examples.rb (limited to 'spec') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 161a32c51e6..b1764d7ac09 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -74,6 +74,10 @@ describe ApplicationSetting, models: true do .only_integer .is_greater_than(0) end + + it_behaves_like 'an object with email-formated attributes', :admin_notification_email do + subject { setting } + end end context 'restricted signup domains' do diff --git a/spec/models/email_spec.rb b/spec/models/email_spec.rb new file mode 100644 index 00000000000..a20a6149649 --- /dev/null +++ b/spec/models/email_spec.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: emails +# +# id :integer not null, primary key +# user_id :integer not null +# email :string(255) not null +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe Email, models: true do + + describe 'validations' do + it_behaves_like 'an object with email-formated attributes', :email do + subject { build(:email) } + end + end + +end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 2aedca20df2..2d8f1cc1ad3 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -31,6 +31,10 @@ describe Member, models: true do it { is_expected.to validate_presence_of(:source) } it { is_expected.to validate_inclusion_of(:access_level).in_array(Gitlab::Access.values) } + it_behaves_like 'an object with email-formated attributes', :invite_email do + subject { build(:project_member) } + end + context "when an invite email is provided" do let(:member) { build(:project_member, invite_email: "user@example.com", user: nil) } @@ -159,7 +163,7 @@ describe Member, models: true do describe "#generate_invite_token" do let!(:member) { create(:project_member, invite_email: "user@example.com", user: nil) } - + it "sets the invite token" do expect { member.generate_invite_token }.to change { member.invite_token} end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cee051f5732..47ce409fe4b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -119,37 +119,15 @@ describe User, models: true do it { is_expected.to validate_length_of(:bio).is_within(0..255) } - describe 'email' do - it 'accepts info@example.com' do - user = build(:user, email: 'info@example.com') - expect(user).to be_valid - end - - it 'accepts info+test@example.com' do - user = build(:user, email: 'info+test@example.com') - expect(user).to be_valid - end - - it "accepts o'reilly@example.com" do - user = build(:user, email: "o'reilly@example.com") - expect(user).to be_valid - end - - it 'rejects test@test@example.com' do - user = build(:user, email: 'test@test@example.com') - expect(user).to be_invalid - end - - it 'rejects mailto:test@example.com' do - user = build(:user, email: 'mailto:test@example.com') - expect(user).to be_invalid - end + it_behaves_like 'an object with email-formated attributes', :email do + subject { build(:user) } + end - it "rejects lol!'+=?><#$%^&*()@gmail.com" do - user = build(:user, email: "lol!'+=?><#$%^&*()@gmail.com") - expect(user).to be_invalid - end + it_behaves_like 'an object with email-formated attributes', :public_email, :notification_email do + subject { build(:user).tap { |user| user.emails << build(:email, email: email_value) } } + end + describe 'email' do context 'when no signup domains listed' do before { allow(current_application_settings).to receive(:restricted_signup_domains).and_return([]) } it 'accepts any email' do diff --git a/spec/support/email_format_shared_examples.rb b/spec/support/email_format_shared_examples.rb new file mode 100644 index 00000000000..b924a208e71 --- /dev/null +++ b/spec/support/email_format_shared_examples.rb @@ -0,0 +1,44 @@ +# Specifications for behavior common to all objects with an email attribute. +# Takes a list of email-format attributes and requires: +# - subject { "the object with a attribute= setter" } +# Note: You have access to `email_value` which is the email address value +# being currently tested). + +shared_examples 'an object with email-formated attributes' do |*attributes| + attributes.each do |attribute| + describe "specifically its :#{attribute} attribute" do + %w[ + info@example.com + info+test@example.com + o'reilly@example.com + mailto:test@example.com + lol!'+=?><#$%^&*()@gmail.com + ].each do |valid_email| + context "with a value of '#{valid_email}'" do + let(:email_value) { valid_email } + + it 'is valid' do + subject.send("#{attribute}=", valid_email) + + expect(subject).to be_valid + end + end + end + + %w[ + foobar + test@test@example.com + ].each do |invalid_email| + context "with a value of '#{invalid_email}'" do + let(:email_value) { invalid_email } + + it 'is invalid' do + subject.send("#{attribute}=", invalid_email) + + expect(subject).to be_invalid + end + end + end + end + end +end -- cgit v1.2.3 From d146d9fd8345afbeb12c2f4184d62213023bc98c Mon Sep 17 00:00:00 2001 From: Bram Daams Date: Sun, 18 Oct 2015 00:11:36 +0200 Subject: Add assignee data to Issuables' hook_data --- spec/models/concerns/issuable_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec') diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 021d62cdf0c..8f09ff03a78 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -79,6 +79,16 @@ describe Issue, "Issuable" do expect(hook_data[:repository][:description]).to eq(issue.project.description) expect(hook_data[:repository][:homepage]).to eq(issue.project.web_url) expect(hook_data[:object_attributes]).to eq(issue.hook_attrs) + expect(hook_data).to_not have_key(:assignee) + end + + context "issue is assigned" do + before { issue.update_attribute(:assignee, user) } + + it "returns correct hook data" do + expect(hook_data[:object_attributes]['assignee_id']).to eq(user.id) + expect(hook_data[:assignee]).to eq(user.hook_attrs) + end end end -- cgit v1.2.3 From 78e36780be31257a59cb3076ba5402e380ca240f Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Sun, 31 Jan 2016 11:05:47 +0200 Subject: Added '/api/v3/projects/:id/merge_requests/:merge_request_id/closes_issues' route in the API Added some documentation for it Added to changelog Added curl example and an attribute table Moved the api route definition from "lib/api/issues.rb" to "lib/api/merge_requests.rb" Fixed the attributes and changed the documentation to be at "merge_requests.md" too Changed generic titles to more specific titles added an underscore added tests. it depends on a newer version of gitlab-test project I'm doing a since I need to add a branch to the `gitlab-test` repo removed the before using 'iid' instead of 'id' in the description to reference the issues. that makes the tests pass Removed the 'closes-issues' key from test_env. so it should pass the tests Moved the two initializations to the describe block Changed the changelog --- spec/factories/merge_requests.rb | 6 ++++++ spec/requests/api/merge_requests_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'spec') diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 0c6a881f868..777bdb95008 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -73,6 +73,12 @@ FactoryGirl.define do merge_user author end + trait :with_closes_issues do + source_branch "markdown" + target_branch "master" + state :opened + end + factory :closed_merge_request, traits: [:closed] factory :reopened_merge_request, traits: [:reopened] factory :merge_request_with_diffs, traits: [:with_diffs] diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index d7bfa17b0b1..90faf82fc01 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -448,6 +448,32 @@ describe API::API, api: true do end end + describe "GET :id/merge_requests/:merge_request_id/closes_issues" do + let(:merge_request_with_closes_issues) { create(:merge_request, :with_closes_issues, author: user, assignee: user, source_project: project, target_project: project, title: "Closed ##{issue.id}", created_at: base_time + 3.seconds, description: "This should close ##{issue.iid}") } + let(:issue) do + create :issue, + author: user, + assignee: user, + project: project, + milestone: nil + end + + it "should return the issues that will be closed on merge" do + get api("/projects/#{project.id}/merge_requests/#{merge_request_with_closes_issues.id}/closes_issues", user) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + expect(json_response.length).to eq(1) + expect(json_response.first['id']).to eq(issue.id) + end + + it "should return an empty array when there are no issues to be closed" do + get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user) + expect(response.status).to eq(200) + expect(json_response).to be_an Array + expect(json_response.length).to eq(0) + end + end + def mr_with_later_created_and_updated_at_time merge_request merge_request.created_at += 1.hour -- cgit v1.2.3 From b91d1890a8f33566d52c653e9ae083a3a3329590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 10 Feb 2016 17:11:23 +0100 Subject: Pass current_user to merge_request.closes_issues in API ans streamline MR API specs --- spec/factories/merge_requests.rb | 6 ------ spec/requests/api/merge_requests_spec.rb | 20 ++++++++------------ 2 files changed, 8 insertions(+), 18 deletions(-) (limited to 'spec') diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 777bdb95008..0c6a881f868 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -73,12 +73,6 @@ FactoryGirl.define do merge_user author end - trait :with_closes_issues do - source_branch "markdown" - target_branch "master" - state :opened - end - factory :closed_merge_request, traits: [:closed] factory :reopened_merge_request, traits: [:reopened] factory :merge_request_with_diffs, traits: [:with_diffs] diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 90faf82fc01..7a722777d59 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -448,25 +448,21 @@ describe API::API, api: true do end end - describe "GET :id/merge_requests/:merge_request_id/closes_issues" do - let(:merge_request_with_closes_issues) { create(:merge_request, :with_closes_issues, author: user, assignee: user, source_project: project, target_project: project, title: "Closed ##{issue.id}", created_at: base_time + 3.seconds, description: "This should close ##{issue.iid}") } - let(:issue) do - create :issue, - author: user, - assignee: user, - project: project, - milestone: nil - end + describe 'GET :id/merge_requests/:merge_request_id/closes_issues' do + it 'returns the issue that will be closed on merge' do + issue = create(:issue, project: project) + mr = merge_request.tap do |mr| + mr.update_attribute(:description, "Closes #{issue.to_reference(mr.project)}") + end - it "should return the issues that will be closed on merge" do - get api("/projects/#{project.id}/merge_requests/#{merge_request_with_closes_issues.id}/closes_issues", user) + get api("/projects/#{project.id}/merge_requests/#{mr.id}/closes_issues", user) expect(response.status).to eq(200) expect(json_response).to be_an Array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(issue.id) end - it "should return an empty array when there are no issues to be closed" do + it 'returns an empty array when there are no issues to be closed' do get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user) expect(response.status).to eq(200) expect(json_response).to be_an Array -- cgit v1.2.3