Sha256: 7eb5a101c928ecb4fb86d2e899a50bcde7afa9a0b835582f56d1bc624f8e3e2e

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 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_successful
    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_successful
    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', params: { 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', params: { 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

14 entries across 14 versions & 1 rubygems

Version Path
introspective_grape-0.6.1 spec/requests/role_api_spec.rb
introspective_grape-0.5.7 spec/requests/role_api_spec.rb
introspective_grape-0.5.6 spec/requests/role_api_spec.rb
introspective_grape-0.5.5 spec/requests/role_api_spec.rb
introspective_grape-0.5.4 spec/requests/role_api_spec.rb
introspective_grape-0.5.2 spec/requests/role_api_spec.rb
introspective_grape-0.5.0 spec/requests/role_api_spec.rb
introspective_grape-0.4.3 spec/requests/role_api_spec.rb
introspective_grape-0.4.2 spec/requests/role_api_spec.rb
introspective_grape-0.4.1 spec/requests/role_api_spec.rb
introspective_grape-0.4.0 spec/requests/role_api_spec.rb
introspective_grape-0.3.9 spec/requests/role_api_spec.rb
introspective_grape-0.3.7 spec/requests/role_api_spec.rb
introspective_grape-0.3.6 spec/requests/role_api_spec.rb