simple_form_autocomplete 1.0.0 → 1.0.1

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: 8608b077bda353dfc18c7033b902d9ce36c40db8
4
- data.tar.gz: 3c66110aea9c60f529f8d891ef71bc88c29f1608
3
+ metadata.gz: 90bd40213c5fff4f2ad13333ccf07d5abf7bb3c5
4
+ data.tar.gz: 8d023eb2862b5b73db42866d2ebd541d39a5a6be
5
5
  SHA512:
6
- metadata.gz: a4c59f26e49b4bb6f022c743e98703c9a59252cb845daffbdf18c8136b0f4dd23800f57823b95801d86b50c4e2c35d2ab3b75a3e76640de78bbb886750323a6d
7
- data.tar.gz: 069c838abcab1d5283a2a359aa941e905f1cb5dba7fb365038add338225a7b0e3c697a51f7b707312e2bf2d0ae413b4fdfdf939ebd29d86caa6019e871781683
6
+ metadata.gz: d1c6948269158776b8bc3f69b9b237a8842686aef5adc30e4dcb44a2919d3cec2bcdf1bc8bb1b8ec344d1b0e33e7f78aa89eb4720065fdedfa26c3ff224a9eb6
7
+ data.tar.gz: 1a1db610a473a10b11f70c2dba29fe25d52c00d6c0753f915ed41ebf553fa9d512060d3022a5fb9234927752737e6cda755106c2aa32cc4d598ec10941a2a70a
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/hash/deep_merge'
2
+
1
3
  module SimpleForm
2
4
  module Inputs
3
5
  class AutocompleteInput < Base
@@ -11,8 +13,8 @@ module SimpleForm
11
13
  def input_html_options
12
14
  super.deep_merge(
13
15
  name: '',
14
- id: options[:id] || input_tag_id,
15
- value: options[:value] || input_tag_value,
16
+ id: options.key?(:input_html) && options[:input_html].key?(:id) ? options[:input_html][:id] : input_tag_id,
17
+ value: options.key?(:value) ? options[:value] : input_tag_value,
16
18
  data: { source: options[:source] }
17
19
  )
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormAutocomplete
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['matt.huggins@gmail.com']
11
11
  spec.description = %q{jQuery autocomplete for SimpleForm form fields}
12
12
  spec.summary = %q{jQuery autocomplete for SimpleForm form fields}
13
- spec.homepage = ''
13
+ spec.homepage = 'https://github.com/mhuggins/simple_form_autocomplete'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -21,6 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'activesupport'
22
22
  spec.add_dependency 'simple_form'
23
23
 
24
+ spec.add_development_dependency 'actionpack'
25
+ spec.add_development_dependency 'activemodel'
24
26
  spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'nokogiri'
25
28
  spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec'
