CSC/ECE 517 Fall 2016/E1668.Test e-mailing functionality: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(99 intermediate revisions by the same user not shown)
Line 4: Line 4:
__TOC__
__TOC__


==Background==
=Background=
[http://expertiza.ncsu.edu/ Expertiza] is a peer review system where the students can submit their work and do reviews on fellow students’ work. Expertiza is an open source project and is based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza facilitates easy creation of assignments and a list of topics for the same. It allows students to suggest a topic for an assignment as well. Students can form teams and invite other students to join their team for various assignments. Moreover, students can post team advertisements and describe the qualities they are looking for in their team members and other students can respond to the same. Expertiza overall gives a simple web interface for assignment management for both the students as well as instructors.
 
There are various ways to use e-mail functionality in the Expertiza. To name a few examples: users should get welcome emails once they register successfully, they should get reminder emails if they missed deadline of submission of their works, they should receive notification emails when other users review their homework, or others finish reviewing one of their reviews. All of these above are functions belongs to emailing. However, currently there is no test for these functions in the Expertise, which should be added to ensure valid usage of e-mailling features.
There are various ways to use e-mail functionality in the Expertiza. To name a few examples: users should get welcome emails once they register successfully, they should get reminder emails if they missed deadline of submission of their works, they should receive notification emails when other users review their homework, or others finish reviewing one of their reviews. All of these above are functions belongs to emailing. However, currently there is no test for these functions in the Expertise, which should be added to ensure valid usage of e-mailling features.


==Project Objectives==
=Project Objectives=
(1)  Feature tests should be written with the use of RSpec for the e-mailing functionality.
We will write feature test to check the e-mailling functionality, RSpec will be used as the testing framework. Example such as assignment record or participant record will be written with the use of fixtures. We will also use [https://github.com/jnicklas/capybara/ Capybara] to interacting with the Expertise. All possible valid or invalid cases for email functionality will be included in our tests.
 
=Technologies Implemented=
===RSpec===
RSpec is a Behaviour-Driven Development tool for Ruby programmers. It is easy to write and understood thus become popular choice for BDD software development practice.
Basically, we can add a new gem in the gem file, like this:
    gem 'rspec-rails'
 
===Capybara===
Capybara is a tool which help to test web application by simulating how you can interact with you app. We will use it to test how we can set the emailing function on the web. We can include Capybara by first adding a gem file:
    gem 'capybara'


(2) All test examples should be written with the use of fixtures, such as assignment record or participant record.
And then include it in the rails_helper.rb:
    require 'capybara/rspec'


(3) Capybara should be used when interacting with the Expertise and writing these feature tests.
===FactoryGirl===
FactoryGirl is a fixture used in Rails application, it is general easy to used and can be installed by adding a gem file:
    gem "factory_girl_rails", "~> 4.0"
And then include it in the rails_helper.rb:
    require 'factory_girl_rails'


(4) All possible valid or invalid cases for email functionality should be included in the tests.
=Test Plans=


==Tests==
===Prerequisite Configuration===
Our tests files are located in the ''email_notification_spec.rb'' and ''edit_emails_spec.rb''. Below are the tests in the "edit_emails_spec.rb", whose functions mostly involve update emailing options in the profile page:
We use Docker to set up the environment to test Expertiza functions, then we install the gem files and create the expertiza_text database in SQL. These are required before we do emailing testing:
    $ docker run --expose 3000 -p 3000:3000 -v /Users/andychen/Desktop/ruby_on_rails/expertiza-developer:/Users/andychen/Desktop/ruby_on_rails/expertiza-developer/expertiza -it update
    $ Bundle install
    $ /etc/init.d/mysql start          # start the MySQL
    $ rake db:migrate
    $ sudo apt-get install npm
    $ sudo npm install -g bower
    $ sudo ln -s “$(which nodejs)” /usr/bin/node
    $ bower install --allow-root
    $ /etc/init.d/mysql start
    $ mysql -u root -p
    $ create database expertiza_test    # create the expertiza test database


(1) Testing email address can be edited successfully in the profile tab.
===Test Cases===
T1: Test users can edit their email addresses in the email option field under profile page.
 
T2: Test you can set emailing functionality for users under profile page.
 
T3: Test after resetting password email can be sent to users.
 
T4: Test after signing-up emails can be sent to users.
 
T5: Test after updating homework emails can be sent to reviewers.
 
T6: Test emails can be sent to users after their work get reviewed
 
==Tested Scenarios==
 
T1, T2 and T3 are tested written in the edit_emails_spec.rb file.
=== T1: Test users can edit their email addresses in the email option field under profile page ===
 
Testing email address can be edited successfully in the profile tab.
Users can update their email addresses anytime by clicking the profile button in the header after they log in. They can fill in the new address in the "E-maill address" tab.  
Users can update their email addresses anytime by clicking the profile button in the header after they log in. They can fill in the new address in the "E-maill address" tab.  
We test if new address can be filled in successfully by using Capybara:
We test if new address can be filled in successfully by using Capybara:
Line 29: Line 75:
     end
     end


   
=== T2: Test you can set emailing functionality for users under profile page ===   
(2) Testing email option can be checked successfully in the profile tab.
Testing email option can be checked successfully in the profile tab.
There are three attributes related to email functionality when we define a user: email_on_review, email_on_submission, email_on_review_of_review. These boolean values can be reset in the profile page under E-mail options checkbox can be checked/unchecked can be checked/unchecked successfully.  
There are three attributes related to email functionality when we define a user: email_on_review, email_on_submission, email_on_review_of_review. These boolean values can be reset in the profile page under E-mail options checkbox can be checked/unchecked can be checked/unchecked successfully.  
We first test that if  the 'When someone else reviews my work' checkbox by using Capybara:
    context 'When someone else reviews my work' do
        it "should check 'When someone else reviews my work' option" do
          find(:css, "#user_email_on_review").set(true)
          review_box = find('#user_email_on_review')
          expect(review_box).to be_checked
        end
    end 


Then, test that if 'When someone else reviews my work' checkbox can be checked/unchecked successfully:
1) We first test that if the 'When someone else reviews my work' checkbox by using Capybara:
   context 'When someone else reviews my work' do
   context 'When someone else reviews my work' do
         it "should check 'When someone else reviews my work' option" do
         it "should check 'When someone else reviews my work' option" do
      #find and check the box for when someone else reviews my work
           find(:css, "#user_email_on_review").set(true)
           find(:css, "#user_email_on_review").set(true)
           review_box = find('#user_email_on_review')
           review_box = find('#user_email_on_review')
Line 49: Line 88:
         end
         end
       it "should uncheck 'When someone else reviews my work' option" do
       it "should uncheck 'When someone else reviews my work' option" do
      #find and uncheck the box for when someone else reviews my work
           find(:css, "#user_email_on_review").set(false)   
           find(:css, "#user_email_on_review").set(false)   
           review_box = find('#user_email_on_review')
           review_box = find('#user_email_on_review')
Line 55: Line 95:
       end
       end


test that if the 'When someone else submits work I am assigned to review' checkbox can be checked/unchecked successfully:
2) Test that if the 'When someone else submits work I am assigned to review' checkbox can be checked/unchecked successfully:
     context 'When someone else submits work I am assigned to review' do
     context 'When someone else submits work I am assigned to review' do
         it "should check 'When someone else submits work I am assigned to review' option" do
         it "should check 'When someone else submits work I am assigned to review' option" do
           find(:css, "#user_email_on_submission").set(true)
           find(:css, "#user_email_on_submission").set(true)
        #find and check the box for When someone else submits work I am assigned to review
           review_box = find('#user_email_on_submission')
           review_box = find('#user_email_on_submission')
           expect(review_box).to be_checked
           expect(review_box).to be_checked
