Author: assaf
Date: Fri May  9 17:15:57 2008
New Revision: 654990

URL: http://svn.apache.org/viewvc?rev=654990&view=rev
Log:
Moved some stakeholder related specs to stakeholder_spec (used to be in 
task_spec).

Modified:
    ode/sandbox/singleshot/spec/common.rb
    ode/sandbox/singleshot/spec/models/stakeholder_spec.rb
    ode/sandbox/singleshot/spec/models/task_spec.rb

Modified: ode/sandbox/singleshot/spec/common.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/common.rb?rev=654990&r1=654989&r2=654990&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/common.rb (original)
+++ ode/sandbox/singleshot/spec/common.rb Fri May  9 17:15:57 2008
@@ -2,10 +2,9 @@
 
   module Authentication
 
-    def self.included(mod)
-      mod.after :all do
+    def self.included(base)
+      base.after :all do
         Person.delete_all
-        Stakeholder.delete_all
       end
     end
 
@@ -42,17 +41,18 @@
 
   module Tasks
 
-    def self.included(mod)
-      mod.after :all do
+    def self.included(base)
+      base.after :all do
+        Stakeholder.delete_all
         Task.delete_all
       end
-      mod.send :include, Authentication
+      base.send :include, Authentication
     end
 
-    def default_task
+    def default_task(with = {})
       { :title=>'Test this',
         :frame_url=>'http://test.host/fill_me',
-        :outcome_url=>'http://test.host/outcome' }
+        :outcome_url=>'http://test.host/outcome' }.merge(with)
     end
 
   end

Modified: ode/sandbox/singleshot/spec/models/stakeholder_spec.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/models/stakeholder_spec.rb?rev=654990&r1=654989&r2=654990&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/models/stakeholder_spec.rb (original)
+++ ode/sandbox/singleshot/spec/models/stakeholder_spec.rb Fri May  9 17:15:57 
2008
@@ -41,97 +41,183 @@
 end
 
 
-describe Task, 'creator' do
+shared_examples_for 'singular role' do
   include Specs::Tasks
 
-  before :all do
-    @person = person('person')
-  end
-
   it 'should not be required' do
-    Task.create(default_task.except(:creator)).should have(:no).errors
+    Task.create(default_task.except(@role)).should have(:no).errors
   end
 
   it 'should not exist unless specified' do
-    task = Task.create(default_task.except(:creator))
-    Task.find(task.id).creator.should be_nil
+    task = Task.create(default_task.except(@role))
+    Task.find(task.id).send(@role).should be_nil
+  end
+
+  it 'should accept person at task creation' do
+    Task.create(default_task.merge(@role=>person('foo'))).should 
have(:no).errors
   end
 
-  it 'should accept creator at task creation' do
-    Task.create(default_task.merge(:creator=>@person)).should have(:no).errors
+  it 'should return person when loading task' do
+    task = Task.create(default_task.merge(@role=>person('foo')))
+    Task.find(task.id).send(@role).should eql(person('foo'))
   end
 
-  it 'should return creator when loading task' do
-    task = Task.create(default_task.merge(:creator=>@person))
-    Task.find(task.id).creator.should eql(@person)
+  it 'should identify person in role' do
+    task = Task.create(default_task.merge(@role=>person('foo')))
+    task.send("[EMAIL PROTECTED]", person('foo')).should be_true
+    task.send("[EMAIL PROTECTED]", person('bar')).should be_false
   end
+end
+
+
+describe Task, 'creator' do
+  before { @role = :creator }
+  it_should_behave_like 'singular role'
 
   it 'should not allow changing creator' do
