-
Notifications
You must be signed in to change notification settings - Fork 126
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
Basic tests for UsersTab add user button #805
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require 'spec_helper' | ||
|
||
module Pageflow | ||
module Admin | ||
describe AddMembershipButtonIfNeeded, type: :view_component do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block has too many lines. [33/25] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block has too many lines. [58/25] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block has too many lines. [59/25] |
||
before do | ||
helper.extend(ActiveAdmin::ViewHelpers) | ||
helper.extend(Pageflow::Admin::MembershipsHelper) | ||
allow(helper).to receive(:new_admin_account_membership_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't stubbing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested by running |
||
allow(helper).to receive(:new_admin_user_membership_path) | ||
allow(helper).to receive(:url_for) | ||
end | ||
|
||
it 'renders add user button when account available' do | ||
account = create(:account) | ||
user_account = create(:account) | ||
create(:user, :member, on: user_account) | ||
account_manager = create(:user, :manager, on: account) | ||
create(:membership, | ||
user: account_manager, | ||
entity: user_account, | ||
role: :manager) | ||
sign_in(account_manager) | ||
|
||
render do | ||
add_membership_button_if_needed(account_manager, account, 'account') | ||
end | ||
|
||
expect(rendered).to have_selector('a', text: 'Add user') | ||
expect(rendered).to_not have_selector('a', class: 'disabled') | ||
end | ||
|
||
it 'renders disabled add user button when account unavailable' do | ||
account = create(:account) | ||
create(:user, :member, on: account) | ||
account_manager = create(:user, :manager, on: account) | ||
sign_in(account_manager) | ||
|
||
render do | ||
add_membership_button_if_needed(account_manager, account, 'account') | ||
end | ||
|
||
expect(rendered).to have_selector('a', class: 'disabled') | ||
end | ||
|
||
it 'renders add account button when account available' do | ||
first_account = create(:account) | ||
user = create(:user, :member, on: first_account) | ||
second_account = create(:account) | ||
account_manager = create(:user, :manager, on: first_account) | ||
create(:membership, | ||
user: account_manager, | ||
entity: second_account, | ||
role: 'manager') | ||
sign_in(account_manager) | ||
|
||
render do | ||
add_membership_button_if_needed(user, user, 'account') | ||
end | ||
|
||
expect(rendered).to have_selector('a', text: 'Add Account') | ||
expect(rendered).to_not have_selector('a', class: 'disabled') | ||
end | ||
|
||
it 'renders disabled add account button when account unavailable' do | ||
first_account = create(:account) | ||
user = create(:user, :member, on: first_account) | ||
account_manager = create(:user, :manager, on: first_account) | ||
sign_in(account_manager) | ||
|
||
render do | ||
add_membership_button_if_needed(user, user, 'account') | ||
end | ||
|
||
expect(rendered).to have_selector('a', class: 'disabled') | ||
end | ||
end | ||
end | ||
end |
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.
Block has too many lines. [27/25]