Permalink
Browse files

Better cache expiration. Use stubs instead of mocks.

  • Loading branch information...
1 parent 2394308 commit 815ceb4c5356c54cbdd4e073ada1ba7d8fa87047 Dimitrij Denissenko committed Sep 7, 2010
Showing with 143 additions and 100 deletions.
  1. +2 −1 app/controllers/project_area_controller.rb
  2. +12 −0 config/initializers/c.extensions/array.rb
  3. +29 −0 db/migrate/20100907201050_add_timestamps_to_projects_and_users.rb
  4. +1 −1 extensions/agile_pm/spec/views/goals/edit.html.erb_spec.rb
  5. +1 −1 extensions/agile_pm/spec/views/goals/index.html.erb_spec.rb
  6. +1 −1 extensions/agile_pm/spec/views/goals/no_milestones.html.erb_spec.rb
  7. +1 −1 extensions/agile_pm/spec/views/goals/show.html.erb_spec.rb
  8. +1 −1 extensions/agile_pm/spec/views/goals/show.js.rjs_spec.rb
  9. +1 −1 extensions/agile_pm/spec/views/sprints/edit.html.erb_spec.rb
  10. +1 −1 extensions/agile_pm/spec/views/sprints/new.html.erb_spec.rb
  11. +1 −1 extensions/agile_pm/spec/views/stories/backlog.html.erb_spec.rb
  12. +2 −2 extensions/agile_pm/spec/views/stories/comment.js.rjs_spec.rb
  13. +2 −2 extensions/agile_pm/spec/views/stories/index.html.erb_spec.rb
  14. +1 −1 extensions/agile_pm/spec/views/stories/new.html.erb_spec.rb
  15. +1 −1 extensions/agile_pm/spec/views/stories/no_sprints.html.erb_spec.rb
  16. +2 −2 extensions/agile_pm/spec/views/stories/show.js.rjs_spec.rb
  17. +1 −1 extensions/retro_blog/spec/controllers/blog_comments_controller_spec.rb
  18. +1 −1 extensions/retro_blog/spec/controllers/blog_controller_spec.rb
  19. +1 −1 extensions/retro_wiki/spec/controllers/wiki_controller_spec.rb
  20. +1 −1 extensions/retro_wiki/spec/controllers/wiki_files_controller_spec.rb
  21. +2 −2 extensions/retro_wiki/spec/helpers/format_helper_spec.rb
  22. +1 −1 spec/controllers/accounts_controller_spec.rb
  23. +3 −3 spec/controllers/application_controller_spec.rb
  24. +2 −2 spec/controllers/every_admin_area_controller.rb
  25. +3 −3 spec/controllers/project_area_controller_spec.rb
  26. +1 −1 spec/controllers/projects_controller_spec.rb
  27. +1 −1 spec/controllers/search_controller_spec.rb
  28. +1 −1 spec/controllers/ticket_reports_controller_spec.rb
  29. +4 −4 spec/controllers/tickets_controller_spec.rb
  30. +1 −1 spec/helpers/browse_helper_spec.rb
  31. +2 −2 spec/helpers/format_helper_spec.rb
  32. +2 −2 spec/helpers/milestones_helper_spec.rb
  33. +1 −1 spec/helpers/navigation_helper_spec.rb
  34. +1 −1 spec/support/helpers/typical_milestones_controller_setup.rb
  35. +6 −5 spec/support/mocks/current_project.rb
  36. +2 −2 spec/support/mocks/current_user.rb
  37. +2 −2 spec/support/mocks/mock_defaults.rb
  38. +1 −1 spec/support/mocks/permit_access.rb
  39. +1 −1 spec/views/admin/groups/edit.html.erb_spec.rb
  40. +1 −1 spec/views/admin/groups/index.html.erb_spec.rb
  41. +1 −1 spec/views/admin/groups/new.html.erb_spec.rb
  42. +1 −1 spec/views/admin/projects/edit.html.erb_spec.rb
  43. +1 −1 spec/views/admin/projects/index.html.erb_spec.rb
  44. +1 −1 spec/views/admin/projects/new.html.erb_spec.rb
  45. +1 −1 spec/views/admin/repositories/edit.html.erb_spec.rb
  46. +1 −1 spec/views/admin/repositories/index.html.erb_spec.rb
  47. +1 −1 spec/views/admin/repositories/new.html.erb_spec.rb
  48. +1 −1 spec/views/admin/users/_form.html.erb_spec.rb
  49. +1 −1 spec/views/admin/users/edit.html.erb_spec.rb
  50. +1 −1 spec/views/admin/users/index.html.erb_spec.rb
  51. +1 −1 spec/views/admin/users/new.html.erb_spec.rb
  52. +1 −1 spec/views/admin/users/search.js.rjs_spec.rb
  53. +2 −2 spec/views/browse/diff.html.erb_spec.rb
  54. +2 −2 spec/views/browse/index.html.erb_spec.rb
  55. +2 −2 spec/views/browse/revisions.html.erb_spec.rb
  56. +2 −2 spec/views/browse/show_binary.html.erb_spec.rb
  57. +2 −2 spec/views/browse/show_file.html.erb_spec.rb
  58. +2 −2 spec/views/browse/show_image.html.erb_spec.rb
  59. +1 −1 spec/views/changesets/diff.html.erb_spec.rb
  60. +1 −1 spec/views/changesets/index.html.erb_spec.rb
  61. +2 −2 spec/views/changesets/show.html.erb_spec.rb
  62. +1 −1 spec/views/milestones/edit.html.erb_spec.rb
  63. +2 −2 spec/views/milestones/index.html.erb_spec.rb
  64. +1 −1 spec/views/milestones/new.html.erb_spec.rb
  65. +2 −2 spec/views/search/index.html.erb_spec.rb
  66. +2 −2 spec/views/tickets/index.html.erb_spec.rb
  67. +2 −2 spec/views/tickets/new.html.erb_spec.rb
  68. +2 −2 spec/views/tickets/search.js.rjs_spec.rb
  69. +2 −2 spec/views/tickets/show.html.erb_spec.rb
