Created
October 1, 2014 06:20
-
-
Save rubyrider/9674a52b5cf81842d470 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'EducationRecord' do | |
let(:user) {users(:john)} | |
let(:candidate) {candidates(:john_candidate)} | |
before do | |
cookies[:user_auth_token] = encrypt_token(user.access_token) | |
end | |
around(:each) do |example| | |
VCR.use_cassette(:get_user_from_sso, {}, &example) | |
end | |
describe '#index' do | |
before do | |
FactoryGirl.create_list(:education_record, 10, candidate: candidate) | |
get "/api/v1/candidate/education-records/", {}, json_content_type(user.access_token) | |
end | |
it 'returns a successful response' do | |
expect(response).to be_success | |
end | |
it "return list of all education histories" do | |
expect(json(response.body).length).to eq(10) | |
end | |
end | |
describe '#create' do | |
before do | |
FactoryGirl.create_list(:education_record, 10, candidate: candidate) | |
post "/api/v1/candidate/education-records/", {education_record: { | |
school: "International Technological University", | |
city: "San Francisco", | |
field_of_study: "Economics", | |
degree: "B.Com", | |
start_year: 5.years.from_now, | |
end_year: 2.years.ago | |
}}.to_json, json_content_type(user.access_token) | |
end | |
it 'returns a successful response' do | |
expect(response).to be_success | |
end | |
it "return the created education record" do | |
response_body = json(response.body) | |
expect(response_body[:school_name]).to eq("International Technological University") | |
end | |
end | |
describe '#show' do | |
subject {create(:education_record, candidate: candidate) } | |
before do | |
get "/api/v1/candidate/education-records/#{subject.id}", {}, json_content_type(user.access_token) | |
end | |
it 'returns a successful response' do | |
expect(response).to be_success | |
end | |
it "returns a valid education history record" do | |
response_body = json(response.body) | |
expect(response_body[:school_name]).to eql(subject.school) | |
end | |
end | |
describe '#update' do | |
subject {create(:education_record, candidate: candidate) } | |
context 'when a valid record is submitted' do | |
before do | |
patch "/api/v1/candidate/education-records/#{subject.id}", {education_record: {school: 'ITU 2'}}.to_json, json_content_type(user.access_token) | |
end | |
it 'returns a succesful response' do | |
expect(response).to be_success | |
end | |
it 'returns record with updated school name' do | |
response_body = json(response.body) | |
expect(response_body[:school_name]).to eql('ITU 2') | |
end | |
end | |
context 'when invalid record is submitted' do | |
before do | |
patch "/api/v1/candidate/education-records/#{subject.id}", {education_record: {school: nil}}.to_json, json_content_type(user.access_token) | |
end | |
it 'returns 422 status code' do | |
expect(response.status).to eql(422) | |
end | |
it 'returns content_type as JSON' do | |
expect(response.content_type).to eql(Mime::JSON) | |
end | |
it 'returns error messages' do | |
errors = json(response.body) | |
expect(errors[:school]).to eql(["can't be blank"]) | |
end | |
end | |
end | |
describe '#destroy' do | |
subject {create(:education_record, candidate: candidate) } | |
context 'when a record exists' do | |
before do | |
delete "/api/v1/candidate/education-records/#{subject.id}",{}, json_content_type(user.access_token) | |
end | |
it 'returns 204 status code' do | |
expect(response.status).to eql(204) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment