Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge 64c9290 into 370d1b0
Browse files Browse the repository at this point in the history
  • Loading branch information
johnathanludwig committed Oct 19, 2016
2 parents 370d1b0 + 64c9290 commit 79435a8
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 50 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Unreleased
### Added
- Users create/update/destroy support
- Role all/find support

## 2.6.0 - 2016-10-17
### Changed
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
esp_sdk (2.6.0)
esp_sdk (2.7.0)
activeresource (~> 4.0.0)
api-auth (~> 2.0.0)
rack
Expand Down
1 change: 1 addition & 0 deletions lib/esp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def self.env
autoload :Metadata, File.expand_path(File.dirname(__FILE__) + '/esp/resources/metadata')
autoload :Tag, File.expand_path(File.dirname(__FILE__) + '/esp/resources/tag')
autoload :Region, File.expand_path(File.dirname(__FILE__) + '/esp/resources/region')
autoload :Role, File.expand_path(File.dirname(__FILE__) + '/esp/resources/role')
autoload :Suppression, File.expand_path(File.dirname(__FILE__) + '/esp/resources/suppression')
autoload :Stat, File.expand_path(File.dirname(__FILE__) + '/esp/resources/stat')
autoload :StatCustomSignature, File.expand_path(File.dirname(__FILE__) + '/esp/resources/stat_custom_signature')
Expand Down
4 changes: 2 additions & 2 deletions lib/esp/resources/region.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module ESP
class Region < ESP::Resource
# Not Implemented. You cannot create or update a CloudTrailEvent.
# Not Implemented. You cannot create or update a Region.
#
# @return [void]
def save
fail ESP::NotImplementedError
end

# Not Implemented. You cannot destroy a an CloudTrailEvent.
# Not Implemented. You cannot destroy a Region.
#
# @return [void]
def destroy
Expand Down
37 changes: 37 additions & 0 deletions lib/esp/resources/role.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module ESP
class Role < ESP::Resource
# Not Implemented. You cannot create or update a Role.
#
# @return [void]
def save
fail ESP::NotImplementedError
end

# Not Implemented. You cannot destroy a Role.
#
# @return [void]
def destroy
fail ESP::NotImplementedError
end

# Not Implemented. You cannot search for a Role.
#
# @return [void]
def self.where(*)
fail ESP::NotImplementedError
end

# @!method self.find(id)
# Find a Region by id
#
# *call-seq* -> +super.find(id)+
#
# @param id [Integer, Numeric, #to_i] Required ID of the region to retrieve.
# @return [ESP::Region]

# @!method self.all
# Return a paginated list.
#
# @return [ActiveResource::PaginatedCollection<ESP::Region>]
end
end
45 changes: 30 additions & 15 deletions lib/esp/resources/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ class User < ESP::Resource
# @return [ESP::Organization]
belongs_to :organization, class_name: 'ESP::Organization'

# Not Implemented. You cannot create or update a User.
# The role assigned to this user.
#
# @return [void]
def save
fail ESP::NotImplementedError
end

# Not Implemented. You cannot destroy a User.
#
# @return [void]
def destroy
fail ESP::NotImplementedError
end
# @return [ESP::Role]
belongs_to :role, class_name: 'ESP::Role'

# The collection of sub organizations that belong to the user.
#
Expand Down Expand Up @@ -67,9 +58,33 @@ def teams
#
# @return [ActiveResource::PaginatedCollection<ESP::User>]

# @!method self.create
# Not Implemented. You cannot create a User.
# @!method self.create(attributes = {})
# Create a User.
# *call-seq* -> +super.create(attributes={})+
#
# @param attributes [Hash] Required hash of user attributes.
# ===== Valid Attributes
#
# See {API documentation}[http://api-docs.evident.io?ruby#user-create] for valid arguments
# @return [ESP::User]
# @example
# user = ESP::User.create(first_name: 'John', last_name: 'Doe', email: "test@email.com")

# @!method save
# Create and update a User.
#
# ===== Valid Attributes
#
# See {API documentation}[http://api-docs.evident.io?ruby#user-create] for valid arguments
#
# @return [Boolean]
# @example
# user = ESP::User.new(first_name: 'John', last_name: 'Doe', email: "test@email.com")
# user.save

# @!method destroy
# Delete a User.
#
# @return [void]
# @return [self]
end
end
2 changes: 1 addition & 1 deletion lib/esp/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ESP
VERSION = '2.6.0'.freeze
VERSION = '2.7.0'.freeze
end
24 changes: 24 additions & 0 deletions test/esp/integration/role_integration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')

