autocomplete_for 1.0.0 → 1.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
- SHA1:
3
- metadata.gz: 241fb40f402bc7ad2f4fe37998e0f14ae6fbf2e3
4
- data.tar.gz: 91cd4c2ce2217629c3d633bd4ec5ac551287f3be
2
+ SHA256:
3
+ metadata.gz: 0f2d8bc6a37381635eeb26a7b8a154136b9ff07e44c056e6ad191287f8971278
4
+ data.tar.gz: e9973f4862e0b067f4319437de7fb554dbb3465be0ad040865d09b7a155226cc
5
5
  SHA512:
6
- metadata.gz: 2db0d664093235bf45a1288e8ca86a69a61cf81957379ac8a2a8f332f930a24172f24821777fbea06f352ec1856dea74b077397e4b737f5c40d991dc558bb57e
7
- data.tar.gz: b6fd4d779346879ff4364da51ee8c81993e252b17f23041d2f43cc5cb9720df901ebe3993d3f45a1069d559eb695c70a35403c785cd13fc33ec690dd65079712
6
+ metadata.gz: c25f187dac5529ab52f8b7fb7901230c47a43597dc779b887b12eec274becd44d466c2a8b21362a80943a41a9f805a89eedc395bace1af49c05a18e5f3919e74
7
+ data.tar.gz: 7c06ef0adc93b3e34ecb98d18d3dc2eea4976a3d64669476239ebd9198cfd6f3204c1ffbb6c41f601053a6c78abec927ebd3c6b0af70976ec32a1b38f9a307a7
@@ -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
 
@@ -13,6 +16,7 @@ It works out-of-the-box with existing front-end autocompletion solutions because
13
16
 
14
17
  ### Example
15
18
 
19
+ ```ruby
16
20
  class Author < ActiveRecord::Base
17
21
  # has a login and open_id column
18
22
  end
@@ -30,21 +34,25 @@ It works out-of-the-box with existing front-end autocompletion solutions because
30
34
  self.author = Author.find(:first, :conditions => {:open_id => @author_open_id})
31
35
  end
32
36
  end
37
+ ```
33
38
 
34
39
  Using autocomplete_for in your models to set belongs_to associations:
35
40
 
41
+ ```ruby
36
42
  author = Author.create! :login => 'baz'
37
43
  post = Post.create! :author_login => 'baz' # automatically finds the author with the login 'baz'
38
44
  puts post.author.login # will output 'baz'
45
+ ```
39
46
 
40
47
  Errors are generated automatically if the given information does not correspond to a valid model:
41
48
 
49
+ ```ruby
42
50
  author = Author.create! :login => 'baz'
43
51
  post = Post.create :author_login => 'quux'
44
52
  puts post.errors[:author_login] # will print an error message
53
+ ```
45
54
 
46
55
  ### Running the tests
47
- You can run the unit tests using `bundle exec rake test`; it assumes you have a Postgres database
48
- configured as per `test/database.yml` (e.g. credentials are valid, database exists).
56
+ You can run the unit tests using `rake`
49
57
 
50
- Copyright (c) 2010 Nulogy Corporation, released under the MIT license
58
+ Copyright (c) 2019 Nulogy Corporation, released under the MIT license
@@ -1 +1,7 @@
1
- require 'autocomplete_for/autocomplete_for.rb'
1
+ # frozen_string_literal: true
2
+
3
+ require "autocomplete_for/autocomplete_for.rb"
4
+ require "autocomplete_for/version.rb"
5
+
6
+ module AutocompleteFor
7
+ end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AutocompleteFor
2
4
  def self.included(base)
3
- base.send :extend, ClassMethods
5
+ base.send(:extend, ClassMethods)
4
6
  end
5
7
 
6
8
  module ClassMethods
7
- def autocomplete_for association, field, options = {}, &block
9
+ def autocomplete_for(association, field, options = {}, &block)
8
10
  allow_nil = options[:allow_nil] || false
9
11
  validate :"validate_#{association}_by_#{field}"
10
12
  before_validation :"associate_#{association}_by_#{field}"
@@ -22,7 +24,7 @@ module AutocompleteFor
22
24
  # def customer_name
