Skip to content
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

Allow disabling user links #673

Merged
merged 2 commits into from
Jan 10, 2018

Conversation

metalelf0
Copy link
Contributor

This commit changes the user link partial to render a span element
instead of a link when the user_path lambda is evaluated to nil.

Therefor, it allows disabling all user links by setting the user_path
lambda to always return nil.

This can be useful if, for any reason, you only want to link to some
user profiles (just write the lambda so that it returns only valid
links, and nil otherwise), or if you want to completely disable the
profile link feature.

This commit changes the user link partial to render a span element
instead of a link when the user_path lambda is evaluated to nil.

Therefor, it allows disabling all user links by setting the `user_path`
lambda to always return nil.

This can be useful if, for any reason, you only want to link to some
user profiles (just write the lambda so that it returns only valid
links, and nil otherwise), or if you want to completely disable the
profile link feature.
@metalelf0
Copy link
Contributor Author

@glebm : I suppose specs are failing because of this example I added in spec/views/thredded/user/link_spec.rb:

  it 'with nil user path' do
    Thredded.user_path = ->(_user) { nil }
    render_partial build_stubbed(:user, id: 5, name: 'joel')
    expect(rendered).to eq <<-HTML.strip_heredoc
      <span class='thredded--username'>joel</span>
    HTML
  end

This has the side effect of changing the Thredded.user_path lambda for the rest of the spec suite. I tried using the with_thredded_setting around block as used elsewhere but it's not working for this specific setting. Any hint about how I can solve this?

@@ -28,4 +28,12 @@ def render_partial(user)
<em>#{I18n.t('thredded.null_user_name')}</em>
HTML
end

it 'with nil user path' do
Copy link
Collaborator

@glebm glebm Jan 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the test failures, this might help:

it 'with nil user path', thredded_reset: [:@@user_path] do

If it doesn't work, try applying thredded_reset to a describe or a context block.

@metalelf0
Copy link
Contributor Author

@glebm thanks, that worked :)

@jayroh
Copy link
Member

jayroh commented Jan 10, 2018

ha - I didn't even know thredded_reset existed! Good to know

@glebm glebm merged commit b0a888e into thredded:master Jan 10, 2018
@glebm glebm added this to the v0.14.1 milestone Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants