You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by as...@apache.org on 2008/08/20 07:48:16 UTC

svn commit: r687247 - in /ode/sandbox/singleshot: app/controllers/ app/models/ app/views/activity/ app/views/layouts/ config/environments/ config/initializers/locale/ db/ db/migrate/ lib/tasks/ spec/controllers/ spec/models/

Author: assaf
Date: Tue Aug 19 22:48:15 2008
New Revision: 687247

URL: http://svn.apache.org/viewvc?rev=687247&view=rev
Log:
Merge branch 'dev'

Conflicts:

	app/models/activity.rb
	spec/controllers/activity_controller_spec.rb

Added:
    ode/sandbox/singleshot/config/initializers/locale/
    ode/sandbox/singleshot/config/initializers/locale/en-US.rb
Modified:
    ode/sandbox/singleshot/app/controllers/activity_controller.rb
    ode/sandbox/singleshot/app/models/activity.rb
    ode/sandbox/singleshot/app/models/task.rb
    ode/sandbox/singleshot/app/views/activity/index.atom.builder
    ode/sandbox/singleshot/app/views/layouts/application.html.erb
    ode/sandbox/singleshot/config/environments/development.rb
    ode/sandbox/singleshot/db/migrate/20080506015153_create_activities.rb
    ode/sandbox/singleshot/db/schema.rb
    ode/sandbox/singleshot/lib/tasks/database.rake
    ode/sandbox/singleshot/spec/controllers/activity_controller_spec.rb
    ode/sandbox/singleshot/spec/models/activity_spec.rb

Modified: ode/sandbox/singleshot/app/controllers/activity_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/activity_controller.rb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/activity_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/activity_controller.rb Tue Aug 19 22:48:15 2008
@@ -17,20 +17,19 @@
 class ActivityController < ApplicationController
 
   def index
-    @title = 'Activities'
-    @subtitle = 'Track activity in tasks you participate in or observe.'
-    @alternate = { Mime::HTML=>activity_url,
-                   Mime::ATOM=>formatted_activity_url(:format=>:atom, :access_key=>authenticated.access_key),
-                   Mime::ICS=>formatted_activity_url(:format=>:ics, :access_key=>authenticated.access_key) }
+    @title = I18n.t('activities.index.title')
+    @subtitle = I18n.t('activities.index.subtitle')
     @activities = Activity.for_stakeholder(authenticated).with_dependents.paginate(:page=>params['page'], :per_page=>50)
     @next = activity_url(:page=>@activities.next_page) if @activities.next_page
     @previous = activity_url(:page=>@activities.previous_page) if @activities.previous_page
     respond_to do |want|
       want.html do
+        @atom_feed_url = formatted_activity_url(:format=>:atom, :access_key=>authenticated.access_key)
         @graph = Activity.for_stakeholder(authenticated).for_dates(Date.current - 1.month)
       end
-      want.atom
-      want.ics
+      want.atom { @root_url = activity_url }
+      want.json
+      want.xml
     end
   end
 

Modified: ode/sandbox/singleshot/app/models/activity.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/activity.rb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/activity.rb (original)
+++ ode/sandbox/singleshot/app/models/activity.rb Tue Aug 19 22:48:15 2008
@@ -4,7 +4,7 @@
 # Table name: activities
 #
 #  id         :integer         not null, primary key
-#  person_id  :integer
+#  person_id  :integer         not null
 #  task_id    :integer         not null
 #  name       :string(255)     not null
 #  created_at :datetime        not null
@@ -29,8 +29,11 @@
 class Activity < ActiveRecord::Base
 
   belongs_to :person
+  validates_presence_of :person_id
+  
   belongs_to :task
   validates_presence_of :task
+  
   validates_presence_of :name
 
   def readonly? #:nodoc:

Modified: ode/sandbox/singleshot/app/models/task.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/task.rb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/task.rb (original)
+++ ode/sandbox/singleshot/app/models/task.rb Tue Aug 19 22:48:15 2008
@@ -373,7 +373,8 @@
   has_many :activities, :include=>[:task, :person], :order=>'activities.created_at DESC', :dependent=>:delete_all
 
   def log_activity(person, name)