23
25
  # self.customer_to.name : @customer_name
24
26
  # end
25
- define_method(:"#{association}_#{field}") do
27
+ define_method(:"#{association}_#{field}") do
26
28
  send(association.to_sym) ? send(association.to_sym).send(field.to_sym) : instance_variable_get(:"@#{association}_#{field}")
27
29
  end
28
30
 
@@ -30,15 +32,16 @@ module AutocompleteFor
30
32
  # def validate_customer_by_name
31
33
  # return unless @customer_name
32
34
  # return if self.customer
33
- # return if @@customer_name_allow_nil && @customer_name == ""
35
+ # return if @@customer_name_allow_nil && @customer_name == ""
34
36
  #
35
- # self.errors.add :customer_name, "#{@customer_name} does not exist"
37
+ # self.errors.add :customer_name, "#{@customer_name} does not exist"
36
38
  # end
37
- define_method(:"validate_#{association}_by_#{field}") do
38
- return unless instance_variable_get(:"@#{association}_#{field}")
39
+ define_method(:"validate_#{association}_by_#{field}") do
40
+ return unless instance_variable_get(:"@#{association}_#{field}")
39
41
  return if send(association.to_sym)
40
42
  return if self.class.instance_variable_get(:"@#{association}_#{field}_allow_nil") && instance_variable_get(:"@#{association}_#{field}") == ""
41
- self.errors.add(:"#{association}_#{field}", :does_not_exist)
43
+
44
+ errors.add(:"#{association}_#{field}", :does_not_exist)
42
45
  end
43
46
 
44
47
  # Resolve the autocompleted name to an actual entity
@@ -61,12 +64,13 @@ module AutocompleteFor
61
64
  # end
62
65
  define_method(:"associate_#{association}_by_#{field}") do
63
66
  return unless instance_variable_get(:"@#{association}_#{field}")
64
- if instance_variable_get(:"@#{association}_#{field}") == ''
65
- self.send(:"#{association}=", nil)
67
+
68
+ if instance_variable_get(:"@#{association}_#{field}") == ""
69
+ send(:"#{association}=", nil)
66
70
  return
67
71
  end
68
72
 
69
- self.send(:"autocomplete_find_#{association}_by_#{field}")
73
+ send(:"autocomplete_find_#{association}_by_#{field}")
70
74
  end
71
75
 
72
76
  # set up validation on association in case the customer_name isn't set
@@ -76,20 +80,23 @@ module AutocompleteFor
76
80
 
77
81
  instance_variable_set(error_fields_name, error_fields)
78
82
 
79
- unless allow_nil
83
+ unless allow_nil
80
84
  # we must make sure that the validate_by_customer validation runs
81
85
  # after ALL validations on autocomplete fields
82
- #skip_callback :validate, :by, :"#{association}"
86
+ # skip_callback :validate, :by, :"#{association}"
83
87
 
84
88
  validate :"validate_by_#{association}"
85
89
 
86
90
  unless instance_methods.include?("validate_by_#{association}")
87
91
 
88
92
  # def validate_by_customer
89
- # self.errors.add_on_blank(:customer) unless @@customer_autocompolete_error_fields.any? {|ef| self.errors[ef]}
93
+ # self.errors.add_on_blank(:customer) unless @@customer_autocomplete_error_fields.any? {|ef| self.errors[ef]}
90
94
  # end
91
95
  define_method(:"validate_by_#{association}") do
92
- self.errors.add_on_blank(:"#{association}") unless self.class.instance_variable_get(error_fields_name).any? {|ef| self.errors[ef].any? }
96
+ return if self.class.instance_variable_get(error_fields_name).any? { |ef| errors[ef].any? }
97
+ return unless send(:read_attribute_for_validation, association.to_sym).blank?
98
+
99
+ errors.add(association.to_sym, :blank, options)
93
100
  end
94
101
  end
95
102
  end
@@ -97,4 +104,4 @@ module AutocompleteFor
97
104
  end
98
105
  end
99
106
 