Line 64: Line 105:
    
    
         it "should uncheck 'When someone else submits work I am assigned to review' option" do
         it "should uncheck 'When someone else submits work I am assigned to review' option" do
        #find and uncheck the box for When someone else submits work I am assigned to review
           find(:css, "#user_email_on_submission").set(false)
           find(:css, "#user_email_on_submission").set(false)
           review_box = find('#user_email_on_submission')
           review_box = find('#user_email_on_submission')
Line 70: Line 112:
     end
     end


test that if the "When someone else reviews one of my reviews (metareviews my work)" checkbox can be checked/unchecked successfully:
3) Test that if the "When someone else reviews one of my reviews (metareviews my work)" checkbox can be checked/unchecked successfully:
     context 'When someone else reviews one of my reviews (metareviews my work)' do
     context 'When someone else reviews one of my reviews (metareviews my work)' do
         it "should check 'When someone else reviews one of my reviews (metareviews my work)' option" do
         it "should check 'When someone else reviews one of my reviews (metareviews my work)' option" do
        #find and check the box for When someone else reviews one of my reviews (metareviews my work)
           find(:css, "#user_email_on_review_of_review").set(true)
           find(:css, "#user_email_on_review_of_review").set(true)
           review_box = find('#user_email_on_review_of_review')
           review_box = find('#user_email_on_review_of_review')