-    activities.build :person=>person || modified_by, :name=>name
+    person ||= modified_by
+    activities.build :person=>person, :name=>name if person
   end
 
   LOG_CHANGE_ATTRIBUTES = [:title, :description, :priority, :due_on]

Modified: ode/sandbox/singleshot/app/views/activity/index.atom.builder
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/activity/index.atom.builder?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/activity/index.atom.builder (original)
+++ ode/sandbox/singleshot/app/views/activity/index.atom.builder Tue Aug 19 22:48:15 2008
@@ -1,10 +1,9 @@
-atom_feed :root_url=>@alternate[Mime::HTML] do |feed|
+atom_feed :root_url=>@root_url do |feed|
   feed.title "Singleshot: #{@title}"
   feed.subtitle @subtitle
   feed.updated @activities.first.created_at unless @activities.empty?
   feed.link :href=>@next, :rel=>'next', :type=>Mime::ATOM if @next
   feed.link :href=>@previous, :rel=>'previous', :type=>Mime::ATOM if @previous
-  feed.link :href=>@alternate[Mime::ICS], :rel=>'alternate', :type=>Mime::ICS if @alternate[Mime::ICS]
   feed.generator 'Singleshot', :version=>Singleshot::VERSION
 
   for (task, person, published), related in @activities.group_by { |activity| [activity.task, activity.person, activity.created_at] }

Modified: ode/sandbox/singleshot/app/views/layouts/application.html.erb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/views/layouts/application.html.erb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/layouts/application.html.erb (original)
+++ ode/sandbox/singleshot/app/views/layouts/application.html.erb Tue Aug 19 22:48:15 2008
@@ -4,7 +4,7 @@
     <%= javascript_include_tag :all, :cache=>true %>
     <%= stylesheet_link_tag 'default', :cache=>true %>
     <%= stylesheet_link_tag 'print', :media=>'print', :cache=>true %>
-    <%= @alternate.map { |mime, url| auto_discovery_link_tag mime.to_sym, url } if @alternate %>
+    <%= auto_discovery_link_tag :atom, @atom_feed_url if @atom_feed_url %>
     <%= tag :link, :rel=>'search', :type=>Mime::OSD, :href=>open_search_url, :title=>'Search your tasks list' %>
     <%= tag :link, :rel=>'next', :type=>Mime::HTML, :href=>@next if @next %>
     <%= tag :previous, :rel=>'previous', :type=>Mime::HTML, :href=>@previous if @previous %>

Modified: ode/sandbox/singleshot/config/environments/development.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/environments/development.rb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/config/environments/development.rb (original)
+++ ode/sandbox/singleshot/config/environments/development.rb Tue Aug 19 22:48:15 2008
@@ -20,7 +20,7 @@
 
 # These Gems are used for development.
 config.gem 'annotate-models', :lib=>'annotate_models'
-config.gem 'rspec', :lib=>'spec',                     :version=>'~> 1.1.4'
+#config.gem 'rspec', :lib=>'spec',                     :version=>'~> 1.1.4'
 # Faker: Used to populate development database with fake data.
 config.gem 'faker',                                   :version=>'~>0.3'
 # SQLite3: Development and test databases use SQLite3 by default.

Added: ode/sandbox/singleshot/config/initializers/locale/en-US.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/initializers/locale/en-US.rb?rev=687247&view=auto
==============================================================================
--- ode/sandbox/singleshot/config/initializers/locale/en-US.rb (added)
+++ ode/sandbox/singleshot/config/initializers/locale/en-US.rb Tue Aug 19 22:48:15 2008
@@ -0,0 +1,8 @@
+I18n.backend.store_translations :'en-US', {
+  :activities => {
+    :index => {
+      :title => "Activities",
+      :subtitle => "Activity from all tasks you own or observe"
+    }            
+  }
+}

