diff options
Diffstat (limited to 'spec')
30 files changed, 600 insertions, 219 deletions
diff --git a/spec/factories.rb b/spec/factories.rb index f7f65bffb8b..a960571206c 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -39,10 +39,10 @@ FactoryGirl.define do owner end - factory :users_project do + factory :project_member do user project - project_access { UsersProject::MASTER } + access_level { ProjectMember::MASTER } end factory :issue do diff --git a/spec/factories/users_groups.rb b/spec/factories/group_members.rb index 49c3a367e16..debb86d997f 100644 --- a/spec/factories/users_groups.rb +++ b/spec/factories/group_members.rb @@ -1,6 +1,6 @@ # == Schema Information # -# Table name: users_groups +# Table name: group_members # # id :integer not null, primary key # group_access :integer not null @@ -12,8 +12,8 @@ # FactoryGirl.define do - factory :users_group do - group_access { UsersGroup::OWNER } + factory :group_member do + access_level { GroupMember::OWNER } group user end diff --git a/spec/features/atom/dashboard_spec.rb b/spec/features/atom/dashboard_spec.rb index e5d9f8ab5d5..a72a41fdf39 100644 --- a/spec/features/atom/dashboard_spec.rb +++ b/spec/features/atom/dashboard_spec.rb @@ -10,5 +10,34 @@ describe "Dashboard Feed", feature: true do page.body.should have_selector("feed title") end end + + context 'feed content' do + let(:project) { create(:project) } + let(:issue) { create(:issue, project: project, author: user, description: '') } + let(:note) { create(:note, noteable: issue, author: user, note: 'Bug confirmed', project: project) } + + before do + project.team << [user, :master] + issue_event(issue, user) + note_event(note, user) + visit dashboard_path(:atom, private_token: user.private_token) + end + + it "should have issue opened event" do + page.body.should have_content("#{user.name} opened issue ##{issue.iid}") + end + + it "should have issue comment event" do + page.body.should have_content("#{user.name} commented on issue ##{issue.iid}") + end + end + end + + def issue_event(issue, user) + EventCreateService.new.open_issue(issue, user) + end + + def note_event(note, user) + EventCreateService.new.leave_note(note, user) end end diff --git a/spec/features/notes_on_merge_requests_spec.rb b/spec/features/notes_on_merge_requests_spec.rb index 47776ba7f3f..92f3a6c0929 100644 --- a/spec/features/notes_on_merge_requests_spec.rb +++ b/spec/features/notes_on_merge_requests_spec.rb @@ -133,7 +133,7 @@ describe 'Comments' do describe "when adding a note" do before do - find("a[data-line-code=\"#{line_code}\"]").click + click_diff_line end describe "the notes holder" do @@ -144,7 +144,7 @@ describe 'Comments' do describe "the note form" do it "shouldn't add a second form for same row" do - find("a[data-line-code=\"#{line_code}\"]").click + click_diff_line should have_css("tr[id='#{line_code}'] + .js-temp-notes-holder form", count: 1) end @@ -161,8 +161,8 @@ describe 'Comments' do describe "with muliple note forms" do before do - find("a[data-line-code=\"#{line_code}\"]").click - find("a[data-line-code=\"#{line_code_2}\"]").click + click_diff_line + click_diff_line(line_code_2) end it { should have_css(".js-temp-notes-holder", count: 2) } @@ -193,7 +193,7 @@ describe 'Comments' do should have_content("Another comment on line 10") should have_css(".notes_holder") should have_css(".notes_holder .note", count: 1) - should have_link("Reply") + should have_button('Reply') end end end @@ -206,4 +206,9 @@ describe 'Comments' do def line_code_2 sample_compare.changes.last[:line_code] end + + def click_diff_line(data = nil) + data ||= line_code + find("button[data-line-code=\"#{data}\"]").click + end end diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index ba6af6f8b45..46337f8bafd 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -12,7 +12,7 @@ describe GitlabMarkdownHelper do let(:issue) { create(:issue, project: project) } let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let(:snippet) { create(:project_snippet, project: project) } - let(:member) { project.users_projects.where(user_id: user).first } + let(:member) { project.project_members.where(user_id: user).first } before do # Helper expects a @project instance variable diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb new file mode 100644 index 00000000000..570b03827a8 --- /dev/null +++ b/spec/lib/gitlab/git_access_spec.rb @@ -0,0 +1,127 @@ +require 'spec_helper' + +describe Gitlab::GitAccess do + let(:access) { Gitlab::GitAccess.new } + let(:project) { create(:project) } + let(:user) { create(:user) } + + describe 'download_allowed?' do + describe 'master permissions' do + before { project.team << [user, :master] } + + context 'pull code' do + subject { access.download_allowed?(user, project) } + + it { should be_true } + end + end + + describe 'guest permissions' do + before { project.team << [user, :guest] } + + context 'pull code' do + subject { access.download_allowed?(user, project) } + + it { should be_false } + end + end + + describe 'blocked user' do + before do + project.team << [user, :master] + user.block + end + + context 'pull code' do + subject { access.download_allowed?(user, project) } + + it { should be_false } + end + end + + describe 'without acccess to project' do + context 'pull code' do + subject { access.download_allowed?(user, project) } + + it { should be_false } + end + end + end + + describe 'push_allowed?' do + def protect_feature_branch + create(:protected_branch, name: 'feature', project: project) + end + + def changes + { + push_new_branch: '000000000 570e7b2ab refs/heads/wow', + push_master: '6f6d7e7ed 570e7b2ab refs/heads/master', + push_protected_branch: '6f6d7e7ed 570e7b2ab refs/heads/feature', + push_remove_protected_branch: '570e7b2ab 000000000 refs/heads/feature', + push_tag: '6f6d7e7ed 570e7b2ab refs/tags/v1.0.0', + push_new_tag: '000000000 570e7b2ab refs/tags/v7.8.9', + push_all: ['6f6d7e7ed 570e7b2ab refs/heads/master', '6f6d7e7ed 570e7b2ab refs/heads/feature'] + } + end + + def self.permissions_matrix + { + master: { + push_new_branch: true, + push_master: true, + push_protected_branch: true, + push_remove_protected_branch: false, + push_tag: true, + push_new_tag: true, + push_all: true, + }, + + developer: { + push_new_branch: true, + push_master: true, + push_protected_branch: false, + push_remove_protected_branch: false, + push_tag: false, + push_new_tag: true, + push_all: false, + }, + + reporter: { + push_new_branch: false, + push_master: false, + push_protected_branch: false, + push_remove_protected_branch: false, + push_tag: false, + push_new_tag: false, + push_all: false, + }, + + guest: { + push_new_branch: false, + push_master: false, + push_protected_branch: false, + push_remove_protected_branch: false, + push_tag: false, + push_new_tag: false, + push_all: false, + } + } + end + + permissions_matrix.keys.each do |role| + describe "#{role} access" do + before { protect_feature_branch } + before { project.team << [user, role] } + + permissions_matrix[role].each do |action, allowed| + context action do + subject { access.push_allowed?(user, project, changes[action]) } + + it { should allowed ? be_true : be_false } + end + end + end + end + end +end diff --git a/spec/lib/gitlab/satellite/action_spec.rb b/spec/lib/gitlab/satellite/action_spec.rb index 0622caf1e3b..2af1e9e32f9 100644 --- a/spec/lib/gitlab/satellite/action_spec.rb +++ b/spec/lib/gitlab/satellite/action_spec.rb @@ -59,7 +59,7 @@ describe 'Gitlab::Satellite::Action' do called = false #set assumptions - File.rm(project.satellite.lock_file) unless !File.exists? project.satellite.lock_file + FileUtils.rm_f(project.satellite.lock_file) File.exists?(project.satellite.lock_file).should be_false diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 702431e0712..799dce442cc 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -402,10 +402,10 @@ describe Notify do describe 'project access changed' do let(:project) { create(:project) } let(:user) { create(:user) } - let(:users_project) { create(:users_project, + let(:project_member) { create(:project_member, project: project, user: user) } - subject { Notify.project_access_granted_email(users_project.id) } + subject { Notify.project_access_granted_email(project_member.id) } it_behaves_like 'an email sent from GitLab' @@ -416,7 +416,7 @@ describe Notify do should have_body_text /#{project.name}/ end it 'contains new user role' do - should have_body_text /#{users_project.human_access}/ + should have_body_text /#{project_member.human_access}/ end end @@ -506,7 +506,7 @@ describe Notify do describe 'group access changed' do let(:group) { create(:group) } let(:user) { create(:user) } - let(:membership) { create(:users_group, group: group, user: user) } + let(:membership) { create(:group_member, group: group, user: user) } subject { Notify.group_access_granted_email(membership.id) } diff --git a/spec/models/users_group_spec.rb b/spec/models/group_member_spec.rb index 0b6f7a08198..6acbc9bb4ae 100644 --- a/spec/models/users_group_spec.rb +++ b/spec/models/group_member_spec.rb @@ -1,9 +1,9 @@ # == Schema Information # -# Table name: users_groups +# Table name: group_members # # id :integer not null, primary key -# group_access :integer not null +# access_level :integer not null # group_id :integer not null # user_id :integer not null # created_at :datetime @@ -13,34 +13,11 @@ require 'spec_helper' -describe UsersGroup do - describe "Associations" do - it { should belong_to(:group) } - it { should belong_to(:user) } - end - - describe "Mass assignment" do - end - - describe "Validation" do - let!(:users_group) { create(:users_group) } - - it { should validate_presence_of(:user_id) } - it { should validate_uniqueness_of(:user_id).scoped_to(:group_id).with_message(/already exists/) } - - it { should validate_presence_of(:group_id) } - it { should ensure_inclusion_of(:group_access).in_array(UsersGroup.group_access_roles.values) } - end - - describe "Delegate methods" do - it { should respond_to(:user_name) } - it { should respond_to(:user_email) } - end - +describe GroupMember do context 'notification' do describe "#after_create" do it "should send email to user" do - membership = build(:users_group) + membership = build(:group_member) membership.stub(notification_service: double('NotificationService').as_null_object) membership.should_receive(:notification_service) membership.save @@ -49,18 +26,18 @@ describe UsersGroup do describe "#after_update" do before do - @membership = create :users_group + @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(:group_access, UsersGroup::MASTER) + @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(:group_access, UsersGroup::OWNER) + @membership.update_attribute(:access_level, GroupMember::OWNER) end end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 8259ed88d83..1d4ba8a2b85 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -20,7 +20,7 @@ describe Group do describe "Associations" do it { should have_many :projects } - it { should have_many :users_groups } + it { should have_many :group_members } end it { should validate_presence_of :name } @@ -39,26 +39,26 @@ describe Group do describe :add_users do let(:user) { create(:user) } - before { group.add_user(user, UsersGroup::MASTER) } + before { group.add_user(user, GroupMember::MASTER) } - it { group.users_groups.masters.map(&:user).should include(user) } + it { group.group_members.masters.map(&:user).should include(user) } end describe :add_users do let(:user) { create(:user) } - before { group.add_users([user.id], UsersGroup::GUEST) } + before { group.add_users([user.id], GroupMember::GUEST) } it "should update the group permission" do - group.users_groups.guests.map(&:user).should include(user) - group.add_users([user.id], UsersGroup::DEVELOPER) - group.users_groups.developers.map(&:user).should include(user) - group.users_groups.guests.map(&:user).should_not include(user) + group.group_members.guests.map(&:user).should include(user) + group.add_users([user.id], GroupMember::DEVELOPER) + group.group_members.developers.map(&:user).should include(user) + group.group_members.guests.map(&:user).should_not include(user) end end describe :avatar_type do let(:user) { create(:user) } - before { group.add_user(user, UsersGroup::MASTER) } + before { group.add_user(user, GroupMember::MASTER) } it "should be true if avatar is image" do group.update_attribute(:avatar, 'uploads/avatar.png') diff --git a/spec/models/members_spec.rb b/spec/models/members_spec.rb new file mode 100644 index 00000000000..6866c4794c2 --- /dev/null +++ b/spec/models/members_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Member do + describe "Associations" do + it { should belong_to(:user) } + end + + describe "Validation" do + subject { Member.new(access_level: Member::GUEST) } + + it { should validate_presence_of(:user) } + it { should validate_presence_of(:source) } + it { should ensure_inclusion_of(:access_level).in_array(Gitlab::Access.values) } + end + + describe "Delegate methods" do + it { should respond_to(:user_name) } + it { should respond_to(:user_email) } + end +end diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index d06dee6ce92..da51100e0d7 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -321,8 +321,8 @@ describe Note do describe :read do before do - @p1.users_projects.create(user: @u2, project_access: UsersProject::GUEST) - @p2.users_projects.create(user: @u3, project_access: UsersProject::GUEST) + @p1.project_members.create(user: @u2, access_level: ProjectMember::GUEST) + @p2.project_members.create(user: @u3, access_level: ProjectMember::GUEST) end it { @abilities.allowed?(@u1, :read_note, @p1).should be_false } @@ -332,8 +332,8 @@ describe Note do describe :write do before do - @p1.users_projects.create(user: @u2, project_access: UsersProject::DEVELOPER) - @p2.users_projects.create(user: @u3, project_access: UsersProject::DEVELOPER) + @p1.project_members.create(user: @u2, access_level: ProjectMember::DEVELOPER) + @p2.project_members.create(user: @u3, access_level: ProjectMember::DEVELOPER) end it { @abilities.allowed?(@u1, :write_note, @p1).should be_false } @@ -343,9 +343,9 @@ describe Note do describe :admin do before do - @p1.users_projects.create(user: @u1, project_access: UsersProject::REPORTER) - @p1.users_projects.create(user: @u2, project_access: UsersProject::MASTER) - @p2.users_projects.create(user: @u3, project_access: UsersProject::MASTER) + @p1.project_members.create(user: @u1, access_level: ProjectMember::REPORTER) + @p1.project_members.create(user: @u2, access_level: ProjectMember::MASTER) + @p2.project_members.create(user: @u3, access_level: ProjectMember::MASTER) end it { @abilities.allowed?(@u1, :admin_note, @p1).should be_false } diff --git a/spec/models/users_project_spec.rb b/spec/models/project_member_spec.rb index 3f38164e964..0178d065e57 100644 --- a/spec/models/users_project_spec.rb +++ b/spec/models/project_member_spec.rb @@ -1,6 +1,6 @@ # == Schema Information # -# Table name: users_projects +# Table name: project_members # # id :integer not null, primary key # user_id :integer not null @@ -13,30 +13,7 @@ require 'spec_helper' -describe UsersProject do - describe "Associations" do - it { should belong_to(:project) } - it { should belong_to(:user) } - end - - describe "Mass assignment" do - end - - describe "Validation" do - let!(:users_project) { create(:users_project) } - - it { should validate_presence_of(:user) } - it { should validate_uniqueness_of(:user_id).scoped_to(:project_id).with_message(/already exists/) } - - it { should validate_presence_of(:project) } - it { should ensure_inclusion_of(:project_access).in_array(UsersProject.access_roles.values) } - end - - describe "Delegate methods" do - it { should respond_to(:user_name) } - it { should respond_to(:user_email) } - end - +describe ProjectMember do describe :import_team do before do @abilities = Six.new @@ -78,10 +55,10 @@ describe UsersProject do @user_1 = create :user @user_2 = create :user - UsersProject.add_users_into_projects( + ProjectMember.add_users_into_projects( [@project_1.id, @project_2.id], [@user_1.id, @user_2.id], - UsersProject::MASTER + ProjectMember::MASTER ) end @@ -104,7 +81,7 @@ describe UsersProject do @project_1.team << [ @user_1, :developer] @project_2.team << [ @user_2, :reporter] - UsersProject.truncate_teams([@project_1.id, @project_2.id]) + ProjectMember.truncate_teams([@project_1.id, @project_2.id]) end it { @project_1.users.should be_empty } diff --git a/spec/models/project_security_spec.rb b/spec/models/project_security_spec.rb index 1f2bd7a56ff..5c8d1e7438b 100644 --- a/spec/models/project_security_spec.rb +++ b/spec/models/project_security_spec.rb @@ -30,7 +30,7 @@ describe Project do describe "Guest Rules" do before do - @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::GUEST) + @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::GUEST) end it "should allow for project user any guest actions" do @@ -42,7 +42,7 @@ describe Project do describe "Report Rules" do before do - @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::REPORTER) + @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER) end it "should allow for project user any report actions" do @@ -54,8 +54,8 @@ describe Project do describe "Developer Rules" do before do - @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::REPORTER) - @p1.users_projects.create(project: @p1, user: @u3, project_access: UsersProject::DEVELOPER) + @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::REPORTER) + @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::DEVELOPER) end it "should deny for developer master-specific actions" do @@ -73,8 +73,8 @@ describe Project do describe "Master Rules" do before do - @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::DEVELOPER) - @p1.users_projects.create(project: @p1, user: @u3, project_access: UsersProject::MASTER) + @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::DEVELOPER) + @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER) end it "should deny for developer master-specific actions" do @@ -92,8 +92,8 @@ describe Project do describe "Admin Rules" do before do - @p1.users_projects.create(project: @p1, user: @u2, project_access: UsersProject::DEVELOPER) - @p1.users_projects.create(project: @p1, user: @u3, project_access: UsersProject::MASTER) + @p1.project_members.create(project: @p1, user: @u2, access_level: ProjectMember::DEVELOPER) + @p1.project_members.create(project: @p1, user: @u3, access_level: ProjectMember::MASTER) end it "should deny for masters admin-specific actions" do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1c11ac39567..524cab2b925 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -38,7 +38,7 @@ describe Project do it { should have_many(:merge_requests).dependent(:destroy) } it { should have_many(:issues).dependent(:destroy) } it { should have_many(:milestones).dependent(:destroy) } - it { should have_many(:users_projects).dependent(:destroy) } + it { should have_many(:project_members).dependent(:destroy) } it { should have_many(:notes).dependent(:destroy) } it { should have_many(:snippets).class_name('ProjectSnippet').dependent(:destroy) } it { should have_many(:deploy_keys_projects).dependent(:destroy) } @@ -144,6 +144,62 @@ describe Project do end end + describe 'comment merge requests with commits' do + before do + @user = create(:user) + group = create(:group) + group.add_owner(@user) + + @project = create(:project, namespace: group) + @fork_project = Projects::ForkService.new(@project, @user).execute + @merge_request = create(:merge_request, source_project: @project, + source_branch: 'master', + target_branch: 'feature', + target_project: @project) + @fork_merge_request = create(:merge_request, source_project: @fork_project, + source_branch: 'master', + target_branch: 'feature', + target_project: @project) + + @commits = @merge_request.commits + end + + context 'push to origin repo source branch' do + before do + @project.comment_mr_with_commits('master', @commits, @user) + end + + it { @merge_request.notes.should_not be_empty } + it { @fork_merge_request.notes.should be_empty } + end + + context 'push to origin repo target branch' do + before do + @project.comment_mr_with_commits('feature', @commits, @user) + end + + it { @merge_request.notes.should be_empty } + it { @fork_merge_request.notes.should be_empty } + end + + context 'push to fork repo source branch' do + before do + @fork_project.comment_mr_with_commits('master', @commits, @user) + end + + it { @merge_request.notes.should be_empty } + it { @fork_merge_request.notes.should_not be_empty } + end + + context 'push to fork repo target branch' do + before do + @fork_project.comment_mr_with_commits('feature', @commits, @user) + end + + it { @merge_request.notes.should be_empty } + it { @fork_merge_request.notes.should be_empty } + end + end describe :find_with_namespace do context 'with namespace' do diff --git a/spec/models/system_hook_spec.rb b/spec/models/system_hook_spec.rb index 2b98acdeb6c..4ab5261dc9d 100644 --- a/spec/models/system_hook_spec.rb +++ b/spec/models/system_hook_spec.rb @@ -58,7 +58,7 @@ describe SystemHook do user = create(:user) project = create(:project) project.team << [user, :master] - project.users_projects.destroy_all + project.project_members.destroy_all WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 7221328a45f..0250014bc21 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -52,7 +52,7 @@ describe User do describe "Associations" do it { should have_one(:namespace) } it { should have_many(:snippets).class_name('Snippet').dependent(:destroy) } - it { should have_many(:users_projects).dependent(:destroy) } + it { should have_many(:project_members).dependent(:destroy) } it { should have_many(:groups) } it { should have_many(:keys).dependent(:destroy) } it { should have_many(:events).class_name('Event').dependent(:destroy) } @@ -182,7 +182,7 @@ describe User do @group = create :group @group.add_owner(@user) - @group.add_user(@user2, UsersGroup::OWNER) + @group.add_user(@user2, GroupMember::OWNER) end it { @user2.several_namespaces?.should be_true } diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index e7f91c5e46e..caded2c9289 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -7,8 +7,8 @@ describe API::API, api: true do let(:user) { create(:user) } let(:user2) { create(:user) } let!(:project) { create(:project, creator_id: user.id) } - let!(:master) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } - let!(:guest) { create(:users_project, user: user2, project: project, project_access: UsersProject::GUEST) } + let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) } + let!(:guest) { create(:project_member, user: user2, project: project, access_level: ProjectMember::GUEST) } let!(:branch_name) { 'feature' } let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index b56269d275d..38e0a284c36 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -6,8 +6,8 @@ describe API::API, api: true do let(:user) { create(:user) } let(:user2) { create(:user) } let!(:project) { create(:project, creator_id: user.id) } - let!(:master) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } - let!(:guest) { create(:users_project, user: user2, project: project, project_access: UsersProject::GUEST) } + let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) } + let!(:guest) { create(:project_member, user: user2, project: project, access_level: ProjectMember::GUEST) } before { project.team << [user, :reporter] } diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb index f27a60e4bc0..42ccad71aaf 100644 --- a/spec/requests/api/groups_spec.rb +++ b/spec/requests/api/groups_spec.rb @@ -174,10 +174,10 @@ describe API::API, api: true do let(:guest) { create(:user) } let!(:group_with_members) do group = create(:group) - group.add_users([reporter.id], UsersGroup::REPORTER) - group.add_users([developer.id], UsersGroup::DEVELOPER) - group.add_users([master.id], UsersGroup::MASTER) - group.add_users([guest.id], UsersGroup::GUEST) + group.add_users([reporter.id], GroupMember::REPORTER) + group.add_users([developer.id], GroupMember::DEVELOPER) + group.add_users([master.id], GroupMember::MASTER) + group.add_users([guest.id], GroupMember::GUEST) group end let!(:group_no_members) { create(:group) } @@ -195,11 +195,11 @@ describe API::API, api: true do response.status.should == 200 json_response.should be_an Array json_response.size.should == 5 - json_response.find { |e| e['id']==owner.id }['access_level'].should == UsersGroup::OWNER - json_response.find { |e| e['id']==reporter.id }['access_level'].should == UsersGroup::REPORTER - json_response.find { |e| e['id']==developer.id }['access_level'].should == UsersGroup::DEVELOPER - json_response.find { |e| e['id']==master.id }['access_level'].should == UsersGroup::MASTER - json_response.find { |e| e['id']==guest.id }['access_level'].should == UsersGroup::GUEST + json_response.find { |e| e['id']==owner.id }['access_level'].should == GroupMember::OWNER + json_response.find { |e| e['id']==reporter.id }['access_level'].should == GroupMember::REPORTER + json_response.find { |e| e['id']==developer.id }['access_level'].should == GroupMember::DEVELOPER + json_response.find { |e| e['id']==master.id }['access_level'].should == GroupMember::MASTER + json_response.find { |e| e['id']==guest.id }['access_level'].should == GroupMember::GUEST end end @@ -213,29 +213,29 @@ describe API::API, api: true do describe "POST /groups/:id/members" do context "when not a member of the group" do it "should not add guest as member of group_no_members when adding being done by person outside the group" do - post api("/groups/#{group_no_members.id}/members", reporter), user_id: guest.id, access_level: UsersGroup::MASTER + post api("/groups/#{group_no_members.id}/members", reporter), user_id: guest.id, access_level: GroupMember::MASTER response.status.should == 403 end end context "when a member of the group" do it "should return ok and add new member" do - count_before=group_no_members.users_groups.count + count_before=group_no_members.group_members.count new_user = create(:user) - post api("/groups/#{group_no_members.id}/members", owner), user_id: new_user.id, access_level: UsersGroup::MASTER + post api("/groups/#{group_no_members.id}/members", owner), user_id: new_user.id, access_level: GroupMember::MASTER response.status.should == 201 json_response['name'].should == new_user.name - json_response['access_level'].should == UsersGroup::MASTER - group_no_members.users_groups.count.should == count_before + 1 + json_response['access_level'].should == GroupMember::MASTER + group_no_members.group_members.count.should == count_before + 1 end it "should return error if member already exists" do - post api("/groups/#{group_with_members.id}/members", owner), user_id: master.id, access_level: UsersGroup::MASTER + post api("/groups/#{group_with_members.id}/members", owner), user_id: master.id, access_level: GroupMember::MASTER response.status.should == 409 end it "should return a 400 error when user id is not given" do - post api("/groups/#{group_no_members.id}/members", owner), access_level: UsersGroup::MASTER + post api("/groups/#{group_no_members.id}/members", owner), access_level: GroupMember::MASTER response.status.should == 400 end @@ -262,10 +262,10 @@ describe API::API, api: true do context "when a member of the group" do it "should delete guest's membership of group" do - count_before=group_with_members.users_groups.count + count_before=group_with_members.group_members.count delete api("/groups/#{group_with_members.id}/members/#{guest.id}", owner) response.status.should == 200 - group_with_members.users_groups.count.should == count_before - 1 + group_with_members.group_members.count.should == count_before - 1 end it "should return a 404 error when user id is not known" do diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index e8eebda95b4..9876452f81d 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -169,6 +169,15 @@ describe API::API, api: true do response.status.should == 400 json_response['message']['labels']['?']['title'].should == ['is invalid'] end + + it 'should return 400 if title is too long' do + post api("/projects/#{project.id}/issues", user), + title: 'g' * 256 + response.status.should == 400 + json_response['message']['title'].should == [ + 'is too long (maximum is 255 characters)' + ] + end end describe "PUT /projects/:id/issues/:issue_id to update only title" do @@ -237,6 +246,15 @@ describe API::API, api: true do json_response['labels'].should include 'label_bar' json_response['labels'].should include 'label/bar' end + + it 'should return 400 if title is too long' do + put api("/projects/#{project.id}/issues/#{issue.id}", user), + title: 'g' * 256 + response.status.should == 400 + json_response['message']['title'].should == [ + 'is too long (maximum is 255 characters)' + ] + end end describe "PUT /projects/:id/issues/:issue_id to update state and label" do diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb index ee9088933a1..dbddc8a7da4 100644 --- a/spec/requests/api/labels_spec.rb +++ b/spec/requests/api/labels_spec.rb @@ -47,7 +47,7 @@ describe API::API, api: true do name: 'Foo', color: '#FFAA' response.status.should == 400 - json_response['message'].should == 'Color is invalid' + json_response['message']['color'].should == ['is invalid'] end it 'should return 400 for too long color code' do @@ -55,7 +55,7 @@ describe API::API, api: true do name: 'Foo', color: '#FFAAFFFF' response.status.should == 400 - json_response['message'].should == 'Color is invalid' + json_response['message']['color'].should == ['is invalid'] end it 'should return 400 for invalid name' do @@ -63,7 +63,7 @@ describe API::API, api: true do name: '?', color: '#FFAABB' response.status.should == 400 - json_response['message'].should == 'Title is invalid' + json_response['message']['title'].should == ['is invalid'] end it 'should return 409 if label already exists' do @@ -84,7 +84,7 @@ describe API::API, api: true do it 'should return 404 for non existing label' do delete api("/projects/#{project.id}/labels", user), name: 'label2' response.status.should == 404 - json_response['message'].should == 'Label not found' + json_response['message'].should == '404 Label Not Found' end it 'should return 400 for wrong parameters' do @@ -132,11 +132,14 @@ describe API::API, api: true do it 'should return 400 if no label name given' do put api("/projects/#{project.id}/labels", user), new_name: 'label2' response.status.should == 400 + json_response['message'].should == '400 (Bad request) "name" not given' end it 'should return 400 if no new parameters given' do put api("/projects/#{project.id}/labels", user), name: 'label1' response.status.should == 400 + json_response['message'].should == 'Required parameters '\ + '"new_name" or "color" missing' end it 'should return 400 for invalid name' do @@ -145,7 +148,7 @@ describe API::API, api: true do new_name: '?', color: '#FFFFFF' response.status.should == 400 - json_response['message'].should == 'Title is invalid' + json_response['message']['title'].should == ['is invalid'] end it 'should return 400 for invalid name' do @@ -153,7 +156,7 @@ describe API::API, api: true do name: 'label1', color: '#FF' response.status.should == 400 - json_response['message'].should == 'Color is invalid' + json_response['message']['color'].should == ['is invalid'] end it 'should return 400 for too long color code' do @@ -161,7 +164,7 @@ describe API::API, api: true do name: 'Foo', color: '#FFAAFFFF' response.status.should == 400 - json_response['message'].should == 'Color is invalid' + json_response['message']['color'].should == ['is invalid'] end end end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index d39962670b1..5ba3a330991 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -163,6 +163,28 @@ describe API::API, api: true do json_response['message']['labels']['?']['title'].should == ['is invalid'] end + + context 'with existing MR' do + before do + post api("/projects/#{project.id}/merge_requests", user), + title: 'Test merge_request', + source_branch: 'stable', + target_branch: 'master', + author: user + @mr = MergeRequest.all.last + end + + it 'should return 409 when MR already exists for source/target' do + expect do + post api("/projects/#{project.id}/merge_requests", user), + title: 'New test merge_request', + source_branch: 'stable', + target_branch: 'master', + author: user + end.to change { MergeRequest.count }.by(0) + response.status.should == 409 + end + end end context 'forked projects' do @@ -210,16 +232,26 @@ describe API::API, api: true do response.status.should == 400 end - it "should return 404 when target_branch is specified and not a forked project" do - post api("/projects/#{project.id}/merge_requests", user), - title: 'Test merge_request', target_branch: 'master', source_branch: 'stable', author: user, target_project_id: fork_project.id - response.status.should == 404 - end + context 'when target_branch is specified' do + it 'should return 422 if not a forked project' do + post api("/projects/#{project.id}/merge_requests", user), + title: 'Test merge_request', + target_branch: 'master', + source_branch: 'stable', + author: user, + target_project_id: fork_project.id + response.status.should == 422 + end - it "should return 404 when target_branch is specified and for a different fork" do - post api("/projects/#{fork_project.id}/merge_requests", user2), - title: 'Test merge_request', target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: unrelated_project.id - response.status.should == 404 + it 'should return 422 if targeting a different fork' do + post api("/projects/#{fork_project.id}/merge_requests", user2), + title: 'Test merge_request', + target_branch: 'master', + source_branch: 'stable', + author: user2, + target_project_id: unrelated_project.id + response.status.should == 422 + end end it "should return 201 when target_branch is specified and for the same project" do @@ -256,7 +288,7 @@ describe API::API, api: true do merge_request.close put api("/projects/#{project.id}/merge_request/#{merge_request.id}/merge", user) response.status.should == 405 - json_response['message'].should == 'Method Not Allowed' + json_response['message'].should == '405 Method Not Allowed' end it "should return 401 if user has no permissions to merge" do @@ -316,7 +348,8 @@ describe API::API, api: true do end it "should return 404 if note is attached to non existent merge request" do - post api("/projects/#{project.id}/merge_request/111/comments", user), note: "My comment" + post api("/projects/#{project.id}/merge_request/404/comments", user), + note: 'My comment' response.status.should == 404 end end diff --git a/spec/requests/api/project_members_spec.rb b/spec/requests/api/project_members_spec.rb index 3c480c2ac4b..836f21f3e0b 100644 --- a/spec/requests/api/project_members_spec.rb +++ b/spec/requests/api/project_members_spec.rb @@ -6,12 +6,12 @@ describe API::API, api: true do let(:user2) { create(:user) } let(:user3) { create(:user) } let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) } - let(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } - let(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } + let(:project_member) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) } + let(:project_member2) { create(:project_member, user: user3, project: project, access_level: ProjectMember::DEVELOPER) } describe "GET /projects/:id/members" do - before { users_project } - before { users_project2 } + before { project_member } + before { project_member2 } it "should return project team members" do get api("/projects/#{project.id}/members", user) @@ -36,13 +36,13 @@ describe API::API, api: true do end describe "GET /projects/:id/members/:user_id" do - before { users_project } + before { project_member } it "should return project team member" do get api("/projects/#{project.id}/members/#{user.id}", user) response.status.should == 200 json_response['username'].should == user.username - json_response['access_level'].should == UsersProject::MASTER + json_response['access_level'].should == ProjectMember::MASTER end it "should return a 404 error if user id not found" do @@ -55,29 +55,29 @@ describe API::API, api: true do it "should add user to project team" do expect { post api("/projects/#{project.id}/members", user), user_id: user2.id, - access_level: UsersProject::DEVELOPER - }.to change { UsersProject.count }.by(1) + access_level: ProjectMember::DEVELOPER + }.to change { ProjectMember.count }.by(1) response.status.should == 201 json_response['username'].should == user2.username - json_response['access_level'].should == UsersProject::DEVELOPER + json_response['access_level'].should == ProjectMember::DEVELOPER end it "should return a 201 status if user is already project member" do post api("/projects/#{project.id}/members", user), user_id: user2.id, - access_level: UsersProject::DEVELOPER + access_level: ProjectMember::DEVELOPER expect { post api("/projects/#{project.id}/members", user), user_id: user2.id, - access_level: UsersProject::DEVELOPER - }.not_to change { UsersProject.count }.by(1) + access_level: ProjectMember::DEVELOPER + }.not_to change { ProjectMember.count }.by(1) response.status.should == 201 json_response['username'].should == user2.username - json_response['access_level'].should == UsersProject::DEVELOPER + json_response['access_level'].should == ProjectMember::DEVELOPER end it "should return a 400 error when user id is not given" do - post api("/projects/#{project.id}/members", user), access_level: UsersProject::MASTER + post api("/projects/#{project.id}/members", user), access_level: ProjectMember::MASTER response.status.should == 400 end @@ -93,17 +93,17 @@ describe API::API, api: true do end describe "PUT /projects/:id/members/:user_id" do - before { users_project2 } + before { project_member2 } it "should update project team member" do - put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: UsersProject::MASTER + put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER response.status.should == 200 json_response['username'].should == user3.username - json_response['access_level'].should == UsersProject::MASTER + json_response['access_level'].should == ProjectMember::MASTER end it "should return a 404 error if user_id is not found" do - put api("/projects/#{project.id}/members/1234", user), access_level: UsersProject::MASTER + put api("/projects/#{project.id}/members/1234", user), access_level: ProjectMember::MASTER response.status.should == 404 end @@ -119,20 +119,20 @@ describe API::API, api: true do end describe "DELETE /projects/:id/members/:user_id" do - before { users_project } - before { users_project2 } + before { project_member } + before { project_member2 } it "should remove user from project team" do expect { delete api("/projects/#{project.id}/members/#{user3.id}", user) - }.to change { UsersProject.count }.by(-1) + }.to change { ProjectMember.count }.by(-1) end it "should return 200 if team member is not part of a project" do delete api("/projects/#{project.id}/members/#{user3.id}", user) expect { delete api("/projects/#{project.id}/members/#{user3.id}", user) - }.to_not change { UsersProject.count }.by(1) + }.to_not change { ProjectMember.count }.by(1) end it "should return 200 if team member already removed" do @@ -144,7 +144,7 @@ describe API::API, api: true do it "should return 200 OK when the user was not member" do expect { delete api("/projects/#{project.id}/members/1000000", user) - }.to change { UsersProject.count }.by(0) + }.to change { ProjectMember.count }.by(0) response.status.should == 200 json_response['message'].should == "Access revoked" json_response['id'].should == 1000000 diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 058b831e783..571d8506277 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -8,8 +8,8 @@ describe API::API, api: true do let(:admin) { create(:admin) } let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) } let(:snippet) { create(:project_snippet, author: user, project: project, title: 'example') } - let(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } - let(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } + let(:project_member) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) } + let(:project_member2) { create(:project_member, user: user3, project: project, access_level: ProjectMember::DEVELOPER) } describe "GET /projects" do before { project } @@ -188,9 +188,24 @@ describe API::API, api: true do response.status.should == 201 end - it "should respond with 404 on failure" do + it 'should respond with 400 on failure' do post api("/projects/user/#{user.id}", admin) - response.status.should == 404 + response.status.should == 400 + json_response['message']['creator'].should == ['can\'t be blank'] + json_response['message']['namespace'].should == ['can\'t be blank'] + json_response['message']['name'].should == [ + 'can\'t be blank', + 'is too short (minimum is 0 characters)', + 'can contain only letters, digits, \'_\', \'-\' and \'.\' and '\ + 'space. It must start with letter, digit or \'_\'.' + ] + json_response['message']['path'].should == [ + 'can\'t be blank', + 'is too short (minimum is 0 characters)', + 'can contain only letters, digits, \'_\', \'-\' and \'.\'. It must '\ + 'start with letter, digit or \'_\', optionally preceeded by \'.\'. '\ + 'It must not end in \'.git\'.' + ] end it "should assign attributes to project" do @@ -254,7 +269,7 @@ describe API::API, api: true do describe "GET /projects/:id" do before { project } - before { users_project } + before { project_member } it "should return a project by id" do get api("/projects/#{project.id}", user) @@ -283,7 +298,10 @@ describe API::API, api: true do describe 'permissions' do context 'personal project' do - before { get api("/projects/#{project.id}", user) } + before do + project.team << [user, :master] + get api("/projects/#{project.id}", user) + end it { response.status.should == 200 } it { json_response['permissions']["project_access"]["access_level"].should == Gitlab::Access::MASTER } @@ -305,7 +323,7 @@ describe API::API, api: true do end describe "GET /projects/:id/events" do - before { users_project } + before { project_member } it "should return a project events" do get api("/projects/#{project.id}/events", user) @@ -407,9 +425,9 @@ describe API::API, api: true do response.status.should == 200 end - it "should return success when deleting unknown snippet id" do + it 'should return 404 when deleting unknown snippet id' do delete api("/projects/#{project.id}/snippets/1234", user) - response.status.should == 200 + response.status.should == 404 end end @@ -456,7 +474,21 @@ describe API::API, api: true do describe "POST /projects/:id/keys" do it "should not create an invalid ssh key" do post api("/projects/#{project.id}/keys", user), { title: "invalid key" } - response.status.should == 404 + response.status.should == 400 + json_response['message']['key'].should == [ + 'can\'t be blank', + 'is too short (minimum is 0 characters)', + 'is invalid' + ] + end + + it 'should not create a key without title' do + post api("/projects/#{project.id}/keys", user), key: 'some key' + response.status.should == 400 + json_response['message']['title'].should == [ + 'can\'t be blank', + 'is too short (minimum is 0 characters)' + ] end it "should create new ssh key" do diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index 17173aaeeac..a339dbfe9db 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -8,8 +8,8 @@ describe API::API, api: true do let(:user) { create(:user) } let(:user2) { create(:user) } let!(:project) { create(:project, creator_id: user.id) } - let!(:master) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } - let!(:guest) { create(:users_project, user: user2, project: project, project_access: UsersProject::GUEST) } + let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) } + let!(:guest) { create(:project_member, user: user2, project: project, access_level: ProjectMember::GUEST) } before { project.team << [user, :reporter] } diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 8bbe9b5b736..b0752ebe43c 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -51,6 +51,7 @@ describe API::API, api: true do it "should return a 404 error if user id not found" do get api("/users/9999", user) response.status.should == 404 + json_response['message'].should == '404 Not found' end end @@ -98,18 +99,47 @@ describe API::API, api: true do end it "should not create user with invalid email" do - post api("/users", admin), { email: "invalid email", password: 'password' } + post api('/users', admin), + email: 'invalid email', + password: 'password', + name: 'test' response.status.should == 400 end - it "should return 400 error if password not given" do - post api("/users", admin), { email: 'test@example.com' } + it 'should return 400 error if name not given' do + post api('/users', admin), email: 'test@example.com', password: 'pass1234' + response.status.should == 400 + end + + it 'should return 400 error if password not given' do + post api('/users', admin), email: 'test@example.com', name: 'test' response.status.should == 400 end it "should return 400 error if email not given" do - post api("/users", admin), { password: 'pass1234' } + post api('/users', admin), password: 'pass1234', name: 'test' + response.status.should == 400 + end + + it 'should return 400 error if user does not validate' do + post api('/users', admin), + password: 'pass', + email: 'test@example.com', + username: 'test!', + name: 'test', + bio: 'g' * 256, + projects_limit: -1 response.status.should == 400 + json_response['message']['password']. + should == ['is too short (minimum is 8 characters)'] + json_response['message']['bio']. + should == ['is too long (maximum is 255 characters)'] + json_response['message']['projects_limit']. + should == ['must be greater than or equal to 0'] + json_response['message']['username']. + should == ['can contain only letters, digits, '\ + '\'_\', \'-\' and \'.\'. It must start with letter, digit or '\ + '\'_\', optionally preceeded by \'.\'. It must not end in \'.git\'.'] end it "shouldn't available for non admin users" do @@ -117,21 +147,37 @@ describe API::API, api: true do response.status.should == 403 end - context "with existing user" do - before { post api("/users", admin), { email: 'test@example.com', password: 'password', username: 'test' } } + context 'with existing user' do + before do + post api('/users', admin), + email: 'test@example.com', + password: 'password', + username: 'test', + name: 'foo' + end - it "should not create user with same email" do + it 'should return 409 conflict error if user with same email exists' do expect { - post api("/users", admin), { email: 'test@example.com', password: 'password' } + post api('/users', admin), + name: 'foo', + email: 'test@example.com', + password: 'password', + username: 'foo' }.to change { User.count }.by(0) + response.status.should == 409 + json_response['message'].should == 'Email has already been taken' end - it "should return 409 conflict error if user with email exists" do - post api("/users", admin), { email: 'test@example.com', password: 'password' } - end - - it "should return 409 conflict error if same username exists" do - post api("/users", admin), { email: 'foo@example.com', password: 'pass', username: 'test' } + it 'should return 409 conflict error if same username exists' do + expect do + post api('/users', admin), + name: 'foo', + email: 'foo@example.com', + password: 'password', + username: 'test' + end.to change { User.count }.by(0) + response.status.should == 409 + json_response['message'].should == 'Username has already been taken' end end end @@ -173,6 +219,20 @@ describe API::API, api: true do user.reload.bio.should == 'new test bio' end + it 'should update user with his own email' do + put api("/users/#{user.id}", admin), email: user.email + response.status.should == 200 + json_response['email'].should == user.email + user.reload.email.should == user.email + end + + it 'should update user with his own username' do + put api("/users/#{user.id}", admin), username: user.username + response.status.should == 200 + json_response['username'].should == user.username + user.reload.username.should == user.username + end + it "should update admin status" do put api("/users/#{user.id}", admin), {admin: true} response.status.should == 200 @@ -190,7 +250,7 @@ describe API::API, api: true do it "should not allow invalid update" do put api("/users/#{user.id}", admin), {email: 'invalid email'} - response.status.should == 404 + response.status.should == 400 user.reload.email.should_not == 'invalid email' end @@ -202,25 +262,49 @@ describe API::API, api: true do it "should return 404 for non-existing user" do put api("/users/999999", admin), {bio: 'update should fail'} response.status.should == 404 + json_response['message'].should == '404 Not found' + end + + it 'should return 400 error if user does not validate' do + put api("/users/#{user.id}", admin), + password: 'pass', + email: 'test@example.com', + username: 'test!', + name: 'test', + bio: 'g' * 256, + projects_limit: -1 + response.status.should == 400 + json_response['message']['password']. + should == ['is too short (minimum is 8 characters)'] + json_response['message']['bio']. + should == ['is too long (maximum is 255 characters)'] + json_response['message']['projects_limit']. + should == ['must be greater than or equal to 0'] + json_response['message']['username']. + should == ['can contain only letters, digits, '\ + '\'_\', \'-\' and \'.\'. It must start with letter, digit or '\ + '\'_\', optionally preceeded by \'.\'. It must not end in \'.git\'.'] end context "with existing user" do before { post api("/users", admin), { email: 'test@example.com', password: 'password', username: 'test', name: 'test' } post api("/users", admin), { email: 'foo@bar.com', password: 'password', username: 'john', name: 'john' } - @user_id = User.all.last.id + @user = User.all.last } -# it "should return 409 conflict error if email address exists" do -# put api("/users/#{@user_id}", admin), { email: 'test@example.com' } -# response.status.should == 409 -# end -# -# it "should return 409 conflict error if username taken" do -# @user_id = User.all.last.id -# put api("/users/#{@user_id}", admin), { username: 'test' } -# response.status.should == 409 -# end + it 'should return 409 conflict error if email address exists' do + put api("/users/#{@user.id}", admin), email: 'test@example.com' + response.status.should == 409 + @user.reload.email.should == @user.email + end + + it 'should return 409 conflict error if username taken' do + @user_id = User.all.last.id + put api("/users/#{@user.id}", admin), username: 'test' + response.status.should == 409 + @user.reload.username.should == @user.username + end end end @@ -229,7 +313,14 @@ describe API::API, api: true do it "should not create invalid ssh key" do post api("/users/#{user.id}/keys", admin), { title: "invalid key" } - response.status.should == 404 + response.status.should == 400 + json_response['message'].should == '400 (Bad request) "key" not given' + end + + it 'should not create key without title' do + post api("/users/#{user.id}/keys", admin), key: 'some key' + response.status.should == 400 + json_response['message'].should == '400 (Bad request) "title" not given' end it "should create ssh key" do @@ -254,6 +345,7 @@ describe API::API, api: true do it 'should return 404 for non-existing user' do get api('/users/999999/keys', admin) response.status.should == 404 + json_response['message'].should == '404 User Not Found' end it 'should return array of ssh keys' do @@ -292,11 +384,13 @@ describe API::API, api: true do user.save delete api("/users/999999/keys/#{key.id}", admin) response.status.should == 404 + json_response['message'].should == '404 User Not Found' end it 'should return 404 error if key not foud' do delete api("/users/#{user.id}/keys/42", admin) response.status.should == 404 + json_response['message'].should == '404 Key Not Found' end end end @@ -324,6 +418,7 @@ describe API::API, api: true do it "should return 404 for non-existing user" do delete api("/users/999999", admin) response.status.should == 404 + json_response['message'].should == '404 User Not Found' end end @@ -375,6 +470,7 @@ describe API::API, api: true do it "should return 404 Not Found within invalid ID" do get api("/user/keys/42", user) response.status.should == 404 + json_response['message'].should == '404 Not found' end it "should return 404 error if admin accesses user's ssh key" do @@ -383,6 +479,7 @@ describe API::API, api: true do admin get api("/user/keys/#{key.id}", admin) response.status.should == 404 + json_response['message'].should == '404 Not found' end end @@ -403,6 +500,13 @@ describe API::API, api: true do it "should not create ssh key without key" do post api("/user/keys", user), title: 'title' response.status.should == 400 + json_response['message'].should == '400 (Bad request) "key" not given' + end + + it 'should not create ssh key without title' do + post api('/user/keys', user), key: 'some key' + response.status.should == 400 + json_response['message'].should == '400 (Bad request) "title" not given' end it "should not create ssh key without title" do diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index df355f6f07a..f8377650e0a 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -64,12 +64,12 @@ describe NotificationService do before do note.project.namespace_id = group.id - note.project.group.add_user(@u_watcher, UsersGroup::MASTER) + note.project.group.add_user(@u_watcher, GroupMember::MASTER) note.project.save - user_project = note.project.users_projects.find_by_user_id(@u_watcher.id) + user_project = note.project.project_members.find_by_user_id(@u_watcher.id) user_project.notification_level = Notification::N_PARTICIPATING user_project.save - user_group = note.project.group.users_groups.find_by_user_id(@u_watcher.id) + user_group = note.project.group.group_members.find_by_user_id(@u_watcher.id) user_group.notification_level = Notification::N_GLOBAL user_group.save end diff --git a/spec/services/system_hooks_service_spec.rb b/spec/services/system_hooks_service_spec.rb index 7497bdb0b3c..573446d3a19 100644 --- a/spec/services/system_hooks_service_spec.rb +++ b/spec/services/system_hooks_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe SystemHooksService do let (:user) { create :user } let (:project) { create :project } - let (:users_project) { create :users_project } + let (:project_member) { create :project_member } let (:key) { create(:key, user: user) } context 'event data' do @@ -11,8 +11,8 @@ describe SystemHooksService do it { event_data(user, :destroy).should include(:event_name, :name, :created_at, :email, :user_id) } it { event_data(project, :create).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) } it { event_data(project, :destroy).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) } - it { event_data(users_project, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access, :project_visibility) } - it { event_data(users_project, :destroy).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access, :project_visibility) } + it { event_data(project_member, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :access_level, :project_visibility) } + it { event_data(project_member, :destroy).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :access_level, :project_visibility) } it { event_data(key, :create).should include(:username, :key, :id) } it { event_data(key, :destroy).should include(:username, :key, :id) } end @@ -22,8 +22,8 @@ describe SystemHooksService do it { event_name(user, :destroy).should eq "user_destroy" } it { event_name(project, :create).should eq "project_create" } it { event_name(project, :destroy).should eq "project_destroy" } - it { event_name(users_project, :create).should eq "user_add_to_team" } - it { event_name(users_project, :destroy).should eq "user_remove_from_team" } + it { event_name(project_member, :create).should eq "user_add_to_team" } + it { event_name(project_member, :destroy).should eq "user_remove_from_team" } it { event_name(key, :create).should eq 'key_create' } it { event_name(key, :destroy).should eq 'key_destroy' } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6934cabadfa..60322b67a79 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,14 @@ -# This file is copied to spec/ when you run 'rails generate rspec:install' -ENV["RAILS_ENV"] ||= 'test' -require File.expand_path("../../config/environment", __FILE__) - -require 'simplecov' unless ENV['CI'] +if ENV['SIMPLECOV'] + require 'simplecov' +end -if ENV['TRAVIS'] +if ENV['COVERALLS'] require 'coveralls' - Coveralls.wear! + Coveralls.wear_merged!('rails') end +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'capybara/rails' require 'capybara/rspec' |