diff --git a/lib/x-editable-rails/view_helpers.rb b/lib/x-editable-rails/view_helpers.rb
index bfaa44f..54cd7be 100644
--- a/lib/x-editable-rails/view_helpers.rb
+++ b/lib/x-editable-rails/view_helpers.rb
@@ -152,11 +152,9 @@ def format_source(source, value)
if source.is_a?(Array) && source.first.is_a?(String) && source.size == 2
{ '1' => source[0], '0' => source[1] }
end
- when String
+ else
if source.is_a?(Array) && source.first.is_a?(String)
- source.inject({}){|hash, key| hash.merge(key => key)}
- elsif source.is_a?(Hash)
- source
+ source.map { |v| { value: v, text: v } }
end
end
diff --git a/test/view_helpers_test.rb b/test/view_helpers_test.rb
index 5724451..2601547 100644
--- a/test/view_helpers_test.rb
+++ b/test/view_helpers_test.rb
@@ -106,6 +106,30 @@ def initialize(attributes={})
"ViewHelpers#editable should generate content tag with url source as a data attribute"
end
+ test "editable should generate content tag without current value" do
+ subject_1 = Subject.new(content: nil)
+
+ assert_match %r{]+>},
+ editable(subject_1, :content),
+ "ViewHelpers#editable should generate content tag with the current value"
+
+ assert_match %r{]+>},
+ editable(subject_1, :content, type: "select", source: ["foo", "bar"]),
+ "ViewHelpers#editable should generate content tag with the current value"
+
+ assert_match %r{]+>},
+ editable(subject_1, :content, type: "select", source: [["foo", "Foo"], ["bar", "Bar"]]),
+ "ViewHelpers#editable should generate content tag with the current value"
+
+ assert_match %r{]+>},
+ editable(subject_1, :content, type: "select", source: { "foo" => "Foo", "bar" => "Bar" }),
+ "ViewHelpers#editable should generate content tag with the current value"
+
+ assert_match %r{]+>},
+ 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"
+ end
+
private
def view_helpers_test_subject_path(subject)