repeated_auto_complete 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module AutoCompleteFormBuilderHelper
|
2
2
|
|
3
3
|
def class_name
|
4
|
-
|
4
|
+
if @object
|
5
|
+
"#{@object.class.to_s.underscore}"
|
6
|
+
else
|
7
|
+
"#{@object_name.to_s.underscore}"
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
11
|
def sanitized_object_name
|
8
|
-
@object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
|
12
|
+
@object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
|
9
13
|
end
|
10
14
|
|
11
15
|
def is_used_as_nested_attribute?
|
12
|
-
/\[#{class_name.pluralize}_attributes\]\[[0-9]+\]/.match @object_name
|
16
|
+
/\[#{class_name.pluralize}_attributes\]\[[0-9]+\]/.match @object_name.to_s
|
13
17
|
end
|
14
18
|
|
15
19
|
def text_field_with_auto_complete(method, tag_options = {}, completion_options = {})
|
@@ -19,6 +23,8 @@ module AutoCompleteFormBuilderHelper
|
|
19
23
|
unique_object_name = "#{class_name}_#{@options[:child_index]}"
|
20
24
|
elsif is_used_as_nested_attribute?
|
21
25
|
unique_object_name = sanitized_object_name
|
26
|
+
elsif !(@object_name.to_s =~ /\[\]$/)
|
27
|
+
unique_object_name = sanitized_object_name
|
22
28
|
else
|
23
29
|
unique_object_name = "#{class_name}_#{Object.new.object_id.abs}"
|
24
30
|
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{repeated_auto_complete}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Pat Shaughnessy"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-16}
|
13
13
|
s.description = %q{auto_complete plugin refactored to handle complex forms and named scopes}
|
14
14
|
s.email = %q{pat@patshaughnessy.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,8 +32,38 @@ class AutoCompleteFormBuilderHelperTest < Test::Unit::TestCase
|
|
32
32
|
@controller = controller_class.new
|
33
33
|
|
34
34
|
end
|
35
|
-
|
36
|
-
def
|
35
|
+
|
36
|
+
def test_auto_complete_field_in_normal_form_does_not_have_random_id
|
37
|
+
_erbout = ''
|
38
|
+
fields_for(@person) do |f|
|
39
|
+
_erbout = f.text_field_with_auto_complete(:name)
|
40
|
+
end
|
41
|
+
assert _erbout.index('id="person_name"')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_compare_to_macro_in_normal_form
|
45
|
+
standard_auto_complete_html = text_field_with_auto_complete(:person, :name)
|
46
|
+
|
47
|
+
_erbout = ''
|
48
|
+
fields_for(@person) do |f|
|
49
|
+
_erbout.concat f.text_field_with_auto_complete(:name)
|
50
|
+
assert_equal 'person', f.class_name
|
51
|
+
end
|
52
|
+
assert_equal standard_auto_complete_html, _erbout.gsub(/paramName:'person\[name\]'/, '')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_compare_to_macro_in_normal_form_with_symbol
|
56
|
+
standard_auto_complete_html = text_field_with_auto_complete(:some_class, :name)
|
57
|
+
|
58
|
+
_erbout = ''
|
59
|
+
fields_for(:some_class) do |f|
|
60
|
+
_erbout.concat f.text_field_with_auto_complete(:name)
|
61
|
+
assert_equal 'some_class', f.class_name
|
62
|
+
end
|
63
|
+
assert_equal standard_auto_complete_html, _erbout.gsub(/paramName:'some_class\[name\]'/, '')
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_two_auto_complete_fields_in_nested_form_have_different_ids
|
37
67
|
id_attribute_pattern = /id=\"[^\"]*\"/i
|
38
68
|
_erbout = ''
|
39
69
|
_erbout2 = ''
|
@@ -44,7 +74,7 @@ class AutoCompleteFormBuilderHelperTest < Test::Unit::TestCase
|
|
44
74
|
assert_equal [], _erbout.scan(id_attribute_pattern) & _erbout2.scan(id_attribute_pattern)
|
45
75
|
end
|
46
76
|
|
47
|
-
def
|
77
|
+
def test_compare_macro_to_fields_for_in_nested_form
|
48
78
|
standard_auto_complete_html = text_field_with_auto_complete(:person, :name)
|
49
79
|
|
50
80
|
_erbout = ''
|
@@ -119,5 +149,4 @@ class AutoCompleteFormBuilderHelperTest < Test::Unit::TestCase
|
|
119
149
|
assert _erbout.index('person_1234_name')
|
120
150
|
end
|
121
151
|
end
|
122
|
-
|
123
152
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repeated_auto_complete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Shaughnessy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|