Add some unit tests to the OutcomesController spec

This adds some unit tests to the outcomes controller to test the create,
update, and destroy methods, which were previously not tested.

Fixes CNVS-17136

Test Plan:

    None.  This commit does not touch any application code, only
    unit tests

Change-Id: I6f08d2eba4327e11d249679db7bdde082bfd20ed
Reviewed-on: https://gerrit.instructure.com/44958
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
QA-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Benjamin Porter 2014-11-25 21:35:15 -07:00
parent cc4e80dcbd
commit f4ed70089c
1 changed files with 119 additions and 3 deletions

View File

@ -24,11 +24,11 @@ describe OutcomesController do
@outcome = context.created_learning_outcomes.create!(:title => 'outcome')
@outcome_group.add_outcome(@outcome)
end
def course_outcome
context_outcome(@course)
end
def account_outcome
context_outcome(@account)
end
@ -127,7 +127,7 @@ describe OutcomesController do
end
end
describe "GET 'detail'" do
describe "GET 'details'" do
it "should require authorization" do
course_outcome
get 'details', :course_id => @course.id, :outcome_id => @outcome.id
@ -180,4 +180,120 @@ describe OutcomesController do
expect(data).not_to be_empty
end
end
describe "POST 'create'" do
before :once do
OUTCOME_PARAMS = {
:description => "A long description",
:short_description => "A short description"
}
end
it "should require authorization" do
course_outcome
post 'create', :course_id => @course.id
assert_unauthorized
end
it "should not let a student create a outcome" do
user_session(@student)
post 'create', :course_id => @course.id,
:learning_outcome => { :short_description => TEST_STRING }
assert_unauthorized
end
it "should allow creating a new outcome with the root group" do
user_session(@teacher)
post 'create', :course_id => @course.id, :learning_outcome => OUTCOME_PARAMS
expect(response).to be_redirect
expect(assigns[:outcome]).not_to be_nil
expect(assigns[:outcome][:description]).to eql("A long description")
expect(assigns[:outcome][:short_description]).to eql("A short description")
expect(@course.learning_outcome_links.map { |n| n.content }.include?(assigns[:outcome])).to be_truthy
@course.learning_outcome_groups.each do |group|
if group.child_outcome_links.map { |n| n.content }.include?(assigns[:outcome])
expect(group).to eql(@course.root_outcome_group)
end
end
end
it "should allow creating a new outcome with a specific group" do
# create a new group that is a child of the root group that we can
# set our new outcome to belong to
user_session(@teacher)
outcome_group = @course.root_outcome_group.child_outcome_groups.build(
:title => "Child outcome group", :context => @course)
expect(outcome_group.save).to be_truthy
expect(outcome_group.id).not_to be_nil
expect(outcome_group).not_to be_nil
post 'create', :course_id => @course.id, :learning_outcome_group_id => outcome_group.id,
:learning_outcome => OUTCOME_PARAMS
expect(response).to be_redirect
expect(assigns[:outcome]).not_to be_nil
expect(assigns[:outcome][:description]).to eql("A long description")
expect(assigns[:outcome][:short_description]).to eql("A short description")
expect(@course.learning_outcome_links.map { |n| n.content }.include?(assigns[:outcome])).to be_truthy
@course.learning_outcome_groups.each do |group|
if group.child_outcome_links.map { |n| n.content }.include?(assigns[:outcome])
expect(group).to eql(outcome_group)
end
end
end
end
describe "PUT 'update'" do
TEST_STRING = "Some test String"
before :each do
course_outcome
end
it "should require authorization" do
put 'update', :course_id => @course.id, :id => @outcome.id,
:learning_outcome => { :short_description => TEST_STRING }
assert_unauthorized
end
it "should not let a student update the outcome" do
user_session(@student)
put 'update', :course_id => @course.id, :id => @outcome.id,
:learning_outcome => { :short_description => TEST_STRING }
assert_unauthorized
end
it "should allow updating the outcome" do
user_session(@teacher)
put 'update', :course_id => @course.id, :id => @outcome.id,
:learning_outcome => { :short_description => TEST_STRING }
@outcome.reload
expect(@outcome[:short_description]).to eql TEST_STRING
end
end
describe "DELETE 'destroy'" do
before :each do
course_outcome
end
it "should require authorization" do
delete 'destroy', :course_id => @course.id, :id => @outcome.id
assert_unauthorized
end
it "should not let a student delete the outcome" do
user_session(@student)
delete 'destroy', :course_id => @course.id, :id => @outcome.id
assert_unauthorized
end
it "should delete the outcome from the database" do
user_session(@teacher)
delete 'destroy', :course_id => @course.id, :id => @outcome.id
@outcome.reload
expect(@outcome).to be_deleted
end
end
end