validates_existence 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rails3.rb CHANGED
@@ -42,7 +42,7 @@ module Perfectline
42
42
  errors.push(attribute.to_s.ends_with?("_id") ? normalized : association.primary_key_name)
43
43
  end
44
44
  errors.each do |error|
45
- record.errors.add(error, options[:message], :defaults => "does not exist")
45
+ record.errors.add(error, options[:message], :message => "does not exist")
46
46
  end
47
47
  end
48
48
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_existence
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
4
+ prerelease:
5
+ version: 0.6.2
10
6
  platform: ruby
11
7
  authors:
12
8
  - Tanel Suurhans
@@ -15,8 +11,7 @@ autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
13
 
18
- date: 2011-04-15 00:00:00 +03:00
19
- default_executable:
14
+ date: 2011-05-02 00:00:00 Z
20
15
  dependencies: []
21
16
 
22
17
  description: A library for validating model association existence.
@@ -36,27 +31,6 @@ files:
36
31
  - lib/rails3.rb
37
32
  - lib/validates_existence.rb
38
33
  - rails/init.rb
39
- - test/rails2/models/name.rb
40
- - test/rails2/models/user.rb
41
- - test/rails2/models/user_with_allow_nil.rb
42
- - test/rails2/models/user_with_both.rb
43
- - test/rails2/models/user_with_fk.rb
44
- - test/rails2/models/user_with_has_many.rb
45
- - test/rails2/models/user_with_poly.rb
46
- - test/rails2/models/user_with_poly_allow_nil.rb
47
- - test/rails2/test_helper.rb
48
- - test/rails2/validates_existence_test.rb
49
- - test/rails3/models/name.rb
50
- - test/rails3/models/user.rb
51
- - test/rails3/models/user_with_allow_nil.rb
52
- - test/rails3/models/user_with_both.rb
53
- - test/rails3/models/user_with_fk.rb
54
- - test/rails3/models/user_with_has_many.rb
55
- - test/rails3/models/user_with_poly.rb
56
- - test/rails3/models/user_with_poly_allow_nil.rb
57
- - test/rails3/test_helper.rb
58
- - test/rails3/validates_existence_test.rb
59
- has_rdoc: true
60
34
  homepage: http://github.com/perfectline/validates_existence/tree/master
61
35
  licenses: []
62
36
 
@@ -70,42 +44,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
44
  requirements:
71
45
  - - ">="
72
46
  - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
47
  version: "0"
76
48
  required_rubygems_version: !ruby/object:Gem::Requirement
77
49
  none: false
78
50
  requirements:
79
51
  - - ">="
80
52
  - !ruby/object:Gem::Version
81
- segments:
82
- - 0
83
53
  version: "0"
84
54
  requirements: []
85
55
 
86
56
  rubyforge_project:
87
- rubygems_version: 1.3.7
57
+ rubygems_version: 1.7.2
88
58
  signing_key:
89
59
  specification_version: 3
90
60
  summary: Validates Rails model belongs_to association existence.