100
- ActiveRecord::Base.send :include, AutocompleteFor
107
+ ActiveRecord::Base.send(:include, AutocompleteFor)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AutocompleteFor
4
+ VERSION = "1.1"
5
+ end
metadata CHANGED
@@ -1,80 +1,146 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autocomplete_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kirby
8
+ - Alistair McKinnell
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2011-10-26 00:00:00.000000000 Z
12
+ date: 2020-11-05 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: pg
15
+ name: activerecord
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
20
+ version: '5.1'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '6.1'
24
+ type: :runtime
21
25
  prerelease: false
22
26
  version_requirements: !ruby/object:Gem::Requirement
23
27
  requirements:
24
28
  - - ">="
25
29
  - !ruby/object:Gem::Version
26
- version: '0'
30
+ version: '5.1'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '6.1'
27
34
  - !ruby/object:Gem::Dependency
28
- name: rake
35
+ name: appraisal
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rails
29
50
  requirement: !ruby/object:Gem::Requirement
30
51
  requirements:
31
52
  - - ">="
32
53
  - !ruby/object:Gem::Version
33
- version: '0'
54
+ version: '5.1'
55
+ - - "<"
56
+ - !ruby/object:Gem::Version
57
+ version: '6.0'
34
58
  type: :development
35
59
  prerelease: false
36
60
  version_requirements: !ruby/object:Gem::Requirement
37
61
  requirements:
38
62
  - - ">="
39
63
  - !ruby/object:Gem::Version
40
- version: '0'
64
+ version: '5.1'
65
+ - - "<"
66
+ - !ruby/object:Gem::Version
67
+ version: '6.0'
41
68
  - !ruby/object:Gem::Dependency
42
- name: activerecord
69
+ name: rake
43
70
  requirement: !ruby/object:Gem::Requirement
44
71
  requirements:
45
72
  - - "~>"
46
73
  - !ruby/object:Gem::Version
47
- version: '5.0'
48
- type: :runtime
74
+ version: '13.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '13.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec-rails
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '4.0'
89
+ type: :development
49
90
  prerelease: false
50
91
  version_requirements: !ruby/object:Gem::Requirement
51
92
  requirements:
52
93
  - - "~>"
53
94
  - !ruby/object:Gem::Version
54
- version: '5.0'
95
+ version: '4.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rubocop
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.2'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.2'
110
+ - !ruby/object:Gem::Dependency
111
+ name: sqlite3
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.3'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.3'
55
124
  description: Model-side logic for autocompleting belongs_to associations
56
- email: sskirby@gmail.com
125
+ email: skirby@gmail.com
57
126
  executables: []
58
127
  extensions: []
59
- extra_rdoc_files:
60
- - README.markdown
128
+ extra_rdoc_files: []
61
129
  files:
62
- - Gemfile
63
- - Gemfile.lock
64
130
  - MIT-LICENSE
65
131
  - README.markdown
66
- - Rakefile
67
- - autocomplete_for.gemspec
68
132
  - lib/autocomplete_for.rb
69
133
  - 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
- homepage: http://github.com/nulogy/autocomplete_for
76
- licenses: []
77
- metadata: {}
134
+ - lib/autocomplete_for/version.rb
135
+ homepage: https://github.com/nulogy/autocomplete_for
136
+ licenses:
137
+ - MIT
138
+ - GPL-3.0
139
+ metadata:
140
+ homepage_uri: https://github.com/nulogy/autocomplete_for
141
+ changelog_uri: https://github.com/nulogy/autocomplete_for/blob/master/CHANGELOG.md
142
+ source_code_uri: https://github.com/nulogy/autocomplete_for
143
+ bug_tracker_uri: https://github.com/nulogy/autocomplete_for/issues
78
144
  post_install_message:
79
145
  rdoc_options: []
80
146
  require_paths:
@@ -83,16 +149,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
149
  requirements:
84
150
  - - ">="
85
151
  - !ruby/object:Gem::Version
86
- version: '0'
152
+ version: '2.6'
87
153
  required_rubygems_version: !ruby/object:Gem::Requirement
88
154
  requirements:
89
155
  - - ">="
90
156
  - !ruby/object:Gem::Version
91
157
  version: '0'
92
158
  requirements: []
93
- rubyforge_project: autocomplete_for
94
- rubygems_version: 2.6.14
159
+ rubygems_version: 3.1.4
95
160
  signing_key:
96
- specification_version: 3
97
- summary: Model-side logic for autocompleting belongs_to associations
161
+ specification_version: 4
162
+ summary: Autocomplete for models
98
163
  test_files: []
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :gemcutter
2
-
3
- gemspec
@@ -1,41 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- autocomplete_for (1.0.0)
5
- activerecord (~> 5.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (5.2.0)
11
- activesupport (= 5.2.0)
12
- activerecord (5.2.0)
13
- activemodel (= 5.2.0)
14
- activesupport (= 5.2.0)
15
- arel (>= 9.0)
16
- activesupport (5.2.0)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- arel (9.0.0)
22
- concurrent-ruby (1.0.5)
23
- i18n (1.0.1)
24
- concurrent-ruby (~> 1.0)
25
- minitest (5.11.3)
26
- pg (1.0.0)
27
- rake (12.3.1)
28
- thread_safe (0.3.6)
29
- tzinfo (1.2.5)
30
- thread_safe (~> 0.1)
31
-
32
- PLATFORMS
33
- ruby
34
-
35
- DEPENDENCIES
36
- autocomplete_for!
37
- pg
38
- rake
39
-
40
- BUNDLED WITH
41
- 1.16.2
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rdoc/task'
4
- require 'bundler'
5
- Bundler::GemHelper.install_tasks
6
-
7
- desc 'Default: run unit tests.'
8
- task :default => :test
9
-
10
- desc 'Test the autocomplete_for plugin.'
11
- Rake::TestTask.new(:test) do |t|
12
- t.libs << 'lib'
13
- t.libs << 'test'
14
- t.pattern = 'test/**/*_test.rb'
15
- t.verbose = true
16
- end
17
-
18
- desc 'Generate documentation for the autocomplete_for plugin.'
19
- Rake::RDocTask.new(:rdoc) do |rdoc|
20
- rdoc.rdoc_dir = 'rdoc'
21
- rdoc.title = 'AutocompleteFor'
22
- rdoc.options << '--line-numbers' << '--inline-source'
23
- rdoc.rdoc_files.include('README.markdown')
24
- rdoc.rdoc_files.include('lib/**/*.rb')
25
- end
@@ -1,57 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "autocomplete_for"
8
- s.version = "1.0.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Sean Kirby"]
12
- s.date = "2011-10-26"
13
- s.description = "Model-side logic for autocompleting belongs_to associations"
14
- s.email = "sskirby@gmail.com"
15
- s.extra_rdoc_files = [
16
- "README.markdown"
17
- ]
18
- s.files = [
19
- "Gemfile",
20
- "Gemfile.lock",
21
- "MIT-LICENSE",
22
- "README.markdown",
23
- "Rakefile",
24
- "autocomplete_for.gemspec",
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"
32
- ]
33
- s.homepage = "http://github.com/nulogy/autocomplete_for"
34
- s.require_paths = ["lib"]
35
- s.rubyforge_project = "autocomplete_for"
36
- s.rubygems_version = "1.8.10"
37
- s.summary = "Model-side logic for autocompleting belongs_to associations"
38
-
39
- if s.respond_to? :specification_version then
40
- s.specification_version = 3
41
-
42
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
- s.add_development_dependency(%q<pg>, [">= 0"])
44
- s.add_development_dependency(%q<rake>, [">= 0"])
45
- s.add_runtime_dependency(%q<activerecord>, ["~> 5.0"])
46
- else
47
- s.add_dependency(%q<pg>, [">= 0"])
48
- s.add_dependency(%q<rake>, [">= 0"])
49
- s.add_dependency(%q<activerecord>, ["~> 5.0"])
50
- end
51
- else
52
- s.add_dependency(%q<pg>, [">= 0"])
53
- s.add_dependency(%q<rake>, [">= 0"])
54
- s.add_dependency(%q<activerecord>, ["~> 5.0"])
55
- end
56
- end
57
-
@@ -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
@@ -1,6 +0,0 @@
1
- postgresql:
2
- adapter: postgresql
3
- database: autocomplete_for_plugin_test
4
- username: test
5
- password: pass
6
- host: localhost
@@ -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
@@ -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