Line 79: Line 122:
    
    
         it "should uncheck 'When someone else reviews one of my reviews (metareviews my work)' option" do
         it "should uncheck 'When someone else reviews one of my reviews (metareviews my work)' option" do
        #find and uncheck the box for When someone else reviews one of my reviews (metareviews my work)
           find(:css, "#user_email_on_review_of_review").set(false)
           find(:css, "#user_email_on_review_of_review").set(false)
           review_box = find('#user_email_on_review_of_review')
           review_box = find('#user_email_on_review_of_review')
Line 85: Line 129:
       end
       end


test that if the "Send me copies of emails sent for assignments" checkbox can be checked/unchecked successfully:
4) Test that if the "Send me copies of emails sent for assignments" checkbox can be checked/unchecked successfully:
     context 'Send me copies of emails sent for assignments' do
     context 'Send me copies of emails sent for assignments' do
         it "should check 'Send me copies of emails sent for assignments' option" do
         it "should check 'Send me copies of emails sent for assignments' option" do
Line 98: Line 142:
       end
       end


Below are the tests located in the ''email_notification_spec.rb'' file, we use a gem named 'capybara-email' to open the email we intend to send and check for the content for related mailing task:


(3) Testing email can be sent to users successfully if they reset their password.
 
Below are the tests located in the email_notification_spec.rb file, we use a gem named 'capybara-email' to open the email we intend to send and check for the content for related mailing task:
    gem 'capybara-email'
 
=== T3: Test after resetting password email can be sent to users ===
 
Testing email can be sent to users successfully if they reset their password.
Users can reset their password if they forget about their previous ones. They can get a new password in email sent by the Expertiza system. We use capybara to test and check for password-reset content:
Users can reset their password if they forget about their previous ones. They can get a new password in email sent by the Expertiza system. We use capybara to test and check for password-reset content:


Line 123: Line 172:
   end
   end


(4) Testing welcome email can be sent to users successfully if they sign up successfully.
=== T4: Test after signing-up emails can be sent to users ===
 
Testing welcome email can be sent to users successfully if they sign up successfully.
Users will get welcome email once they get new accounts in the Expertiza, we use capybara to test and check for welcome email content:  
Users will get welcome email once they get new accounts in the Expertiza, we use capybara to test and check for welcome email content:  
   feature 'Welcome mailer' do
   feature 'Welcome mailer' do
Line 150: Line 201:
   end
   end


(5) Testing email notification can be sent to the users successfully once their assigned homework get updated.
=== T5: Test after updating homework emails can be sent to reviewers===
 
Testing email notification can be sent to the users successfully once their assigned homework get updated.
Each assignment are created with a contributor and reviewer, once the contributor updates their homework, the reviewer will receive a notification email informing about this action and view the update. We use capybara and check for the content for update email:
Each assignment are created with a contributor and reviewer, once the contributor updates their homework, the reviewer will receive a notification email informing about this action and view the update. We use capybara and check for the content for update email:
   feature 'update assignment email notification' do
   feature 'update assignment email notification' do
Line 179: Line 232:
   end
   end


(6) Testing email can be sent to the users successfully once their work get reviewed.
===T6: Test emails can be sent to users after their work get reviewed===
Testing email can be sent to the users successfully once their work get reviewed.
Once a user's assignment get reviewed by a reviewer, a notification email will be sent to the user to check for the content of the review. We use capybara to test and check for the content for review email:
Once a user's assignment get reviewed by a reviewer, a notification email will be sent to the user to check for the content of the review. We use capybara to test and check for the content for review email:
     feature 'New submission notification' do
     feature 'New submission notification' do
