Skip to content

Commit

Permalink
Fix presenter finding logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
phiggins committed Apr 2, 2012
1 parent 53d772f commit d8f9059
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
15 changes: 9 additions & 6 deletions core/lib/refinery/application_controller.rb
Expand Up @@ -71,12 +71,15 @@ def force_ssl?

# use a different model for the meta information.
def present(model)
presenter = if model && model.class.present? && defined?("#{model.class}Presenter")
"#{model.class.name}Presenter".constantize
else
BasePresenter
end
@meta = presenter.new(model)
@meta = presenter_for(model).new(model)
end

def presenter_for(model, default=BasePresenter)
return default if model.nil?

"#{model.class.name}Presenter".constantize
rescue NameError
default
end

def refinery_user_required?
Expand Down
15 changes: 15 additions & 0 deletions core/spec/lib/refinery/application_controller_spec.rb
Expand Up @@ -68,5 +68,20 @@ def index
end
end
end

describe "#presenter_for" do
it "returns BasePresenter for nil" do
controller.send(:presenter_for, nil).should eq(BasePresenter)
end

it "returns BasePresenter when the instance's class does not have a presenter" do
controller.send(:presenter_for, Object.new).should eq(BasePresenter)
end

it "returns the class's presenter when the instance's class has a presenter" do
model = Refinery::Page.new
controller.send(:presenter_for, model).should eq(Refinery::PagePresenter)
end
end
end
end

0 comments on commit d8f9059

Please sign in to comment.