Skip to content

Commit

Permalink
Make sure to work with subclass of subclass of Yuba::ViewModel as exp…
Browse files Browse the repository at this point in the history
…ected
  • Loading branch information
willnet committed Aug 30, 2018
1 parent a358ca1 commit bc78a37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/yuba/view_model/rendering.rb
Expand Up @@ -19,8 +19,6 @@ def _protected_ivars

def view_model_assigns
return {} unless defined?(@_view_model)
# TODO: get all public methods between self and Yuba::ViewModel
# now get only in self
methods = @_view_model.public_methods(false)
methods.reject! do |method_name|
%i[initialize].include?(method_name) ||
Expand Down
11 changes: 11 additions & 0 deletions test/yuba/view_model/rendering_test.rb
Expand Up @@ -23,6 +23,10 @@ def _protected_ivars
property :name, public: true
end

inherited_view_model_class = Class.new(simple_view_model_class) do
property :email, public: true
end

view_model_class_with_predicate_method = Class.new(Yuba::ViewModel) do
property :name, public: true

Expand All @@ -44,4 +48,11 @@ def enable?
action_controller.render(view_model: view_model)
assert_equal({ name: 'willnet' }, action_controller.view_assigns)
end

test 'subclass of subclass of Yuba::ViewModel works' do
action_controller = action_controller_class.new
view_model = inherited_view_model_class.new(name: 'willnet', email: 'test@example.com')
action_controller.render(view_model: view_model)
assert_equal({ name: 'willnet', email: 'test@example.com' }, action_controller.view_assigns)
end
end

0 comments on commit bc78a37

Please sign in to comment.