Line 201: Line 255:
     end
     end


==Execution and Test Results==
The tests were executed by submitting the following command from  the terminal.
    $ rpec --format doc feature <RSpec file location>
The results of our work shows below:
[[File:Picture1.png]]
[[File:Picture2.png]]
[[File:Picture3.png]]
=Conclusion and Possible Future Work=
According to our test, the emailing functionality works well under various scenarios. Possible future work may include setting up assignment examples along with participants and check emailing function work among related members.


==Reference==
=Reference=
#[https://github.com/expertiza/expertiza Expertiza on GitHub]
#[https://github.com/expertiza/expertiza Expertiza on GitHub]
#[https://github.com/jnicklas/capybara Capybara Documentation on Github]
#[https://github.com/jnicklas/capybara Capybara Documentation on Github]
#[https://en.wikipedia.org/wiki/RSpec RSpec Tutorial on Wiki]
#[https://en.wikipedia.org/wiki/RSpec RSpec Tutorial on Wiki]

Latest revision as of 05:27, 9 November 2016

E1668 -Test e-mailling functionality

Background

Expertiza is a peer review system where the students can submit their work and do reviews on fellow students’ work. Expertiza is an open source project and is based on Ruby on Rails framework. Expertiza facilitates easy creation of assignments and a list of topics for the same. It allows students to suggest a topic for an assignment as well. Students can form teams and invite other students to join their team for various assignments. Moreover, students can post team advertisements and describe the qualities they are looking for in their team members and other students can respond to the same. Expertiza overall gives a simple web interface for assignment management for both the students as well as instructors.

There are various ways to use e-mail functionality in the Expertiza. To name a few examples: users should get welcome emails once they register successfully, they should get reminder emails if they missed deadline of submission of their works, they should receive notification emails when other users review their homework, or others finish reviewing one of their reviews. All of these above are functions belongs to emailing. However, currently there is no test for these functions in the Expertise, which should be added to ensure valid usage of e-mailling features.

Project Objectives

We will write feature test to check the e-mailling functionality, RSpec will be used as the testing framework. Example such as assignment record or participant record will be written with the use of fixtures. We will also use Capybara to interacting with the Expertise. All possible valid or invalid cases for email functionality will be included in our tests.

Technologies Implemented

RSpec

RSpec is a Behaviour-Driven Development tool for Ruby programmers. It is easy to write and understood thus become popular choice for BDD software development practice. Basically, we can add a new gem in the gem file, like this:

   gem 'rspec-rails'

Capybara

Capybara is a tool which help to test web application by simulating how you can interact with you app. We will use it to test how we can set the emailing function on the web. We can include Capybara by first adding a gem file:

   gem 'capybara'

And then include it in the rails_helper.rb:

   require 'capybara/rspec'

FactoryGirl

FactoryGirl is a fixture used in Rails application, it is general easy to used and can be installed by adding a gem file:

   gem "factory_girl_rails", "~> 4.0"

And then include it in the rails_helper.rb:

   require 'factory_girl_rails'

Test Plans

Prerequisite Configuration

We use Docker to set up the environment to test Expertiza functions, then we install the gem files and create the expertiza_text database in SQL. These are required before we do emailing testing:

   $ docker run --expose 3000 -p 3000:3000 -v /Users/andychen/Desktop/ruby_on_rails/expertiza-developer:/Users/andychen/Desktop/ruby_on_rails/expertiza-developer/expertiza -it update
   $ Bundle install
   $ /etc/init.d/mysql start           # start the MySQL
   $ rake db:migrate
   $ sudo apt-get install npm
   $ sudo npm install -g bower
   $ sudo ln -s “$(which nodejs)” /usr/bin/node
   $ bower install --allow-root
   $ /etc/init.d/mysql start
   $ mysql -u root -p
   $ create database expertiza_test    # create the expertiza test database

Test Cases

T1: Test users can edit their email addresses in the email option field under profile page.

T2: Test you can set emailing functionality for users under profile page.

T3: Test after resetting password email can be sent to users.

T4: Test after signing-up emails can be sent to users.

T5: Test after updating homework emails can be sent to reviewers.

