Commit bab575a0fa4dc9f27843100915976262e386dcb6

Authored by Jared Pace
1 parent 0ab40a69
Exists in master and in 1 other branch production

Add project watchers

app/models/project.rb
... ... @@ -5,6 +5,7 @@ class Project
5 5 field :name, :type => String
6 6 field :api_key
7 7  
  8 + embeds_many :watchers
8 9 references_many :errs
9 10  
10 11 before_validation :generate_api_key, :on => :create
... ...
app/models/watcher.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class Watcher
  2 + include Mongoid::Document
  3 + include Mongoid::Timestamps
  4 +
  5 + field :email
  6 +
  7 + embedded_in :project, :inverse_of => :watchers
  8 +
  9 + validates_presence_of :email
  10 +
  11 +end
... ...
spec/factories/project_factories.rb
1 1 Factory.sequence(:project_name) {|n| "Project ##{n}"}
  2 +Factory.sequence(:email) {|n| "email#{n}@example.com"}
2 3  
3 4 Factory.define(:project) do |p|
4 5 p.name { Factory.next :project_name }
  6 +end
  7 +
  8 +Factory.define(:watcher) do |w|
  9 + w.project {|p| p.association :project}
  10 + w.email { Factory.next :email }
5 11 end
6 12 \ No newline at end of file
... ...
spec/models/watcher_spec.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Watcher do
  4 +
  5 + context 'validations' do
  6 + it 'requires an email address' do
  7 + watcher = Factory.build(:watcher, :email => nil)
  8 + watcher.should_not be_valid
  9 + watcher.errors[:email].should include("can't be blank")
  10 + end
  11 + end
  12 +
  13 +end
... ...