Commit 507edf53c908348eb77eafb2b924b48ae42f7952
1 parent
fbd103d2
Exists in
master
and in
1 other branch
Run unmerge smoothly on problem which migration form err was incorrect.
Showing
2 changed files
with
9 additions
and
6 deletions
Show diff stats
app/models/problem.rb
... | ... | @@ -76,7 +76,9 @@ class Problem |
76 | 76 | end |
77 | 77 | |
78 | 78 | def unmerge! |
79 | - [self] + errs[1..-1].map(&:id).map do |err_id| | |
79 | + problem_errs = errs.to_a | |
80 | + problem_errs.shift | |
81 | + [self] + problem_errs.map(&:id).map do |err_id| | |
80 | 82 | err = Err.find(err_id) |
81 | 83 | app.problems.create.tap do |new_problem| |
82 | 84 | err.update_attribute(:problem_id, new_problem.id) | ... | ... |
spec/models/problem_spec.rb
... | ... | @@ -98,11 +98,12 @@ describe Problem do |
98 | 98 | merged_problem = Problem.merge!(problem1, problem2) |
99 | 99 | merged_problem.errs.length.should == 2 |
100 | 100 | |
101 | - lambda { | |
102 | - problems = merged_problem.unmerge! | |
103 | - problems.length.should == 2 | |
104 | - merged_problem.errs(true).length.should == 1 | |
105 | - }.should change(Problem, :count).by(1) | |
101 | + expect { merged_problem.unmerge! }.to change(Problem, :count).by(1) | |
102 | + merged_problem.errs(true).length.should == 1 | |
103 | + end | |
104 | + | |
105 | + it "runs smoothly for problem without errs" do | |
106 | + expect { Factory(:problem).unmerge! }.not_to raise_error | |
106 | 107 | end |
107 | 108 | end |
108 | 109 | ... | ... |