autocomplete_for 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +113 -12
- data/README.markdown +4 -1
- data/autocomplete_for.gemspec +9 -10
- data/lib/autocomplete_for/autocomplete_for.rb +9 -7
- metadata +46 -9
- data/rails/init.rb +0 -1
- data/test/autocomplete_for_test.rb +0 -149
- data/test/database.yml +0 -6
- data/test/schema.rb +0 -16
- data/test/test_helper.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 488cda3ef4a488f04d649f1b5fd539c65959c09093b6cac6d0409e103fc92b77
|
4
|
+
data.tar.gz: 61b17c4dfa2672dbf7d2681959227c28d244a8d0d48c719e7d6f421604ceea54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59a5b77031868f7de641229e20ffdb169d0f87ebc3f2fe3932e368e7763598b4f6da8117beddc177d41eed3a1c8d661cb9cfe973ccd11d01a42fd0d9a2d08f82
|
7
|
+
data.tar.gz: 495885e901b101bf93f6e7db78b4f4196d9a9005c2f48b259c189601c916fadffd0be86375cd4450b66b93856db3d14a1e3e3efeca2250bc02db78051d7cb064
|
data/Gemfile.lock
CHANGED
@@ -1,33 +1,131 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
autocomplete_for (1.0.
|
5
|
-
activerecord (~> 5.0)
|
4
|
+
autocomplete_for (1.0.1)
|
5
|
+
activerecord (~> 5.0.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
actioncable (5.0.7)
|
11
|
+
actionpack (= 5.0.7)
|
12
|
+
nio4r (>= 1.2, < 3.0)
|
13
|
+
websocket-driver (~> 0.6.1)
|
14
|
+
actionmailer (5.0.7)
|
15
|
+
actionpack (= 5.0.7)
|
16
|
+
actionview (= 5.0.7)
|
17
|
+
activejob (= 5.0.7)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.0.7)
|
21
|
+
actionview (= 5.0.7)
|
22
|
+
activesupport (= 5.0.7)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (~> 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (5.0.7)
|
28
|
+
activesupport (= 5.0.7)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubis (~> 2.7.0)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activejob (5.0.7)
|
34
|
+
activesupport (= 5.0.7)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.0.7)
|
37
|
+
activesupport (= 5.0.7)
|
38
|
+
activerecord (5.0.7)
|
39
|
+
activemodel (= 5.0.7)
|
40
|
+
activesupport (= 5.0.7)
|
41
|
+
arel (~> 7.0)
|
42
|
+
activesupport (5.0.7)
|
17
43
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
44
|
i18n (>= 0.7, < 2)
|
19
45
|
minitest (~> 5.1)
|
20
46
|
tzinfo (~> 1.1)
|
21
|
-
arel (
|
47
|
+
arel (7.1.4)
|
48
|
+
builder (3.2.3)
|
22
49
|
concurrent-ruby (1.0.5)
|
23
|
-
|
50
|
+
crass (1.0.4)
|
51
|
+
diff-lcs (1.3)
|
52
|
+
erubis (2.7.0)
|
53
|
+
globalid (0.4.1)
|
54
|
+
activesupport (>= 4.2.0)
|
55
|
+
i18n (1.1.0)
|
24
56
|
concurrent-ruby (~> 1.0)
|
57
|
+
loofah (2.2.2)
|
58
|
+
crass (~> 1.0.2)
|
59
|
+
nokogiri (>= 1.5.9)
|
60
|
+
mail (2.7.0)
|
61
|
+
mini_mime (>= 0.1.1)
|
62
|
+
method_source (0.9.0)
|
63
|
+
mini_mime (1.0.1)
|
64
|
+
mini_portile2 (2.3.0)
|
25
65
|
minitest (5.11.3)
|
26
|
-
|
66
|
+
nio4r (2.3.1)
|
67
|
+
nokogiri (1.8.4)
|
68
|
+
mini_portile2 (~> 2.3.0)
|
69
|
+
pg (1.1.3)
|
70
|
+
rack (2.0.5)
|
71
|
+
rack-test (0.6.3)
|
72
|
+
rack (>= 1.0)
|
73
|
+
rails (5.0.7)
|
74
|
+
actioncable (= 5.0.7)
|
75
|
+
actionmailer (= 5.0.7)
|
76
|
+
actionpack (= 5.0.7)
|
77
|
+
actionview (= 5.0.7)
|
78
|
+
activejob (= 5.0.7)
|
79
|
+
activemodel (= 5.0.7)
|
80
|
+
activerecord (= 5.0.7)
|
81
|
+
activesupport (= 5.0.7)
|
82
|
+
bundler (>= 1.3.0)
|
83
|
+
railties (= 5.0.7)
|
84
|
+
sprockets-rails (>= 2.0.0)
|
85
|
+
rails-dom-testing (2.0.3)
|
86
|
+
activesupport (>= 4.2.0)
|
87
|
+
nokogiri (>= 1.6)
|
88
|
+
rails-html-sanitizer (1.0.4)
|
89
|
+
loofah (~> 2.2, >= 2.2.2)
|
90
|
+
railties (5.0.7)
|
91
|
+
actionpack (= 5.0.7)
|
92
|
+
activesupport (= 5.0.7)
|
93
|
+
method_source
|
94
|
+
rake (>= 0.8.7)
|
95
|
+
thor (>= 0.18.1, < 2.0)
|
27
96
|
rake (12.3.1)
|
97
|
+
rspec-core (3.8.0)
|
98
|
+
rspec-support (~> 3.8.0)
|
99
|
+
rspec-expectations (3.8.1)
|
100
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
101
|
+
rspec-support (~> 3.8.0)
|
102
|
+
rspec-mocks (3.8.0)
|
103
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
+
rspec-support (~> 3.8.0)
|
105
|
+
rspec-rails (3.8.0)
|
106
|
+
actionpack (>= 3.0)
|
107
|
+
activesupport (>= 3.0)
|
108
|
+
railties (>= 3.0)
|
109
|
+
rspec-core (~> 3.8.0)
|
110
|
+
rspec-expectations (~> 3.8.0)
|
111
|
+
rspec-mocks (~> 3.8.0)
|
112
|
+
rspec-support (~> 3.8.0)
|
113
|
+
rspec-support (3.8.0)
|
114
|
+
sprockets (3.7.2)
|
115
|
+
concurrent-ruby (~> 1.0)
|
116
|
+
rack (> 1, < 3)
|
117
|
+
sprockets-rails (3.2.1)
|
118
|
+
actionpack (>= 4.0)
|
119
|
+
activesupport (>= 4.0)
|
120
|
+
sprockets (>= 3.0.0)
|
121
|
+
sqlite3 (1.3.13)
|
122
|
+
thor (0.20.0)
|
28
123
|
thread_safe (0.3.6)
|
29
124
|
tzinfo (1.2.5)
|
30
125
|
thread_safe (~> 0.1)
|
126
|
+
websocket-driver (0.6.5)
|
127
|
+
websocket-extensions (>= 0.1.0)
|
128
|
+
websocket-extensions (0.1.3)
|
31
129
|
|
32
130
|
PLATFORMS
|
33
131
|
ruby
|
@@ -35,7 +133,10 @@ PLATFORMS
|
|
35
133
|
DEPENDENCIES
|
36
134
|
autocomplete_for!
|
37
135
|
pg
|
136
|
+
rails (~> 5.0.1)
|
38
137
|
rake
|
138
|
+
rspec-rails (~> 3.8)
|
139
|
+
sqlite3 (~> 1.3)
|
39
140
|
|
40
141
|
BUNDLED WITH
|
41
142
|
1.16.2
|
data/README.markdown
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
## Current Version
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/nulogy/autocomplete_for.svg?branch=master)](https://travis-ci.org/nulogy/autocomplete_for)
|
4
|
+
|
2
5
|
This version was introduced to support Rails 5. It depends on activerecord ~> 5.0 and contains several large gem upgrades.
|
3
6
|
This is not a backwards compatible upgrade, and introduces many breaking changes if there is no gem compatibility.
|
4
7
|
|
@@ -47,4 +50,4 @@ Errors are generated automatically if the given information does not correspond
|
|
47
50
|
You can run the unit tests using `bundle exec rake test`; it assumes you have a Postgres database
|
48
51
|
configured as per `test/database.yml` (e.g. credentials are valid, database exists).
|
49
52
|
|
50
|
-
Copyright (c)
|
53
|
+
Copyright (c) 2018 Nulogy Corporation, released under the MIT license
|
data/autocomplete_for.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "autocomplete_for"
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sean Kirby"]
|
@@ -23,12 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
"Rakefile",
|
24
24
|
"autocomplete_for.gemspec",
|
25
25
|
"lib/autocomplete_for.rb",
|
26
|
-
"lib/autocomplete_for/autocomplete_for.rb"
|
27
|
-
"rails/init.rb",
|
28
|
-
"test/autocomplete_for_test.rb",
|
29
|
-
"test/database.yml",
|
30
|
-
"test/schema.rb",
|
31
|
-
"test/test_helper.rb"
|
26
|
+
"lib/autocomplete_for/autocomplete_for.rb"
|
32
27
|
]
|
33
28
|
s.homepage = "http://github.com/nulogy/autocomplete_for"
|
34
29
|
s.require_paths = ["lib"]
|
@@ -42,16 +37,20 @@ Gem::Specification.new do |s|
|
|
42
37
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
38
|
s.add_development_dependency(%q<pg>, [">= 0"])
|
44
39
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
45
|
-
s.add_runtime_dependency(%q<activerecord>, ["~> 5.0"])
|
40
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 5.0.1"])
|
46
41
|
else
|
47
42
|
s.add_dependency(%q<pg>, [">= 0"])
|
48
43
|
s.add_dependency(%q<rake>, [">= 0"])
|
49
|
-
s.add_dependency(%q<activerecord>, ["~> 5.0"])
|
44
|
+
s.add_dependency(%q<activerecord>, ["~> 5.0.1"])
|
50
45
|
end
|
51
46
|
else
|
52
47
|
s.add_dependency(%q<pg>, [">= 0"])
|
53
48
|
s.add_dependency(%q<rake>, [">= 0"])
|
54
|
-
s.add_dependency(%q<activerecord>, ["~> 5.0"])
|
49
|
+
s.add_dependency(%q<activerecord>, ["~> 5.0.1"])
|
55
50
|
end
|
51
|
+
|
52
|
+
s.add_development_dependency("rails", "~> 5.0.1")
|
53
|
+
s.add_development_dependency("rspec-rails", "~> 3.8")
|
54
|
+
s.add_development_dependency("sqlite3", "~> 1.3")
|
56
55
|
end
|
57
56
|
|
@@ -22,7 +22,7 @@ module AutocompleteFor
|
|
22
22
|
# def customer_name
|
23
23
|
# self.customer_to.name : @customer_name
|
24
24
|
# end
|
25
|
-
define_method(:"#{association}_#{field}") do
|
25
|
+
define_method(:"#{association}_#{field}") do
|
26
26
|
send(association.to_sym) ? send(association.to_sym).send(field.to_sym) : instance_variable_get(:"@#{association}_#{field}")
|
27
27
|
end
|
28
28
|
|
@@ -30,12 +30,12 @@ module AutocompleteFor
|
|
30
30
|
# def validate_customer_by_name
|
31
31
|
# return unless @customer_name
|
32
32
|
# return if self.customer
|
33
|
-
# return if @@customer_name_allow_nil && @customer_name == ""
|
33
|
+
# return if @@customer_name_allow_nil && @customer_name == ""
|
34
34
|
#
|
35
|
-
# self.errors.add :customer_name, "#{@customer_name} does not exist"
|
35
|
+
# self.errors.add :customer_name, "#{@customer_name} does not exist"
|
36
36
|
# end
|
37
|
-
define_method(:"validate_#{association}_by_#{field}") do
|
38
|
-
return unless instance_variable_get(:"@#{association}_#{field}")
|
37
|
+
define_method(:"validate_#{association}_by_#{field}") do
|
38
|
+
return unless instance_variable_get(:"@#{association}_#{field}")
|
39
39
|
return if send(association.to_sym)
|
40
40
|
return if self.class.instance_variable_get(:"@#{association}_#{field}_allow_nil") && instance_variable_get(:"@#{association}_#{field}") == ""
|
41
41
|
self.errors.add(:"#{association}_#{field}", :does_not_exist)
|
@@ -76,7 +76,7 @@ module AutocompleteFor
|
|
76
76
|
|
77
77
|
instance_variable_set(error_fields_name, error_fields)
|
78
78
|
|
79
|
-
unless allow_nil
|
79
|
+
unless allow_nil
|
80
80
|
# we must make sure that the validate_by_customer validation runs
|
81
81
|
# after ALL validations on autocomplete fields
|
82
82
|
#skip_callback :validate, :by, :"#{association}"
|
@@ -89,7 +89,9 @@ module AutocompleteFor
|
|
89
89
|
# self.errors.add_on_blank(:customer) unless @@customer_autocompolete_error_fields.any? {|ef| self.errors[ef]}
|
90
90
|
# end
|
91
91
|
define_method(:"validate_by_#{association}") do
|
92
|
-
|
92
|
+
return if self.class.instance_variable_get(error_fields_name).any? {|ef| self.errors[ef].any? }
|
93
|
+
return unless self.send(:read_attribute_for_validation, association.to_sym).blank?
|
94
|
+
self.errors.add(association.to_sym, :blank, options)
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autocomplete_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Kirby
|
@@ -44,14 +44,56 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 5.0.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 5.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.0.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
55
97
|
description: Model-side logic for autocompleting belongs_to associations
|
56
98
|
email: sskirby@gmail.com
|
57
99
|
executables: []
|
@@ -67,11 +109,6 @@ files:
|
|
67
109
|
- autocomplete_for.gemspec
|
68
110
|
- lib/autocomplete_for.rb
|
69
111
|
- lib/autocomplete_for/autocomplete_for.rb
|
70
|
-
- rails/init.rb
|
71
|
-
- test/autocomplete_for_test.rb
|
72
|
-
- test/database.yml
|
73
|
-
- test/schema.rb
|
74
|
-
- test/test_helper.rb
|
75
112
|
homepage: http://github.com/nulogy/autocomplete_for
|
76
113
|
licenses: []
|
77
114
|
metadata: {}
|
@@ -91,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
128
|
version: '0'
|
92
129
|
requirements: []
|
93
130
|
rubyforge_project: autocomplete_for
|
94
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.7.7
|
95
132
|
signing_key:
|
96
133
|
specification_version: 3
|
97
134
|
summary: Model-side logic for autocompleting belongs_to associations
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'autocomplete_for'
|
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AutocompleteForTest < ActiveSupport::TestCase
|
4
|
-
load_schema
|
5
|
-
|
6
|
-
class Vendor < ActiveRecord::Base; end
|
7
|
-
class Customer < ActiveRecord::Base; end
|
8
|
-
|
9
|
-
class AutoCompleteForCustomerTestModel < ActiveRecord::Base
|
10
|
-
belongs_to :customer
|
11
|
-
|
12
|
-
autocomplete_for :customer, :name, :allow_nil => true do
|
13
|
-
self.customer = Customer.find(:first, :conditions => {:name => @customer_name})
|
14
|
-
end
|
15
|
-
autocomplete_for :customer, :code, :allow_nil => true do
|
16
|
-
self.customer = Customer.find(:first, :conditions => {:code => @customer_code})
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class AutoCompleteForVendorTestModel < ActiveRecord::Base
|
21
|
-
belongs_to :vendor
|
22
|
-
|
23
|
-
autocomplete_for :vendor, :name do
|
24
|
-
self.vendor = Vendor.find(:first, :conditions => {:name => @vendor_name})
|
25
|
-
end
|
26
|
-
autocomplete_for :vendor, :code do
|
27
|
-
self.vendor = Vendor.find(:first, :conditions => {:code => @vendor_code})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def setup
|
32
|
-
Vendor.destroy_all
|
33
|
-
Customer.destroy_all
|
34
|
-
@vendor_nil_code = Vendor.create! :name => "Nil Code"
|
35
|
-
@vendor = Vendor.create! :name => "Vendor Name", :code => "Vendor Code"
|
36
|
-
@autocomplete_for_vendor = AutoCompleteForVendorTestModel.new
|
37
|
-
|
38
|
-
@customer = Customer.create! :name => "Customer Name", :code => "Customer Code"
|
39
|
-
@autocomplete_for_customer = AutoCompleteForCustomerTestModel.new
|
40
|
-
end
|
41
|
-
|
42
|
-
test "with valid name" do
|
43
|
-
@autocomplete_for_vendor.update_attributes! :vendor_name => @vendor.name
|
44
|
-
|
45
|
-
assert_equal @vendor, @autocomplete_for_vendor.vendor
|
46
|
-
end
|
47
|
-
|
48
|
-
test "with invalid name" do
|
49
|
-
@autocomplete_for_vendor.update_attributes :vendor_name => "Not a Vendor Name"
|
50
|
-
|
51
|
-
assert_nil @autocomplete_for_vendor.vendor
|
52
|
-
assert @autocomplete_for_vendor.errors[:vendor_name].any?
|
53
|
-
assert @autocomplete_for_vendor.errors[:vendor_code].empty?
|
54
|
-
assert @autocomplete_for_vendor.errors[:vendor].empty?
|
55
|
-
end
|
56
|
-
|
57
|
-
test "with blank name" do
|
58
|
-
@autocomplete_for_vendor.update_attributes :vendor_name => ""
|
59
|
-
|
60
|
-
assert_nil @autocomplete_for_vendor.vendor
|
61
|
-
assert @autocomplete_for_vendor.errors[:vendor_name].any?
|
62
|
-
assert @autocomplete_for_vendor.errors[:vendor_code].empty?
|
63
|
-
assert @autocomplete_for_vendor.errors[:vendor].empty?
|
64
|
-
end
|
65
|
-
|
66
|
-
test "with nil name" do
|
67
|
-
@autocomplete_for_vendor.update_attributes :vendor_name => nil
|
68
|
-
|
69
|
-
assert_nil @autocomplete_for_vendor.vendor
|
70
|
-
assert_equal 1, @autocomplete_for_vendor.errors[:vendor].size, @autocomplete_for_vendor.errors[:vendor]
|
71
|
-
assert @autocomplete_for_vendor.errors[:vendor_code].empty?
|
72
|
-
assert @autocomplete_for_vendor.errors[:vendor_name].empty?
|
73
|
-
end
|
74
|
-
|
75
|
-
test "should clear existing association" do
|
76
|
-
@autocomplete_for_vendor.update_attributes! :vendor => @vendor
|
77
|
-
assert_equal @vendor, @autocomplete_for_vendor.vendor
|
78
|
-
|
79
|
-
@autocomplete_for_vendor.update_attributes :vendor_name => ""
|
80
|
-
assert_nil @autocomplete_for_vendor.vendor
|
81
|
-
assert @autocomplete_for_vendor.errors[:vendor_name].any?
|
82
|
-
|
83
|
-
assert @autocomplete_for_vendor.errors[:vendor_code].empty?
|
84
|
-
assert @autocomplete_for_vendor.errors[:vendor].empty?
|
85
|
-
end
|
86
|
-
|
87
|
-
test "should not clear existing association" do
|
88
|
-
@autocomplete_for_vendor.update_attributes! :vendor => @vendor
|
89
|
-
assert_equal @vendor, @autocomplete_for_vendor.vendor
|
90
|
-
|
91
|
-
@autocomplete_for_vendor.update_attributes! :vendor_name => nil
|
92
|
-
assert_equal @vendor, @autocomplete_for_vendor.vendor
|
93
|
-
end
|
94
|
-
|
95
|
-
test "should clear existing association using field that can be nil" do
|
96
|
-
@autocomplete_for_vendor.update_attributes! :vendor => @vendor
|
97
|
-
assert_equal @vendor, @autocomplete_for_vendor.vendor
|
98
|
-
|
99
|
-
@autocomplete_for_vendor.update_attributes :vendor_code => ""
|
100
|
-
assert_nil @autocomplete_for_vendor.vendor
|
101
|
-
assert @autocomplete_for_vendor.errors[:vendor_code].any?
|
102
|
-
|
103
|
-
assert @autocomplete_for_vendor.errors[:vendor_name].empty?
|
104
|
-
assert @autocomplete_for_vendor.errors[:vendor].empty?
|
105
|
-
end
|
106
|
-
|
107
|
-
test "allow_nil with valid name" do
|
108
|
-
@autocomplete_for_customer.update_attributes! :customer_name => @customer.name
|
109
|
-
|
110
|
-
assert_equal @customer, @autocomplete_for_customer.customer
|
111
|
-
end
|
112
|
-
|
113
|
-
test "allow_nil with invalid name" do
|
114
|
-
@autocomplete_for_customer.update_attributes :customer_name => "Not A Customer Name"
|
115
|
-
|
116
|
-
assert_nil @autocomplete_for_customer.customer
|
117
|
-
assert @autocomplete_for_customer.errors[:customer_name].any?
|
118
|
-
assert @autocomplete_for_customer.errors[:customer_code].empty?
|
119
|
-
assert @autocomplete_for_customer.errors[:customer].empty?
|
120
|
-
end
|
121
|
-
|
122
|
-
test "allow_nil with blank name" do
|
123
|
-
@autocomplete_for_customer.update_attributes! :customer_name => ""
|
124
|
-
|
125
|
-
assert_nil @autocomplete_for_customer.customer
|
126
|
-
end
|
127
|
-
|
128
|
-
test "allow_nil with nil name" do
|
129
|
-
@autocomplete_for_customer.update_attributes! :customer_name => nil
|
130
|
-
|
131
|
-
assert_nil @autocomplete_for_customer.customer
|
132
|
-
end
|
133
|
-
|
134
|
-
test "allow_nil should clear existing association" do
|
135
|
-
@autocomplete_for_customer.update_attributes! :customer => @customer
|
136
|
-
assert_equal @customer, @autocomplete_for_customer.customer
|
137
|
-
|
138
|
-
@autocomplete_for_customer.update_attributes! :customer_name => ""
|
139
|
-
assert_nil @autocomplete_for_customer.customer
|
140
|
-
end
|
141
|
-
|
142
|
-
test "allow_nil should not clear existing association" do
|
143
|
-
@autocomplete_for_customer.update_attributes! :customer => @customer
|
144
|
-
assert_equal @customer, @autocomplete_for_customer.customer
|
145
|
-
|
146
|
-
@autocomplete_for_customer.update_attributes! :customer_name => nil
|
147
|
-
assert_equal @customer, @autocomplete_for_customer.customer
|
148
|
-
end
|
149
|
-
end
|
data/test/database.yml
DELETED
data/test/schema.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define(:version => 0) do
|
2
|
-
create_table :customers, :force => true do |t|
|
3
|
-
t.string :name, :unique => true
|
4
|
-
t.string :code, :unique => true
|
5
|
-
end
|
6
|
-
create_table :vendors, :force => true do |t|
|
7
|
-
t.string :name, :unique => true
|
8
|
-
t.string :code, :unique => true
|
9
|
-
end
|
10
|
-
create_table :auto_complete_for_customer_test_models, :force => true do |t|
|
11
|
-
t.integer :customer_id
|
12
|
-
end
|
13
|
-
create_table :auto_complete_for_vendor_test_models, :force => true do |t|
|
14
|
-
t.integer :vendor_id
|
15
|
-
end
|
16
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'active_support'
|
3
|
-
require 'active_support/core_ext'
|
4
|
-
require 'active_support/test_case'
|
5
|
-
require 'yaml'
|
6
|
-
require 'minitest'
|
7
|
-
require 'active_record'
|
8
|
-
|
9
|
-
def load_schema
|
10
|
-
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
11
|
-
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
12
|
-
db_adapter = ENV['DB'] || 'postgresql'
|
13
|
-
|
14
|
-
if config[db_adapter].nil?
|
15
|
-
raise "DB Adapter #{db_adapter} has no entries in database.yml."
|
16
|
-
end
|
17
|
-
|
18
|
-
ActiveRecord::Base.establish_connection(config[db_adapter])
|
19
|
-
load(File.dirname(__FILE__) + "/schema.rb")
|
20
|
-
require File.dirname(__FILE__) + '/../rails/init'
|
21
|
-
end
|