module ESP::Integration
class RoleTest < ESP::Integration::TestCase
context ESP::Role do
context 'live calls' do
setup do
@role = ESP::Role.last
fail "Live DB does not have any roles. Add a role and run tests again." if @role.blank?
end

context '#CRUD' do
should 'be able to read' do
assert_not_nil @role

role = ESP::Role.find(@role.id)

assert_not_nil role
end
end
end
end
end
end
33 changes: 33 additions & 0 deletions test/esp/integration/user_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,46 @@ class UserTest < ESP::Integration::TestCase
end
end

context '#role' do
should 'return an role' do
role = @user.role

assert_equal @user.role_id, role.id
end
end

context '.where' do
should 'return user objects' do
users = ESP::User.where(id_eq: @user.id)

assert_equal ESP::User, users.resource_class
end
end

context '#CRUD' do
should 'be able to create, update and destroy' do
user = ESP::User.new(first_name: 'Bob', last_name: 'Belcher', email: 'burgerboss@gmail.com', organization_id: 1)

assert_predicate user, :new?

user.save

refute_predicate user, :new?

user.first_name = 'Gene'
user.save

assert_nothing_raised do
ESP::User.find(user.id)
end

user.destroy

assert_raises ActiveResource::ResourceNotFound do
ESP::User.find(user.id)
end
end
end
end
end
end
Expand Down
44 changes: 44 additions & 0 deletions test/esp/resources/role_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')

module ESP
class RoleTest < ActiveSupport::TestCase
context ESP::Role do
context '#create' do
should 'not be implemented' do
assert_raises ESP::NotImplementedError do
ESP::Role.create(name: 'test')
end
end
end

context '#update' do
should 'not be implemented' do
role = build(:role)
assert_raises ESP::NotImplementedError do
role.save
end
end
end

context '#destroy' do
should 'not be implemented' do
role = build(:role)
assert_raises ESP::NotImplementedError do
role.destroy
end
end
end

context '.find' do
should 'call the show api and return a role if searching by id' do
stub_role = stub_request(:get, %r{roles/5.json*}).to_return(body: json(:role))

role = ESP::Role.find(5)

assert_requested(stub_role)
assert_equal ESP::Role, role.class
end
end
end
end
end
10 changes: 5 additions & 5 deletions test/esp/resources/suppression_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ class SuppressionTest < ActiveSupport::TestCase
context '#create' do
should 'not be implemented' do
assert_raises ESP::NotImplementedError do
ESP::User.create(name: 'test')
ESP::Suppression.create(reason: 'test')
end
end
end

context '#update' do
should 'not be implemented' do
u = build(:user)
s = build(:suppression)
assert_raises ESP::NotImplementedError do
u.save
s.save
end
end
end

context '#destroy' do
should 'not be implemented' do
u = build(:user)
s = build(:suppression)
assert_raises ESP::NotImplementedError do
u.destroy
s.destroy
end
end
end
Expand Down
37 changes: 11 additions & 26 deletions test/esp/resources/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,6 @@
module ESP
class UserTest < ActiveSupport::TestCase
context ESP::User do
context '#create' do
should 'not be implemented' do
assert_raises ESP::NotImplementedError do
ESP::User.create(name: 'test')
end
end
end

context '#update' do
should 'not be implemented' do
u = build(:user)
assert_raises ESP::NotImplementedError do
u.save
end
end
end

context '#destroy' do
should 'not be implemented' do
u = build(:user)
assert_raises ESP::NotImplementedError do
u.destroy
end
end
end

context '#organization' do
should 'call the api' do
u = build(:user, organization_id: 1)
Expand Down Expand Up @@ -91,6 +65,17 @@ class UserTest < ActiveSupport::TestCase
assert_not_requested(:put, /teams.json*/)
end
end

context '#role' do
should 'call the api' do
u = build(:user, role_id: 1)
stub_role = stub_request(:get, %r{roles/#{u.role_id}.json*}).to_return(body: json(:role))

u.role

assert_requested(stub_role)
end
end
end
end
end
9 changes: 9 additions & 0 deletions test/factories/roles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryGirl.define do
factory :role, class: 'ESP::Role' do
skip_create

sequence(:id) { |n| n }
type "roles"
name "customer"
end
end

0 comments on commit 79435a8

Please sign in to comment.