@@ -37,7 +37,8 @@ def module_accessible?(project, item)
protected
def fresh_when(options = {})
- options[:etag] = [User.current, Project.current, flash] + Array(options[:etag])
+ options[:etag] = [User.current, Project.current, flash] + Array.wrap(options[:etag])
+ options[:last_modified] = ([User.current, Project.current].map(&:updated_at) + Array.wrap(options[:last_modified])).compact.max
super
end
@@ -0,0 +1,12 @@
+# Backport from Rails 3
+class Array
+ def self.wrap(object)
+ if object.nil?
+ []
+ elsif object.respond_to?(:to_ary)
+ object.to_ary
+ else
+ [object]
+ end
+ end
+end
@@ -0,0 +1,29 @@
+class AddTimestampsToProjectsAndUsers < ActiveRecord::Migration
+ def self.up
+ add_column :projects, :created_at, :timestamp
+ add_column :projects, :updated_at, :timestamp
+ add_column :users, :updated_at, :timestamp
+
+ rows = select_all %(
+ SELECT projects.id, MIN(LEAST(tickets.created_at, milestones.created_at)) AS created_at
+ FROM projects
+ INNER JOIN tickets ON tickets.project_id = projects.id
+ INNER JOIN milestones ON milestones.project_id = projects.id
+ WHERE projects.created_at IS NULL
+ GROUP BY projects.id
+ )
+ rows.each do |row|
+ update "UPDATE projects SET created_at = #{quote(row['created_at'])} WHERE id = #{row['id']}"
+ end
+
+ update "UPDATE projects SET created_at = #{quote(Time.now.utc.to_s(:db))} WHERE created_at IS NULL"
+ update "UPDATE projects SET updated_at = #{quote(Time.now.utc.to_s(:db))} WHERE updated_at IS NULL"
+ update "UPDATE users SET updated_at = #{quote(Time.now.utc.to_s(:db))} WHERE updated_at IS NULL"
+ end
+
+ def self.down
+ remove_column :projects, :created_at
+ remove_column :projects, :updated_at
+ remove_column :users, :updated_at
+ end
+end
@@ -3,7 +3,7 @@
describe "/goals/edit.html.erb" do
before(:each) do
- @project = mock_current_project! :name => 'Retrospectiva'
+ @project = stub_current_project! :name => 'Retrospectiva'
@milestone = assigns[:milestone] = stub_model(Milestone)
@goal = assigns[:goal] = stub_model(Goal, :sprint => stub_model(Sprint, :title => 'Sprint 1'))
assigns[:sprints] = [stub_model(Sprint)]
@@ -3,7 +3,7 @@
describe "/goals/index.html.erb" do
before(:each) do
- @project = mock_current_project!
+ @project = stub_current_project!
@sprint = assigns[:current_sprint] = stub_model(Sprint, :title => 'Sprint 1')
@milestone = assigns[:milestone] = stub_model(Milestone, :sprints => [@sprint, stub_model(Sprint, :title => 'Sprint 2')])
assigns[:milestones] = [@milestone, stub_model(Milestone)]
@@ -3,7 +3,7 @@
describe "/goals/no_milestones.html.erb" do
before(:each) do
- @project = mock_current_project! :name => 'Retrospectiva'
+ @project = stub_current_project! :name => 'Retrospectiva'
template.stub!(:permitted?).and_return(true)
template.stub!(:x_stylesheet_link_tag)
end
@@ -3,7 +3,7 @@
describe "/goals/show.html.erb" do
before(:each) do
- @project = mock_current_project! :name => 'Retrospectiva'
+ @project = stub_current_project! :name => 'Retrospectiva'
assigns[:milestone] = stub_model(Milestone)
assigns[:goal] = stub_model(Goal, :sprint => stub_model(Sprint, :title => 'Sprint 1'))
@@ -3,7 +3,7 @@
describe "/goals/show.js.rjs" do
before(:each) do
- @project = mock_current_project! :name => 'Retrospectiva'
+ @project = stub_current_project! :name => 'Retrospectiva'
assigns[:milestone] = stub_model(Milestone)
assigns[:goal] = stub_model(Goal, :sprint => stub_model(Sprint, :title => 'Sprint 1'))
@@ -3,7 +3,7 @@
describe "/sprints/edit.html.erb" do
before(:each) do
- @project = mock_current_project! :name => 'Retrospectiva'
+ @project = stub_current_project! :name => 'Retrospectiva'
@milestone = assigns[:milestone] = stub_model(Milestone)
@sprint = assigns[:sprint] = stub_model(Sprint)
@@ -3,7 +3,7 @@
describe "/sprints/new.html.erb" do
before(:each) do
- @project = mock_current_project! :name => 'Retrospectiva'
+ @project = stub_current_project! :name => 'Retrospectiva'
@milestone = assigns[:milestone] = stub_model(Milestone, :to_param => '37')
@sprint = assigns[:sprint] = stub_model(Sprint, :new_record? => true)
@@ -3,7 +3,7 @@
describe "/stories/backlog.html.erb" do
before(:each) do
- @project = mock_current_project!
+ @project = stub_current_project!
@stories = [stub_model(Story), stub_model(Story), stub_model(Story)]
@stories.stub!(:active_count).and_return(1)
@@ -3,8 +3,8 @@
describe "/stories/comment.js.rjs" do
before(:each) do
- @user = mock_current_user! :name => 'Doesnt Matter', :email => 'test@localhost.localdomain'
- @project = mock_current_project! :name => 'Retrospectiva'
+ @user = stub_current_user! :name => 'Doesnt Matter', :email => 'test@localhost.localdomain'
+ @project = stub_current_project! :name => 'Retrospectiva'
@sprint = assigns[:sprint] = stub_model(Sprint)
@milestone = assigns[:milestone] = stub_model(Milestone)
@@ -3,9 +3,9 @@
describe "/stories/index.html.erb" do
before(:each) do
- @project = mock_current_project!
+ @project = stub_current_project!
- @user_a = mock_current_user!
+ @user_a = stub_current_user!
@user_b = stub_model(User)
@stories = assigns[:stories] = { @user_a => [ stub_model(Story), stub_model(Story) ], @user_b => stub_model(Story) }
@@ -3,7 +3,7 @@
describe "/stories/new.html.erb" do
before(:each) do
- @project = mock_current_project!
+ @project = stub_current_project!
@sprint = assigns[:sprint] = stub_model(Sprint, :goals => [stub_model(Goal)])
@story = assigns[:story] = stub_model(Story)
@@ -3,7 +3,7 @@
describe "/stories/no_sprints.html.erb" do
before(:each) do
- @project = mock_current_project!
+ @project = stub_current_project!
template.stub!(:permitted?).and_return(true)
end
@@ -5,8 +5,8 @@
before(:each) do
@event = stub_model(StoryComment, :created_at => 3.days.ago)
- @project = mock_current_project!
- @user = mock_current_user! :name => 'Doesnt Matter', :email => 'test@localhost.localdomain'
+ @project = stub_current_project!
+ @user = stub_current_user! :name => 'Doesnt Matter', :email => 'test@localhost.localdomain'
@milestone = assigns[:milestone] = stub_model(Milestone)
@sprint = assigns[:sprint] = stub_model(Sprint)
@story = assigns[:story] = stub_model(Story, :events => [@event], :title => 'My Story', :created_at => 4.days.ago)
@@ -5,7 +5,7 @@
before do
@project = permit_access_with_current_project! :name => 'Retro', :wiki_title => 'Retro'
- @user = mock_current_user! :permitted? => true, :projects => [@project]
+ @user = stub_current_user! :permitted? => true, :projects => [@project]
@blog_post = mock_model(BlogPost)
@@ -5,7 +5,7 @@
before do
@project = permit_access_with_current_project! :name => 'Retro', :wiki_title => 'Retro'
- @user = mock_current_user! :permitted? => true, :projects => [@project]
+ @user = stub_current_user! :permitted? => true, :projects => [@project]
@posts_proxy = @project.stub_association!(:blog_posts)
@posts_proxy.stub!(:posted_by).and_return(@posts_proxy)
@posts_proxy.stub!(:categorized_as).and_return(@posts_proxy)
@@ -5,7 +5,7 @@
before do
@project = permit_access_with_current_project! :name => 'Retro', :wiki_title => 'Retro'
- @user = mock_current_user! :permitted? => true, :projects => [@project]
+ @user = stub_current_user! :permitted? => true, :projects => [@project]
@pages_proxy = @project.stub_association!(:wiki_pages)
end
@@ -5,7 +5,7 @@
before do
@project = permit_access_with_current_project! :name => 'Retro', :wiki_title => 'Retro'
- @user = mock_current_user! :permitted? => true, :projects => [@project]
+ @user = stub_current_user! :permitted? => true, :projects => [@project]
@files_proxy = @project.stub_association!(:wiki_files)
@files_proxy.stub!(:count).and_return(5)
@files_proxy.stub!(:maximum)
@@ -2,8 +2,8 @@
describe FormatHelper do
before do
- @project = mock_current_project! :existing_wiki_page_titles => ['Wiki'], :existing_revisions => []
- @user = mock_current_user! :permitted? => true
+ @project = stub_current_project! :existing_wiki_page_titles => ['Wiki'], :existing_revisions => []
+ @user = stub_current_user! :permitted? => true
helper.stub!(:permitted?).and_return(true)
end
@@ -3,7 +3,7 @@
describe AccountsController do
before do
- @user = mock_current_user!
+ @user = stub_current_user!
@project = permit_access_with_current_project!
@new = mock_model(User)
User.stub!(:new).and_return(@new)
@@ -5,7 +5,7 @@
describe 'permission checks' do
before do
- @user = mock_current_user! :public? => true, :permitted => true
+ @user = stub_current_user! :public? => true, :permitted => true
end
it 'should forward checks currently logged-in user' do
@@ -252,7 +252,7 @@ def do_get(options = {})
@tickets.stub!(:maximum)
@project = permit_access_with_current_project! :name => 'Any', :tickets => @tickets
- @user = mock_current_user! :public? => false, :name => 'Agent', :email => 'agent@mail.com'
+ @user = stub_current_user! :public? => false, :name => 'Agent', :email => 'agent@mail.com'
end
describe 'storing' do
@@ -331,7 +331,7 @@ def do_get
before do
permit_access_with_current_project!
controller.stub!(:load_channels).and_return([])
- @user = mock_current_user! :name => 'Doesnt Matter'
+ @user = stub_current_user! :name => 'Doesnt Matter'
end
def do_get
@@ -26,15 +26,15 @@ def action_names
end
it "should grant access to administrators" do
- mock_current_user!(:admin? => true, :name => 'Admin')
+ stub_current_user!(:admin? => true, :name => 'Admin')
controller.class.rspec_reset
action_names.each do |action|
lambda { request_restfully(action) }.should_not raise_error(RetroAM::NoAuthorizationError)
end
end
it "should deny access to ordinary users" do
- mock_current_user!(:admin? => false, :name => 'Ordinary')
+ stub_current_user!(:admin? => false, :name => 'Ordinary')
controller.class.rspec_reset
action_names.each do |action|
lambda { request_restfully(action) }.should raise_error(RetroAM::NoAuthorizationError)
@@ -3,8 +3,8 @@
describe ProjectAreaController do
before do
- @user = mock_current_user! :admin? => true, :name => 'Agent'
- @project = mock_current_project! :enabled_modules => [], :name => 'Retro'
+ @user = stub_current_user! :admin? => true, :name => 'Agent'
+ @project = stub_current_project! :enabled_modules => [], :name => 'Retro'
@item = mock(RetroAM::MenuMap::Item, :name => 'Item', :active? => true)
RetroAM.menu_items.stub!(:find).and_return(@item)
end
@@ -89,7 +89,7 @@ def authorize?(action_name = 'index', request_params = {})
controller_name :milestones
before do
- @user = mock_current_user! :name => 'Public', :public? => true, :admin? => false, :permitted? => false
+ @user = stub_current_user! :name => 'Public', :public? => true, :admin? => false, :permitted? => false
@project = stub_model Project,
:name => 'Retro', :short_name => 'retro',
:enabled_modules => ['milestones']
@@ -3,7 +3,7 @@
describe ProjectsController do
before do
- @user = mock_current_user! :name => 'Someone'
+ @user = stub_current_user! :name => 'Someone'
end
describe 'loading active projects' do
@@ -5,7 +5,7 @@
before do
@project = permit_access_with_current_project! :name => 'Retrospectiva'
- @user = mock_current_user! :has_access? => true
+ @user = stub_current_user! :has_access? => true
end
describe 'GET /index' do
@@ -5,7 +5,7 @@
before do
@project = permit_access_with_current_project! :name => 'Retrospectiva'
- @user = mock_current_user! :has_access? => true
+ @user = stub_current_user! :has_access? => true
@reports_proxy = []
@project.stub!(:ticket_reports).and_return(@reports_proxy)
end
@@ -4,18 +4,18 @@
it_should_behave_like EveryProjectAreaController
before do
- Status.stub!(:default).and_return(mock_model(Status))
- Priority.stub!(:default).and_return(mock_model(Priority))
+ Status.stub!(:default).and_return(stub_model(Status))
+ Priority.stub!(:default).and_return(stub_model(Priority))
end
before do
@project = permit_access_with_current_project! :name => 'Any'
- @tickets = [mock_model(Ticket)]
+ @tickets = [stub_model(Ticket)]
@tickets_proxy = @project.stub_association!(:tickets)
@tickets_proxy.stub!(:count)
@tickets_proxy.stub!(:maximum)
@changes_proxy = @project.stub_association!(:ticket_changes)
- @user = mock_current_user! :public? => false, :name => 'Agent', :email => 'agent@mail.com'
+ @user = stub_current_user! :public? => false, :name => 'Agent', :email => 'agent@mail.com'
end
describe "handling GET /tickets" do
@@ -6,7 +6,7 @@
before do
@project = projects(:retro)
Project.stub!(:current).and_return(@project)
- @user = mock_current_user! :has_access? => true
+ @user = stub_current_user! :has_access? => true
@path = ['folder', 'file.rb']
@params = { :rev => 'R123', :path => @path }
helper.extend ApplicationHelper
@@ -2,8 +2,8 @@
describe FormatHelper do
before do
- @project = mock_current_project!
- @user = mock_current_user!
+ @project = stub_current_project!
+ @user = stub_current_user!
end
describe 'formatting internal links' do
@@ -11,7 +11,7 @@
describe 'ticket stats and links' do
before do
- @project = mock_current_project! :to_param => 'retro'
+ @project = stub_current_project! :to_param => 'retro'
@milestone = mock_model Milestone,
:id => '1',
:ticket_counts => { 'open' => 10, 'in_progress' => 0, 'resolved' => 90 }.with_indifferent_access
@@ -30,7 +30,7 @@
before do
helper.stub!(:image_spacer).and_return('I')
- @project = mock_current_project!
+ @project = stub_current_project!
@milestone = mock_model Milestone,
:progress_percentages => { 'open' => 80, 'in_progress' => 20, 'resolved' => 0 }.with_indifferent_access
end
@@ -6,7 +6,7 @@
before do
@project = projects(:retro)
Project.stub!(:current).and_return(@project)
- @user = mock_current_user! :has_access? => true
+ @user = stub_current_user! :has_access? => true
end
describe 'linking to changesets' do
Oops, something went wrong.

0 comments on commit 815ceb4

Please sign in to comment.