Skip to content

Commit

Permalink
Fix hound issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeynon committed Apr 15, 2016
1 parent 33b208b commit c6e6ea2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
17 changes: 10 additions & 7 deletions lib/mountain_view/presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def partial
"#{slug}/#{slug}"
end

def exposed_methods
public_methods(false) - [:slug, :properties, :render, :partial]
end

private

def default_properties
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/dummy/app/components/card/card_component.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 15 additions & 15 deletions test/mountain_view/presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c6e6ea2

Please sign in to comment.