Skip to content

Allow disabling user links#673

Merged
glebm merged 2 commits intothredded:masterfrom
metalelf0:allow-disabling-user-links
Jan 10, 2018
Merged

Allow disabling user links#673
glebm merged 2 commits intothredded:masterfrom
metalelf0:allow-disabling-user-links

Conversation

@metalelf0
Copy link
Copy Markdown
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
Copy Markdown
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?

HTML
end

it 'with nil user path' do
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@glebm thanks, that worked :)

@jayroh
Copy link
Copy Markdown
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