91
- test_files:
92
- - test/rails2/models/name.rb
93
- - test/rails2/models/user.rb
94
- - test/rails2/models/user_with_allow_nil.rb
95
- - test/rails2/models/user_with_both.rb
96
- - test/rails2/models/user_with_fk.rb
97
- - test/rails2/models/user_with_has_many.rb
98
- - test/rails2/models/user_with_poly.rb
99
- - test/rails2/models/user_with_poly_allow_nil.rb
100
- - test/rails2/test_helper.rb
101
- - test/rails2/validates_existence_test.rb
102
- - test/rails3/models/name.rb
103
- - test/rails3/models/user.rb
104
- - test/rails3/models/user_with_allow_nil.rb
105
- - test/rails3/models/user_with_both.rb
106
- - test/rails3/models/user_with_fk.rb
107
- - test/rails3/models/user_with_has_many.rb
108
- - test/rails3/models/user_with_poly.rb
109
- - test/rails3/models/user_with_poly_allow_nil.rb
110
- - test/rails3/test_helper.rb
111
- - test/rails3/validates_existence_test.rb
61
+ test_files: []
62
+
@@ -1,3 +0,0 @@
1
- class Name < ActiveRecord::Base
2
-
3
- end
@@ -1,7 +0,0 @@
1
- class User < ActiveRecord::Base
2
-
3
- belongs_to :name
4
-
5
- validates_existence_of :name
6
-
7
- end
@@ -1,9 +0,0 @@
1
- class UserWithAllowNil < ActiveRecord::Base
2
-
3
- self.table_name = "users"
4
-
5
- belongs_to :name
6
-
7
- validates_existence_of :name, :allow_nil => true
8
-
9
- end
@@ -1,7 +0,0 @@
1
- class UserWithBoth < ActiveRecord::Base
2
- self.table_name = "users"
3
-
4
- belongs_to :name
5
-
6
- validates_existence_of :name, :both => false
7
- end
@@ -1,9 +0,0 @@
1
- class UserWithFk < ActiveRecord::Base
2
-
3
- self.table_name = "users2"
4
-
5
- belongs_to :name, :foreign_key => :custom_id
6
-
7
- validates_existence_of :name
8
-
9
- end
@@ -1,7 +0,0 @@
1
- class UserWithHasMany < ActiveRecord::Base
2
- self.table_name = "users"
3
-
4
- has_many :names
5
-
6
- validates_existence_of :names
7
- end
@@ -1,9 +0,0 @@
1
- class UserWithPoly < ActiveRecord::Base
2
-
3
- self.table_name = "users"
4
-
5
- belongs_to :relation, :polymorphic => true
6
-
7
- validates_existence_of :relation
8
-
9
- end
@@ -1,9 +0,0 @@
1
- class UserWithPolyAllowNil < ActiveRecord::Base
2
-
3
- self.table_name = "users"
4
-
5
- belongs_to :relation, :polymorphic => true
6
-
7
- validates_existence_of :relation, :allow_nil => true
8
-
9
- end
@@ -1,27 +0,0 @@
1
- require 'rubygems'
2
-
3
- gem 'rails', '2.3.8'
4
-
5
- require 'sqlite3'
6
- require 'test/unit'
7
- require 'active_record'
8
- require 'active_record/base'
9
-
10
- ActiveRecord::Migration.verbose = false
11
- ActiveRecord::Base.establish_connection(
12
- "adapter" => "sqlite3",
13
- "database" => ":memory:"
14
- )
15
-
16
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'rails2.rb')
17
-
18
- ActiveRecord::Base.send(:extend, Perfectline::ValidatesExistence::Rails2)
19
-
20
- autoload :Name, File.join(File.dirname(__FILE__), 'models', 'name.rb')
21
- autoload :User, File.join(File.dirname(__FILE__), 'models', 'user.rb')
22
- autoload :UserWithAllowNil, File.join(File.dirname(__FILE__), 'models', 'user_with_allow_nil.rb')
23
- autoload :UserWithPoly, File.join(File.dirname(__FILE__), 'models', 'user_with_poly.rb')
24
- autoload :UserWithPolyAllowNil, File.join(File.dirname(__FILE__), 'models', 'user_with_poly_allow_nil.rb')
25
- autoload :UserWithHasMany, File.join(File.dirname(__FILE__), 'models', 'user_with_has_many.rb')
26
- autoload :UserWithBoth, File.join(File.dirname(__FILE__), 'models', 'user_with_both.rb')
27
- autoload :UserWithFk, File.join(File.dirname(__FILE__), 'models', 'user_with_fk.rb')
@@ -1,96 +0,0 @@
1
- require 'test_helper.rb'
2
-
3
- class TestValidatesExistence < Test::Unit::TestCase
4
-
5
- def setup
6
- ActiveRecord::Schema.define(:version => 1) do
7
-
8
- create_table :names, :force => true do |t|
9
- t.column :name, :string
10
- end
11
-
12
- create_table :users, :force => true do |t|
13
- t.references :name
14
- t.references :relation, :polymorphic => true
15
- end
16
-
17
- create_table :users2, :force => true do |t|
18
- t.column :custom_id, :integer
19
- end
20
-
21
- end
22
- end
23
-
24
- def teardown
25
- ActiveRecord::Base.connection.drop_table(:users)
26
- ActiveRecord::Base.connection.drop_table(:names)
27
- end
28
-
29
- def test_save_with_no_relation
30
- user = User.new
31
- assert_equal user.save, false
32
- assert_not_nil user.errors.on(:name)
33
- assert_not_nil user.errors.on(:name_id)
34
- end
35
-
36
- def test_save_with_relation
37
- name = Name.create(:name => "foo")
38
- assert_equal User.new(:name => name).save, true
39
- end
40
-
41
- def test_save_with_bogus_id
42
- assert_equal User.new(:name_id => 100).save, false
43
- end
44
-
45
- def test_allow_nil
46
- assert_equal UserWithAllowNil.new.save, true
47
- end
48
-
49
- def test_poly_relation
50
- assert_equal UserWithPoly.new.save, false
51
- end
52
-
53
- def test_poly_relation_with_name
54
- name = Name.create(:name => "bar")
55
- assert_equal UserWithPoly.new(:relation => name).save, true
56
- end
57
-
58
- def test_poly_relation_with_allow_nil
59
- assert_equal UserWithPolyAllowNil.new.save, true
60
- end
61
-
62
- def test_argument_error
63
- assert_raise ArgumentError do
64
- UserWithHasMany.new.save
65
- end
66
- end
67
-
68
- def test_errors_on_one_field
69
- user = UserWithBoth.new
70
- user.save
71
-
72
- assert_not_nil user.errors.on(:name)
73
- assert_nil user.errors.on(:name_id)
74
- end
75
-
76
- def test_save_with_new_record
77
- name = Name.create(:name => "foobar")
78
- user = User.create(:name => name)
79
-
80
- user.name = Name.new
81
- user.save
82
-
83
- assert_not_nil user.errors.on(:name)
84
- end
85
-
86
- def test_save_with_custom_fk
87
- user = UserWithFk.new
88
- user.save
89
-
90
- assert_not_nil user.errors.on(:name)
91
- assert_not_nil user.errors.on(:custom_id)
92
- end
93
-
94
- end
95
-
96
-
@@ -1,3 +0,0 @@
1
- class Name < ActiveRecord::Base
2
-
3
- end
@@ -1,7 +0,0 @@
1
- class User < ActiveRecord::Base
2
-
3
- belongs_to :name
4
-
5
- validates :name, :existence => true
6
-
7
- end
@@ -1,9 +0,0 @@
1
- class UserWithAllowNil < ActiveRecord::Base
2
-
3
- self.table_name = "users"
4
-
5
- belongs_to :name
6
-
7
- validates :name, :existence => true, :allow_nil => true
8
-
9
- end
@@ -1,7 +0,0 @@
1
- class UserWithBoth < ActiveRecord::Base
2
- self.table_name = "users"
3
-
4
- belongs_to :name
5
-
6
- validates :name, :existence => {:both => false}
7
- end
@@ -1,9 +0,0 @@
1
- class UserWithFk < ActiveRecord::Base
2
-
3
- self.table_name = "users2"
4
-
5
- belongs_to :name, :foreign_key => :custom_id
6
-
7
- validates :name, :existence => true
8
-
9
- end
@@ -1,7 +0,0 @@
1
- class UserWithHasMany < ActiveRecord::Base
2
- self.table_name = "users"
3
-
4
- has_many :names
5
-
6
- validates :names, :existence => true
7
- end
@@ -1,9 +0,0 @@
1
- class UserWithPoly < ActiveRecord::Base
2
-
3
- self.table_name = "users"
4
-
5
- belongs_to :relation, :polymorphic => true
6
-
7
- validates :relation, :existence => true
8
-
9
- end
@@ -1,9 +0,0 @@
1
- class UserWithPolyAllowNil < ActiveRecord::Base
2
-
3
- self.table_name = "users"
4
-
5
- belongs_to :relation, :polymorphic => true
6
-
7
- validates :relation, :existence => true, :allow_nil => true
8
-
9
- end
@@ -1,27 +0,0 @@
1
- require 'rubygems'
2
-
3
- gem 'rails', '3.0.5'
4
-
5
- require 'sqlite3'
6
- require 'test/unit'
7
- require 'active_record'
8
- require 'active_record/base'
9
-
10
- ActiveRecord::Migration.verbose = false
11
- ActiveRecord::Base.establish_connection(
12
- "adapter" => "sqlite3",
13
- "database" => ":memory:"
14
- )
15
-
16
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'rails3.rb')
17
-
18
- ActiveRecord::Base.send(:include, Perfectline::ValidatesExistence::Rails3)
19
-
20
- autoload :Name, File.join(File.dirname(__FILE__), 'models', 'name.rb')
21
- autoload :User, File.join(File.dirname(__FILE__), 'models', 'user.rb')
22
- autoload :UserWithAllowNil, File.join(File.dirname(__FILE__), 'models', 'user_with_allow_nil.rb')
23
- autoload :UserWithPoly, File.join(File.dirname(__FILE__), 'models', 'user_with_poly.rb')
24
- autoload :UserWithPolyAllowNil, File.join(File.dirname(__FILE__), 'models', 'user_with_poly_allow_nil.rb')
25
- autoload :UserWithHasMany, File.join(File.dirname(__FILE__), 'models', 'user_with_has_many.rb')
26
- autoload :UserWithBoth, File.join(File.dirname(__FILE__), 'models', 'user_with_both.rb')
27
- autoload :UserWithFk, File.join(File.dirname(__FILE__), 'models', 'user_with_fk.rb')
@@ -1,96 +0,0 @@
1
- require 'test_helper.rb'
2
-
3
- class TestValidatesExistence < Test::Unit::TestCase
4
-
5
- def setup
6
- ActiveRecord::Schema.define(:version => 1) do
7
-
8
- create_table :names, :force => true do |t|
9
- t.column :name, :string
10
- end
11
-
12
- create_table :users, :force => true do |t|
13
- t.references :name
14
- t.references :relation, :polymorphic => true
15
- end
16
-
17
- create_table :users2, :force => true do |t|
18
- t.column :custom_id, :integer
19
- end
20
-
21
- end
22
- end
23
-
24
- def teardown
25
- ActiveRecord::Base.connection.drop_table(:users)
26
- ActiveRecord::Base.connection.drop_table(:names)
27
- end
28
-
29
- def test_save_with_no_relation
30
- user = User.new
31
- assert_equal user.save, false
32
- assert_not_nil user.errors[:name]
33
- assert_not_nil user.errors[:name_id]
34
- end
35
-
36
- def test_save_with_relation
37
- name = Name.create(:name => "foo")
38
- assert_equal User.new(:name => name).save, true
39
- end
40
-
41
- def test_save_with_bogus_id
42
- assert_equal User.new(:name_id => 100).save, false
43
- end
44
-
45
- def test_allow_nil
46
- assert_equal UserWithAllowNil.new.save, true
47
- end
48
-
49
- def test_poly_relation
50
- assert_equal UserWithPoly.new.save, false
51
- end
52
-
53
- def test_poly_relation_with_name
54
- name = Name.create(:name => "bar")
55
- assert_equal UserWithPoly.new(:relation => name).save, true
56
- end
57
-
58
- def test_poly_relation_with_allow_nil
59
- assert_equal UserWithPolyAllowNil.new.save, true
60
- end
61
-
62
- def test_argument_error
63
- assert_raise ArgumentError do
64
- UserWithHasMany.new.save
65
- end
66
- end
67
-
68
- def test_errors_on_one_field
69
- user = UserWithBoth.new
70
- user.save
71
-
72
- assert_not_nil user.errors[:name]
73
- assert_empty user.errors[:name_id]
74
- end
75
-
76
- def test_save_with_new_record
77
- name = Name.create(:name => "foobar")
78
- user = User.create(:name => name)
79
-
80
- user.name = Name.new
81
- user.save
82
-
83
- assert_not_nil user.errors[:name]
84
- end
85
-
86
- def test_save_with_custom_fk
87
- user = UserWithFk.new
88
- user.save
89
-
90
- assert_not_nil user.errors[:name]
91
- assert_not_nil user.errors[:custom_id]
92
- end
93
-
94
- end
95
-
96
-