Commit ab681ed7c1510bbabe10ae19f04cb992ca9497c4
1 parent
95197da5
Exists in
master
and in
1 other branch
Replace issue creation interactor spec with issue_spec
Showing
2 changed files
with
77 additions
and
63 deletions
Show diff stats
spec/interactors/issue_creation_spec.rb
| ... | ... | @@ -1,63 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | - | |
| 3 | -describe IssueCreation do | |
| 4 | - subject(:issue_creation) do | |
| 5 | - IssueCreation.new(problem, user, tracker_name, request) | |
| 6 | - end | |
| 7 | - | |
| 8 | - let(:request) do | |
| 9 | - double(:request, | |
| 10 | - :host => 'github.com', | |
| 11 | - :port => '80', | |
| 12 | - :scheme => 'http' | |
| 13 | - ) | |
| 14 | - end | |
| 15 | - let(:problem) { notice.problem } | |
| 16 | - let(:notice) { Fabricate(:notice) } | |
| 17 | - let(:user) { Fabricate(:admin) } | |
| 18 | - let(:errors) { issue_creation.errors[:base] } | |
| 19 | - let(:tracker_name) { nil } | |
| 20 | - | |
| 21 | - it "adds the error when issue tracker isn't configured" do | |
| 22 | - issue_creation.execute | |
| 23 | - expect(errors).to include("This app has no issue tracker setup.") | |
| 24 | - end | |
| 25 | - | |
| 26 | - it 'creates an issue if issue tracker is configured' do | |
| 27 | - problem.app.issue_tracker = Fabricate(:issue_tracker) | |
| 28 | - issue_creation.execute | |
| 29 | - expect(errors).to be_empty | |
| 30 | - end | |
| 31 | - | |
| 32 | - context "with user's github" do | |
| 33 | - let(:tracker_name) { 'user_github' } | |
| 34 | - | |
| 35 | - it "adds the error when repo isn't set up" do | |
| 36 | - issue_creation.execute | |
| 37 | - expect(errors).to include("This app doesn't have a GitHub repo set up.") | |
| 38 | - end | |
| 39 | - | |
| 40 | - context 'with repo set up' do | |
| 41 | - before do | |
| 42 | - notice.app.update_attribute(:github_repo, 'errbit/errbit') | |
| 43 | - end | |
| 44 | - | |
| 45 | - it "adds the error when github account isn't linked" do | |
| 46 | - issue_creation.execute | |
| 47 | - expect(errors).to include("You haven't linked your Github account.") | |
| 48 | - end | |
| 49 | - | |
| 50 | - it 'creates an issue if github account is linked' do | |
| 51 | - user.github_login = 'admin' | |
| 52 | - user.github_oauth_token = 'oauthtoken' | |
| 53 | - user.save! | |
| 54 | - | |
| 55 | - ErrbitGithubPlugin::IssueTracker.should_receive(:new).and_return( | |
| 56 | - double(:create_issue => true) | |
| 57 | - ) | |
| 58 | - issue_creation.execute | |
| 59 | - expect(errors).to be_empty | |
| 60 | - end | |
| 61 | - end | |
| 62 | - end | |
| 63 | -end |
| ... | ... | @@ -0,0 +1,77 @@ |
| 1 | +require "spec_helper" | |
| 2 | + | |
| 3 | +describe Issue do | |
| 4 | + | |
| 5 | + subject(:issue) { Issue.new(user: user, title: title, body: body) } | |
| 6 | + | |
| 7 | + let(:problem) { notice.problem } | |
| 8 | + let(:notice) { Fabricate(:notice) } | |
| 9 | + let(:user) { Fabricate(:admin) } | |
| 10 | + | |
| 11 | + context "when app has no issue tracker" do | |
| 12 | + let(:title) { "Foo" } | |
| 13 | + let(:body) { "barrr" } | |
| 14 | + let(:errors) { issue.errors[:base] } | |
| 15 | + | |
| 16 | + context "#save" do | |
| 17 | + it "returns false" do | |
| 18 | + expect(issue.save).to be false | |
| 19 | + end | |
| 20 | + | |
| 21 | + it "returns an error" do | |
| 22 | + issue.save | |
| 23 | + expect(errors).to include("This app has no issue tracker setup.") | |
| 24 | + end | |
| 25 | + end | |
| 26 | + end | |
| 27 | + | |
| 28 | + context "when has no title" do | |
| 29 | + let(:tracker) { Fabricate(:issue_tracker) } | |
| 30 | + let(:body) { "barrr" } | |
| 31 | + | |
| 32 | + pending "returns an error" do | |
| 33 | + end | |
| 34 | + end | |
| 35 | + | |
| 36 | + context "when has no body" do | |
| 37 | + let(:tracker) { Fabricate(:issue_tracker) } | |
| 38 | + let(:title) { "Foo" } | |
| 39 | + | |
| 40 | + pending "returns an error" do | |
| 41 | + end | |
| 42 | + end | |
| 43 | + | |
| 44 | + context "when app has a issue tracker" do | |
| 45 | + let(:issue_tracker) { Fabricate(:issue_tracker) } | |
| 46 | + let(:title) { "Foo" } | |
| 47 | + let(:body) { "barrr" } | |
| 48 | + | |
| 49 | + before do | |
| 50 | + issue.issue_tracker = issue_tracker | |
| 51 | + end | |
| 52 | + | |
| 53 | + context "#save" do | |
| 54 | + | |
| 55 | + it "creates the issue" do | |
| 56 | + issue.save | |
| 57 | + expect(issue_tracker.tracker.output.count).to be 1 | |
| 58 | + end | |
| 59 | + | |
| 60 | + it "returns true" do | |
| 61 | + expect(issue.save).to be true | |
| 62 | + end | |
| 63 | + | |
| 64 | + it "sends the title" do | |
| 65 | + issue.save | |
| 66 | + saved_issue = issue_tracker.tracker.output.first | |
| 67 | + expect(saved_issue.first).to be title | |
| 68 | + end | |
| 69 | + | |
| 70 | + it "sends the body" do | |
| 71 | + issue.save | |
| 72 | + saved_issue = issue_tracker.tracker.output.first | |
| 73 | + expect(saved_issue[1]).to be body | |
| 74 | + end | |
| 75 | + end | |
| 76 | + end | |
| 77 | +end | ... | ... |