Skip to content

Commit

Permalink
Add deprecated methods (deprecated by DocumentPresenter) into the new…
Browse files Browse the repository at this point in the history
… presenters
  • Loading branch information
cbeer committed Jul 7, 2016
1 parent bd81c15 commit 5bcf0df
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/presenters/blacklight/document_presenter.rb
Expand Up @@ -127,10 +127,16 @@ def field_values(field_config, options={})

# @deprecated
def render_field_value(values, field_config = Configuration::NullField.new)
FieldPresenter.new(@controller, @document, field_config, value: values).render
field_values(field_config, value: Array(values))
end
deprecation_deprecate render_field_value: 'Use FieldPresenter instead'

# @deprecated
def render_values(values, field_config = Configuration::NullField.new)
field_values(field_config, value: Array(values))
end
deprecation_deprecate render_values: 'Use FieldPresenter instead'

private

def index_presenter
Expand Down
33 changes: 33 additions & 0 deletions app/presenters/blacklight/index_presenter.rb
@@ -1,6 +1,9 @@
# frozen_string_literal: true
module Blacklight
class IndexPresenter
extend Deprecation
self.deprecation_horizon = 'Blacklight version 7.0.0'

attr_reader :document, :configuration, :view_context

# @param [SolrDocument] document
Expand Down Expand Up @@ -34,6 +37,12 @@ def label(field_or_string_or_proc, opts = {})
field_values(config, value: value)
end

# @deprecated
def render_document_index_label(*args)
label(*args)
end
deprecation_deprecate render_document_index_label: 'Use #label instead'

##
# Render the index field label for a document
#
Expand All @@ -47,6 +56,30 @@ def field_value field, options = {}
field_values(field_config, options)
end

# @deprecated
def render_index_field_value(*args)
field_value(*args)
end
deprecation_deprecate render_index_field_value: 'replaced by #field_value'

# @deprecated
def get_field_values(field_config, options={})
field_values(field_config, options)
end
deprecation_deprecate get_field_values: "replaced by #field_value"

# @deprecated
def render_field_values(values, field_config = Configuration::NullField.new)
field_values(field_config, value: Array(values))
end
deprecation_deprecate render_field_values: "replaced by #field_value"

# @deprecated
def render_values(values, field_config = Configuration::NullField.new)
field_values(field_config, value: Array(values))
end
deprecation_deprecate render_values: "replaced by #field_value"

private

##
Expand Down
30 changes: 30 additions & 0 deletions app/presenters/blacklight/show_presenter.rb
Expand Up @@ -45,6 +45,12 @@ def html_title
end
end

# @deprecated
def document_show_html_title
html_title
end
deprecation_deprecate document_show_html_title: "use #html_title"

##
# Get the value of the document's "title" field, or a placeholder
# value (if empty)
Expand Down Expand Up @@ -76,6 +82,30 @@ def field_value field, options={}
field_values(field_config(field), options)
end

# @deprecated
def render_document_show_field_value(*args)
field_value(*args)
end
deprecation_deprecate render_document_show_field_value: 'replaced by #field_value'

# @deprecated
def get_field_values(field_config, options={})
field_values(field_config, options)
end
deprecation_deprecate get_field_values: "replaced by #field_value"

# @deprecated
def render_field_values(values, field_config = Configuration::NullField.new)
field_values(field_config, value: Array(values))
end
deprecation_deprecate render_field_values: "replaced by #field_value"

# @deprecated
def render_values(values, field_config = Configuration::NullField.new)
field_values(field_config, value: Array(values))
end
deprecation_deprecate render_values: "replaced by #field_value"

private

##
Expand Down
8 changes: 8 additions & 0 deletions spec/presenters/document_presenter_spec.rb
Expand Up @@ -428,4 +428,12 @@ def mock_document_app_helper_url *args
end
end
end

describe '#render_values' do
it 'renders field values as a string' do
expect(subject.render_values('x')).to eq 'x'
expect(subject.render_values(['x', 'y'])).to eq 'x and y'
expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z'
end
end
end
26 changes: 26 additions & 0 deletions spec/presenters/index_presenter_spec.rb
Expand Up @@ -143,5 +143,31 @@
end
end
end

describe 'deprecated methods' do
before do
allow(Deprecation).to receive(:warn)
end

let(:field_config) { config.add_index_field 'qwerty' }

describe '#get_field_values' do
it 'renders values for the given field' do
expect(subject.get_field_values(field_config, value: ['x', 'y'])).to eq 'x and y'
end
end

describe '#render_field_values' do
it 'renders values for the given field' do
expect(subject.render_field_values('x')).to eq 'x'
end
end

describe '#render_values' do
it 'renders values for the given field' do
expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z'
end
end
end
end

26 changes: 26 additions & 0 deletions spec/presenters/show_presenter_spec.rb
Expand Up @@ -283,5 +283,31 @@ def mock_document_app_helper_url *args
end
end
end

describe 'deprecated methods' do
before do
allow(Deprecation).to receive(:warn)
end

let(:field_config) { config.add_index_field 'qwerty' }

describe '#get_field_values' do
it 'renders values for the given field' do
expect(subject.get_field_values(field_config, value: ['x', 'y'])).to eq 'x and y'
end
end

describe '#render_field_values' do
it 'renders values for the given field' do
expect(subject.render_field_values('x')).to eq 'x'
end
end

describe '#render_values' do
it 'renders values for the given field' do
expect(subject.render_values(['x', 'y', 'z'])).to eq 'x, y, and z'
end
end
end
end

0 comments on commit 5bcf0df

Please sign in to comment.