26
30
  end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleForm::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(simple_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 label class' do
21
+ label = subject.xpath('//label[@for="ingredient_name"]')
22
+ expect(label.attribute('class').value).to match /\bautocomplete\b/
23
+ end
24
+
25
+ it 'should set the default input class' do
26
+ input = subject.xpath('//input[@id="ingredient_name_autocomplete"]')
27
+ expect(input.attribute('class').value).to match /\bautocomplete\b/
28
+ end
29
+
30
+ it 'should set the source url' do
31
+ input = subject.xpath('//input[@id="ingredient_name_autocomplete"]')
32
+ expect(input.attribute('data-source').value).to eq ingredients_autocomplete_path
33
+ end
34
+
35
+ it 'should set the source json' do
36
+ input = subject.xpath('//input[@id="ingredient_unit_autocomplete"]')
37
+ expect(input.attribute('data-source').value).to eq CGI.escape_element(collection.to_json)
38
+ end
39
+
40
+ it 'should render a hidden input' do
41
+ input = subject.xpath('//input[@id="ingredient_name"]')
42
+ expect(input.attribute('type').value).to eq 'hidden'
43
+ end
44
+ end
45
+
46
+ describe 'with custom options' do
47
+ let(:options) do
48
+ {
49
+ input_html: { id: 'baz', class: 'completer', data: { foo: 'bar' } },
50
+ label_html: { class: 'completer-label', data: { lorem: 'ipsem' } },
51
+ }
52
+ end
53
+
54
+ it 'should set the custom label class' do
55
+ label = subject.xpath('//label[@for="baz"]')
56
+ expect(label.attribute('class').value).to match /\bcompleter-label\b/
57
+ end
58
+
59
+ it 'should set the custom label data attribute' do
60
+ label = subject.xpath('//label[@for="baz"]')
61
+ expect(label.attribute('data-lorem').value).to match /\bipsem\b/
62
+ end
63
+
64
+ it 'should set the custom input class' do
65
+ input = subject.xpath('//input[@id="baz"]')
66
+ expect(input.attribute('class').value).to match /\bcompleter\b/
67
+ end
68
+
69
+ it 'should set the custom input id' do
70
+ input = subject.xpath('//input[@id="baz"]')
71
+ expect(input.attribute('id').value).to eq 'baz'
72
+ end
73
+
74
+ it 'should set the custom input data attribute' do
75
+ input = subject.xpath('//input[@id="baz"]')
76
+ expect(input.attribute('data-foo').value).to eq 'bar'
77
+ end
78
+
79
+ it 'should set the custom input data attribute' do
80
+ input = subject.xpath('//input[@id="baz"]')
81
+ expect(input.attribute('data-foo').value).to eq 'bar'
82
+ end
83
+
84
+ it 'should maintain the input source data attribute' do
85
+ input = subject.xpath('//input[@id="baz"]')
86
+ expect(input.attribute('data-source').value).to eq ingredients_autocomplete_path
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,24 @@
1
+ require 'active_support/core_ext/object/to_json'
2
+ require 'cgi'
3
+ require 'nokogiri'
4
+ require 'simple_form'
5
+ require 'simple_form_autocomplete'
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc,
8
+ # in spec/support/ and its subdirectories.
9
+ Dir[File.expand_path('spec/support/**/*.rb')].each(&method(:require))
10
+
11
+ RSpec.configure do |config|
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+
18
+ # Enable filtered runs.
19
+ config.run_all_when_everything_filtered = true
20
+ config.filter_run focus: true
21
+
22
+ # Include needed helper methods.
23
+ config.include AutocompleteSpecHelper
24
+ end
@@ -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 SimpleForm::ActionViewExtensions::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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
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-07 00:00:00.000000000 Z
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
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'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
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'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: rake
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +108,20 @@ dependencies:
66
108
  - - ">="
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  description: jQuery autocomplete for SimpleForm form fields
70
126
  email:
71
127
  - matt.huggins@gmail.com
@@ -74,6 +130,7 @@ extensions: []
74
130
  extra_rdoc_files: []
75
131
  files:
76
132
  - ".gitignore"
133
+ - ".rspec"
77
134
  - Gemfile
78
135
  - LICENSE.txt
79
136
  - README.md
@@ -85,7 +142,12 @@ files:
85
142
  - lib/simple_form_autocomplete/engine.rb
86
143
  - lib/simple_form_autocomplete/version.rb
87
144
  - simple_form_autocomplete.gemspec
88
- homepage: ''
145
+ - spec/simple_form/inputs/autocomplete_input_spec.rb
146
+ - spec/spec_helper.rb
147
+ - spec/support/controller.rb
148
+ - spec/support/helpers.rb
149
+ - spec/support/models.rb
150
+ homepage: https://github.com/mhuggins/simple_form_autocomplete
89
151
  licenses:
90
152
  - MIT
91
153
  metadata: {}
@@ -109,4 +171,9 @@ rubygems_version: 2.2.2
109
171
  signing_key:
110
172
  specification_version: 4
111
173
  summary: jQuery autocomplete for SimpleForm form fields
112
- test_files: []
174
+ test_files:
175
+ - spec/simple_form/inputs/autocomplete_input_spec.rb
176
+ - spec/spec_helper.rb
177
+ - spec/support/controller.rb
178
+ - spec/support/helpers.rb
179
+ - spec/support/models.rb