From bdc52c0fe9a272bb1c9a6d5db12ecb08d1c7a43b Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Fri, 15 Apr 2016 09:40:22 +0100 Subject: [PATCH] Fix hound issues --- lib/mountain_view/presenter.rb | 17 ++++++----- .../app/components/card/card_component.rb | 4 +-- test/mountain_view/presenter_test.rb | 30 +++++++++---------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/mountain_view/presenter.rb b/lib/mountain_view/presenter.rb index 894bbb4..ea49a42 100644 --- a/lib/mountain_view/presenter.rb +++ b/lib/mountain_view/presenter.rb @@ -20,6 +20,10 @@ def partial "#{slug}/#{slug}" end + def exposed_methods + public_methods(false) - [:slug, :properties, :render, :partial] + end + private def default_properties @@ -47,11 +51,11 @@ def properties(*args) end alias_method :property, :properties - private - - def define_property_methods(names=[]) + private + + def define_property_methods(names = []) names.each do |name| - next if method_defined?(name) + next if method_defined?(name) define_method name do properties[name.to_sym] end @@ -62,11 +66,10 @@ def define_property_methods(names=[]) module ViewContext attr_reader :_component delegate :properties, to: :_component - + def inject_component_context(component) @_component = component - methods = component.public_methods(false) - [:slug, :properties, :render, :partial] - methods.each do |meth| + component.exposed_methods.each do |meth| next if self.class.method_defined?(meth) self.class.delegate meth, to: :_component end diff --git a/test/dummy/app/components/card/card_component.rb b/test/dummy/app/components/card/card_component.rb index 0355442..fa9742c 100644 --- a/test/dummy/app/components/card/card_component.rb +++ b/test/dummy/app/components/card/card_component.rb @@ -1,13 +1,13 @@ class CardComponent < MountainView::Presenter include ActionView::Helpers::TagHelper - + properties :title, :description, :link, :image_url, :location property :data, default: [] def title [location, properties[:title]].compact.join(", ") end - + def has_description? description.present? end diff --git a/test/mountain_view/presenter_test.rb b/test/mountain_view/presenter_test.rb index a34e01e..fd7bb6a 100644 --- a/test/mountain_view/presenter_test.rb +++ b/test/mountain_view/presenter_test.rb @@ -10,29 +10,29 @@ def title end class MountainView::PresenterTest < ActiveSupport::TestCase - test 'returns the correct partial path' do + test "returns the correct partial path" do presenter = MountainView::Presenter.new("header") assert_equal "header/header", presenter.partial end - - test 'exposes properties as provided' do - properties = {:foo => 'bar', :hello => 'world'} + + test "exposes properties as provided" do + properties = {foo: "bar", hello: "world"} presenter = MountainView::Presenter.new("header", properties) assert_equal properties, presenter.properties end - - test 'inherited presenter returns the correct title' do - presenter = InheritedPresenter.new('inherited', {:title => 'Bar'}) - assert_equal 'Foobar', presenter.title + + test "inherited presenter returns the correct title" do + presenter = InheritedPresenter.new("inherited", title: "Bar") + assert_equal "Foobar", presenter.title end - - test 'inherited presenter responds to #data' do - presenter = InheritedPresenter.new('inherited', {:data => ['Foobar']}) - assert_equal ['Foobar'], presenter.data + + test "inherited presenter responds to #data" do + presenter = InheritedPresenter.new("inherited", data: ["Foobar"]) + assert_equal ["Foobar"], presenter.data end - - test 'inherited presenter returns the default value for #data' do - presenter = InheritedPresenter.new('inherited', {}) + + test "inherited presenter returns the default value for #data" do + presenter = InheritedPresenter.new("inherited", {}) assert_equal [], presenter.data end end