T6: Test emails can be sent to users after their work get reviewed

Tested Scenarios

T1, T2 and T3 are tested written in the edit_emails_spec.rb file.

T1: Test users can edit their email addresses in the email option field under profile page

Testing email address can be edited successfully in the profile tab. Users can update their email addresses anytime by clicking the profile button in the header after they log in. They can fill in the new address in the "E-maill address" tab. We test if new address can be filled in successfully by using Capybara:

   describe 'email address' do
     it 'should edit email address' do
       fill_in 'E-mail address', with: 'ychen75@ncsu.edu'
       expect(find_field('E-mail address').value).to eq 'ychen75@ncsu.edu'
     end
   end

T2: Test you can set emailing functionality for users under profile page

Testing email option can be checked successfully in the profile tab. There are three attributes related to email functionality when we define a user: email_on_review, email_on_submission, email_on_review_of_review. These boolean values can be reset in the profile page under E-mail options checkbox can be checked/unchecked can be checked/unchecked successfully.

1) We first test that if the 'When someone else reviews my work' checkbox by using Capybara:

 context 'When someone else reviews my work' do
       it "should check 'When someone else reviews my work' option" do
      #find and check the box for when someone else reviews my work
         find(:css, "#user_email_on_review").set(true)
         review_box = find('#user_email_on_review')
         expect(review_box).to be_checked
       end
     it "should uncheck 'When someone else reviews my work' option" do
     #find and uncheck the box for when someone else reviews my work
         find(:css, "#user_email_on_review").set(false)  
         review_box = find('#user_email_on_review')
         expect(review_box).not_to be_checked
       end
     end

2) Test that if the 'When someone else submits work I am assigned to review' checkbox can be checked/unchecked successfully:

   context 'When someone else submits work I am assigned to review' do
       it "should check 'When someone else submits work I am assigned to review' option" do
         find(:css, "#user_email_on_submission").set(true)
       #find and check the box for When someone else submits work I am assigned to review
         review_box = find('#user_email_on_submission')
         expect(review_box).to be_checked
       end
 
       it "should uncheck 'When someone else submits work I am assigned to review' option" do
        #find and uncheck the box for When someone else submits work I am assigned to review
         find(:css, "#user_email_on_submission").set(false)
         review_box = find('#user_email_on_submission')
         expect(review_box).not_to be_checked
       end
   end

3) Test that if the "When someone else reviews one of my reviews (metareviews my work)" checkbox can be checked/unchecked successfully:

   context 'When someone else reviews one of my reviews (metareviews my work)' do
       it "should check 'When someone else reviews one of my reviews (metareviews my work)' option" do
       #find and check the box for When someone else reviews one of my reviews (metareviews my work)
         find(:css, "#user_email_on_review_of_review").set(true)
         review_box = find('#user_email_on_review_of_review')
         expect(review_box).to be_checked
       end
 
       it "should uncheck 'When someone else reviews one of my reviews (metareviews my work)' option" do
       #find and uncheck the box for When someone else reviews one of my reviews (metareviews my work)
         find(:css, "#user_email_on_review_of_review").set(false)
         review_box = find('#user_email_on_review_of_review')
         expect(review_box).not_to be_checked
       end
     end

4) Test that if the "Send me copies of emails sent for assignments" checkbox can be checked/unchecked successfully:

   context 'Send me copies of emails sent for assignments' do
       it "should check 'Send me copies of emails sent for assignments' option" do
         review_box = find('#user_copy_of_emails')
         expect(review_box).to be_checked
       end
 
       it "should uncheck 'Send me copies of emails sent for assignments' option" do
         review_box = find(:css, "#user_copy_of_emails")
         expect(review_box).not_to be_checked
       end
     end


Below are the tests located in the email_notification_spec.rb file, we use a gem named 'capybara-email' to open the email we intend to send and check for the content for related mailing task:

   gem 'capybara-email'

T3: Test after resetting password email can be sent to users