Modified: ode/sandbox/singleshot/db/migrate/20080506015153_create_activities.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/db/migrate/20080506015153_create_activities.rb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/db/migrate/20080506015153_create_activities.rb (original)
+++ ode/sandbox/singleshot/db/migrate/20080506015153_create_activities.rb Tue Aug 19 22:48:15 2008
@@ -17,7 +17,7 @@
 class CreateActivities < ActiveRecord::Migration
   def self.up
     create_table  'activities' do |t|
-      t.belongs_to  'person'
+      t.belongs_to  'person',     :null=>false
       t.belongs_to  'task',       :null=>false
       t.string      'name',       :null=>false
       t.datetime    'created_at', :null=>false

Modified: ode/sandbox/singleshot/db/schema.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/db/schema.rb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/db/schema.rb (original)
+++ ode/sandbox/singleshot/db/schema.rb Tue Aug 19 22:48:15 2008
@@ -12,7 +12,7 @@
 ActiveRecord::Schema.define(:version => 20080621023051) do
 
   create_table "activities", :force => true do |t|
-    t.integer  "person_id"
+    t.integer  "person_id",  :null => false
     t.integer  "task_id",    :null => false
     t.string   "name",       :null => false
     t.datetime "created_at", :null => false

Modified: ode/sandbox/singleshot/lib/tasks/database.rake
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/tasks/database.rake?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/tasks/database.rake (original)
+++ ode/sandbox/singleshot/lib/tasks/database.rake Tue Aug 19 22:48:15 2008
@@ -1,4 +1,7 @@
 begin
   require 'annotate_models/tasks'
+  
+  desc task('annotate_models').comment
+  task 'db:annotate'=>'annotate_models'
 rescue LoadError
 end

Modified: ode/sandbox/singleshot/spec/controllers/activity_controller_spec.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/controllers/activity_controller_spec.rb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/controllers/activity_controller_spec.rb (original)
+++ ode/sandbox/singleshot/spec/controllers/activity_controller_spec.rb Tue Aug 19 22:48:15 2008
@@ -17,25 +17,30 @@
 require File.dirname(__FILE__) + '/../spec_helper'
 
 
-describe ActivityController do
+describe ActivityController, 'index' do
 
-  describe 'index' do
-
-    it 'should map to /activity' do
-      route_for(:controller=>'activity', :action=>'index').should eql('/activity')
-    end
+  it 'should map to /activity' do
+    route_for(:controller=>'activity', :action=>'index').should eql('/activity')
+  end
 
-    it 'should require authentication' do
+  it 'should require authentication' do
+    get 'index'
+    response.should redirect_to(session_url)
+  end
+  
+  describe 'response' do
+    before :each do
+      authenticate
       get 'index'
-      response.should redirect_to(session_url)
     end
-
-    it 'should return root element activities' do
-      authenticate do
-        get 'index', :format=>Mime::XML
-      end
+    
+    it "should have 'Activities' in the title" do
+      assigns[:title].should == 'Activities'
+    end
+    
+    it "should expand on the title in the subtitle" do
+      assigns[:subtitle].should == "Activity from all tasks you own or observe"
     end
-
   end
 
 end

Modified: ode/sandbox/singleshot/spec/models/activity_spec.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/models/activity_spec.rb?rev=687247&r1=687246&r2=687247&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/models/activity_spec.rb (original)
+++ ode/sandbox/singleshot/spec/models/activity_spec.rb Tue Aug 19 22:48:15 2008
@@ -18,131 +18,120 @@
 
 
 describe Activity do
+  
+  before :each do
+    @person = person('person')
+    @task = Task.create!(defaults(:creator=>@person))
+    @activity = Activity.last
+  end
+
+  it 'should have a person' do
+    @activity.person.should == @person
+  end
+
+  it 'should not be valid without a person' do
+    Activity.create(:task=>@task, :name=>'created').should have(1).error_on(:person_id)
+  end
 
