activeform-rails 0.0.3 → 0.0.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da4b299980d8dad8dec13b65e08b063881df0aee
|
4
|
+
data.tar.gz: d693b3722f7606d402c47ff4ab7ebfaff78c1a27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16ce180dccfd8380f8eb0062b25ed77afa05d27e0e60f9e8b9521e3bb3272f45c37dcae16849e5210fdd9a4c4756ce911b9f29b183ce9c44f57f63e9ebba14e5
|
7
|
+
data.tar.gz: afd9533b79686c341c4860e1e5e22d02e5cfb7aa185d2961cb25e0488625126eefd19188e16a39607c1ae2751b4506f8d7ffbae32b1199f99f2469fcfccef5a8
|
data/lib/activeform-rails.rb
CHANGED
@@ -8,13 +8,12 @@ module ActiveForm
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
def validates_uniqueness_of(attribute, model_name, options = {})
|
11
|
-
@attribute = attribute
|
12
11
|
validates_each attribute, options do |form, attr, value|
|
13
12
|
@form = form
|
14
13
|
@model = form.send(model_name)
|
15
14
|
@klass = @model.class
|
16
15
|
@hash = { attribute => value }
|
17
|
-
add_error_message if another_model?
|
16
|
+
add_error_message(attribute) if another_model?
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -36,8 +35,8 @@ module ActiveForm
|
|
36
35
|
I18n.t('activerecord.errors.messages.exclusion')
|
37
36
|
end
|
38
37
|
|
39
|
-
def add_error_message
|
40
|
-
@form.errors.add(
|
38
|
+
def add_error_message(attribute)
|
39
|
+
@form.errors.add(attribute, error_message)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
@@ -4,8 +4,9 @@ describe ActiveForm::ValidateUniqueness do
|
|
4
4
|
class ValidateUniquenessForm
|
5
5
|
include ActiveForm::Form
|
6
6
|
include ActiveForm::ValidateUniqueness
|
7
|
-
properties :name, on: :user
|
7
|
+
properties :name, :firstname, on: :user
|
8
8
|
validates_uniqueness_of :name, :user, allow_nil: true
|
9
|
+
validates_uniqueness_of :firstname, :user, allow_nil: true
|
9
10
|
end
|
10
11
|
|
11
12
|
context "when there is no user" do
|
@@ -17,7 +18,7 @@ describe ActiveForm::ValidateUniqueness do
|
|
17
18
|
end
|
18
19
|
|
19
20
|
context "when there is user with the same email" do
|
20
|
-
context "when the user
|
21
|
+
context "when the user has an available name" do
|
21
22
|
it "is valid" do
|
22
23
|
user = User.create(name: 'name')
|
23
24
|
form = ValidateUniquenessForm.new(user: user)
|
@@ -25,13 +26,21 @@ describe ActiveForm::ValidateUniqueness do
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
context "when the user
|
29
|
+
context "when the user has unavailable name" do
|
29
30
|
it "is not valid" do
|
30
31
|
User.create(name: 'name')
|
31
32
|
user = User.new(name: 'name')
|
32
33
|
form = ValidateUniquenessForm.new(user: user)
|
33
34
|
expect(form).to_not be_valid
|
34
35
|
end
|
36
|
+
|
37
|
+
it "assign an error to the name" do
|
38
|
+
User.create(name: 'name')
|
39
|
+
user = User.new(name: 'name')
|
40
|
+
form = ValidateUniquenessForm.new(user: user)
|
41
|
+
form.valid?
|
42
|
+
expect(form.errors[:name]).to_not be_empty
|
43
|
+
end
|
35
44
|
end
|
36
45
|
end
|
37
46
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,7 @@ ActiveRecord::Base.establish_connection(
|
|
8
8
|
)
|
9
9
|
|
10
10
|
['CREATE TABLE categories(id INTEGER PRIMARY KEY, title, user_id)',
|
11
|
-
'CREATE TABLE users(id INTEGER PRIMARY KEY, name)'].each do |sql|
|
11
|
+
'CREATE TABLE users(id INTEGER PRIMARY KEY, name, firstname)'].each do |sql|
|
12
12
|
ActiveRecord::Base.connection.execute sql
|
13
13
|
end
|
14
14
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeform-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guirec Corbel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|