Commit 2cecdbaa119e4021a6b11863f1f25ed9e8840c5f
1 parent
2e601cb5
Exists in
master
and in
1 other branch
Add a deploy model
Showing
5 changed files
with
49 additions
and
3 deletions
Show diff stats
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +class Deploy | ||
2 | + include Mongoid::Document | ||
3 | + include Mongoid::Timestamps | ||
4 | + | ||
5 | + field :username | ||
6 | + field :repository | ||
7 | + field :environment | ||
8 | + field :revision | ||
9 | + | ||
10 | + embedded_in :project, :inverse_of => :deploys | ||
11 | + | ||
12 | + validates_presence_of :username, :environment | ||
13 | + | ||
14 | +end |
app/models/project.rb
@@ -6,6 +6,7 @@ class Project | @@ -6,6 +6,7 @@ class Project | ||
6 | field :api_key | 6 | field :api_key |
7 | 7 | ||
8 | embeds_many :watchers | 8 | embeds_many :watchers |
9 | + embeds_many :deploys | ||
9 | references_many :errs | 10 | references_many :errs |
10 | 11 | ||
11 | before_validation :generate_api_key, :on => :create | 12 | before_validation :generate_api_key, :on => :create |
spec/factories/project_factories.rb
@@ -8,4 +8,12 @@ end | @@ -8,4 +8,12 @@ end | ||
8 | Factory.define(:watcher) do |w| | 8 | Factory.define(:watcher) do |w| |
9 | w.project {|p| p.association :project} | 9 | w.project {|p| p.association :project} |
10 | w.email { Factory.next :email } | 10 | w.email { Factory.next :email } |
11 | +end | ||
12 | + | ||
13 | +Factory.define(:deploy) do |d| | ||
14 | + d.project {|p| p.association :project} | ||
15 | + d.username 'clyde.frog' | ||
16 | + d.repository 'git@github.com/jdpace/hypnotoad.git' | ||
17 | + d.environment 'production' | ||
18 | + d.revision '2e601cb575ca97f1a1097f12d0edfae241a70263' | ||
11 | end | 19 | end |
12 | \ No newline at end of file | 20 | \ No newline at end of file |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe Deploy do | ||
4 | + | ||
5 | + context 'validations' do | ||
6 | + it 'requires a username' do | ||
7 | + deploy = Factory.build(:deploy, :username => nil) | ||
8 | + deploy.should_not be_valid | ||
9 | + deploy.errors[:username].should include("can't be blank") | ||
10 | + end | ||
11 | + | ||
12 | + it 'requires an environment' do | ||
13 | + deploy = Factory.build(:deploy, :environment => nil) | ||
14 | + deploy.should_not be_valid | ||
15 | + deploy.errors[:environment].should include("can't be blank") | ||
16 | + end | ||
17 | + end | ||
18 | + | ||
19 | +end |
spec/models/notice_spec.rb
@@ -80,13 +80,17 @@ describe Notice do | @@ -80,13 +80,17 @@ describe Notice do | ||
80 | end | 80 | end |
81 | 81 | ||
82 | describe "email notifications" do | 82 | describe "email notifications" do |
83 | + before do | ||
84 | + @watcher = Factory(:watcher) | ||
85 | + @error = Factory(:err, :project => @watcher.project) | ||
86 | + end | ||
87 | + | ||
83 | App.email_at_notices.each do |threshold| | 88 | App.email_at_notices.each do |threshold| |
84 | it "sends an email notification after #{threshold} notice(s)" do | 89 | it "sends an email notification after #{threshold} notice(s)" do |
85 | - error = Factory(:err) | ||
86 | - error.notices.stub(:count).and_return(threshold) | 90 | + @error.notices.stub(:count).and_return(threshold) |
87 | Mailer.should_receive(:error_notification). | 91 | Mailer.should_receive(:error_notification). |
88 | and_return(mock('email', :deliver => true)) | 92 | and_return(mock('email', :deliver => true)) |
89 | - Factory(:notice, :err => error) | 93 | + Factory(:notice, :err => @error) |
90 | end | 94 | end |
91 | end | 95 | end |
92 | end | 96 | end |