-  describe 'person' do
-    it 'should be part of activity' do
-      Task.create! defaults(:creator=>person('person'))
-      Activity.last.person.should == person('person')
-    end
-
-    it 'should be optional' do
-      lambda { Task.create! defaults }.should_not raise_error
-      Activity.last.person.should be_nil
-    end
-  end
-
-  describe 'task' do
-    it 'should be part of activity' do
-      Task.create! defaults
-      Activity.last.task.should == Task.last
-    end
-
-    it 'should be required' do
-      Activity.create(:person=>person('person'), :name=>'created').should have(1).error_on(:task)
-    end
-  end
-
-  describe 'name' do
-    it 'should be part of activity' do
-      Task.create! defaults
-      Activity.last.name.should == 'created'
-    end
-
-    it 'should be required' do
-      Task.create! defaults
-      Activity.create(:person=>person('person'), :task=>Task.last).should have(1).error_on(:name)
-    end
+  it 'should not exist if person destroyed' do
+    lambda { @person.destroy }.should change(Activity, :count).to(0)
+  end
+  
+  it 'should have a task' do
+    @activity.task.should == @task
+  end
+  
+  it 'should not be valid without a task' do
+    Activity.create(:person=>@person, :name=>'created').should have(1).error_on(:task)
+  end
+
+  it 'should not exist if task destroyed' do
+    lambda { @task.destroy }.should change(Activity, :count).to(0)
+  end
+
+  it 'should have a name' do
+    @activity.name.should == 'created'
+  end
+
+  it 'should not be valid without a name' do
+    Activity.create(:person=>@person, :task=>@task).should have(1).error_on(:name)
   end
 
   it 'should have created_at timestamp' do
-    Task.create! defaults
-    Activity.last.created_at.should be_close(Time.now, 2)
+    @activity.created_at.should be_close(Time.now, 2)
   end
   
   it 'should be read only' do
-    Task.create! defaults
-    lambda { Activity.last.update_attributes! :name=>'updated' }.should raise_error(ActiveRecord::ReadOnlyRecord)
+    lambda { @activity.update_attributes! :name=>'updated' }.should raise_error(ActiveRecord::ReadOnlyRecord)
+  end
+  
+end
+
+
+describe Activity, 'for_dates' do
+  it 'should accept time and find all activities since that day' do
+    Activity.for_dates(3.days.ago).proxy_options[:conditions][:created_at].should ==
+      (3.days.ago.beginning_of_day..Time.current.end_of_day)
+  end
+  
+  it 'should accept date and find all activities since that day' do
+    Activity.for_dates(Date.current - 3.days).proxy_options[:conditions][:created_at].should ==
+      (3.days.ago.beginning_of_day..Time.current.end_of_day)
   end
 
-  it 'should be removed when destroying task' do
-    Task.create! defaults
-    lambda { Task.last.destroy }.should change(Activity, :count).to(0)
+  it 'should accept time range and find all activities in these dates' do
+    Activity.for_dates(3.days.ago..1.day.ago).proxy_options[:conditions][:created_at].should ==
+      (3.days.ago.beginning_of_day..1.day.ago.end_of_day)
   end
 
-  it 'should be removed when destroying person' do
-    Task.create! defaults(:creator=>person('creator'))
-    lambda { person('creator').destroy }.should change(Activity, :count).to(0)
+  it 'should accept date range and find all activities in these dates' do
+    Activity.for_dates(Date.current - 3.days..Date.current - 1.day).proxy_options[:conditions][:created_at].should ==
+      (3.days.ago.beginning_of_day..1.day.ago.end_of_day)
   end
+end
+
 
+describe Activity, 'for_stakeholder' do
+  it 'should return activities from all tasks associated with stakeholder' do
+    Task.create! defaults(:creator=>person('person'))
+    Task.create! defaults(:owner=>person('person'))
+    Activity.for_stakeholder(person('person')).map(&:task).uniq.size.should == 2
+  end
 
