<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Zyang44</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Zyang44"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Zyang44"/>
	<updated>2026-05-14T07:14:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=143164</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=143164"/>
		<updated>2022-03-21T18:46:24Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: /* Related Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).&lt;br /&gt;
&lt;br /&gt;
====Eula Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/eula_controller.rb here]. The methods are:&lt;br /&gt;
&lt;br /&gt;
*action_allowed?&lt;br /&gt;
*display&lt;br /&gt;
*accept&lt;br /&gt;
*decline&lt;br /&gt;
&lt;br /&gt;
====Courses Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/courses_controller.rb here]. The methods which miss test cases are:&lt;br /&gt;
&lt;br /&gt;
*copy&lt;br /&gt;
*view_teaching_assistants&lt;br /&gt;
*add_ta&lt;br /&gt;
*remove_ta&lt;br /&gt;
*set_course_fields&lt;br /&gt;
&lt;br /&gt;
====Test Frame for eula controller====&lt;br /&gt;
In the case of controllers, unit testing is about testing the functional logic. &lt;br /&gt;
&lt;br /&gt;
1. action_allowed? - This is the first action that takes place when the user tries to access the eula. This checks whether the current user is authorized to view the page. It is only available for those with student privileges, and also to make sure students cannot do all actions. &lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#action_allowed?' do&lt;br /&gt;
&lt;br /&gt;
    context 'when current user is student' do&lt;br /&gt;
      # first test to make sure student cannot do all actions&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be false&lt;br /&gt;
      end&lt;br /&gt;
      # then test to make sure student can do accept and decline actions&lt;br /&gt;
      it 'allows accept action' do&lt;br /&gt;
        controller.params = {action: 'accept'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
      it 'allows decline action' do&lt;br /&gt;
        controller.params = {action: 'decline'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # make sure action_allowed is only available for those with student privileges&lt;br /&gt;
    context 'when current user is anything besides student' do&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        user = instructor&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. display - this action can be called to displays the current page.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#display' do&lt;br /&gt;
&lt;br /&gt;
    # check it displays current page&lt;br /&gt;
    it 'displays current page' do&lt;br /&gt;
      expect(response.status).to eq(200)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. accept - this action can be called if the is_new_user attribute is updated&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#accept' do&lt;br /&gt;
&lt;br /&gt;
    # test if the is_new_user attribute is updated&lt;br /&gt;
    it 'updates is_new_user attribute' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :accept, params, session&lt;br /&gt;
      expect(session[:user].is_new_user).to eq(false)&lt;br /&gt;
    end&lt;br /&gt;
    it 'accept redirects to student_task/list' do      &lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      post :accept, params, session&lt;br /&gt;
      expect(response).to redirect_to('/student_task/list')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. decline - this action can be called if the message is displayed before the redirect.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#decline' do&lt;br /&gt;
&lt;br /&gt;
    # test if the message is displayed before redirect&lt;br /&gt;
    it 'displays the flash notice' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(flash[:notice]).to eq 'Please accept the license agreement in order to use the system.'&lt;br /&gt;
    end&lt;br /&gt;
    # test if it shows the same page again&lt;br /&gt;
    it 'redirects to display same page' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(response).to redirect_to('/eula/display')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Frame for courses controller====&lt;br /&gt;
1. copy - this action is to copy the same course from an original existed course, but it can only be done by a different professor.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#copy' do&lt;br /&gt;
    let(:ccc) { build(:course)}&lt;br /&gt;
&lt;br /&gt;
    context 'when new course id fetches successfully' do&lt;br /&gt;
      it 'redirects to the new course' do&lt;br /&gt;
        allow(Course).to receive(:find).with('1').and_return(ccc)&lt;br /&gt;
        allow(ccc).to receive(:dup).and_return(ccc)&lt;br /&gt;
        allow(ccc).to receive(:save!).and_return(true)&lt;br /&gt;
        allow(CourseNode).to receive(:get_parent_id).and_return(1)&lt;br /&gt;
        allow(CourseNode).to receive(:create).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        params = { id: 1 }&lt;br /&gt;
        session = { user: instructor }&lt;br /&gt;
        get :copy, params, session&lt;br /&gt;
        expect(response).to redirect_to('/courses/edit')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. view_teaching_assistants - this action is to displays all the teaching assistants for a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#view_teaching_assistants' do&lt;br /&gt;
    let(:course) { double('Course', instructor_id: 6, path: '/cscs', name: 'abc') }&lt;br /&gt;
    let(:ta) { build(:teaching_assistant, id: 8) }&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(Ta).to receive(:find_all_by_course_id).with('1').and_return([ta])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'should render the view_teaching_assistants page' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(course).to receive(:instructor_id).and_return(1)&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      session = { instructor_id: 1 }&lt;br /&gt;
      get :view_teaching_assistants, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@ta_mappings)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. add_ta - this action is called to add a teaching assistant to a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#add_ta' do&lt;br /&gt;
    let(:user) { build(:student)}&lt;br /&gt;
    let(:course) { build(:course)}&lt;br /&gt;
&lt;br /&gt;
    it 'should add a ta to the course' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(User).to receive(:find).with('2').and_return(user)&lt;br /&gt;
      allow(TaMapping).to receive(:create).and_return(true)&lt;br /&gt;
      allow(Role).to receive(:find_by_name).with('Teaching Assistant').and_return(true)&lt;br /&gt;
      allow(user).to receive(:save).and_return(true)&lt;br /&gt;
&lt;br /&gt;
      params = { course_id: 1, user: { name: 'Teaching Assistant' } }&lt;br /&gt;
      post :add_ta, params&lt;br /&gt;
      expect(response).to be_redirect&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. remove_ta - this action is called to remove a teaching assistant from a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#remove_ta' do&lt;br /&gt;
    let(:ta) { build(:student)}&lt;br /&gt;
    let(:course) { build(:course)}&lt;br /&gt;
    let(:ta_mapping) { build(:ta_mapping)}&lt;br /&gt;
&lt;br /&gt;
    it 'should remove a ta from the course' do&lt;br /&gt;
      allow(TaMapping).to receive(:find).with('1').and_return(ta_mapping)&lt;br /&gt;
      allow(User).to receive(:find).with('1').and_return(ta)&lt;br /&gt;
      allow(ta_mapping).to receive(:destroy).and_return(true)&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      post :remove_ta, params&lt;br /&gt;
      expect(response).to be_redirect&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. set_course_fields - this action is called in the update and create methods to set the fields of a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#set_course_fields' do&lt;br /&gt;
    it 'should set the course fields' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(course).to receive(:set_course_fields).and_return(true)&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      session = { instructor_id: 1 }&lt;br /&gt;
      post :set_course_fields, params, session&lt;br /&gt;
      expect(response).to redirect_to('/')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The total coverage of the test is xxx%, meeting our minimum coverage requirement.&lt;br /&gt;
&lt;br /&gt;
=== Related Links===&lt;br /&gt;
&lt;br /&gt;
A video of all tests running can be seen [https://youtu.be/901jenyL1mY here]&lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza/tree/beta here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/njdowdle/expertiza/tree/beta here]&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
There were 6 modules in the controller for which we wrote unit tests following behavior driven approach. We did not consider any edge cases for now therefore there is scope to further improve the testing coverage to reach 100%.&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=143163</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=143163"/>
		<updated>2022-03-21T18:46:13Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: /* Related Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).&lt;br /&gt;
&lt;br /&gt;
====Eula Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/eula_controller.rb here]. The methods are:&lt;br /&gt;
&lt;br /&gt;
*action_allowed?&lt;br /&gt;
*display&lt;br /&gt;
*accept&lt;br /&gt;
*decline&lt;br /&gt;
&lt;br /&gt;
====Courses Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/courses_controller.rb here]. The methods which miss test cases are:&lt;br /&gt;
&lt;br /&gt;
*copy&lt;br /&gt;
*view_teaching_assistants&lt;br /&gt;
*add_ta&lt;br /&gt;
*remove_ta&lt;br /&gt;
*set_course_fields&lt;br /&gt;
&lt;br /&gt;
====Test Frame for eula controller====&lt;br /&gt;
In the case of controllers, unit testing is about testing the functional logic. &lt;br /&gt;
&lt;br /&gt;
1. action_allowed? - This is the first action that takes place when the user tries to access the eula. This checks whether the current user is authorized to view the page. It is only available for those with student privileges, and also to make sure students cannot do all actions. &lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#action_allowed?' do&lt;br /&gt;
&lt;br /&gt;
    context 'when current user is student' do&lt;br /&gt;
      # first test to make sure student cannot do all actions&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be false&lt;br /&gt;
      end&lt;br /&gt;
      # then test to make sure student can do accept and decline actions&lt;br /&gt;
      it 'allows accept action' do&lt;br /&gt;
        controller.params = {action: 'accept'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
      it 'allows decline action' do&lt;br /&gt;
        controller.params = {action: 'decline'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # make sure action_allowed is only available for those with student privileges&lt;br /&gt;
    context 'when current user is anything besides student' do&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        user = instructor&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. display - this action can be called to displays the current page.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#display' do&lt;br /&gt;
&lt;br /&gt;
    # check it displays current page&lt;br /&gt;
    it 'displays current page' do&lt;br /&gt;
      expect(response.status).to eq(200)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. accept - this action can be called if the is_new_user attribute is updated&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#accept' do&lt;br /&gt;
&lt;br /&gt;
    # test if the is_new_user attribute is updated&lt;br /&gt;
    it 'updates is_new_user attribute' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :accept, params, session&lt;br /&gt;
      expect(session[:user].is_new_user).to eq(false)&lt;br /&gt;
    end&lt;br /&gt;
    it 'accept redirects to student_task/list' do      &lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      post :accept, params, session&lt;br /&gt;
      expect(response).to redirect_to('/student_task/list')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. decline - this action can be called if the message is displayed before the redirect.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#decline' do&lt;br /&gt;
&lt;br /&gt;
    # test if the message is displayed before redirect&lt;br /&gt;
    it 'displays the flash notice' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(flash[:notice]).to eq 'Please accept the license agreement in order to use the system.'&lt;br /&gt;
    end&lt;br /&gt;
    # test if it shows the same page again&lt;br /&gt;
    it 'redirects to display same page' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(response).to redirect_to('/eula/display')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Frame for courses controller====&lt;br /&gt;
1. copy - this action is to copy the same course from an original existed course, but it can only be done by a different professor.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#copy' do&lt;br /&gt;
    let(:ccc) { build(:course)}&lt;br /&gt;
&lt;br /&gt;
    context 'when new course id fetches successfully' do&lt;br /&gt;
      it 'redirects to the new course' do&lt;br /&gt;
        allow(Course).to receive(:find).with('1').and_return(ccc)&lt;br /&gt;
        allow(ccc).to receive(:dup).and_return(ccc)&lt;br /&gt;
        allow(ccc).to receive(:save!).and_return(true)&lt;br /&gt;
        allow(CourseNode).to receive(:get_parent_id).and_return(1)&lt;br /&gt;
        allow(CourseNode).to receive(:create).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        params = { id: 1 }&lt;br /&gt;
        session = { user: instructor }&lt;br /&gt;
        get :copy, params, session&lt;br /&gt;
        expect(response).to redirect_to('/courses/edit')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. view_teaching_assistants - this action is to displays all the teaching assistants for a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#view_teaching_assistants' do&lt;br /&gt;
    let(:course) { double('Course', instructor_id: 6, path: '/cscs', name: 'abc') }&lt;br /&gt;
    let(:ta) { build(:teaching_assistant, id: 8) }&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(Ta).to receive(:find_all_by_course_id).with('1').and_return([ta])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'should render the view_teaching_assistants page' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(course).to receive(:instructor_id).and_return(1)&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      session = { instructor_id: 1 }&lt;br /&gt;
      get :view_teaching_assistants, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@ta_mappings)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. add_ta - this action is called to add a teaching assistant to a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#add_ta' do&lt;br /&gt;
    let(:user) { build(:student)}&lt;br /&gt;
    let(:course) { build(:course)}&lt;br /&gt;
&lt;br /&gt;
    it 'should add a ta to the course' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(User).to receive(:find).with('2').and_return(user)&lt;br /&gt;
      allow(TaMapping).to receive(:create).and_return(true)&lt;br /&gt;
      allow(Role).to receive(:find_by_name).with('Teaching Assistant').and_return(true)&lt;br /&gt;
      allow(user).to receive(:save).and_return(true)&lt;br /&gt;
&lt;br /&gt;
      params = { course_id: 1, user: { name: 'Teaching Assistant' } }&lt;br /&gt;
      post :add_ta, params&lt;br /&gt;
      expect(response).to be_redirect&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. remove_ta - this action is called to remove a teaching assistant from a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#remove_ta' do&lt;br /&gt;
    let(:ta) { build(:student)}&lt;br /&gt;
    let(:course) { build(:course)}&lt;br /&gt;
    let(:ta_mapping) { build(:ta_mapping)}&lt;br /&gt;
&lt;br /&gt;
    it 'should remove a ta from the course' do&lt;br /&gt;
      allow(TaMapping).to receive(:find).with('1').and_return(ta_mapping)&lt;br /&gt;
      allow(User).to receive(:find).with('1').and_return(ta)&lt;br /&gt;
      allow(ta_mapping).to receive(:destroy).and_return(true)&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      post :remove_ta, params&lt;br /&gt;
      expect(response).to be_redirect&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. set_course_fields - this action is called in the update and create methods to set the fields of a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#set_course_fields' do&lt;br /&gt;
    it 'should set the course fields' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(course).to receive(:set_course_fields).and_return(true)&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      session = { instructor_id: 1 }&lt;br /&gt;
      post :set_course_fields, params, session&lt;br /&gt;
      expect(response).to redirect_to('/')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The total coverage of the test is xxx%, meeting our minimum coverage requirement.&lt;br /&gt;
&lt;br /&gt;
=== Related Links===&lt;br /&gt;
&lt;br /&gt;
A video of all tests running can be seen [https://youtu.be/901jenyL1mYhere]&lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza/tree/beta here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/njdowdle/expertiza/tree/beta here]&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
There were 6 modules in the controller for which we wrote unit tests following behavior driven approach. We did not consider any edge cases for now therefore there is scope to further improve the testing coverage to reach 100%.&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142976</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142976"/>
		<updated>2022-03-17T23:19:11Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).&lt;br /&gt;
&lt;br /&gt;
====Eula Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/eula_controller.rb here]. The methods are:&lt;br /&gt;
&lt;br /&gt;
*action_allowed?&lt;br /&gt;
*display&lt;br /&gt;
*accept&lt;br /&gt;
*decline&lt;br /&gt;
&lt;br /&gt;
====Courses Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/courses_controller.rb here]. The methods which miss test cases are:&lt;br /&gt;
&lt;br /&gt;
*copy&lt;br /&gt;
*view_teaching_assistants&lt;br /&gt;
*add_ta&lt;br /&gt;
*remove_ta&lt;br /&gt;
*set_course_fields&lt;br /&gt;
&lt;br /&gt;
====Test Frame for eula controller====&lt;br /&gt;
In the case of controllers, unit testing is about testing the functional logic. &lt;br /&gt;
&lt;br /&gt;
1. action_allowed? - This is the first action that takes place when the user tries to access the eula. This checks whether the current user is authorized to view the page. It is only available for those with student privileges, and also to make sure students cannot do all actions. &lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#action_allowed?' do&lt;br /&gt;
&lt;br /&gt;
    context 'when current user is student' do&lt;br /&gt;
      # first test to make sure student cannot do all actions&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be false&lt;br /&gt;
      end&lt;br /&gt;
      # then test to make sure student can do accept and decline actions&lt;br /&gt;
      it 'allows accept action' do&lt;br /&gt;
        controller.params = {action: 'accept'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
      it 'allows decline action' do&lt;br /&gt;
        controller.params = {action: 'decline'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # make sure action_allowed is only available for those with student privileges&lt;br /&gt;
    context 'when current user is anything besides student' do&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        user = instructor&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. display - this action can be called to displays the current page.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#display' do&lt;br /&gt;
&lt;br /&gt;
    # check it displays current page&lt;br /&gt;
    it 'displays current page' do&lt;br /&gt;
      expect(response.status).to eq(200)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. accept - this action can be called if the is_new_user attribute is updated&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#accept' do&lt;br /&gt;
&lt;br /&gt;
    # test if the is_new_user attribute is updated&lt;br /&gt;
    it 'updates is_new_user attribute' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :accept, params, session&lt;br /&gt;
      expect(session[:user].is_new_user).to eq(false)&lt;br /&gt;
    end&lt;br /&gt;
    it 'accept redirects to student_task/list' do      &lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      post :accept, params, session&lt;br /&gt;
      expect(response).to redirect_to('/student_task/list')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. decline - this action can be called if the message is displayed before the redirect.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#decline' do&lt;br /&gt;
&lt;br /&gt;
    # test if the message is displayed before redirect&lt;br /&gt;
    it 'displays the flash notice' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(flash[:notice]).to eq 'Please accept the license agreement in order to use the system.'&lt;br /&gt;
    end&lt;br /&gt;
    # test if it shows the same page again&lt;br /&gt;
    it 'redirects to display same page' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(response).to redirect_to('/eula/display')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Frame for courses controller====&lt;br /&gt;
1. copy - this action is to copy the same course from an original existed course, but it can only be done by a different professor.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#copy' do&lt;br /&gt;
    let(:ccc) { build(:course)}&lt;br /&gt;
&lt;br /&gt;
    context 'when new course id fetches successfully' do&lt;br /&gt;
      it 'redirects to the new course' do&lt;br /&gt;
        allow(Course).to receive(:find).with('1').and_return(ccc)&lt;br /&gt;
        allow(ccc).to receive(:dup).and_return(ccc)&lt;br /&gt;
        allow(ccc).to receive(:save!).and_return(true)&lt;br /&gt;
        allow(CourseNode).to receive(:get_parent_id).and_return(1)&lt;br /&gt;
        allow(CourseNode).to receive(:create).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        params = { id: 1 }&lt;br /&gt;
        session = { user: instructor }&lt;br /&gt;
        get :copy, params, session&lt;br /&gt;
        expect(response).to redirect_to('/courses/edit')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. view_teaching_assistants - this action is to displays all the teaching assistants for a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#view_teaching_assistants' do&lt;br /&gt;
    let(:course) { double('Course', instructor_id: 6, path: '/cscs', name: 'abc') }&lt;br /&gt;
    let(:ta) { build(:teaching_assistant, id: 8) }&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(Ta).to receive(:find_all_by_course_id).with('1').and_return([ta])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'should render the view_teaching_assistants page' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(course).to receive(:instructor_id).and_return(1)&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      session = { instructor_id: 1 }&lt;br /&gt;
      get :view_teaching_assistants, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@ta_mappings)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. add_ta - this action is called to add a teaching assistant to a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#add_ta' do&lt;br /&gt;
    let(:user) { build(:student)}&lt;br /&gt;
    let(:course) { build(:course)}&lt;br /&gt;
&lt;br /&gt;
    it 'should add a ta to the course' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(User).to receive(:find).with('2').and_return(user)&lt;br /&gt;
      allow(TaMapping).to receive(:create).and_return(true)&lt;br /&gt;
      allow(Role).to receive(:find_by_name).with('Teaching Assistant').and_return(true)&lt;br /&gt;
      allow(user).to receive(:save).and_return(true)&lt;br /&gt;
&lt;br /&gt;
      params = { course_id: 1, user: { name: 'Teaching Assistant' } }&lt;br /&gt;
      post :add_ta, params&lt;br /&gt;
      expect(response).to be_redirect&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. remove_ta - this action is called to remove a teaching assistant from a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#remove_ta' do&lt;br /&gt;
    let(:ta) { build(:student)}&lt;br /&gt;
    let(:course) { build(:course)}&lt;br /&gt;
    let(:ta_mapping) { build(:ta_mapping)}&lt;br /&gt;
&lt;br /&gt;
    it 'should remove a ta from the course' do&lt;br /&gt;
      allow(TaMapping).to receive(:find).with('1').and_return(ta_mapping)&lt;br /&gt;
      allow(User).to receive(:find).with('1').and_return(ta)&lt;br /&gt;
      allow(ta_mapping).to receive(:destroy).and_return(true)&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      post :remove_ta, params&lt;br /&gt;
      expect(response).to be_redirect&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. set_course_fields - this action is called in the update and create methods to set the fields of a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#set_course_fields' do&lt;br /&gt;
    it 'should set the course fields' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(course).to receive(:set_course_fields).and_return(true)&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      session = { instructor_id: 1 }&lt;br /&gt;
      post :set_course_fields, params, session&lt;br /&gt;
      expect(response).to redirect_to('/')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
The total coverage of the test is xxx%, meeting our minimum coverage requirement.&lt;br /&gt;
&lt;br /&gt;
=== Related Links===&lt;br /&gt;
&lt;br /&gt;
A video of all tests running can be seen [xxx here]&lt;br /&gt;
&lt;br /&gt;
The main repository can be found [https://github.com/expertiza/expertiza/tree/beta here]&lt;br /&gt;
&lt;br /&gt;
The forked git repository for this project can be found [https://github.com/njdowdle/expertiza/tree/beta here]&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;br /&gt;
&lt;br /&gt;
There were 6 modules in the controller for which we wrote unit tests following behavior driven approach. We did not consider any edge cases for now therefore there is scope to further improve the testing coverage to reach 100%.&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142975</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142975"/>
		<updated>2022-03-17T23:16:31Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: /* Test Frame for courses controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).&lt;br /&gt;
&lt;br /&gt;
====Eula Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/eula_controller.rb here]. The methods are:&lt;br /&gt;
&lt;br /&gt;
*action_allowed?&lt;br /&gt;
*display&lt;br /&gt;
*accept&lt;br /&gt;
*decline&lt;br /&gt;
&lt;br /&gt;
====Courses Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/courses_controller.rb here]. The methods which miss test cases are:&lt;br /&gt;
&lt;br /&gt;
*copy&lt;br /&gt;
*view_teaching_assistants&lt;br /&gt;
*add_ta&lt;br /&gt;
*remove_ta&lt;br /&gt;
*set_course_fields&lt;br /&gt;
&lt;br /&gt;
====Test Frame for eula controller====&lt;br /&gt;
In the case of controllers, unit testing is about testing the functional logic. &lt;br /&gt;
&lt;br /&gt;
1. action_allowed? - This is the first action that takes place when the user tries to access the eula. This checks whether the current user is authorized to view the page. It is only available for those with student privileges, and also to make sure students cannot do all actions. &lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#action_allowed?' do&lt;br /&gt;
&lt;br /&gt;
    context 'when current user is student' do&lt;br /&gt;
      # first test to make sure student cannot do all actions&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be false&lt;br /&gt;
      end&lt;br /&gt;
      # then test to make sure student can do accept and decline actions&lt;br /&gt;
      it 'allows accept action' do&lt;br /&gt;
        controller.params = {action: 'accept'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
      it 'allows decline action' do&lt;br /&gt;
        controller.params = {action: 'decline'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # make sure action_allowed is only available for those with student privileges&lt;br /&gt;
    context 'when current user is anything besides student' do&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        user = instructor&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. display - this action can be called to displays the current page.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#display' do&lt;br /&gt;
&lt;br /&gt;
    # check it displays current page&lt;br /&gt;
    it 'displays current page' do&lt;br /&gt;
      expect(response.status).to eq(200)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. accept - this action can be called if the is_new_user attribute is updated&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#accept' do&lt;br /&gt;
&lt;br /&gt;
    # test if the is_new_user attribute is updated&lt;br /&gt;
    it 'updates is_new_user attribute' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :accept, params, session&lt;br /&gt;
      expect(session[:user].is_new_user).to eq(false)&lt;br /&gt;
    end&lt;br /&gt;
    it 'accept redirects to student_task/list' do      &lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      post :accept, params, session&lt;br /&gt;
      expect(response).to redirect_to('/student_task/list')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. decline - this action can be called if the message is displayed before the redirect.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#decline' do&lt;br /&gt;
&lt;br /&gt;
    # test if the message is displayed before redirect&lt;br /&gt;
    it 'displays the flash notice' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(flash[:notice]).to eq 'Please accept the license agreement in order to use the system.'&lt;br /&gt;
    end&lt;br /&gt;
    # test if it shows the same page again&lt;br /&gt;
    it 'redirects to display same page' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(response).to redirect_to('/eula/display')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Frame for courses controller====&lt;br /&gt;
1. copy - this action is to copy the same course from an original existed course, but it can only be done by a different professor.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#copy' do&lt;br /&gt;
    let(:ccc) { build(:course)}&lt;br /&gt;
&lt;br /&gt;
    context 'when new course id fetches successfully' do&lt;br /&gt;
      it 'redirects to the new course' do&lt;br /&gt;
        allow(Course).to receive(:find).with('1').and_return(ccc)&lt;br /&gt;
        allow(ccc).to receive(:dup).and_return(ccc)&lt;br /&gt;
        allow(ccc).to receive(:save!).and_return(true)&lt;br /&gt;
        allow(CourseNode).to receive(:get_parent_id).and_return(1)&lt;br /&gt;
        allow(CourseNode).to receive(:create).and_return(true)&lt;br /&gt;
&lt;br /&gt;
        params = { id: 1 }&lt;br /&gt;
        session = { user: instructor }&lt;br /&gt;
        get :copy, params, session&lt;br /&gt;
        expect(response).to redirect_to('/courses/edit')&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. view_teaching_assistants - this action is to displays all the teaching assistants for a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#view_teaching_assistants' do&lt;br /&gt;
    let(:course) { double('Course', instructor_id: 6, path: '/cscs', name: 'abc') }&lt;br /&gt;
    let(:ta) { build(:teaching_assistant, id: 8) }&lt;br /&gt;
    before(:each) do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(Ta).to receive(:find_all_by_course_id).with('1').and_return([ta])&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    it 'should render the view_teaching_assistants page' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(course).to receive(:instructor_id).and_return(1)&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      session = { instructor_id: 1 }&lt;br /&gt;
      get :view_teaching_assistants, params, session&lt;br /&gt;
      expect(controller.instance_variable_get(:@ta_mappings)).to eq(nil)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. add_ta - this action is called to add a teaching assistant to a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#add_ta' do&lt;br /&gt;
    let(:user) { build(:student)}&lt;br /&gt;
    let(:course) { build(:course)}&lt;br /&gt;
&lt;br /&gt;
    it 'should add a ta to the course' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(User).to receive(:find).with('2').and_return(user)&lt;br /&gt;
      allow(TaMapping).to receive(:create).and_return(true)&lt;br /&gt;
      allow(Role).to receive(:find_by_name).with('Teaching Assistant').and_return(true)&lt;br /&gt;
      allow(user).to receive(:save).and_return(true)&lt;br /&gt;
&lt;br /&gt;
      params = { course_id: 1, user: { name: 'Teaching Assistant' } }&lt;br /&gt;
      post :add_ta, params&lt;br /&gt;
      expect(response).to be_redirect&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. remove_ta - this action is called to remove a teaching assistant from a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#remove_ta' do&lt;br /&gt;
    let(:ta) { build(:student)}&lt;br /&gt;
    let(:course) { build(:course)}&lt;br /&gt;
    let(:ta_mapping) { build(:ta_mapping)}&lt;br /&gt;
&lt;br /&gt;
    it 'should remove a ta from the course' do&lt;br /&gt;
      allow(TaMapping).to receive(:find).with('1').and_return(ta_mapping)&lt;br /&gt;
      allow(User).to receive(:find).with('1').and_return(ta)&lt;br /&gt;
      allow(ta_mapping).to receive(:destroy).and_return(true)&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      post :remove_ta, params&lt;br /&gt;
      expect(response).to be_redirect&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. set_course_fields - this action is called in the update and create methods to set the fields of a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#set_course_fields' do&lt;br /&gt;
    it 'should set the course fields' do&lt;br /&gt;
      allow(Course).to receive(:find).with('1').and_return(course)&lt;br /&gt;
      allow(course).to receive(:set_course_fields).and_return(true)&lt;br /&gt;
      params = { id: 1 }&lt;br /&gt;
      session = { instructor_id: 1 }&lt;br /&gt;
      post :set_course_fields, params, session&lt;br /&gt;
      expect(response).to redirect_to('/')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142941</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142941"/>
		<updated>2022-03-17T01:34:25Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).&lt;br /&gt;
&lt;br /&gt;
====Eula Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/eula_controller.rb here]. The methods are:&lt;br /&gt;
&lt;br /&gt;
*action_allowed?&lt;br /&gt;
*display&lt;br /&gt;
*accept&lt;br /&gt;
*decline&lt;br /&gt;
&lt;br /&gt;
====Courses Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/courses_controller.rb here]. The methods which miss test cases are:&lt;br /&gt;
&lt;br /&gt;
*copy&lt;br /&gt;
*view_teaching_assistants&lt;br /&gt;
*add_ta&lt;br /&gt;
*remove_ta&lt;br /&gt;
*set_course_fields&lt;br /&gt;
&lt;br /&gt;
====Test Frame for eula controller====&lt;br /&gt;
In the case of controllers, unit testing is about testing the functional logic. &lt;br /&gt;
&lt;br /&gt;
1. action_allowed? - This is the first action that takes place when the user tries to access the eula. This checks whether the current user is authorized to view the page. It is only available for those with student privileges, and also to make sure students cannot do all actions. &lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#action_allowed?' do&lt;br /&gt;
&lt;br /&gt;
    context 'when current user is student' do&lt;br /&gt;
      # first test to make sure student cannot do all actions&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be false&lt;br /&gt;
      end&lt;br /&gt;
      # then test to make sure student can do accept and decline actions&lt;br /&gt;
      it 'allows accept action' do&lt;br /&gt;
        controller.params = {action: 'accept'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
      it 'allows decline action' do&lt;br /&gt;
        controller.params = {action: 'decline'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # make sure action_allowed is only available for those with student privileges&lt;br /&gt;
    context 'when current user is anything besides student' do&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        user = instructor&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. display - this action can be called to displays the current page.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#display' do&lt;br /&gt;
&lt;br /&gt;
    # check it displays current page&lt;br /&gt;
    it 'displays current page' do&lt;br /&gt;
      expect(response.status).to eq(200)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. accept - this action can be called if the is_new_user attribute is updated&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#accept' do&lt;br /&gt;
&lt;br /&gt;
    # test if the is_new_user attribute is updated&lt;br /&gt;
    it 'updates is_new_user attribute' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :accept, params, session&lt;br /&gt;
      expect(session[:user].is_new_user).to eq(false)&lt;br /&gt;
    end&lt;br /&gt;
    it 'accept redirects to student_task/list' do      &lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      post :accept, params, session&lt;br /&gt;
      expect(response).to redirect_to('/student_task/list')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. decline - this action can be called if the message is displayed before the redirect.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#decline' do&lt;br /&gt;
&lt;br /&gt;
    # test if the message is displayed before redirect&lt;br /&gt;
    it 'displays the flash notice' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(flash[:notice]).to eq 'Please accept the license agreement in order to use the system.'&lt;br /&gt;
    end&lt;br /&gt;
    # test if it shows the same page again&lt;br /&gt;
    it 'redirects to display same page' do&lt;br /&gt;
      params = {id: 1}&lt;br /&gt;
      session = {user: student}&lt;br /&gt;
      get :decline, params, session&lt;br /&gt;
      expect(response).to redirect_to('/eula/display')&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Frame for courses controller====&lt;br /&gt;
1. copy - this action is to copy the same course from an original existed course, but it can only be done by a different professor.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. view_teaching_assistants - this action is to displays all the teaching assistants for a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. add_ta - this action is called to add a teaching assistant to a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. remove_ta - this action is called to remove a teaching assistant from a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
5. set_course_fields - this action is called in the update and create methods to set the fields of a course.&lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142940</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142940"/>
		<updated>2022-03-17T01:08:28Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: /* Test Frame for eula controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).&lt;br /&gt;
&lt;br /&gt;
====Eula Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/eula_controller.rb here]. The methods are:&lt;br /&gt;
&lt;br /&gt;
*action_allowed?&lt;br /&gt;
*display&lt;br /&gt;
*accept&lt;br /&gt;
*decline&lt;br /&gt;
&lt;br /&gt;
====Courses Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/courses_controller.rb here]. The methods which miss test cases are:&lt;br /&gt;
&lt;br /&gt;
*copy&lt;br /&gt;
*view_teaching_assistants&lt;br /&gt;
*add_ta&lt;br /&gt;
*remove_ta&lt;br /&gt;
*set_course_fields&lt;br /&gt;
&lt;br /&gt;
====Test Frame for eula controller====&lt;br /&gt;
In the case of controllers, unit testing is about testing the functional logic. &lt;br /&gt;
&lt;br /&gt;
1. action_allowed? - This is the first action that takes place when the user tries to access the eula. This checks whether the current user is authorized to view the page. It is only available for those with student privileges, and also to make sure students cannot do all actions. &lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#action_allowed?' do&lt;br /&gt;
&lt;br /&gt;
    context 'when current user is student' do&lt;br /&gt;
      # first test to make sure student cannot do all actions&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be false&lt;br /&gt;
      end&lt;br /&gt;
      # then test to make sure student can do accept and decline actions&lt;br /&gt;
      it 'allows accept action' do&lt;br /&gt;
        controller.params = {action: 'accept'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
      it 'allows decline action' do&lt;br /&gt;
        controller.params = {action: 'decline'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # make sure action_allowed is only available for those with student privileges&lt;br /&gt;
    context 'when current user is anything besides student' do&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        user = instructor&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. display - this action can be called to displays the current page.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#display' do&lt;br /&gt;
&lt;br /&gt;
    # check it displays current page&lt;br /&gt;
    it 'displays current page' do&lt;br /&gt;
      expect(response.status).to eq(200)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. display - this action can be called to displays the current page.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#display' do&lt;br /&gt;
&lt;br /&gt;
    # check it displays current page&lt;br /&gt;
    it 'displays current page' do&lt;br /&gt;
      expect(response.status).to eq(200)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Frame for courses controller====&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142939</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142939"/>
		<updated>2022-03-17T01:07:09Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).&lt;br /&gt;
&lt;br /&gt;
====Eula Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/eula_controller.rb here]. The methods are:&lt;br /&gt;
&lt;br /&gt;
*action_allowed?&lt;br /&gt;
*display&lt;br /&gt;
*accept&lt;br /&gt;
*decline&lt;br /&gt;
&lt;br /&gt;
====Courses Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/courses_controller.rb here]. The methods which miss test cases are:&lt;br /&gt;
&lt;br /&gt;
*copy&lt;br /&gt;
*view_teaching_assistants&lt;br /&gt;
*add_ta&lt;br /&gt;
*remove_ta&lt;br /&gt;
*set_course_fields&lt;br /&gt;
&lt;br /&gt;
====Test Frame for eula controller====&lt;br /&gt;
In the case of controllers, unit testing is about testing the functional logic. &lt;br /&gt;
&lt;br /&gt;
1. action_allowed? - This is the first action that takes place when the user tries to access the eula. This checks whether the current user is authorized to view the page. It is only available for those with student privileges, and also to make sure students cannot do all actions. &lt;br /&gt;
&lt;br /&gt;
Code snippet:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
describe '#action_allowed?' do&lt;br /&gt;
&lt;br /&gt;
    context 'when current user is student' do&lt;br /&gt;
      # first test to make sure student cannot do all actions&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be false&lt;br /&gt;
      end&lt;br /&gt;
      # then test to make sure student can do accept and decline actions&lt;br /&gt;
      it 'allows accept action' do&lt;br /&gt;
        controller.params = {action: 'accept'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
      it 'allows decline action' do&lt;br /&gt;
        controller.params = {action: 'decline'}&lt;br /&gt;
        user = student&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    # make sure action_allowed is only available for those with student privileges&lt;br /&gt;
    context 'when current user is anything besides student' do&lt;br /&gt;
      it 'allows all actions' do&lt;br /&gt;
        user = instructor&lt;br /&gt;
        stub_current_user(user, user.role.name, user.role)&lt;br /&gt;
        expect(controller.send(:action_allowed?)).to be true&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. display - this action can be called to displays the current page.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  describe '#display' do&lt;br /&gt;
&lt;br /&gt;
    # check it displays current page&lt;br /&gt;
    it 'displays current page' do&lt;br /&gt;
      expect(response.status).to eq(200)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Test Frame for courses controller====&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142928</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142928"/>
		<updated>2022-03-15T21:45:52Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
At the beginning of the project, we first ran the original test cases but it only cover part of the methods in controllers. Therefore, in total, we wrote tests to cover all 4 methods in the eula_controller and added 5 tests to cover all 12 methods in the courses_controller. We created unit test cases with the help of mocked objects (factory objects and stub objects).&lt;br /&gt;
&lt;br /&gt;
====Eula Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/eula_controller.rb here]. The methods are:&lt;br /&gt;
&lt;br /&gt;
*action_allowed?&lt;br /&gt;
*display&lt;br /&gt;
*accept&lt;br /&gt;
*decline&lt;br /&gt;
&lt;br /&gt;
====Courses Controller Methods====&lt;br /&gt;
The code of the controller can be found [https://github.com/expertiza/expertiza/blob/beta/app/controllers/courses_controller.rb here]. The methods which miss test cases are:&lt;br /&gt;
&lt;br /&gt;
*copy&lt;br /&gt;
*view_teaching_assistants&lt;br /&gt;
*add_ta&lt;br /&gt;
*remove_ta&lt;br /&gt;
*set_course_fields&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142927</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142927"/>
		<updated>2022-03-15T20:50:31Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submissions and providing reusable objects for peer review. It is an open-source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer-review other students' submissions, enabling them to work together to improve others' learning experiences.&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2203 which is adding unit tests for courses_controller.rb, eula_controller.rb. &lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
courses_controller.rb&lt;br /&gt;
courses_controller_spec.rb&lt;br /&gt;
eula_controller.rb&lt;br /&gt;
eula_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/courses_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/eula_controller_spec.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142926</id>
		<title>CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses controller, eula controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2203:_Adding_tests_for_courses_controller,_eula_controller&amp;diff=142926"/>
		<updated>2022-03-15T20:33:58Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: Created page with &amp;quot;== About Expertiza==  [http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submission and providing...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is the software benefits for both instructors and students by supporting various types of submission and providing reusable objects for peer review. It is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. It allows the instructors not only to create and customize new or existing assignments, but also to create a list of topics the students can sign up for. Students can form teams to work on various projects and assignments. Expertiza also lets students peer review other students' submissions, enables them working together to improve others' learning experience.&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022&amp;diff=142925</id>
		<title>CSC/ECE 517 Spring 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022&amp;diff=142925"/>
		<updated>2022-03-15T20:30:34Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: /* OSS Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2203: Adding tests for courses_controller, eula_controller]]&lt;br /&gt;
&lt;br /&gt;
== Final Projects ==&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022&amp;diff=142924</id>
		<title>CSC/ECE 517 Spring 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022&amp;diff=142924"/>
		<updated>2022-03-15T20:23:29Z</updated>

		<summary type="html">&lt;p&gt;Zyang44: /* OSS Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022 - E2203: Testing for courses_controller, eula_controller]]&lt;br /&gt;
&lt;br /&gt;
== Final Projects ==&lt;/div&gt;</summary>
		<author><name>Zyang44</name></author>
	</entry>
</feed>