-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Api::Utils.resource_search_by_href_slug helper method #14443
Merged
gtanzillo
merged 2 commits into
ManageIQ:master
from
abellotti:api_resource_search_by_href_slug
Mar 27, 2017
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
RSpec.describe Api::Utils do | ||
describe ".resource_search_by_href_slug" do | ||
before { allow(User).to receive_messages(:server_timezone => "UTC") } | ||
|
||
it "returns nil when nil is specified" do | ||
actual = described_class.resource_search_by_href_slug(nil) | ||
|
||
expect(actual).to be_nil | ||
end | ||
|
||
it "raises an exception with missing id" do | ||
expect { described_class.resource_search_by_href_slug("vms/") } | ||
.to raise_error("Invalid href_slug vms/ specified") | ||
end | ||
|
||
it "raises an exception with missing collection" do | ||
expect { described_class.resource_search_by_href_slug("/10") } | ||
.to raise_error("Invalid href_slug /10 specified") | ||
end | ||
|
||
it "raises an exception with missing delimited" do | ||
expect { described_class.resource_search_by_href_slug("vms") } | ||
.to raise_error("Invalid href_slug vms specified") | ||
end | ||
|
||
it "raises an exception with a bogus href_slug" do | ||
expect { described_class.resource_search_by_href_slug("bogus/123") } | ||
.to raise_error("Invalid href_slug bogus/123 specified") | ||
end | ||
|
||
it "raises an exception with a non primary collection href_slug" do | ||
expect { described_class.resource_search_by_href_slug("auth/123") } | ||
.to raise_error("Invalid href_slug auth/123 specified") | ||
end | ||
|
||
it "raises an ActiveRecord::RecordNotFound with a non-existent href_slug" do | ||
expect { described_class.resource_search_by_href_slug("vms/99999") } | ||
.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
|
||
it "returns the resource with a valid href_slug" do | ||
vm = FactoryGirl.create(:vm_vmware) | ||
|
||
actual = described_class.resource_search_by_href_slug("vms/#{vm.id}") | ||
|
||
expect(actual).to eq(vm) | ||
end | ||
|
||
it "does not return the resource when Rbac fails" do | ||
owner_tenant = FactoryGirl.create(:tenant) | ||
|
||
unauth_tenant = FactoryGirl.create(:tenant) | ||
unauth_group = FactoryGirl.create(:miq_group, :tenant => unauth_tenant) | ||
|
||
vm = FactoryGirl.create(:vm_vmware, :tenant => owner_tenant) | ||
User.current_user = FactoryGirl.create(:user, :miq_groups => [unauth_group]) | ||
|
||
actual = described_class.resource_search_by_href_slug("vms/#{vm.id}") | ||
|
||
expect(actual).to eq(nil) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abellotti can we pass in the user_object here with the default being User.curent_user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, didn't know the usage from your side. Will update. 👍