Commit 9a1ad6b5566d45dae346a96be91f71ff4eddb708

Authored by Arthur Neves
1 parent 8afb5c2f
Exists in master and in 1 other branch production

Add body and title vadation to issue model

Showing 2 changed files with 32 additions and 2 deletions   Show diff stats
app/models/issue.rb
@@ -7,6 +7,16 @@ class Issue @@ -7,6 +7,16 @@ class Issue
7 end 7 end
8 8
9 def save 9 def save
  10 + unless body
  11 + errors.add :base, "The issue has no body"
  12 + return false
  13 + end
  14 +
  15 + unless title
  16 + errors.add :base, "The issue has no title"
  17 + return false
  18 + end
  19 +
10 if issue_tracker 20 if issue_tracker
11 issue_tracker.tracker.errors.each do |k, err| 21 issue_tracker.tracker.errors.each do |k, err|
12 errors.add k, err 22 errors.add k, err
spec/models/issue_spec.rb
@@ -28,15 +28,35 @@ describe Issue, type: 'model' do @@ -28,15 +28,35 @@ describe Issue, type: 'model' do
28 end 28 end
29 29
30 context "when has no title" do 30 context "when has no title" do
  31 + let(:title) { nil }
31 let(:body) { "barrr" } 32 let(:body) { "barrr" }
32 33
33 - pending "returns an error" 34 + context "#save" do
  35 + it "returns false" do
  36 + expect(issue.save).to be false
  37 + end
  38 +
  39 + it "returns an error" do
  40 + issue.save
  41 + expect(errors).to include("The issue has no title")
  42 + end
  43 + end
34 end 44 end
35 45
36 context "when has no body" do 46 context "when has no body" do
37 let(:title) { "Foo" } 47 let(:title) { "Foo" }
  48 + let(:body) { nil }
38 49
39 - pending "returns an error" 50 + context "#save" do
  51 + it "returns false" do
  52 + expect(issue.save).to be false
  53 + end
  54 +
  55 + it "returns an error" do
  56 + issue.save
  57 + expect(errors).to include("The issue has no body")
  58 + end
  59 + end
40 end 60 end
41 61
42 context "when app has a issue tracker" do 62 context "when app has a issue tracker" do