active_node 2.3.5 → 2.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/active_node/validations.rb +12 -0
- data/lib/active_node/version.rb +1 -1
- data/spec/functional/validations_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b884b5d0dd3dad07e649785c7f93ebc1ddf306b6
|
4
|
+
data.tar.gz: 59b3577cb8953aa800694f5c29db1e4f15800dcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a8cb52eb6fc1dcde0ebad7bd241e9d77e14551d76fa034c3e5be6d8f8891e256dd1df34f27a7850552c2dc51e39c27f342da8a58bdfc928f11423fed27f9071
|
7
|
+
data.tar.gz: 6e5a9e4e2550236549f1d1620551b70d981cc55decfe56bb9d2a4e75825ef6032f04899129df18c95f503de816b06a6ede216c897063d25b4a50c875b13cfd98
|
data/.travis.yml
CHANGED
@@ -34,6 +34,18 @@ module ActiveNode
|
|
34
34
|
autoload :UniquenessValidator, 'active_node/validations/uniqueness'
|
35
35
|
|
36
36
|
module ClassMethods
|
37
|
+
# Initializes and saves an object in a single step.
|
38
|
+
def create(attributes = nil, &block)
|
39
|
+
if attributes.is_a?(Array)
|
40
|
+
attributes.collect { |attr| create(attr, &block) }
|
41
|
+
else
|
42
|
+
object = new(attributes)
|
43
|
+
yield(object) if block_given?
|
44
|
+
object.save
|
45
|
+
object
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
37
49
|
# Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
|
38
50
|
# so an exception is raised if the record is invalid.
|
39
51
|
def create!(attributes = nil, &block)
|
data/lib/active_node/version.rb
CHANGED
@@ -27,4 +27,19 @@ describe ActiveNode::Validations do
|
|
27
27
|
expect(House.find(house.id)).to be_valid
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
describe "#create" do
|
32
|
+
it "should not create invalid object" do
|
33
|
+
expect(Client.create).not_to be_persisted
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should create valid object" do
|
37
|
+
expect(Client.create(name: 'abc7')).to be_persisted
|
38
|
+
expect(Client.all.first.name).to eq('abc7')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create an instance of the model class" do
|
42
|
+
expect(Client.create(name: 'abc7')).to be_a(Client)
|
43
|
+
end
|
44
|
+
end
|
30
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_node
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heinrich Klobuczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|