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

55 lines
1.6 KiB
Ruby

require 'spec_helper'
describe ApiRetailerInvitationsController, type: :controller do
render_views
let (:owner) {FactoryGirl.create(:user)}
let (:retailer) {FactoryGirl.create(:retailer, user: owner)}
let (:retailer_invitation_teacher) {FactoryGirl.create(:retailer_invitation, retailer: retailer)}
before(:each) do
controller.current_user = owner
end
describe "index" do
it "works" do
get :index, params: { id: retailer.id }
response.should be_success
JSON.parse(response.body)['total_entries'].should eql 0
retailer_invitation_teacher.touch
get :index, params: { id: retailer.id }
response.should be_success
JSON.parse(response.body)['total_entries'].should eql 1
end
end
describe "create" do
it "works" do
UserMailer.deliveries.clear
post :create, params: { id: retailer.id, first_name: "Seth", last_name: "Call", email: "seth@jamkazam.com" }, :as => 'json'
response.should be_success
UserMailer.deliveries.length.should eql 1
JSON.parse(response.body)['id'].should eql RetailerInvitation.find_by_email("seth@jamkazam.com").id
end
end
describe "resend" do
it "works" do
UserMailer.deliveries.clear
post :resend, params: { id: retailer.id, invitation_id: retailer_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: retailer.id, invitation_id: retailer_invitation_teacher.id }, :as => 'json'
response.should be_success
end
end
end