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/09 03:27:07 UTC
svn commit: r684168 - in /ode/sandbox/singleshot: ./ app/controllers/
app/models/ app/views/layouts/ config/ lib/extensions/ lib/tasks/
public/stylesheets/ spec/ spec/controllers/ spec/models/
Author: assaf
Date: Fri Aug 8 18:27:06 2008
New Revision: 684168
URL: http://svn.apache.org/viewvc?rev=684168&view=rev
Log:
Merge branch 'dev'
Conflicts:
app/models/activity.rb
public/stylesheets/default.css
spec/models/activity_spec.rb
Added:
ode/sandbox/singleshot/spec/controllers/activity_controller_spec.rb
ode/sandbox/singleshot/spec/models/person_spec.rb
ode/sandbox/singleshot/spec/people.rb
ode/sandbox/singleshot/spec/tasks.rb
Removed:
ode/sandbox/singleshot/spec/enhancements.rb
ode/sandbox/singleshot/spec/models/helper.rb
Modified:
ode/sandbox/singleshot/.gitignore
ode/sandbox/singleshot/app/controllers/activity_controller.rb
ode/sandbox/singleshot/app/models/activity.rb
ode/sandbox/singleshot/app/models/person.rb
ode/sandbox/singleshot/app/views/layouts/application.html.erb
ode/sandbox/singleshot/config/environment.rb
ode/sandbox/singleshot/lib/extensions/ical_template.rb
ode/sandbox/singleshot/lib/extensions/validators.rb
ode/sandbox/singleshot/lib/tasks/setup.rake
ode/sandbox/singleshot/public/stylesheets/default.css
ode/sandbox/singleshot/spec/models/activity_spec.rb
ode/sandbox/singleshot/spec/models/stakeholder_spec.rb
ode/sandbox/singleshot/spec/models/task_spec.rb
ode/sandbox/singleshot/spec/spec_helper.rb
Modified: ode/sandbox/singleshot/.gitignore
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/.gitignore?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/.gitignore (original)
+++ ode/sandbox/singleshot/.gitignore Fri Aug 8 18:27:06 2008
@@ -1,5 +1,7 @@
-tmp
-log
db/*.sqlite3
+log/*.log
+tmp/**/*
+.DS_Store
+secret.key
vendor/rails
index
Modified: ode/sandbox/singleshot/app/controllers/activity_controller.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/controllers/activity_controller.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/controllers/activity_controller.rb (original)
+++ ode/sandbox/singleshot/app/controllers/activity_controller.rb Fri Aug 8 18:27:06 2008
@@ -1,3 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
class ActivityController < ApplicationController
access_key_authentication
Modified: ode/sandbox/singleshot/app/models/activity.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/activity.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/activity.rb (original)
+++ ode/sandbox/singleshot/app/models/activity.rb Fri Aug 8 18:27:06 2008
@@ -37,12 +37,19 @@
!new_record?
end
+<<<<<<< HEAD:app/models/activity.rb
+=======
+ # Eager loads all activities and their dependents (task, person).
+ named_scope :with_dependents, :include=>[:task, :person]
+
+>>>>>>> dev:app/models/activity.rb
# Returns activities from all tasks associated with this stakeholder.
named_scope :for_stakeholder, lambda { |person|
{ :joins=>'JOIN stakeholders AS involved ON involved.task_id=activities.task_id',
:conditions=>["involved.person_id=? AND involved.role != 'excluded'", person.id],
:order=>'activities.created_at DESC', :group=>'activities.task_id, activities.person_id, activities.name' } }
+<<<<<<< HEAD:app/models/activity.rb
named_scope :with_dependents, :include=>[:task, :person]
named_scope :for_dates, lambda { |range|
@@ -51,6 +58,13 @@
range = range.to_time..Time.current.end_of_day
when Range
range = range.min.to_time.beginning_of_day..range.max.to_time.end_of_day
+=======
+ # Returns activities for a range of dates (from..to) or from a given date to today.
+ named_scope :for_dates, lambda { |arg|
+ range = case arg
+ when Date, Time; arg.to_time.in_time_zone.beginning_of_day..Time.current.end_of_day
+ when Range; arg.first.to_time.in_time_zone.beginning_of_day..arg.last.to_time.in_time_zone.end_of_day
+>>>>>>> dev:app/models/activity.rb
end
{ :conditions=>{ :created_at=>range } } }
Modified: ode/sandbox/singleshot/app/models/person.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/app/models/person.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/models/person.rb (original)
+++ ode/sandbox/singleshot/app/models/person.rb Fri Aug 8 18:27:06 2008
@@ -40,9 +40,9 @@
# it will return an array of people. Matches against the identity returned in to_param.
def identify(identity)
case identity
- when Array then Person.find(:all, :conditions=>{:identity=>identity.flatten.uniq})
when Person then identity
- else Person.find_by_identity(identity) or raise ActiveRecord::RecordNotFound
+ when Array then Person.find(:all, :conditions=>{:identity=>identity.flatten.uniq})
+ else Person.find_by_identity(identity.to_s) or raise ActiveRecord::RecordNotFound
end
end
@@ -88,15 +88,15 @@
# TODO: Some way to check minimum size of passwords.
def password=(password)
- seed = SHA1.hexdigest(OpenSSL::Random.random_bytes(128))[0,10]
- crypted = SHA1.hexdigest("#{seed}:#{password}")
- self[:password] = "#{seed}:#{crypted}"
+ salt = SHA1.hexdigest(OpenSSL::Random.random_bytes(128))[0,10]
+ crypted = SHA1.hexdigest("#{salt}:#{password}")
+ self[:password] = "#{salt}:#{crypted}"
end
def password?(password)
return false unless self[:password]
- seed, crypted = self[:password].split(':')
- crypted == SHA1.hexdigest("#{seed}:#{password}")
+ salt, crypted = self[:password].split(':')
+ crypted == SHA1.hexdigest("#{salt}:#{password}")
end
def reset_password!
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=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/app/views/layouts/application.html.erb (original)
+++ ode/sandbox/singleshot/app/views/layouts/application.html.erb Fri Aug 8 18:27:06 2008
@@ -14,7 +14,7 @@
<li><%= link_to 'Logout', session_url, :method=>:delete %></li>
</ul>
<ul class='tabs'><%=
- [ ['â Inbox', tasks_url, 'Pending and available tasks'],
+ [ ['â Tasks list', tasks_url, 'Your task list'],
['All Tasks', following_tasks_url, 'Tasks you create, observing or administrating'],
['Completed', completed_tasks_url, 'Tasks you completed'],
['Activity', activity_url, 'Recent task activity'] ].map { |tab|
Modified: ode/sandbox/singleshot/config/environment.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/config/environment.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/config/environment.rb (original)
+++ ode/sandbox/singleshot/config/environment.rb Fri Aug 8 18:27:06 2008
@@ -57,10 +57,7 @@
# no regular words or you'll be exposed to dictionary attacks.
config.action_controller.session = {
:session_key => '_singleshot_session',
- # NOTE: This secret is not so secret, it shows up in the source distribution.
- # Change to something else before deploying in production!
- # Use rake secret to generate a new crypto-strong secrent.
- :secret => '01d45defc4a9585c2e0a9d6bb1d10ff3488fa2ffef1fd439ad03894cc2ae4e5025bdc6487972679b97a7ac79bd385ee07b36c7952f7882d35bdc9bc60aa584bf'
+ :secret => File.read('secret.key')
}
# Use the database for sessions instead of the cookie-based default,
Modified: ode/sandbox/singleshot/lib/extensions/ical_template.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/extensions/ical_template.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/extensions/ical_template.rb (original)
+++ ode/sandbox/singleshot/lib/extensions/ical_template.rb Fri Aug 8 18:27:06 2008
@@ -94,9 +94,8 @@
end
def compile(template)
- content_type_handler = (@view.send!(:controller).respond_to?(:response) ? "controller.response" : "controller")
<<-RUBY
- #{content_type_handler}.content_type ||= "#{Mime::ICS};method=PUBLISH"
+ set_controller_content_type("#{Mime::ICS};method=PUBLISH");
ical = ActionView::ICalBuilder.new controller.request do |calendar|
#{template.source}
end
Modified: ode/sandbox/singleshot/lib/extensions/validators.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/extensions/validators.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/extensions/validators.rb (original)
+++ ode/sandbox/singleshot/lib/extensions/validators.rb Fri Aug 8 18:27:06 2008
@@ -1,9 +1,10 @@
module ActiveRecord
module Validators
module Url
-
+
def self.included(mod)
- ActiveRecord::Errors.default_error_messages[:invalid_url] = 'Not a valid URL'
+ I18n.backend.store_translations :'en-US',
+ { :active_record => { :error_messages => { :invalid_url => "is not a valid URL" } } }
mod.extend ClassMethods
end
@@ -20,8 +21,7 @@
# # Only allow HTPS
# validates_url :secure_url, :schemes=>['https']
def validates_url(*attr_names)
- configuration = { :message => ActiveRecord::Errors.default_error_messages[:invalid_url], :on=>:save,
- :schemes=>['http', 'https'] }
+ configuration = { :on=>:save, :schemes=>['http', 'https'] }
configuration.update(attr_names.extract_options!)
# Normalize URL.
@@ -39,7 +39,8 @@
# Validate URL.
validates_each(attr_names, configuration) do |record, attr_name, value|
uri = URI.parse(value) rescue nil
- record.errors.add attr_name, configuration[:message] unless uri && uri.scheme && uri.host &&
+ message = record.errors.generate_message(attr_name, :invalid_url, :default=>configuration[:message])
+ record.errors.add attr_name, message unless uri && uri.scheme && uri.host &&
configuration[:schemes].include?(uri.scheme.downcase)
end
end
@@ -49,9 +50,10 @@
end
module Email
-
+
def self.included(mod)
- ActiveRecord::Errors.default_error_messages[:invalid_email] = 'Not a valid e-mail address'
+ I18n.backend.store_translations :'en-US',
+ { :active_record => { :error_messages => { :invalid_email => "is not a valid email address" } } }
mod.extend ClassMethods
end
@@ -60,9 +62,10 @@
# Validates that each attribute looks like a valid e-mail address. Does not check that the
# e-mail address makes sense, only that it is more likely to be an e-mail address than a phone number.
def validates_email(*attr_names)
- configuration = { :message => ActiveRecord::Errors.default_error_messages[:invalid_email], :on => :save }
+ configuration = { :on => :save }
configuration.update(attr_names.extract_options!)
- configuration.update(:with => /^([^@\s]+)@[-a-z0-9]+(\.[-a-z0-9]+)*$/)
+ configuration[:with] = /^([^@\s]+)@[-a-z0-9]+(\.[-a-z0-9]+)*$/
+ configuration[:message] ||= I18n.translate('active_record.error_messages.invalid_email')
attr_names << configuration
validates_format_of *attr_names
end
Modified: ode/sandbox/singleshot/lib/tasks/setup.rake
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/lib/tasks/setup.rake?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/lib/tasks/setup.rake (original)
+++ ode/sandbox/singleshot/lib/tasks/setup.rake Fri Aug 8 18:27:06 2008
@@ -1,4 +1,12 @@
require 'rails_generator/secret_key_generator'
+task 'secret.key' do |task|
+ secret = Rails::SecretKeyGenerator.new(ENV['ID']).generate_secret
+ File.open task.name, 'w' do |file|
+ file.write secret
+ end
+ puts "Generated new secret in #{task.name}"
+end
+
desc 'Run this task first to setup your test/development environment'
-task 'setup'=>['gems:install', 'db:create', 'db:test:clone', 'db:populate']
+task 'setup'=>['secret.key', 'gems:install', 'db:create', 'db:test:clone', 'db:populate']
Modified: ode/sandbox/singleshot/public/stylesheets/default.css
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/public/stylesheets/default.css?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/public/stylesheets/default.css (original)
+++ ode/sandbox/singleshot/public/stylesheets/default.css Fri Aug 8 18:27:06 2008
@@ -257,18 +257,19 @@
margin: 0;
border-bottom: 1px solid #eee;
text-overflow: ellipsis;
- overflow: hidden;
- white-space: nowrap;
+ overflow: hidden;
+ white-space: nowrap;
}
table.tasks tbody td img {
vertical-align: middle;
}
-table.tasks tbody tr.inactive, table.tasks tbody tr.inactive td a {
- color: #888;
-}
table.tasks tbody tr.overdue td, table.tasks tbody .overdue td a {
color: #f04040;
}
+table.tasks tbody tr.completed td, table.tasks tbody tr.completed td a,
+table.tasks tbody tr.cancelled td, table.tasks tbody tr.cancelled td a {
+ color: #888;
+}
table.tasks tbody td .priority_1 {
color: #f04040;
}
@@ -291,7 +292,7 @@
}
ol.dates li.date h2 {
font-size: 1.0em;
- padding: 0 0 0.3em 0;
+ padding: 0 0 0.6em 0;
margin: 0 0 0.6em 0;
border-bottom: 1px solid #ccc;
}
@@ -405,16 +406,25 @@
div.pagination {
margin: 0 auto 0 auto;
text-align: center;
+ margin-bottom: 3em;
+}
+div.pagination a, div.pagination span {
+ margin-left: 0.3em;
+ padding: 0.1em 0.3em 0.2em 0.3em;
}
div.pagination a {
- padding: 0.3em;
+ border: 1px solid #ccc;
+}
+div.pagination span {
border: 1px solid #ccc;
}
div.pagination a:hover {
- border: 1px solid #055da4;
+ color: #fff;
+ background-color: #055da4;;
}
-div.pagination span {
- padding: 0.3em;
+div.pagination span.prev_page, div.pagination span.next_page {
+ color: #888;
+ display: none;
}
/** Footer **/
Added: 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=684168&view=auto
==============================================================================
--- ode/sandbox/singleshot/spec/controllers/activity_controller_spec.rb (added)
+++ ode/sandbox/singleshot/spec/controllers/activity_controller_spec.rb Fri Aug 8 18:27:06 2008
@@ -0,0 +1,42 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+
+describe ActivityController do
+
+ describe 'index' do
+
+ it 'should map to /activity' do
+ route_for(:controller=>'activity', :action=>'index').should eql('/activity')
+ end
+
+ it 'should require authentication' do
+ get 'index'
+ response.should redirect_to(session_url)
+ end
+
+ it 'should return root element activities' do
+ authenticate do
+ get 'index', :format=>Mime::XML
+ p response.body
+ end
+ 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=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/models/activity_spec.rb (original)
+++ ode/sandbox/singleshot/spec/models/activity_spec.rb Fri Aug 8 18:27:06 2008
@@ -15,7 +15,6 @@
require File.dirname(__FILE__) + '/../spec_helper'
-require File.dirname(__FILE__) + '/helper'
describe Activity do
@@ -78,17 +77,24 @@
describe 'for_dates' do
- it 'should return activities in date range' do
- now = Time.zone.now
- activities = (0..3).each do |i|
- Task.create! defaults(:creator=>person('creator'))
- Activity.update_all ['created_at=?', now - i.day], ['id=?', Activity.last.id]
- end
- min, max = Activity.minimum(:created_at) + 1.day, Activity.maximum(:created_at)
- Activity.for_dates(min.to_date..max.to_date).count == 1
- Activity.for_dates(min.to_date..max.to_date).each do |activity|
- activity.created_at.should be_between(min, max)
- end
+ 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
@@ -127,9 +133,8 @@
end
it 'should not eager load dependencies' do
- Activity.for_stakeholder(person('person')).proxy_options[:include].should be_empty
+ Activity.for_stakeholder(person('person')).proxy_options[:include].should be_nil
end
-
end
end
Added: ode/sandbox/singleshot/spec/models/person_spec.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/models/person_spec.rb?rev=684168&view=auto
==============================================================================
--- ode/sandbox/singleshot/spec/models/person_spec.rb (added)
+++ ode/sandbox/singleshot/spec/models/person_spec.rb Fri Aug 8 18:27:06 2008
@@ -0,0 +1,46 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+
+describe Person do
+
+ describe 'activities' do
+ before do
+ Task.create! defaults(:creator=>person('creator'), :owner=>person(:owner))
+ Task.create! defaults(:owner=>person(:owner))
+ end
+
+ it 'should return all activities associated with that person' do
+ person(:creator).activities.map { |a| [a.name, a.task, a.person] }.
+ should include(['created', Task.first, person(:creator)])
+ person(:owner).activities.map { |a| [a.name, a.task, a.person] }.
+ should include(['owner', Task.first, person(:owner)], ['owner', Task.last, person(:owner)])
+ end
+
+ it 'should return only activities associated with that person' do
+ person(:creator).activities.map(&:person).uniq.should == [person(:creator)]
+ person(:owner).activities.map(&:person).uniq.should == [person(:owner)]
+ end
+
+ it 'should allow eager loading with dependents' do
+ person(:owner).activities.with_dependents.proxy_options[:include].should include(:task, :person)
+ end
+
+ end
+
+end
\ No newline at end of file
Modified: ode/sandbox/singleshot/spec/models/stakeholder_spec.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/models/stakeholder_spec.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/models/stakeholder_spec.rb (original)
+++ ode/sandbox/singleshot/spec/models/stakeholder_spec.rb Fri Aug 8 18:27:06 2008
@@ -1,5 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
require File.dirname(__FILE__) + '/../spec_helper'
-require File.dirname(__FILE__) + '/helper'
describe Stakeholder do
Modified: ode/sandbox/singleshot/spec/models/task_spec.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/models/task_spec.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/models/task_spec.rb (original)
+++ ode/sandbox/singleshot/spec/models/task_spec.rb Fri Aug 8 18:27:06 2008
@@ -1,5 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
require File.dirname(__FILE__) + '/../spec_helper'
-require File.dirname(__FILE__) + '/helper'
describe Task do
@@ -233,7 +248,7 @@
describe 'due_on' do
- it 'should not be required' do
+ it 'should be optional' do
Task.create(defaults.except(:due_on)).should have(:no).errors
end
@@ -261,7 +276,7 @@
Task.last.due_on.should == now.to_date
end
- it 'should accept blank string and set to nil' do
+ it 'should accept blank string as nil' do
Task.create! defaults(:due_on=>Time.now)
Task.last.update_attributes :due_on=>''
Task.last.due_on.should be_nil
@@ -272,28 +287,30 @@
describe 'over_due?' do
- it 'should be false if task has no due date' do
+ it 'should be false if no due date' do
Task.create(defaults).over_due?.should be_false
end
- it 'should be false if task due date in the future' do
+ it 'should be false if due date in the future' do
Task.create(defaults(:due_on=>Date.tomorrow)).over_due?.should be_false
end
- it 'should be false if task due today' do
+ it 'should be false if due today' do
Task.create(defaults(:due_on=>Date.today)).over_due?.should be_false
end
- it 'should be true if task due date in the past' do
+ it 'should be true if due date in the past' do
Task.create(defaults(:due_on=>Date.yesterday)).over_due?.should be_true
end
- it 'should be true only if task is ready or active' do
+ it 'should be true only when task is ready or active' do
for status in Task::STATUSES
task_with_status(status, :due_on=>Date.yesterday).over_due?.should == (status == 'ready' || status == 'active')
end
end
+ it 'should respect current time zone'
+
end
Added: ode/sandbox/singleshot/spec/people.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/people.rb?rev=684168&view=auto
==============================================================================
--- ode/sandbox/singleshot/spec/people.rb (added)
+++ ode/sandbox/singleshot/spec/people.rb Fri Aug 8 18:27:06 2008
@@ -0,0 +1,69 @@
+module SpecHelpers
+
+ module People
+ def self.included(base)
+ base.after :each do
+ Person.delete_all
+ end
+ end
+
+ def person(identity)
+ Person.identify(identity) rescue Person.create!(:email=>"#{identity}@apache.org", :password=>'secret')
+ end
+
+ def people(*identities)
+ identities.map { |identity| person(identity) }
+ end
+ end
+
+ # Authentication support for use with controllers.
+ module Authentication
+
+ # Authenticates as the specified person.
+ #
+ # You can use this with a block to authenticate only for the duration of a block:
+ # authenticate owner do
+ # ...
+ # end
+ #
+ # Without arguments, authenticates as 'person'.
+ def authenticate(person = person('person'))
+ #credentials = [person.identity, 'secret']
+ #request.headers['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(*credentials)
+ if block_given?
+ begin
+ previous, session[:person_id] = session[:person_id], person.id
+ credentials = [person.identity, 'secret']
+ request.headers['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(*credentials)
+ p 'here'
+ yield
+ ensure
+ session[:person_id] = previous
+ request.headers.delete('HTTP_AUTHORIZATION')
+ end
+ else
+ session[:person_id] = person.is
+ credentials = [person.identity, 'secret']
+ request.headers['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(*credentials)
+ end
+ end
+
+ # Returns the currently authenticated person.
+ def authenticated
+ Person.find(session[:person_id]) if session[:person_id]
+ end
+
+ # Returns true if the previous request was authenticated and authorized.
+ def authorized?
+ !(response.redirected_to == session_url || response.code == '401')
+ end
+
+ end
+end
+
+
+Spec::Runner.configure do |config|
+ config.include SpecHelpers::People, :type=>:model
+ config.include SpecHelpers::People, :type=>:controller
+ config.include SpecHelpers::Authentication, :type=>:controller
+end
Modified: ode/sandbox/singleshot/spec/spec_helper.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/spec_helper.rb?rev=684168&r1=684167&r2=684168&view=diff
==============================================================================
--- ode/sandbox/singleshot/spec/spec_helper.rb (original)
+++ ode/sandbox/singleshot/spec/spec_helper.rb Fri Aug 8 18:27:06 2008
@@ -3,7 +3,19 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec/rails'
-require File.expand_path(File.dirname(__FILE__) + "/enhancements")
+require File.expand_path(File.dirname(__FILE__) + '/people')
+require File.expand_path(File.dirname(__FILE__) + '/tasks')
+
+module ActionController
+ # TestResponse for functional, CgiResponse for integration.
+ class AbstractResponse
+ StatusCodes::SYMBOL_TO_STATUS_CODE.each do |symbol, code|
+ unless instance_methods.include?("#{symbol}?")
+ define_method("#{symbol}?") { self.code == code.to_s }
+ end
+ end
+ end
+end
Spec::Runner.configure do |config|
config.use_transactional_fixtures = true
Added: ode/sandbox/singleshot/spec/tasks.rb
URL: http://svn.apache.org/viewvc/ode/sandbox/singleshot/spec/tasks.rb?rev=684168&view=auto
==============================================================================
--- ode/sandbox/singleshot/spec/tasks.rb (added)
+++ ode/sandbox/singleshot/spec/tasks.rb Fri Aug 8 18:27:06 2008
@@ -0,0 +1,53 @@
+module SpecHelpers
+
+ module Tasks
+ def self.included(base)
+ base.after :each do
+ Activity.delete_all
+ Stakeholder.delete_all
+ Task.delete_all
+ end
+ end
+
+ def defaults(attributes = {})
+ { :title=>'Test this',
+ :outcome_url=>'http://test.host/outcome' }.merge(attributes)
+ end
+
+ def task_with_status(status, attributes = nil)
+ attributes ||= {}
+ attributes = attributes.reverse_merge(:admins=>person('admin'))
+ task = case status
+ when 'active'
+ Task.create!(defaults(attributes).merge(:status=>'active', :owner=>person('owner')))
+ when 'completed' # Start as active, modified by owner.
+ active = task_with_status('active', attributes)
+ active.modify_by(person('owner')).update_attributes! :status=>'completed'
+ active
+ when 'cancelled', 'suspended' # Start as active, modified by admin.
+ active = task_with_status('ready', attributes)
+ active.modify_by(person('admin')).update_attributes! :status=>status
+ active
+ else
+ Task.create!(defaults(attributes).merge(:status=>status))
+ end
+
+ def task.transition_to(status, attributes = nil)
+ attributes ||= {}
+ modify_by(attributes.delete(:modified_by) || Person.identify('admin')).update_attributes attributes.merge(:status=>status)
+ self
+ end
+ def task.can_transition?(status, attributes = nil)
+ transition_to(status, attributes).errors_on(:status).empty?
+ rescue ActiveRecord::ReadOnlyRecord
+ false
+ end
+ task
+ end
+ end
+end
+
+Spec::Runner.configure do |config|
+ config.include SpecHelpers::Tasks, :type=>:model
+ config.include SpecHelpers::Tasks, :type=>:controller
+end