formtastic_autocomplete 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e47db92830d55f97c2cecdb602c16f8f04f1c732
4
- data.tar.gz: c2f6b4daf7053174ec6285a975d42aea3a7cbbcb
3
+ metadata.gz: 8d7020f69be2008de9f4ca0279cef2c563930e43
4
+ data.tar.gz: 3ef18be7bf67d496e61cb93f549d4f503e883b1a
5
5
  SHA512:
6
- metadata.gz: f325d28e36dc291a12c0aaef47c671383f936dd0bfdec8e98e1de06c8bd1f359e09df38fe07751a0e2293f32dba9e09c7545a6b8edb1e8c3ff0a79cb24ec3fe5
7
- data.tar.gz: a4584c100809b9c98126f2dc9b93502d1329ad6437030832ff06a453f2b84d83454fdaecf79ca85c452ccfd5ca9e89c5e03cae6b218b42998e1ca944025f4a98
6
+ metadata.gz: 8057caadece4bd0db354a8b3a502949eae3e8cea92b3721874c8cc1df342605cc39d7de644abfce012521753a0ea9d444c8bce042741e80ed80a9cdca836f8f3
7
+ data.tar.gz: 265de806b619a7e2fc096314a22ecbe1a3555aa610fa2123b2f674cbf66a2a5462873ca45b8bdd999037b0cff1651684dd0e95b6592d7ef3aed8210b4b7b5043
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -18,9 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.add_dependency 'activesupport'
21
22
  spec.add_dependency 'formtastic'
22
23
 
24
+ spec.add_development_dependency 'actionpack'
25
+ spec.add_development_dependency 'activemodel'
23
26
  spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'nokogiri'
24
28
  spec.add_development_dependency 'rake'
25
29
  spec.add_development_dependency 'rails'
30
+ spec.add_development_dependency 'rspec'
26
31
  end
@@ -1,26 +1,32 @@
1
+ require 'active_support/core_ext/hash/deep_merge'
2
+
1
3
  module Formtastic
2
4
  module Inputs
3
5
  class AutocompleteInput < StringInput
4
- def input
5
- @builder.text_field(method, input_html_options) <<
6
- @builder.hidden_field(method, hidden_html_options)
6
+ def to_html
7
+ input_wrapping do
8
+ label_html <<
9
+ builder.text_field(method, input_html_options) <<
10
+ builder.hidden_field(method, hidden_html_options)
11
+ end
7
12
  end
8
13
 
9
14
  private
10
15
 
11
16
  def input_html_options
