constructorio-rails 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rock.yml +10 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +9 -0
- data/constructorio-rails.gemspec +30 -0
- data/lib/constructorio-rails/configuration.rb +5 -0
- data/lib/constructorio-rails/fields.rb +27 -0
- data/lib/constructorio-rails/helper.rb +11 -0
- data/lib/constructorio-rails/railtie.rb +15 -0
- data/lib/constructorio-rails/tasks/import.rake +25 -0
- data/lib/constructorio-rails/version.rb +3 -0
- data/lib/constructorio-rails.rb +122 -0
- data/test/configuration_test.rb +15 -0
- data/test/constructorio_test.rb +106 -0
- data/test/test_helper.rb +51 -0
- data/test/view_helper_test.rb +11 -0
- metadata +225 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3b8edbc3b6f373a1b8c92f5760fdb19e6de91dd
|
4
|
+
data.tar.gz: a6ad7706d8cb3fa41fae30db59ec2588469692e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dcaa359ea8997998d0c5f21ff049f13da85f0409595b078f51b042c8276045773c8e4035211cec5137ead9391fb968b1fde6e627aedddbed6c71e693556d4546
|
7
|
+
data.tar.gz: 561b910821512c183a81e6548d304be3db362ae739b39f8474a3ad74be795e858942b254c4fe5327b1fd65feb96ed72b4bee0a7bbe4ca2ab2333d397263c8fe3
|
data/.gitignore
ADDED
data/.rock.yml
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Steven Lai
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Constructor.io
|
2
|
+
|
3
|
+
A Ruby client for the [Constructor.io API](http://constructor.io/docs). Constructor.io provides a lightning-fast, typo-tolerant autocomplete service that ranks your users' queries by popularity to let them find what they're looking for as quickly as possible.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'constructorio'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself:
|
16
|
+
|
17
|
+
$ gem install customerio
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Configuration for Rails
|
22
|
+
|
23
|
+
Add an initializer file at config/initializers/constructor-io.rb with values from the [customer dashboard](http://constructor.io/dashboard):
|
24
|
+
```
|
25
|
+
ConstructorIO.configure do |config|
|
26
|
+
config.api_token = 'API_TOKEN'
|
27
|
+
config.autocomplete_key = 'AUTOCOMPLETE_KEY'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
To add autocomplete to a model:
|
31
|
+
|
32
|
+
```
|
33
|
+
class MyModel < ActiveRecord::Base
|
34
|
+
include ConstructorIO
|
35
|
+
constructorio_autocomplete(['attribute1', 'attribute2'])
|
36
|
+
end
|
37
|
+
|
38
|
+
```
|
39
|
+
|
40
|
+
To attach an autocomplete dropdown to an input field, just insert this in your view:
|
41
|
+
|
42
|
+
```
|
43
|
+
<%= constructorio_autocomplete(dom_id: 'id_of_input_field') %>
|
44
|
+
```
|
45
|
+
|
46
|
+
To import an existing data set into Constructor.io, you can use the rake task:
|
47
|
+
|
48
|
+
```
|
49
|
+
rake constructorio:import:model CLASS='MyModel'
|
50
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'constructorio-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "constructorio-rails"
|
8
|
+
spec.version = ConstructorIORails::VERSION
|
9
|
+
spec.authors = ["Steven Lai"]
|
10
|
+
spec.email = ["lai.steven@gmail.com"]
|
11
|
+
spec.summary = %q{Rails gem for Constructor.io}
|
12
|
+
spec.description = %q{Rails gem for Constructor.io's autocomplete service. Enables Rails models to send updates to the Constructor.io API automatically, and provides a view helper to add autocomplete on any input.}
|
13
|
+
spec.homepage = "http://constructor.io"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activerecord"
|
22
|
+
spec.add_dependency 'faraday', '~> 0.9', '>= 0.9.0'
|
23
|
+
spec.add_dependency "activesupport", ">= 3.2"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency 'pry', '~> 0.10', '>= 0.10.1'
|
27
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.10'
|
28
|
+
spec.add_development_dependency 'mocha', '~> 1.1', '>= 1.1.0'
|
29
|
+
spec.add_development_dependency "minitest", '~> 5.5', '>= 5.5.1'
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module ConstructorIORails
|
4
|
+
class Fields
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_accessor :set
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@set = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def add(model_name, field)
|
14
|
+
@set[model_name] ||= {}
|
15
|
+
@set[model_name][field] = 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def list(model_name)
|
19
|
+
if @set[model_name].is_a?(Hash)
|
20
|
+
@set[model_name].keys
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# usage: <%= autocomplete :dom_id => "search" %>
|
2
|
+
|
3
|
+
module ConstructorIORails
|
4
|
+
module Helper
|
5
|
+
def constructorio_autocomplete(options = {})
|
6
|
+
result = %Q|<script type="text/javascript" src="//cnstrc.com/js/ac.js"></script>\n|
|
7
|
+
result += %Q|<script>$(document).ready(function(){ $('##{options[:dom_id]}').constructorAutocomplete({ key: '#{ConstructorIORails.configuration.autocomplete_key}' }); })</script>|
|
8
|
+
return result.html_safe
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module ConstructorIORails
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer 'constructorio.action_view' do
|
6
|
+
ActiveSupport.on_load(:action_view) do
|
7
|
+
include ConstructorIORails::Helper
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
rake_tasks do
|
12
|
+
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
namespace :constructorio do
|
2
|
+
import_model_desc = <<-DESC.gsub(/ /, '')
|
3
|
+
Import data from your model (pass name as CLASS environment variable).
|
4
|
+
|
5
|
+
$ rake environment constructorio:import:model CLASS='MyModel'
|
6
|
+
DESC
|
7
|
+
|
8
|
+
task :import => 'import:model'
|
9
|
+
|
10
|
+
namespace :import do
|
11
|
+
desc import_model_desc
|
12
|
+
|
13
|
+
task :model do
|
14
|
+
klass = eval(ENV['CLASS'].to_s)
|
15
|
+
fields = ConstructorIORails::Fields.instance.list(klass.model_name)
|
16
|
+
if fields.any?
|
17
|
+
klass.all.each do |record|
|
18
|
+
fields.each do |field|
|
19
|
+
klass.add_record(record[field.to_sym], ConstructorIORails.configuration.autocomplete_key)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'constructorio-rails/version'
|
2
|
+
require 'constructorio-rails/configuration'
|
3
|
+
require 'constructorio-rails/helper'
|
4
|
+
require 'constructorio-rails/fields'
|
5
|
+
require 'active_record'
|
6
|
+
require 'faraday'
|
7
|
+
require 'active_support/core_ext/string/output_safety'
|
8
|
+
|
9
|
+
require 'constructorio-rails/railtie' if defined?(Rails)
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'pry'
|
13
|
+
rescue LoadError
|
14
|
+
end
|
15
|
+
|
16
|
+
class MissingItemName < StandardError; end
|
17
|
+
|
18
|
+
module ConstructorIORails
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_accessor :configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configuration
|
25
|
+
@configuration ||= Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
end
|
31
|
+
|
32
|
+
# This injects the methods on the included hook
|
33
|
+
def self.included base
|
34
|
+
base.send :include, InstanceMethods
|
35
|
+
base.extend ClassMethods
|
36
|
+
end
|
37
|
+
|
38
|
+
module ClassMethods
|
39
|
+
# "fields" is expected to be an array of strings or an array of hashes, like:
|
40
|
+
# "product_name", "description"
|
41
|
+
# - or -
|
42
|
+
# { 'attribute' => 'product_name', 'metadata' => { metadata_one => ->{ something_dynamic }} }
|
43
|
+
def constructorio_autocomplete(fields, autocomplete_key = ConstructorIORails.configuration.autocomplete_key)
|
44
|
+
# All fields require an attribute
|
45
|
+
field_names = fields.map { |f| f.is_a?(String) ? f : f['attribute'] }
|
46
|
+
raise MissingItemName if field_names.include? nil
|
47
|
+
|
48
|
+
field_names.each do |field|
|
49
|
+
ConstructorIORails::Fields.instance.add(self.model_name, field)
|
50
|
+
end
|
51
|
+
|
52
|
+
# transform the data
|
53
|
+
transformed = {}
|
54
|
+
fields.each do |field|
|
55
|
+
if field.is_a?(String)
|
56
|
+
transformed[field] = {}
|
57
|
+
else
|
58
|
+
transformed[field['attribute']] = field['metadata']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
after_save do |record|
|
63
|
+
updated_fields = record.changed.select { |c| field_names.include? c }
|
64
|
+
updated_fields.each do |field|
|
65
|
+
record.send(:constructorio_add_record, record[field.to_sym], transformed[field], autocomplete_key)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
before_destroy do |record|
|
70
|
+
field_names.each do |field|
|
71
|
+
record.send(:constructorio_delete_record, record[field.to_sym], transformed[field], autocomplete_key)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
module InstanceMethods
|
78
|
+
def constructorio_add_record(value, metadata = {}, autocomplete_key)
|
79
|
+
constructorio_call_api("post", value, metadata, autocomplete_key)
|
80
|
+
end
|
81
|
+
|
82
|
+
def constructorio_delete_record(value, metadata = {}, autocomplete_key)
|
83
|
+
constructorio_call_api("delete", value, metadata, autocomplete_key)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def constructorio_make_request_body(value, metadata)
|
89
|
+
request_body = { "item_name" => "#{value}" }
|
90
|
+
unless metadata.empty?
|
91
|
+
metadata.each do |k, v|
|
92
|
+
v = instance_exec(&v) if v.is_a? Proc
|
93
|
+
request_body[k] = v
|
94
|
+
end
|
95
|
+
end
|
96
|
+
request_body
|
97
|
+
end
|
98
|
+
|
99
|
+
def constructorio_call_api(method, value, metadata, autocomplete_key)
|
100
|
+
api_token = ConstructorIORails.configuration.api_token
|
101
|
+
api_url = ConstructorIORails.configuration.api_url || "https://ac.constructor.io/"
|
102
|
+
@http_client ||= Faraday.new(url: api_url)
|
103
|
+
@http_client.basic_auth(api_token, '')
|
104
|
+
|
105
|
+
request_body = constructorio_make_request_body(value, metadata)
|
106
|
+
constructorio_send_request(method, @http_client, request_body, autocomplete_key)
|
107
|
+
end
|
108
|
+
|
109
|
+
def constructorio_send_request(method, http_client, request_body, autocomplete_key)
|
110
|
+
response = http_client.send(method) do |request|
|
111
|
+
request.url "/v1/item?autocomplete_key=#{autocomplete_key}"
|
112
|
+
request.headers['Content-Type'] = 'application/json'
|
113
|
+
request.body = request_body.to_json
|
114
|
+
end
|
115
|
+
if response.status.to_s =~ /^2/
|
116
|
+
return nil
|
117
|
+
else
|
118
|
+
return response.status
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ConfigurationTest < MiniTest::Test
|
4
|
+
def test_configure_api_token
|
5
|
+
assert_equal ConstructorIORails.configuration.api_token, "example_api_token"
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_configure_autocomplete_key
|
9
|
+
assert_equal ConstructorIORails.configuration.autocomplete_key, "example_autocomplete_key"
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_configure_api_url
|
13
|
+
assert_equal ConstructorIORails.configuration.api_url, "http://example.constructor.io"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ConstructorIORailsTest < MiniTest::Test
|
4
|
+
def test_add_record_makes_request
|
5
|
+
person = Person.new(
|
6
|
+
first_name: "Steven",
|
7
|
+
last_name: "Lai",
|
8
|
+
address: "New York"
|
9
|
+
)
|
10
|
+
|
11
|
+
person.stubs(:constructorio_send_request)
|
12
|
+
|
13
|
+
person.expects(:constructorio_make_request_body)
|
14
|
+
assert person.save
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_add_simple_record_makes_request
|
18
|
+
person = PersonSimple.new(
|
19
|
+
first_name: "Steven",
|
20
|
+
last_name: "Lai",
|
21
|
+
address: "New York"
|
22
|
+
)
|
23
|
+
|
24
|
+
person.stubs(:constructorio_send_request)
|
25
|
+
|
26
|
+
person.expects(:constructorio_make_request_body)
|
27
|
+
assert person.save
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_add_record_accepts_procs
|
31
|
+
person = Person.new(
|
32
|
+
first_name: "Steven",
|
33
|
+
last_name: "Lai",
|
34
|
+
address: "New York"
|
35
|
+
)
|
36
|
+
|
37
|
+
person.expects(:constructorio_send_request).with(
|
38
|
+
'post',
|
39
|
+
instance_of(Faraday::Connection),
|
40
|
+
{'item_name' => 'Steven', 'test_metadata' => 'test_values', 'test_proc' => 'NEW YORK'},
|
41
|
+
'person_autocomplete_key'
|
42
|
+
)
|
43
|
+
assert person.save
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_add_simple_record_accepts_procs
|
47
|
+
person = PersonSimple.new(
|
48
|
+
first_name: "Steven",
|
49
|
+
last_name: "Lai",
|
50
|
+
address: "New York"
|
51
|
+
)
|
52
|
+
|
53
|
+
person.expects(:constructorio_send_request).with(
|
54
|
+
'post',
|
55
|
+
instance_of(Faraday::Connection),
|
56
|
+
{'item_name' => 'Steven'},
|
57
|
+
'example_autocomplete_key'
|
58
|
+
)
|
59
|
+
assert person.save
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_add_record_sends_request
|
63
|
+
person = Person.new(
|
64
|
+
first_name: "Steven",
|
65
|
+
last_name: "Lai",
|
66
|
+
address: "New York"
|
67
|
+
)
|
68
|
+
|
69
|
+
person.expects(:constructorio_send_request)
|
70
|
+
assert person.save
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_delete_record_makes_request
|
74
|
+
Person.any_instance.stubs(:constructorio_call_api)
|
75
|
+
person = Person.create(
|
76
|
+
first_name: "Ronald",
|
77
|
+
last_name: "McDonald",
|
78
|
+
address: "Disneyland"
|
79
|
+
)
|
80
|
+
|
81
|
+
person.expects(:constructorio_call_api).with("delete", "Ronald", has_entry('test_proc', instance_of(Proc)),"person_autocomplete_key")
|
82
|
+
person.destroy
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_add_record_without_key_uses_default_key
|
86
|
+
person = PersonNoKey.new(
|
87
|
+
first_name: "Steven",
|
88
|
+
last_name: "Lai",
|
89
|
+
address: "New York"
|
90
|
+
)
|
91
|
+
|
92
|
+
person.expects(:constructorio_call_api).with("post", "Lai", anything, ConstructorIORails.configuration.autocomplete_key)
|
93
|
+
assert person.save
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_fields_are_tracked
|
97
|
+
Person.any_instance.expects(:constructorio_call_api).with("post", "Ronald", anything, "person_autocomplete_key")
|
98
|
+
person = Person.create(
|
99
|
+
first_name: "Ronald",
|
100
|
+
last_name: "McDonald",
|
101
|
+
address: "Disneyland"
|
102
|
+
)
|
103
|
+
|
104
|
+
assert_equal ConstructorIORails::Fields.instance.list('Person'), ["first_name"]
|
105
|
+
end
|
106
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/unit'
|
3
|
+
require 'mocha/mini_test'
|
4
|
+
require_relative '../lib/constructorio-rails'
|
5
|
+
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(
|
8
|
+
adapter: 'sqlite3',
|
9
|
+
database: ':memory:'
|
10
|
+
)
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define do
|
13
|
+
create_table :people, force: true do |t|
|
14
|
+
t.string :first_name
|
15
|
+
t.string :last_name
|
16
|
+
t.string :address
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ConstructorIORails.configure do |config|
|
21
|
+
config.api_token = "example_api_token"
|
22
|
+
config.autocomplete_key = "example_autocomplete_key"
|
23
|
+
config.api_url = "http://example.constructor.io"
|
24
|
+
end
|
25
|
+
|
26
|
+
class Person < ActiveRecord::Base
|
27
|
+
include ConstructorIORails
|
28
|
+
constructorio_autocomplete [{
|
29
|
+
'attribute' => 'first_name',
|
30
|
+
'metadata' => {
|
31
|
+
'test_metadata' => 'test_values',
|
32
|
+
'test_proc' => ->{ self.address.upcase }
|
33
|
+
}
|
34
|
+
}], "person_autocomplete_key"
|
35
|
+
end
|
36
|
+
|
37
|
+
class PersonSimple < ActiveRecord::Base
|
38
|
+
self.table_name = 'people'
|
39
|
+
include ConstructorIORails
|
40
|
+
constructorio_autocomplete [ 'first_name' ]
|
41
|
+
end
|
42
|
+
|
43
|
+
class PersonNoKey < ActiveRecord::Base
|
44
|
+
self.table_name = 'people'
|
45
|
+
include ConstructorIORails
|
46
|
+
constructorio_autocomplete [{'attribute' => 'last_name'}]
|
47
|
+
end
|
48
|
+
|
49
|
+
class FakeView
|
50
|
+
include ConstructorIORails::Helper
|
51
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ViewHelperTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
@fakeview = FakeView.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_autocomplete_html
|
9
|
+
assert_equal @fakeview.constructorio_autocomplete(dom_id: 'a'), "<script type=\"text/javascript\" src=\"//cnstrc.com/js/ac.js\"></script>\n<script>$(document).ready(function(){ $('#a').constructorAutocomplete({ key: 'example_autocomplete_key' }); })</script>"
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: constructorio-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Lai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.9.0
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.9'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activesupport
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.2'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.2'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.7'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.7'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '10.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '10.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: pry
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.10'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.10.1
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0.10'
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.10.1
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: sqlite3
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '1.3'
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.3.10
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1.3'
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 1.3.10
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
name: mocha
|
131
|
+
requirement: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - "~>"
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '1.1'
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.1.0
|
139
|
+
type: :development
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.1'
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 1.1.0
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: minitest
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '5.5'
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 5.5.1
|
159
|
+
type: :development
|
160
|
+
prerelease: false
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '5.5'
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 5.5.1
|
169
|
+
description: Rails gem for Constructor.io's autocomplete service. Enables Rails models
|
170
|
+
to send updates to the Constructor.io API automatically, and provides a view helper
|
171
|
+
to add autocomplete on any input.
|
172
|
+
email:
|
173
|
+
- lai.steven@gmail.com
|
174
|
+
executables: []
|
175
|
+
extensions: []
|
176
|
+
extra_rdoc_files: []
|
177
|
+
files:
|
178
|
+
- ".gitignore"
|
179
|
+
- ".rock.yml"
|
180
|
+
- ".rspec"
|
181
|
+
- Gemfile
|
182
|
+
- LICENSE.txt
|
183
|
+
- README.md
|
184
|
+
- Rakefile
|
185
|
+
- constructorio-rails.gemspec
|
186
|
+
- lib/constructorio-rails.rb
|
187
|
+
- lib/constructorio-rails/configuration.rb
|
188
|
+
- lib/constructorio-rails/fields.rb
|
189
|
+
- lib/constructorio-rails/helper.rb
|
190
|
+
- lib/constructorio-rails/railtie.rb
|
191
|
+
- lib/constructorio-rails/tasks/import.rake
|
192
|
+
- lib/constructorio-rails/version.rb
|
193
|
+
- test/configuration_test.rb
|
194
|
+
- test/constructorio_test.rb
|
195
|
+
- test/test_helper.rb
|
196
|
+
- test/view_helper_test.rb
|
197
|
+
homepage: http://constructor.io
|
198
|
+
licenses:
|
199
|
+
- MIT
|
200
|
+
metadata: {}
|
201
|
+
post_install_message:
|
202
|
+
rdoc_options: []
|
203
|
+
require_paths:
|
204
|
+
- lib
|
205
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
215
|
+
requirements: []
|
216
|
+
rubyforge_project:
|
217
|
+
rubygems_version: 2.2.2
|
218
|
+
signing_key:
|
219
|
+
specification_version: 4
|
220
|
+
summary: Rails gem for Constructor.io
|
221
|
+
test_files:
|
222
|
+
- test/configuration_test.rb
|
223
|
+
- test/constructorio_test.rb
|
224
|
+
- test/test_helper.rb
|
225
|
+
- test/view_helper_test.rb
|