Last active
January 20, 2016 15:27
-
-
Save the-undefined/fd45a7d54c90c937c953 to your computer and use it in GitHub Desktop.
What to use for the `view_context` in a presenter spec
This file contains hidden or 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
class Presenter | |
def user_select_options | |
view_context.options_from_collection_for_select( | |
User.all, | |
:id, | |
:full_name | |
) | |
end | |
private | |
attr_reader :view_context | |
def initialize(view_context: view_context) | |
@view_context = view_context | |
end | |
end |
This file contains hidden or 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
RSpec.describe Presenter do | |
let(:view_context) { ActionView::Base.new } | |
describe '#user_select_options' do | |
it 'should return the users full name' do | |
presenter = described_class.new(view_context: view_context) | |
users = [ | |
['Sir Joe James', 1], | |
['Lord John Doe II', 2], | |
] | |
expect(presenter.user_select_options).to match_array(users) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment