From 513cf3e74c0d070bb0143f07a46ffaf8d22065c7 Mon Sep 17 00:00:00 2001 From: Quinn Harris Date: Wed, 6 Apr 2016 17:43:01 -0500 Subject: [PATCH] Support no provided source --- lib/x-editable-rails/view_helpers.rb | 1 + test/view_helpers_test.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/x-editable-rails/view_helpers.rb b/lib/x-editable-rails/view_helpers.rb index b38cbf1..bfaa44f 100644 --- a/lib/x-editable-rails/view_helpers.rb +++ b/lib/x-editable-rails/view_helpers.rb @@ -88,6 +88,7 @@ def editable(object, method, options = {}) private def normalize_source(source) + return [] unless source source.map do |el| if el.is_a? Array el diff --git a/test/view_helpers_test.rb b/test/view_helpers_test.rb index a5d3a4a..5724451 100644 --- a/test/view_helpers_test.rb +++ b/test/view_helpers_test.rb @@ -87,6 +87,10 @@ def initialize(attributes={}) editable(subject_1, :content, type: "select", source: [{ text: "Foo", value: "foo" }, { text: "Bar", value: "bar" }]), "ViewHelpers#editable should generate content tag with the current value" + refute_match %r{data-source=}, + editable(subject_1, :content, type: "select"), + "ViewHelpers#editable should generate content tag without source" + subject_2 = Subject.new(active: true) assert_match %r{]+>Yes},