fix specs for rails3 to expect a 404 response instead of catching an exception

Change-Id: I7af57c4fcae02f1ba5c0fe5e446a0b6229bc0ca4
Reviewed-on: https://gerrit.instructure.com/29796
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Product-Review: Derek DeVries <ddevries@instructure.com>
QA-Review: Derek DeVries <ddevries@instructure.com>
This commit is contained in:
Derek DeVries 2014-02-07 11:41:40 -07:00
parent fa189a98cd
commit 237e89713a
9 changed files with 39 additions and 19 deletions

View File

@ -242,7 +242,9 @@ describe CoursesController do
it "should not find deleted courses" do
course_with_teacher_logged_in(:active_all => true)
@course.destroy
lambda { get 'show', :id => @course.id }.should raise_exception(ActiveRecord::RecordNotFound)
assert_page_not_found do
get 'show', :id => @course.id
end
end
it "should assign variables" do

View File

@ -49,11 +49,11 @@ describe CrocodocSessionsController do
it "should ensure the attachment is tied to the submission" do
@submission.update_attribute :attachment_ids, nil
lambda {
assert_page_not_found do
post :create,
:submission_id => @submission.id,
:attachment_id => @attachment.id
}.should raise_error(ActiveRecord::RecordNotFound)
end
end
end
@ -75,10 +75,10 @@ describe CrocodocSessionsController do
end
it "should 404 if a crocodoc document is unavailable" do
lambda {
assert_page_not_found do
post :create,
:submission_id => @submission.id,
:attachment_id => @attachment.id
}.should raise_error(ActiveRecord::RecordNotFound)
end
end
end

View File

@ -442,8 +442,13 @@ describe FilesController do
it "should fail if the file path doesn't match" do
course_with_teacher_logged_in(:active_all => true)
file_in_a_module
proc { get "show_relative", :course_id => @course.id, :file_path => @file.full_display_path+"blah" }.should raise_error(ActiveRecord::RecordNotFound)
proc { get "show_relative", :file_id => @file.id, :course_id => @course.id, :file_path => @file.full_display_path+"blah" }.should raise_error(ActiveRecord::RecordNotFound)
assert_page_not_found do
get "show_relative", :course_id => @course.id, :file_path => @file.full_display_path+"blah"
end
assert_page_not_found do
get "show_relative", :file_id => @file.id, :course_id => @course.id, :file_path => @file.full_display_path+"blah"
end
end
it "should ignore bad file_ids" do

View File

@ -334,9 +334,9 @@ describe GradebooksController do
it "should raise an exception on a non-integer :id" do
course_with_teacher_logged_in(:active_all => true)
expect {
assert_page_not_found do
get 'grade_summary', :course_id => @course.id, :id => "lqw"
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
end

View File

@ -65,12 +65,12 @@ describe RubricAssessmentsController do
it "should not pass invalid ids through to the database" do
course_with_teacher_logged_in(:active_all => true)
lambda {
assert_page_not_found do
rubric_assessment_model(:user => @user, :context => @course, :purpose => 'grading')
post 'create', :course_id => @course.id,
:rubric_association_id => @rubric_association.id,
:rubric_assessment => {:user_id => 'garbage', :assessment_type => "no_reason"}
}.should raise_error ActiveRecord::RecordNotFound
end
end
end

View File

@ -513,15 +513,15 @@ describe RubricsController do
before { course_with_teacher_logged_in(active_all: true) }
it "doesn't load nonsense" do
lambda {
assert_page_not_found do
get 'show', id: "cats", course_id: @course.id
}.should raise_error ActiveRecord::RecordNotFound
end
end
it "returns 404 if record doesn't exist" do
lambda {
assert_page_not_found do
get 'show', id: "1", course_id: @course.id
}.should raise_error ActiveRecord::RecordNotFound
end
end

View File

@ -38,9 +38,9 @@ describe SelfEnrollmentsController do
end
it "should not render for an incorrect code" do
lambda {
assert_page_not_found do
get 'new', :self_enrollment_code => 'abc'
}.should raise_exception(ActiveRecord::RecordNotFound)
end
end
it "should render even if self_enrollment is disabled" do

View File

@ -79,7 +79,9 @@ describe UsersController do
it "should fail when the user doesn't exist" do
account_admin_user
user_session(@admin)
lambda { get 'delete', :user_id => (User.all.map(&:id).max + 1)}.should raise_error(ActiveRecord::RecordNotFound)
assert_page_not_found do
get 'delete', :user_id => (User.all.map(&:id).max + 1)
end
end
it "should fail when the current user doesn't have user manage permissions" do
@ -119,7 +121,9 @@ describe UsersController do
account_admin_user
user_session(@admin)
PseudonymSession.find(1).stubs(:destroy).returns(nil)
lambda { post 'destroy', :id => (User.all.map(&:id).max + 1)}.should raise_error(ActiveRecord::RecordNotFound)
assert_page_not_found do
post 'destroy', :id => (User.all.map(&:id).max + 1)
end
end
it "should fail when the current user doesn't have user manage permissions" do

View File

@ -840,6 +840,15 @@ end
response.should render_template("shared/unauthorized")
end
def assert_page_not_found(&block)
if CANVAS_RAILS2
block.should raise_exception(ActiveRecord::RecordNotFound)
else
yield
assert_status(404)
end
end
def assert_require_login
response.should be_redirect
flash[:warning].should eql("You must be logged in to access this page")