Commit d9c1967cc864fbc2807a7830c5cf4db865e737c4
1 parent
f95ac763
Exists in
master
and in
1 other branch
fix problem fabricator and add test to test it
Showing
3 changed files
with
33 additions
and
4 deletions
Show diff stats
app/models/problem.rb
| ... | ... | @@ -116,7 +116,9 @@ class Problem |
| 116 | 116 | self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last) |
| 117 | 117 | last_deploy.created_at |
| 118 | 118 | end |
| 119 | - self.save if persisted? | |
| 119 | + collection.update({'_id' => self.id}, | |
| 120 | + {'$set' => {'app_name' => self.app_name, | |
| 121 | + 'last_deploy_at' => self.last_deploy_at}}) | |
| 120 | 122 | end |
| 121 | 123 | end |
| 122 | 124 | ... | ... |
spec/fabricators/problem_fabricator.rb
| 1 | 1 | Fabricator(:problem) do |
| 2 | - app! | |
| 3 | - comments [] | |
| 2 | + app! { Fabricate(:app) } | |
| 3 | + comments { [] } | |
| 4 | 4 | end |
| 5 | 5 | |
| 6 | 6 | Fabricator(:problem_with_comments, :from => :problem) do |
| 7 | - comments(:count => 3) { |parent, i| Fabricate(:comment, :err => parent) } | |
| 7 | + after_create { |parent| | |
| 8 | + 3.times do | |
| 9 | + Fabricate(:comment, :err => parent) | |
| 10 | + end | |
| 11 | + } | |
| 8 | 12 | end | ... | ... |
spec/models/problem_spec.rb
| 1 | 1 | require 'spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe Problem do |
| 4 | + describe "Fabrication" do | |
| 5 | + context "Fabricate(:problem)" do | |
| 6 | + it 'should be valid' do | |
| 7 | + Fabricate.build(:problem).should be_valid | |
| 8 | + end | |
| 9 | + it 'should have no comment' do | |
| 10 | + lambda do | |
| 11 | + Fabricate(:problem) | |
| 12 | + end.should_not change(Comment, :count) | |
| 13 | + end | |
| 14 | + end | |
| 15 | + | |
| 16 | + context "Fabricate(:problem_with_comments)" do | |
| 17 | + it 'should be valid' do | |
| 18 | + Fabricate.build(:problem_with_comments).should be_valid | |
| 19 | + end | |
| 20 | + it 'should have 3 comments' do | |
| 21 | + lambda do | |
| 22 | + Fabricate(:problem_with_comments) | |
| 23 | + end.should change(Comment, :count).by(3) | |
| 24 | + end | |
| 25 | + end | |
| 26 | + end | |
| 4 | 27 | context '#last_notice_at' do |
| 5 | 28 | it "returns the created_at timestamp of the latest notice" do |
| 6 | 29 | err = Fabricate(:err) | ... | ... |