diff --git a/app/models/deploy.rb b/app/models/deploy.rb new file mode 100644 index 0000000..37e5a1b --- /dev/null +++ b/app/models/deploy.rb @@ -0,0 +1,14 @@ +class Deploy + include Mongoid::Document + include Mongoid::Timestamps + + field :username + field :repository + field :environment + field :revision + + embedded_in :project, :inverse_of => :deploys + + validates_presence_of :username, :environment + +end diff --git a/app/models/project.rb b/app/models/project.rb index d25ae43..52ebeab 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -6,6 +6,7 @@ class Project field :api_key embeds_many :watchers + embeds_many :deploys references_many :errs before_validation :generate_api_key, :on => :create diff --git a/spec/factories/project_factories.rb b/spec/factories/project_factories.rb index 96be2a4..739439e 100644 --- a/spec/factories/project_factories.rb +++ b/spec/factories/project_factories.rb @@ -8,4 +8,12 @@ end Factory.define(:watcher) do |w| w.project {|p| p.association :project} w.email { Factory.next :email } +end + +Factory.define(:deploy) do |d| + d.project {|p| p.association :project} + d.username 'clyde.frog' + d.repository 'git@github.com/jdpace/hypnotoad.git' + d.environment 'production' + d.revision '2e601cb575ca97f1a1097f12d0edfae241a70263' end \ No newline at end of file diff --git a/spec/models/deploy_spec.rb b/spec/models/deploy_spec.rb new file mode 100644 index 0000000..5c46ac8 --- /dev/null +++ b/spec/models/deploy_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Deploy do + + context 'validations' do + it 'requires a username' do + deploy = Factory.build(:deploy, :username => nil) + deploy.should_not be_valid + deploy.errors[:username].should include("can't be blank") + end + + it 'requires an environment' do + deploy = Factory.build(:deploy, :environment => nil) + deploy.should_not be_valid + deploy.errors[:environment].should include("can't be blank") + end + end + +end diff --git a/spec/models/notice_spec.rb b/spec/models/notice_spec.rb index b559f68..b5eaed6 100644 --- a/spec/models/notice_spec.rb +++ b/spec/models/notice_spec.rb @@ -80,13 +80,17 @@ describe Notice do end describe "email notifications" do + before do + @watcher = Factory(:watcher) + @error = Factory(:err, :project => @watcher.project) + end + App.email_at_notices.each do |threshold| it "sends an email notification after #{threshold} notice(s)" do - error = Factory(:err) - error.notices.stub(:count).and_return(threshold) + @error.notices.stub(:count).and_return(threshold) Mailer.should_receive(:error_notification). and_return(mock('email', :deliver => true)) - Factory(:notice, :err => error) + Factory(:notice, :err => @error) end end end -- libgit2 0.21.2