Instantly share code, notes, and snippets.

@Pasta /01_Before.rb Secret
Created Aug 28, 2012

Embed
What would you like to do?
Rspec goodness
require 'spec_helper'
describe Recruiters::UsersController do
subject { response }
describe "SHOW" do
before { @user = create(:criterion).user }
it "must not be accessible if I am not logged in as a recruiter" do
get :show, id: @user.id
should be_redirect
end
context 'I am a signed in recruiter' do
before { @recruiter = login_recruiter }
it "should not be accessible if none of my offers where sent to the candidate" do
get :show, id: @user.id
should be_unauthorized
end
context 'Matching made between candidate and offer of the current recruiter' do
before do
@offer = create :offer, recruiter: @recruiter
@user_offer_choice = create :user_offer_choice, user: @user, offer: @offer, accepted: false
end
it 'should be not be accessible if my offer was refused by the user' do
get :show, id: @user.id
should be_unauthorized
end
it 'should be accessible if my offer was accepter by the user' do
@user_offer_choice.update_column :accepted, true
get :show, id: @user.id
response.should be_success
end
end
end
end
end
require 'spec_helper'
describe Recruiters::UsersController do
subject { response }
describe "GET SHOW" do
let(:user) { create(:criterion).user }
context "when recruiter not signed in" do
before {get :show, id: user.id}
it { should be_redirect }
end
context 'when recruiter signed in' do
let!(:recruiter){ login_recruiter }
let(:offer) { create :offer, recruiter: recruiter}
context "when no matching made" do
before {get :show, id: user.id }
it { should be_unauthorized }
end
context 'when matching made' do
let(:user_offer_choice ){ create :user_offer_choice, user: user, offer: offer, accepted: false }
context "and refused by candidate" do
before {get :show, id: user.id }
it { should be_unauthorized }
end
context "and accepted by candidate" do
before do
user_offer_choice.update_column :accepted, true
get :show, id: user.id, offer_id: offer.id
end
it { should be_success }
it "should have marked the profile as seen" do
user_offer_choice.reload.seen_by_recruiter_at.should_not be_nil
end
end
end
end
end
end
Recruiters::UsersController
GET SHOW
when recruiter not signed in
should be redirect
when recruiter signed in
when no matching made
should == 401
when matching made
and refused by candidate
should == 401
and accepted by candidate
should be success
should have marked the profile as seen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment