Skip to content

Commit

Permalink
[api] Initialize review state with :new
Browse files Browse the repository at this point in the history
to have the request review always in a sane state.

https://bugzilla.suse.com/show_bug.cgi?id=1094820

Signed-off-by: Christian Bruckmayer <cbruckmayer@suse.com>
Co-authored-by: Christian Bruckmayer <cbruckmayer@suse.com>
  • Loading branch information
marcus-h and ChrisBr committed May 30, 2018
1 parent e35aab6 commit b15cf19
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/api/app/models/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def check_initial
def self.new_from_xml_hash(hash)
r = Review.new

r.state = hash.delete('state') { raise ArgumentError, 'no state' }
r.state = r.state.to_sym
r.state = :new
hash.delete('state')

r.by_user = hash.delete('by_user')
r.by_group = hash.delete('by_group')
Expand Down
16 changes: 16 additions & 0 deletions src/api/spec/models/review_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,20 @@
expect(review_by_package.reviewable_by?(by_package: other_package.name)).to be_falsy
end
end

describe '.new_from_xml_hash' do
let(:request_xml) do
"<request>
<review state='accepted' by_user='#{user}'/>
</request>"
end
let(:request_hash) { Xmlhash.parse(request_xml) }
let(:review_hash) { request_hash['review'] }

subject { Review.new_from_xml_hash(review_hash) }

it 'initalizes the review in state :new' do
expect(subject.state).to eq(:new)
end
end
end
27 changes: 26 additions & 1 deletion src/api/test/unit/bs_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,32 @@ def test_parse_bigger
assert_equal 1027, req.number

newxml = req.render_xml
assert_equal xml, newxml
expected = <<-XML.strip_heredoc
<request id="1027" creator="Iggy">
<action type="submit">
<source project="home:Iggy" package="TestPack" rev="1"/>
<target project="kde4" package="mypackage"/>
<options>
<sourceupdate>cleanup</sourceupdate>
</options>
<acceptinfo rev="1" srcmd5="806a6e27ed7915d1bb8d8a989404fd5a" osrcmd5="d41d8cd98f00b204e9800998ecf8427e"/>
</action>
<priority>critical</priority>
<state name="review" who="Iggy" when="2012-11-07T21:13:12">
<comment>No comment</comment>
</state>
<review state="new" when="2017-09-01T09:11:11" by_user="adrian"/>
<review state="new" when="2017-09-01T09:11:11" by_group="test_group"/>
<review state="new" when="2012-11-07T21:13:12" who="tom" by_user="tom">
<comment>review1</comment>
</review>
<review state="new" when="2012-11-07T21:13:13" who="tom" by_user="tom">
<comment>please accept</comment>
</review>
<description>Left blank</description>
</request>
XML
assert_equal expected, newxml

wi = req.webui_infos(diffs: false)
# iggy is *not* target maintainer
Expand Down

0 comments on commit b15cf19

Please sign in to comment.