Commit c60a8075cb777d550c70675c5a87644a47e4938f
1 parent
c22ad2ce
Exists in
master
and in
1 other branch
Show tracker errors when saving issue
Showing
4 changed files
with
23 additions
and
3 deletions
Show diff stats
app/models/issue.rb
@@ -12,6 +12,11 @@ class Issue | @@ -12,6 +12,11 @@ class Issue | ||
12 | 12 | ||
13 | def save | 13 | def save |
14 | if issue_tracker | 14 | if issue_tracker |
15 | + issue_tracker.tracker.errors.each do |k, err| | ||
16 | + errors.add k, err | ||
17 | + end | ||
18 | + return false if errors.present? | ||
19 | + | ||
15 | url = issue_tracker.create_issue(title, body, user: user.as_document) | 20 | url = issue_tracker.create_issue(title, body, user: user.as_document) |
16 | problem.update_attributes(issue_link: url, issue_type: issue_tracker.tracker.class.label) | 21 | problem.update_attributes(issue_link: url, issue_type: issue_tracker.tracker.class.label) |
17 | else | 22 | else |
spec/acceptance/app_regenerate_api_key_spec.rb
@@ -73,6 +73,8 @@ feature "Create an application" do | @@ -73,6 +73,8 @@ feature "Create an application" do | ||
73 | click_on I18n.t('apps.index.new_app') | 73 | click_on I18n.t('apps.index.new_app') |
74 | fill_in 'app_name', :with => 'My new app' | 74 | fill_in 'app_name', :with => 'My new app' |
75 | find('.label_radio.github').click | 75 | find('.label_radio.github').click |
76 | + | ||
77 | + fill_in 'app_github_repo', with: 'foo/bar' | ||
76 | within ".github.tracker_params" do | 78 | within ".github.tracker_params" do |
77 | fill_in 'app_issue_tracker_attributes_options_username', :with => 'token' | 79 | fill_in 'app_issue_tracker_attributes_options_username', :with => 'token' |
78 | fill_in 'app_issue_tracker_attributes_options_password', :with => 'pass' | 80 | fill_in 'app_issue_tracker_attributes_options_password', :with => 'pass' |
spec/errbit_plugin/mock_issue_tracker.rb
@@ -28,8 +28,8 @@ module ErrbitPlugin | @@ -28,8 +28,8 @@ module ErrbitPlugin | ||
28 | 28 | ||
29 | def errors | 29 | def errors |
30 | errors = [] | 30 | errors = [] |
31 | - errors << [:foo, 'foo is required'] unless options[:foo] | ||
32 | - errors << [:bar, 'bar is required'] unless options[:bar] | 31 | + errors << [:base, 'foo is required'] unless options[:foo] |
32 | + errors << [:base, 'bar is required'] unless options[:bar] | ||
33 | errors | 33 | errors |
34 | end | 34 | end |
35 | 35 |
spec/models/issue_spec.rb
@@ -12,11 +12,11 @@ describe Issue do | @@ -12,11 +12,11 @@ describe Issue do | ||
12 | t.instance_variable_set(:@tracker, ErrbitPlugin::MockIssueTracker.new(t.options)) | 12 | t.instance_variable_set(:@tracker, ErrbitPlugin::MockIssueTracker.new(t.options)) |
13 | end | 13 | end |
14 | end | 14 | end |
15 | + let(:errors) { issue.errors[:base] } | ||
15 | 16 | ||
16 | context "when app has no issue tracker" do | 17 | context "when app has no issue tracker" do |
17 | let(:title) { "Foo" } | 18 | let(:title) { "Foo" } |
18 | let(:body) { "barrr" } | 19 | let(:body) { "barrr" } |
19 | - let(:errors) { issue.errors[:base] } | ||
20 | 20 | ||
21 | context "#save" do | 21 | context "#save" do |
22 | it "returns false" do | 22 | it "returns false" do |
@@ -54,6 +54,19 @@ describe Issue do | @@ -54,6 +54,19 @@ describe Issue do | ||
54 | 54 | ||
55 | context "#save" do | 55 | context "#save" do |
56 | 56 | ||
57 | + context "when issue tracker has errors" do | ||
58 | + before do | ||
59 | + issue_tracker.tracker.options.clear | ||
60 | + end | ||
61 | + | ||
62 | + it("returns false") { expect(issue.save).to be false } | ||
63 | + it "adds the errors" do | ||
64 | + issue.save | ||
65 | + expect(errors).to include("foo is required") | ||
66 | + expect(errors).to include("bar is required") | ||
67 | + end | ||
68 | + end | ||
69 | + | ||
57 | it "creates the issue" do | 70 | it "creates the issue" do |
58 | issue.save | 71 | issue.save |
59 | expect(issue_tracker.tracker.output.count).to be 1 | 72 | expect(issue_tracker.tracker.output.count).to be 1 |