-  describe 'for_dates' do
-    it 'should accept time and find all activities since that day' do
-      Activity.for_dates(3.days.ago).proxy_options[:conditions][:created_at].should ==
-        (3.days.ago.beginning_of_day..Time.current.end_of_day)
-    end
-    
-    it 'should accept date and find all activities since that day' do
-      Activity.for_dates(Date.current - 3.days).proxy_options[:conditions][:created_at].should ==
-        (3.days.ago.beginning_of_day..Time.current.end_of_day)
-    end
-
-    it 'should accept time range and find all activities in these dates' do
-      Activity.for_dates(3.days.ago..1.day.ago).proxy_options[:conditions][:created_at].should ==
-        (3.days.ago.beginning_of_day..1.day.ago.end_of_day)
-    end
-
-    it 'should accept date range and find all activities in these dates' do
-      Activity.for_dates(Date.current - 3.days..Date.current - 1.day).proxy_options[:conditions][:created_at].should ==
-        (3.days.ago.beginning_of_day..1.day.ago.end_of_day)
-    end
-  end
-
-
-  describe 'for_stakeholder' do
-    it 'should return activities from all tasks associated with stakeholder' do
-      Task.create! defaults(:creator=>person('person'))
-      Task.create! defaults(:owner=>person('person'))
-      Task.create! defaults(:observers=>person('person'))
-      Activity.for_stakeholder(person('person')).map(&:task).uniq.size.should == 3
-    end
-
-    it 'should not return activities for excluded owner' do
-      Task.create! defaults(:excluded_owners=>person('person'))
-      Activity.for_stakeholder(person('person')).should be_empty
-    end
-
-    it 'should not return activities not relevant to stakeholder' do
-      Task.create! defaults(:creator=>person('creator'))
-      Task.create! defaults(:owner=>person('owner'))
-      Activity.for_stakeholder(person('creator')).first.task.should == Task.first
-      Activity.for_stakeholder(person('owner')).last.task.should == Task.last
-    end
-
-    it 'should order activities from most recent to last' do
-      Task.create! defaults(:creator=>person('person'))
-      Activity.update_all ['created_at=?', Time.zone.now - 5.seconds]
-      Task.create! defaults(:owner=>person('person'))
-      activities = Activity.for_stakeholder(person('person'))
-      activities.first.created_at.should > activities.last.created_at
-    end
-
-    it 'should not return the same activity twice' do
-      Task.create! defaults(:creator=>person('person'), :observers=>person('person'))
-      Activity.for_stakeholder(person('person')).size.should == 1
-    end
-
-    it 'should not eager load dependencies' do
-      Activity.for_stakeholder(person('person')).proxy_options[:include].should be_nil
-    end
-  end
-
-
-  describe 'recently_added' do
-    it 'should return recently added activities' do
-      Activity.recently_added.proxy_options[:order].downcase.split.should == ['created_at', 'desc']
-    end
-    
+  it 'should not return activities for excluded owner' do
+    Task.create! defaults(:excluded_owners=>person('person'))
+    Activity.for_stakeholder(person('person')).should be_empty
   end
 
+  it 'should not return activities not relevant to stakeholder' do
+    Task.create! defaults(:creator=>person('creator'))
+    Task.create! defaults(:owner=>person('owner'))
+    Activity.for_stakeholder(person('creator')).first.task.should == Task.first
+    Activity.for_stakeholder(person('owner')).last.task.should == Task.last
+  end
 
+  it 'should order activities from most recent to last' do
+    Task.create! defaults(:creator=>person('person'))
+    Activity.update_all ['created_at=?', Time.zone.now - 5.seconds]
+    Task.create! defaults(:owner=>person('person'))
+    activities = Activity.for_stakeholder(person('person'))
+    activities.first.created_at.should > activities.last.created_at
+  end
+
+  it 'should not return the same activity twice' do
+    Task.create! defaults(:creator=>person('person'), :observers=>person('person'))
+    Activity.for_stakeholder(person('person')).size.should == 1
+  end
+
+  it 'should not eager load dependencies' do
+    Activity.for_stakeholder(person('person')).proxy_options[:include].should be_nil
+  end
 end
+
+
+describe Activity, 'recently_added' do
+  it 'should return recently added activities' do
+    Activity.recently_added.proxy_options[:order].downcase.split.should == ['created_at', 'desc']
+  end
+  
+end
\ No newline at end of file