Sha256: 01da7b8e0d0c159c8d9f76581e1991f0b443e3396be7c76e877ed0ffed5d7507

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require 'rails_helper'
describe Dummy::RoleAPI, type: :request do
  let(:role) { Role.last }
  let(:user) { User.last }
  let(:company) { Company.last }

  before :all do
    c = Company.make!
    Role.destroy_all
    User.make!(superuser: true)
    Role.make!(user_id: User.last.id, ownable_id: c.id, ownable_type: c.class)
  end

  it 'should return a list of user roles' do
    get '/api/v1/roles'
    response.should be_success
    json.length.should == 1
    json.first['id'].to_i.should == role.id
  end

  it 'should return the specified user role' do
    get "/api/v1/roles/#{role.id}"
    response.should be_success
    json['email'].should == role.email
  end

  it "should return an error if the role doesn't exist" do
    get "/api/v1/roles/#{role.id+1}"
    response.code.should == '404'
  end

  it 'should not duplicate user roles' do
    post '/api/v1/roles', { user_id: user.id, ownable_type: 'Company', ownable_id: company.id }
    response.code.should == '400'
    json['error'].should =~ /user has already been assigned that role/
  end

  it 'validates ownable type value specified in grape_validations' do
    post '/api/v1/roles', { user_id: user.id, ownable_type: 'NotCompany' }
    response.code.should == '400'
    json['error'].should eq "ownable_type does not have a valid value"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
introspective_grape-0.3.5 spec/requests/role_api_spec.rb
introspective_grape-0.3.3 spec/requests/role_api_spec.rb