Testing email can be sent to users successfully if they reset their password. Users can reset their password if they forget about their previous ones. They can get a new password in email sent by the Expertiza system. We use capybara to test and check for password-reset content:

 feature 'Reset password mailer' do
   background do
     FactoryGirl.create :student
     # will clear the message queue
     clear_emails
     visit 'password_retrieval/forgotten'
     find('input#user_email', visible: false).set('expertiza@mailinator.com')
     click_button 'Request password'
     # will find an email sent to expertiza.development@gmail.com and set `current_email`
     open_email('expertiza.development@gmail.com')
   end
   scenario 'testing for content' do
     expect(page).to have_current_path('/password_retrieval/forgotten')
     expect(current_email).to have_content 'Your Expertiza password has been reset. We strongly recommend that you change the password the next time you access the application.'
     expect(current_email).to have_content 'User Name'
     expect(current_email).to have_content 'New password'
   end
 end

T4: Test after signing-up emails can be sent to users

Testing welcome email can be sent to users successfully if they sign up successfully. Users will get welcome email once they get new accounts in the Expertiza, we use capybara to test and check for welcome email content:

 feature 'Welcome mailer' do
   background do
     create(:assignment)
     FactoryGirl.create :student
     # will clear the message queue
     clear_emails
     login_as("instructor6")
     visit '/users/new?role=Student'
     find('input#user_name', visible: false).set('Puma')
     find('input#user_fullname', visible: false).set('Qiaoxuan Xue')
     find('input#user_email', visible: false).set('expertiza@test.com')
     click_button 'Create'
     # Will find an email sent to expertiza.development@gmail.com and set `current_email`
     open_email('expertiza.development@gmail.com')
   end
   scenario 'testing for content' do
     expect(page).to have_current_path('/users/list')
     expect(current_email).to have_content 'Your Expertiza account has been created at http://expertiza.ncsu.edu. We strongly recommend that you change the password the first time you access the application.'
     expect(current_email).to have_content 'User Name'
     expect(current_email).to have_content 'E-mail address'
     expect(current_email).to have_content 'New password'
   end
 end

T5: Test after updating homework emails can be sent to reviewers

Testing email notification can be sent to the users successfully once their assigned homework get updated. Each assignment are created with a contributor and reviewer, once the contributor updates their homework, the reviewer will receive a notification email informing about this action and view the update. We use capybara and check for the content for update email:

 feature 'update assignment email notification' do
   background do
     student = FactoryGirl.create :student
     assignment = FactoryGirl.create :assignment
     # will clear the message queue
     clear_emails
     Mailer.sync_message(
         recipients: 'expertiza.development@gmail.com',
         subject: "One of the assignment#{assignment.name} is updated, you can review it now",
         body: {
             home_page: '123',
             first_name: ApplicationHelper.get_user_first_name(student),
             name: student.name,
             password: student.password,
             partial_name: "update"
         }
     ).deliver_now
     open_email('expertiza.development@gmail.com')
   end
   scenario 'testing for content' do
     expect(current_email).to have_content 'One of the'
     expect(current_email).to have_content 'assignment has just been entered or revised.'
     expect(current_email).to have_content 'You may log into Expertiza and review the work now'
   end
 end

T6: Test emails can be sent to users after their work get reviewed

Testing email can be sent to the users successfully once their work get reviewed. Once a user's assignment get reviewed by a reviewer, a notification email will be sent to the user to check for the content of the review. We use capybara to test and check for the content for review email:

   feature 'New submission notification' do
     background do
       # using the method called same as response.rb => email
       student = FactoryGirl.create :student
       defn = {}
       defn[:body] = {}
       defn[:body][:partial_name] = 'new_submission'
       defn[:body][:first_name] = student.name
       # will clear the message queue
       clear_emails
       Mailer.sync_message(defn).deliver_now
       # Will find an email sent to expertiza.development@gmail.com and set `current_email`
       open_email('expertiza.development@gmail.com')
     end
     scenario 'testing for content' do
       expect(current_email).to have_content 'assignment has just been entered'
     end
   end

Execution and Test Results

The tests were executed by submitting the following command from the terminal.

   $ rpec --format doc feature <RSpec file location>

The results of our work shows below:

Conclusion and Possible Future Work

According to our test, the emailing functionality works well under various scenarios. Possible future work may include setting up assignment examples along with participants and check emailing function work among related members.

Reference

  1. Expertiza on GitHub
  2. Capybara Documentation on Github
  3. RSpec Tutorial on Wiki