Skip to content

Commit

Permalink
Refactored inline boundry check (no projects) to a before_filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
edavis10 committed Feb 16, 2010
1 parent 573665b commit b8dde7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/controllers/bulk_time_entries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BulkTimeEntriesController < ApplicationController
before_filter :load_activities
before_filter :load_allowed_projects
before_filter :load_first_project
before_filter :check_for_no_projects

helper :custom_fields
include BulkTimeEntriesHelper
Expand All @@ -13,10 +14,6 @@ class BulkTimeEntriesController < ApplicationController

def index
@time_entries = [TimeEntry.new(:spent_on => Date.today.to_s)]

if @projects.empty?
render :action => 'no_projects'
end
end

def load_assigned_issues
Expand Down Expand Up @@ -84,6 +81,13 @@ def load_first_project
@first_project = @projects.sort_by(&:lft).first unless @projects.empty?
end

def check_for_no_projects
if @projects.empty?
render :action => 'no_projects'
return false
end
end

def self.allowed_project?(project_id)
return User.current.projects.find_by_id(project_id, :conditions => Project.allowed_to_condition(User.current, :log_time))
end
Expand Down
3 changes: 2 additions & 1 deletion test/functional/bulk_time_entries_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BulkTimeEntriesControllerTest < ActionController::TestCase
should_have_before_filter :load_activities
should_have_before_filter :load_allowed_projects
should_have_before_filter :load_first_project
should_have_before_filter :check_for_no_projects

context "GET to :index" do
context "as a user without any projects" do
Expand All @@ -22,7 +23,7 @@ class BulkTimeEntriesControllerTest < ActionController::TestCase
end

should_respond_with :success
should_assign_to :time_entries
should_not_assign_to :time_entries
should_assign_to :projects
should_render_template :no_projects

Expand Down

0 comments on commit b8dde7e

Please sign in to comment.