Commit 6e8cb844499dfcc77bd92f3daf0f7890400ec072
1 parent
d08e1db9
Exists in
master
and in
4 other branches
Added few tests on Issues::BulkUpdateContext
Showing
2 changed files
with
70 additions
and
37 deletions
Show diff stats
app/contexts/issues/bulk_update_context.rb
| ... | ... | @@ -8,11 +8,14 @@ module Issues |
| 8 | 8 | assignee_id = update_data[:assignee_id] |
| 9 | 9 | status = update_data[:status] |
| 10 | 10 | |
| 11 | - unless status.present? | |
| 12 | - return { | |
| 13 | - count: 0, | |
| 14 | - success: false | |
| 15 | - } | |
| 11 | + new_state = nil | |
| 12 | + | |
| 13 | + if status.present? | |
| 14 | + if status == 'closed' | |
| 15 | + new_state = :close | |
| 16 | + else | |
| 17 | + new_state = :reopen | |
| 18 | + end | |
| 16 | 19 | end |
| 17 | 20 | |
| 18 | 21 | opts = {} |
| ... | ... | @@ -22,12 +25,9 @@ module Issues |
| 22 | 25 | issues = Issue.where(id: issues_ids).all |
| 23 | 26 | issues = issues.select { |issue| can?(current_user, :modify_issue, issue) } |
| 24 | 27 | |
| 25 | - new_state = :reopen | |
| 26 | - new_state = :close if status == 'closed' | |
| 27 | - | |
| 28 | 28 | issues.each do |issue| |
| 29 | 29 | issue.update_attributes(opts) |
| 30 | - issue.send new_state | |
| 30 | + issue.send new_state if new_state | |
| 31 | 31 | end |
| 32 | 32 | |
| 33 | 33 | { | ... | ... |
spec/contexts/issues/bulk_update_context_spec.rb
| ... | ... | @@ -2,14 +2,21 @@ require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe Issues::BulkUpdateContext do |
| 4 | 4 | |
| 5 | + let(:issue) { | |
| 6 | + create(:issue, project: @project) | |
| 7 | + } | |
| 8 | + | |
| 9 | + before do | |
| 10 | + @user = create :user | |
| 11 | + opts = { | |
| 12 | + name: "GitLab" | |
| 13 | + } | |
| 14 | + @project = Projects::CreateContext.new(@user, opts).execute | |
| 15 | + end | |
| 16 | + | |
| 5 | 17 | describe :close_issue do |
| 6 | 18 | |
| 7 | 19 | before do |
| 8 | - @user = create :user | |
| 9 | - opts = { | |
| 10 | - name: "GitLab" | |
| 11 | - } | |
| 12 | - @project = create_project(@user, opts) | |
| 13 | 20 | @issues = 5.times.collect do |
| 14 | 21 | create(:issue, project: @project) |
| 15 | 22 | end |
| ... | ... | @@ -19,31 +26,22 @@ describe Issues::BulkUpdateContext do |
| 19 | 26 | issues_ids: @issues.map(&:id) |
| 20 | 27 | } |
| 21 | 28 | } |
| 22 | - | |
| 23 | 29 | end |
| 24 | 30 | |
| 25 | - it "close issues" do | |
| 26 | - Issues::BulkUpdateContext.new(@project, @user, @params).execute | |
| 27 | - @project.issues.opened.should be_empty | |
| 28 | - @project.issues.closed.should_not be_empty | |
| 29 | - end | |
| 30 | - | |
| 31 | - it "return success" do | |
| 31 | + it { | |
| 32 | 32 | result = Issues::BulkUpdateContext.new(@project, @user, @params).execute |
| 33 | 33 | result[:success].should be_true |
| 34 | 34 | result[:count].should == @issues.count |
| 35 | - end | |
| 35 | + | |
| 36 | + @project.issues.opened.should be_empty | |
| 37 | + @project.issues.closed.should_not be_empty | |
| 38 | + } | |
| 36 | 39 | |
| 37 | 40 | end |
| 38 | 41 | |
| 39 | 42 | describe :reopen_issues do |
| 40 | 43 | |
| 41 | 44 | before do |
| 42 | - @user = create :user | |
| 43 | - opts = { | |
| 44 | - name: "GitLab" | |
| 45 | - } | |
| 46 | - @project = create_project(@user, opts) | |
| 47 | 45 | @issues = 5.times.collect do |
| 48 | 46 | create(:closed_issue, project: @project) |
| 49 | 47 | end |
| ... | ... | @@ -53,25 +51,60 @@ describe Issues::BulkUpdateContext do |
| 53 | 51 | issues_ids: @issues.map(&:id) |
| 54 | 52 | } |
| 55 | 53 | } |
| 56 | - | |
| 57 | 54 | end |
| 58 | 55 | |
| 59 | - it "reopen issues" do | |
| 60 | - Issues::BulkUpdateContext.new(@project, @user, @params).execute | |
| 56 | + it { | |
| 57 | + result = Issues::BulkUpdateContext.new(@project, @user, @params).execute | |
| 58 | + result[:success].should be_true | |
| 59 | + result[:count].should == @issues.count | |
| 60 | + | |
| 61 | 61 | @project.issues.closed.should be_empty |
| 62 | 62 | @project.issues.opened.should_not be_empty |
| 63 | + } | |
| 64 | + | |
| 65 | + end | |
| 66 | + | |
| 67 | + describe :update_assignee do | |
| 68 | + | |
| 69 | + before do | |
| 70 | + @new_assignee = create :user | |
| 71 | + @params = { | |
| 72 | + update: { | |
| 73 | + issues_ids: [issue.id], | |
| 74 | + assignee_id: @new_assignee.id | |
| 75 | + } | |
| 76 | + } | |
| 63 | 77 | end |
| 64 | 78 | |
| 65 | - it "return success" do | |
| 79 | + it { | |
| 66 | 80 | result = Issues::BulkUpdateContext.new(@project, @user, @params).execute |
| 67 | 81 | result[:success].should be_true |
| 68 | - result[:count].should == @issues.count | |
| 69 | - end | |
| 82 | + result[:count].should == 1 | |
| 83 | + | |
| 84 | + @project.issues.first.assignee.should == @new_assignee | |
| 85 | + } | |
| 70 | 86 | |
| 71 | 87 | end |
| 72 | 88 | |
| 73 | - def create_project(user, opts) | |
| 74 | - Projects::CreateContext.new(user, opts).execute | |
| 89 | + describe :update_milestone do | |
| 90 | + | |
| 91 | + before do | |
| 92 | + @milestone = create :milestone | |
| 93 | + @params = { | |
| 94 | + update: { | |
| 95 | + issues_ids: [issue.id], | |
| 96 | + milestone_id: @milestone.id | |
| 97 | + } | |
| 98 | + } | |
| 99 | + end | |
| 100 | + | |
| 101 | + it { | |
| 102 | + result = Issues::BulkUpdateContext.new(@project, @user, @params).execute | |
| 103 | + result[:success].should be_true | |
| 104 | + result[:count].should == 1 | |
| 105 | + | |
| 106 | + @project.issues.first.milestone.should == @milestone | |
| 107 | + } | |
| 75 | 108 | end |
| 76 | -end | |
| 77 | 109 | |
| 110 | +end | ... | ... |