diff --git a/app/models/problem.rb b/app/models/problem.rb index c474a34..62f32fa 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -116,7 +116,9 @@ class Problem self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last) last_deploy.created_at end - self.save if persisted? + collection.update({'_id' => self.id}, + {'$set' => {'app_name' => self.app_name, + 'last_deploy_at' => self.last_deploy_at}}) end end diff --git a/spec/fabricators/problem_fabricator.rb b/spec/fabricators/problem_fabricator.rb index ced1126..80d8fa0 100644 --- a/spec/fabricators/problem_fabricator.rb +++ b/spec/fabricators/problem_fabricator.rb @@ -1,8 +1,12 @@ Fabricator(:problem) do - app! - comments [] + app! { Fabricate(:app) } + comments { [] } end Fabricator(:problem_with_comments, :from => :problem) do - comments(:count => 3) { |parent, i| Fabricate(:comment, :err => parent) } + after_create { |parent| + 3.times do + Fabricate(:comment, :err => parent) + end + } end diff --git a/spec/models/problem_spec.rb b/spec/models/problem_spec.rb index 99bef1e..c39db3f 100644 --- a/spec/models/problem_spec.rb +++ b/spec/models/problem_spec.rb @@ -1,6 +1,29 @@ require 'spec_helper' describe Problem do + describe "Fabrication" do + context "Fabricate(:problem)" do + it 'should be valid' do + Fabricate.build(:problem).should be_valid + end + it 'should have no comment' do + lambda do + Fabricate(:problem) + end.should_not change(Comment, :count) + end + end + + context "Fabricate(:problem_with_comments)" do + it 'should be valid' do + Fabricate.build(:problem_with_comments).should be_valid + end + it 'should have 3 comments' do + lambda do + Fabricate(:problem_with_comments) + end.should change(Comment, :count).by(3) + end + end + end context '#last_notice_at' do it "returns the created_at timestamp of the latest notice" do err = Fabricate(:err) -- libgit2 0.21.2