12
- super.deep_merge(
17
+ {
18
+ class: 'autocomplete'
19
+ }.merge(super).deep_merge(
13
20
  name: '',
14
- class: 'autocomplete',
15
- id: options[:id] || input_tag_id,
16
- value: options[:value] || input_tag_value,
21
+ id: options.key?(:input_html) && options[:input_html].key?(:id) ? options[:input_html][:id] : input_tag_id,
22
+ value: options.key?(:value) ? options[:value] : input_tag_value,
17
23
  data: { source: options[:source] }
18
24
  )
19
25
  end
20
26
 
21
27
  def hidden_html_options
22
28
  {
23
- value: options[:value] || hidden_tag_value
29
+ value: options.key?(:value) ? options[:value] : input_tag_value
24
30
  }
25
31
  end
26
32
 
@@ -1,3 +1,3 @@
1
1
  module FormtasticAutocomplete
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formtastic::Inputs::AutocompleteInput do
4
+ let(:controller) { MockController.new }
5
+
6
+ describe '#input' do
7
+ subject { Nokogiri::HTML(form) }
8
+
9
+ let(:record) { Ingredient.new }
10
+ let(:collection) { %w[cup teaspoon tablespoon] }
11
+ let(:options) { {} }
12
+ let(:form) do
13
+ concat(semantic_form_for(record) { |f|
14
+ concat(f.input :name, { as: :autocomplete, source: ingredients_autocomplete_path }.merge(options))
15
+ concat(f.input :unit, { as: :autocomplete, source: collection }.merge(options))
16
+ })
17
+ end
18
+
19
+ describe 'with default options' do
20
+ it 'should set the default input class' do
21
+ input = subject.xpath('//input[@id="ingredient_name_autocomplete"]')
22
+ expect(input.attribute('class').value).to match /\bautocomplete\b/
23
+ end
24
+
25
+ it 'should set the source url' do
26
+ input = subject.xpath('//input[@id="ingredient_name_autocomplete"]')
27
+ expect(input.attribute('data-source').value).to eq ingredients_autocomplete_path
28
+ end
29
+
30
+ it 'should set the source json' do
31
+ input = subject.xpath('//input[@id="ingredient_unit_autocomplete"]')
32
+ expect(input.attribute('data-source').value).to eq CGI.escape_element(collection.to_json)
33
+ end
34
+
35
+ it 'should render a hidden input' do
36
+ input = subject.xpath('//input[@id="ingredient_name"]')
37
+ expect(input.attribute('type').value).to eq 'hidden'
38
+ end
39
+ end
40
+
41
+ describe 'with custom options' do
42
+ let(:options) { { input_html: { id: 'baz', class: 'completer', data: { foo: 'bar' } } } }
43
+
44
+ it 'should set the custom input class' do
45
+ input = subject.xpath('//input[@id="baz"]')
46
+ expect(input.attribute('class').value).to match /\bcompleter\b/
47
+ end
48
+
49
+ it 'should set the custom input id' do
50
+ input = subject.xpath('//input[@id="baz"]')
51
+ expect(input.attribute('id').value).to eq 'baz'
52
+ end
53
+
54
+ it 'should set the custom input data attribute' do
55
+ input = subject.xpath('//input[@id="baz"]')
56
+ expect(input.attribute('data-foo').value).to eq 'bar'
57
+ end
58
+
59
+ it 'should set the custom input data attribute' do
60
+ input = subject.xpath('//input[@id="baz"]')
61
+ expect(input.attribute('data-foo').value).to eq 'bar'
62
+ end
63
+
64
+ it 'should maintain the input source data attribute' do
65
+ input = subject.xpath('//input[@id="baz"]')
66
+ expect(input.attribute('data-source').value).to eq ingredients_autocomplete_path
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,29 @@
1
+ require 'active_support'
2
+ require 'action_controller'
3
+ require 'action_controller/railtie'
4
+ require 'action_dispatch'
5
+ require 'action_pack'
6
+ require 'action_view'
7
+ require 'cgi'
8
+ require 'nokogiri'
9
+ require 'formtastic'
10
+ require 'formtastic_autocomplete'
11
+
12
+ # Requires supporting ruby files with custom matchers and macros, etc,
13
+ # in spec/support/ and its subdirectories.
14
+ Dir[File.expand_path('spec/support/**/*.rb')].each(&method(:require))
15
+
16
+ RSpec.configure do |config|
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+
23
+ # Enable filtered runs.
24
+ config.run_all_when_everything_filtered = true
25
+ config.filter_run focus: true
26
+
27
+ # Include needed helper methods.
28
+ config.include AutocompleteSpecHelper
29
+ end
@@ -0,0 +1,11 @@
1
+ module TestApp
2
+ class Application < ::Rails::Application
3
+ # Configure the default encoding used in templates for Ruby 1.9.
4
+ config.encoding = 'utf-8'
5
+ config.active_support.deprecation = :stderr
6
+ config.secret_key_base = 'secret'
7
+ config.eager_load = false
8
+ end
9
+ end
10
+
11
+ TestApp::Application.initialize!
@@ -0,0 +1,24 @@
1
+ class MockController
2
+ attr_writer :action_name
3
+
4
+ def _routes
5
+ self
6
+ end
7
+
8
+ def action_name
9
+ defined?(@action_name) ? @action_name : 'edit'
10
+ end
11
+
12
+ def url_for(*args)
13
+ 'http://example.com'
14
+ end
15
+
16
+ def url_options
17
+ {}
18
+ end
19
+
20
+ def hash_for_user_path(*); end
21
+ def hash_for_validating_user_path(*); end
22
+ def hash_for_other_validating_user_path(*); end
23
+ def hash_for_users_path(*); end
24
+ end
@@ -0,0 +1,28 @@
1
+ module AutocompleteSpecHelper
2
+ include ActionController::RecordIdentifier if defined?(ActionController::RecordIdentifier)
3
+ include ActionView::RecordIdentifier if defined?(ActionView::RecordIdentifier)
4
+ include ActionView::Helpers::FormHelper
5
+ include Formtastic::Helpers::FormHelper
6
+
7
+ def self.included(base)
8
+ base.class_eval do
9
+ attr_writer :output_buffer
10
+
11
+ def output_buffer
12
+ @output_buffer ||= ActionView::OutputBuffer.new
13
+ end
14
+
15
+ def protect_against_forgery?
16
+ false
17
+ end
18
+ end
19
+ end
20
+
21
+ def ingredients_path(*)
22
+ '/ingredients'
23
+ end
24
+
25
+ def ingredients_autocomplete_path
26
+ '/ingredients/autocomplete'
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ class Ingredient
2
+ extend ActiveModel::Naming
3
+ include ActiveModel::Conversion
4
+
5
+ attr_accessor :id, :name, :unit
6
+
7
+ def persisted?
8
+ false
9
+ end
10
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic_autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Huggins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-06 00:00:00.000000000 Z
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: formtastic
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,34 @@ dependencies:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activemodel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: bundler
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +80,20 @@ dependencies:
38
80
  - - "~>"
39
81
  - !ruby/object:Gem::Version
40
82
  version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
41
97
  - !ruby/object:Gem::Dependency
42
98
  name: rake
43
99
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +122,20 @@ dependencies:
66
122
  - - ">="
67
123
  - !ruby/object:Gem::Version
68
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
69
139
  description: jQuery autocomplete for Formtastic form fields
70
140
  email:
71
141
  - matt.huggins@gmail.com
@@ -74,6 +144,7 @@ extensions: []
74
144
  extra_rdoc_files: []
75
145
  files:
76
146
  - ".gitignore"
147
+ - ".rspec"
77
148
  - Gemfile
78
149
  - LICENSE.txt
79
150
  - README.md
@@ -85,6 +156,12 @@ files:
85
156
  - lib/formtastic_autocomplete.rb
86
157
  - lib/formtastic_autocomplete/engine.rb
87
158
  - lib/formtastic_autocomplete/version.rb
159
+ - spec/formtastic/inputs/autocomplete_input_spec.rb
160
+ - spec/spec_helper.rb
161
+ - spec/support/application.rb
162
+ - spec/support/controller.rb
163
+ - spec/support/helpers.rb
164
+ - spec/support/models.rb
88
165
  homepage: https://github.com/mhuggins/formtastic_autocomplete
89
166
  licenses:
90
167
  - MIT
@@ -109,4 +186,10 @@ rubygems_version: 2.2.2
109
186
  signing_key:
110
187
  specification_version: 4
111
188
  summary: jQuery autocomplete for Formtastic form fields
112
- test_files: []
189
+ test_files:
190
+ - spec/formtastic/inputs/autocomplete_input_spec.rb
191
+ - spec/spec_helper.rb
192
+ - spec/support/application.rb
193
+ - spec/support/controller.rb
194
+ - spec/support/helpers.rb
195
+ - spec/support/models.rb