jam-cloud/web/spec/controllers/api_school_invitations_cont...

59 lines
1.9 KiB
Ruby

require 'spec_helper'
describe ApiSchoolInvitationsController, type: :controller do
render_views
let (:owner) {FactoryGirl.create(:user)}
let (:school) {FactoryGirl.create(:school, user: owner)}
let (:school_invitation_teacher) {FactoryGirl.create(:school_invitation, school: school, as_teacher: true)}
let (:school_invitation_student) {FactoryGirl.create(:school_invitation, school: school, as_teacher: false)}
before(:each) do
controller.current_user = owner
end
describe "index" do
it "works" do
get :index, params: { id: school.id, as_teacher: true }
response.should be_success
JSON.parse(response.body)['total_entries'].should eql 0
school_invitation_teacher.touch
get :index, params: { id: school.id, as_teacher: true }
response.should be_success
JSON.parse(response.body)['total_entries'].should eql 1
get :index, params: { id: school.id, as_teacher: false }
response.should be_success
JSON.parse(response.body)['total_entries'].should eql 0
end
end
describe "create" do
it "works" do
UserMailer.deliveries.clear
post :create, params: { id: school.id, first_name: "Seth", last_name: "Call", email: "seth@jamkazam.com", as_teacher: true}, :as => 'json'
UserMailer.deliveries.length.should eql 1
response.should be_success
JSON.parse(response.body)['id'].should eql SchoolInvitation.find_by_email("seth@jamkazam.com").id
end
end
describe "resend" do
it "works" do
UserMailer.deliveries.clear
post :resend, params: { id: school.id, invitation_id: school_invitation_teacher.id }, :as => 'json'
UserMailer.deliveries.length.should eql 1
response.should be_success
end
end
describe "delete" do
it "works" do
delete :delete, params: { id: school.id, invitation_id: school_invitation_teacher.id }, :as => 'json'
response.should be_success
end
end
end