-    task = Task.create(default_task.merge(:creator=>@person))
-    task.update_attributes(:creator=>Person.create(:email=>'[EMAIL 
PROTECTED]')).should be_false
+    task = Task.create(default_task.merge(:creator=>person('creator')))
+    task.update_attributes :creator=>person('other')
     task.should have(1).errors_on(:creator)
   end
 
   it 'should not allow setting creator on existing task' do
     task = Task.create(default_task)
-    task.update_attributes(:creator=>@person).should be_false
+    task.update_attributes :creator=>person('creator')
     task.should have(1).errors_on(:creator)
   end
+
 end
 
 
 describe Task, 'owner' do
+  before { @role = :owner }
+  it_should_behave_like 'singular role'
+
+  it 'should allow changing owner on existing task' do
+    task = Task.create(default_task.merge(:owner=>person('owner')))
+    task.update_attributes! :owner=>person('other')
+    task.should have(:no).errors
+  end
+
+  it 'should return new owner after changing owner' do
+    task = Task.create(default_task.merge(:owner=>person('owner')))
+    task.update_attributes! :owner=>person('other')
+    Task.find(task.id).owner.should eql(Person.find_by_email('[EMAIL 
PROTECTED]'))
+  end
+
+  it 'should only store one owner association for task' do
+    task = Task.create(default_task.merge(:owner=>person('owner')))
+    task.update_attributes! :owner=>person('other')
+    Stakeholder.find(:all, :conditions=>{:task_id=>task.id}).size.should eql(1)
+  end
+
+  it 'should allow setting owner to nil' do
+    task = Task.create(default_task.merge(:owner=>person('owner')))
+    task.update_attributes! :owner=>nil
+    task.should have(:no).errors
+  end
+
+  it 'should return no owner after changing to nil' do
+    task = Task.create(default_task.merge(:owner=>person('owner')))
+    task.update_attributes! :owner=>nil
+    Task.find(task.id).owner.should be_nil
+  end
+end
+
+
+shared_examples_for 'plural role' do
   include Specs::Tasks
 
-  before :all do
-    @person = person('person')
+  before do
+    @people = person('foo'), person('bar'), person('baz')
   end
 
   it 'should not be required' do
-    Task.create(default_task.except(:owner)).should have(:no).errors
+    Task.create(default_task.except(@role)).should have(:no).errors
   end
 
   it 'should not exist unless specified' do
-    task = Task.create(default_task.except(:owner))
-    Task.find(task.id).owner.should be_nil
+    task = Task.create(default_task.except(@role))
+    Task.find(task.id).send(@role).should be_empty
   end
 
-  it 'should accept owner at task creation' do
-    Task.create(default_task.merge(:owner=>@person)).should have(:no).errors
+  it 'should accept list of people at task creation' do
+    Task.create(default_task.merge(@role=>@people)).should have(:no).errors
   end
 
-  it 'should return owner when loading task' do
-    task = Task.create(default_task.merge(:owner=>@person))
-    Task.find(task.id).owner.should eql(@person)
+  it 'should list of people when loading task' do
+    task = Task.create(default_task.merge(@role=>@people))
+    Task.find(task.id).send(@role).should eql(@people)
   end
 
-  it 'should allow changing owner on existing task' do
-    task = Task.create(default_task.merge(:owner=>@person))
-    task.update_attributes(:owner=>Person.create(:email=>'[EMAIL PROTECTED]'))
-    task.should have(:no).errors
+  it 'should accept single person' do
+    task = Task.create(default_task.merge(@role=>person('foo')))
+    Task.find(task.id).send(@role).should eql([person('foo')])
   end
 
-  it 'should return new owner after changing owner' do
-    task = Task.create(default_task.merge(:owner=>@person))
-    task.update_attributes(:owner=>Person.create(:email=>'[EMAIL PROTECTED]'))
-    Task.find(task.id).owner.should eql(Person.find_by_email('[EMAIL 
PROTECTED]'))
+  it 'should accept empty list' do
+    task = Task.create(default_task.merge(@role=>[]))
+    Task.find(task.id).send(@role).should be_empty
   end
 
-  it 'should only store one owner association for task' do
-    task = Task.create(default_task.merge(:owner=>@person))
-    task.update_attributes(:owner=>Person.create(:email=>'[EMAIL PROTECTED]'))
-    Stakeholder.find(:all, :conditions=>{:task_id=>task.id}).size.should eql(1)
+  it 'should accept empty list and discard all stakeholders' do
+    task = Task.create(default_task.merge(@role=>@people))
+    task.update_attributes! @role=>[]
+    Task.find(task.id).send(@role).should be_empty
   end
 
-  it 'should allow setting owner to nil' do
-    task = Task.create(default_task.merge(:owner=>@person))
-    task.update_attributes(:owner=>nil)
-    task.should have(:no).errors
+  it 'should accept nil and treat it as empty list' do
+    task = Task.create(default_task.merge(@role=>@people))
+    task.update_attributes! @role=>nil
+    Task.find(task.id).send(@role).should be_empty
   end
 
-  it 'should return no owner after changing to nil' do
-    task = Task.create(default_task.merge(:owner=>@person))
-    task.update_attributes(:owner=>nil)
-    Task.find(task.id).owner.should be_nil
+  it 'should allow adding stakeholders' do
+    task = Task.create(default_task.merge(@role=>person('foo')))
+    task.update_attributes! @role=>task.send(@role) + [person('bar')]
+    Task.find(task.id).send(@role).should include(person('foo'), person('bar'))
+  end
+
+  it 'should add each person only once' do
+    task = Task.create(default_task.merge(@role=>[person('foo')] *3))
+    Task.find(task.id).send(@role).size.should eql(1)
+  end
+
+  it 'should allow removing stakeholders' do
+    task = Task.create(default_task.merge(@role=>[person('foo'), 
person('bar')]))
+    task.update_attributes! @role=>person('bar')
+    Task.find(task.id).send(@role).should eql([person('bar')])
   end
+
+  it 'should identify person in role' do
+    task = Task.create(default_task.merge(@role=>person('foo')))
+    Task.find(task.id).send("[EMAIL PROTECTED]", person('foo')).should be_true
+    Task.find(task.id).send("[EMAIL PROTECTED]", person('bar')).should be_false
+  end
+end
+
+
+describe Task, 'potential_owners' do
+  before { @role = :potential_owners }
+  it_should_behave_like 'plural role'
+
+  it 'should never include excluded owners'
+end
+
+
+describe Task, 'excluded_owners' do
+  before { @role = :excluded_owners }
+  it_should_behave_like 'plural role'
+end
+
+
+describe Task, 'observers' do
+  before { @role = :observers }
+  it_should_behave_like 'plural role'
+end
+
+
+describe Task, 'admins' do
+  before { @role = :admins }
+  it_should_behave_like 'plural role'
 end

Modified: ode/sandbox/singleshot/spec/models/task_spec.rb
URL: 
http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/models/task_spec.rb?rev=654990&r1=654989&r2=654990&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/models/task_spec.rb (original)
+++ ode/sandbox/singleshot/spec/models/task_spec.rb Fri May  9 17:15:57 2008
@@ -421,164 +421,6 @@
 end
 
 
-Task::SINGULAR_ROLES.each do |role|
-  describe Task, role do
-    include Specs::Tasks
-
-    before :all do
-      @person, @other = person('person'), person('alex')
-    end
-
-    it 'should start as nil' do
-      Task.new.send(role).should be_nil
-    end
-
-    it 'should have getter and setter methods' do
-      task = Task.create!(default_task.merge(role=>@person))
-      Task.find(task.id).send(role).should eql(@person)
-    end
-
-    it 'should have checker methods' do
-      task = Task.create!(default_task.merge(role=>@person))
-      Task.find(task.id).send("#{role}?", @person).should be_true
-    end
-
-    it 'should be able to remove person' do
-      task = Task.create!(default_task.merge(role=>@person))
-      lambda { task.update_attributes! role=>nil }.should change(task, 
role).from(@person).to(nil)
-    end
-
-    it 'should be able to change person' do
-      task = Task.create!(default_task.merge(role=>@person))
-      lambda { task.update_attributes! role=>person(@other) }.should 
change(task, role).from(@person).to(person(@other))
-    end
-
-    it 'should accept person at creation' do
-      Task.create!(default_task.merge(role=>@person)).send(role).should 
eql(@person)
-    end
-
-    it 'should treat blank as nil' do
-      task = Task.create!(default_task.merge(role=>@person))
-      lambda { task.update_attributes! role=>'' }.should change(task, 
role).from(@person).to(nil)
-    end
-
-    it 'should accept unknown identities but fail to save' do
-      Task.new(default_task.merge(role=>'unknown')).should 
have(1).error_on(role)
-    end
-
-  end
-end
-
-
-Task::PLURAL_ROLES.each do |role|
-  describe Task, role do
-    include Specs::Tasks
-
-    before :all do
-      @people = Array.new(3) { |i| person("person#{i}") }
-    end
-
-    before :each do
-      @task = Task.new(default_task)
-    end
-
-    def plural(role)
-      role.to_s.pluralize.to_sym
-    end
-
-    it 'should start as empty array' do
-      @task.send(plural(role)).should be_empty
-    end
-
-    it 'should have getter and setter methods' do
-      lambda { @task.update_attributes! plural(role)=>@people }.should 
change(@task, plural(role)).to(@people)
-    end
-
-    it 'should have checker methods' do
-      lambda { @task.send "#{plural(role)}=", @people.first }.
-        should change { @task.send("#{role}?", @people.first) }.to(true)
-      @task.send("#{role}?", @people.last).should be_false
-    end
-
-    it 'should be able to add person' do
-      @task.update_attributes! plural(role)=>@people[0..-2]
-      lambda { @task.update_attributes! plural(role)=>@people }.should 
change(@task, plural(role)).
-        from(@people[0..-2]).to(@people)
-    end
-
-    it 'should be able to remove person' do
-      @task.update_attributes! plural(role)=>@people
-      lambda { @task.update_attributes! plural(role)=>@people[0..-2] }.should 
change(@task, plural(role)).
-        from(@people).to(@people[0..-2])
-    end
-
-    it "should add each person only once" do
-      @task.update_attributes! plural(role)=>[EMAIL PROTECTED], @people.first]
-      @task.send(plural(role)).should eql([EMAIL PROTECTED])
-    end
-
-    it "should accept person at creation" do
-      
Task.create!(default_task.merge(plural(role)=>@people)).send(plural(role)).should
 eql(@people)
-    end
-
-    it "should treat blank as empty" do
-      @task.update_attributes! plural(role)=>@people
-      lambda { @task.update_attributes! plural(role)=>'' }.should 
change(@task, plural(role)).from(@people).to([])
-    end
-
-    it "should accept unknown identities for but fail to save" do
-      Task.new(default_task.merge(plural(role)=>(@people + 
['unknown']))).should have(1).error_on(role)
-    end
-
-  end
-end
-
-
-describe Task, 'creator' do
-  include Specs::Tasks
-
-  it 'should be singular role' do
-    Task::SINGULAR_ROLES.should include(:creator)
-  end
-
-  it 'should default to no one' do
-    Task.new.creator.should be_nil
-  end
-
-end
-
-
-describe Task, 'owner' do
-  include Specs::Tasks
-
-  it 'should be singular role' do
-    Task::SINGULAR_ROLES.should include(:owner)
-  end
-
-  it 'should default to no one' do
-    Task.new.owner.should be_nil
-  end
-
-  it 'should never be excluded owner' do
-    Task.new(:owner=>person('owner'), :excluded_owners=>people('owner', 
'foo')).should have(1).error_on(:owner)
-  end
-  
-end
-
-
-describe Task, 'potential owners' do
-  include Specs::Tasks
-
-  it 'should never include excluded owners' do
-    task = Task.new(default_task.merge(:potential_owners=>people('foo', 'bar', 
'baz'), :excluded_owners=>people('bar', 'qoo')))
-    task.should be_valid
-    task.potential_owners.should eql(people('foo', 'baz'))
-    task.excluded_owners.should eql(people('bar', 'qoo'))
-  end
-
-end
-
-
 describe Task, 'stakeholder?' do
   include Specs::Tasks
 


Reply via email to