mongodb_model 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,7 +40,11 @@ module Mongo::Model::Assignment
|
|
40
40
|
if mass_assignment or force
|
41
41
|
v = type.cast(v) if type
|
42
42
|
send "#{n}=", v
|
43
|
+
else
|
44
|
+
raise "mass assignment for :#{n} attribute not allowed!"
|
43
45
|
end
|
46
|
+
else
|
47
|
+
raise "mass assignment for :#{n} attribute not allowed!"
|
44
48
|
end
|
45
49
|
end
|
46
50
|
else
|
data/lib/mongo/model/model.rb
CHANGED
@@ -25,8 +25,8 @@ module Mongo::Model::Validation
|
|
25
25
|
add_validations(args, Mongo::Model::UniquenessValidator)
|
26
26
|
end
|
27
27
|
|
28
|
-
def validate validation
|
29
|
-
validations
|
28
|
+
def validate validation = nil, &block
|
29
|
+
validations.push block || validation
|
30
30
|
end
|
31
31
|
|
32
32
|
protected
|
data/spec/assignment_spec.rb
CHANGED
@@ -36,7 +36,8 @@ describe 'Model callbacks' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
u = User.new
|
39
|
-
u.set name: 'Alex', has_mail: '1', age: '31', position: [11, 34]
|
39
|
+
u.set name: 'Alex', has_mail: '1', age: '31', position: [11, 34]
|
40
|
+
-> {u.set name: 'Alex', banned: false}.should raise_error(/not allowed/)
|
40
41
|
[u.name, u.has_mail, u.age, u.position, u.banned].should == ['Alex', true, 31, [11, 34], nil]
|
41
42
|
|
42
43
|
# should allow to forcefully cast and update any attribute
|
@@ -67,7 +67,6 @@ describe "Attribute Convertors" do
|
|
67
67
|
|
68
68
|
# # protection
|
69
69
|
o.protected_tags = []
|
70
|
-
o.set protected_tags_as_string: 'Java, Ruby'
|
71
|
-
o.protected_tags.should == []
|
70
|
+
-> {o.set protected_tags_as_string: 'Java, Ruby'}.should raise_error(/not allowed/)
|
72
71
|
end
|
73
72
|
end
|